aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-26 17:23:14 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-26 17:23:14 +0100
commit7dbd418af7760187863af0bcbef5e80c4a2ec95b (patch)
treee2cef267bee52b77b75d77b81d2165943be4e918 /FICS
parent98621395d7a48504c4cbe79581b81048903ee6e7 (diff)
Reformatted CheckFormula()
Diffstat (limited to 'FICS')
-rw-r--r--FICS/formula.c89
1 files changed, 51 insertions, 38 deletions
diff --git a/FICS/formula.c b/FICS/formula.c
index 4839f0f..24aa923 100644
--- a/FICS/formula.c
+++ b/FICS/formula.c
@@ -398,46 +398,59 @@ int ScanForNumber (game *g, int clause, int *i, int op_type,
}
} /* end of function ScanForNumber. */
-/* If eval is 1, CheckFormula looks for the next token in the
- formula given by *g, clause, and *i; usually this is the right
- side of an expression whose operator has precedence OpType; if
- eval is 0, just go to the end of an expression. Return 0 if no
- error; otherwise, return error type.
-*/
-int CheckFormula (game *g, int clause, int *i, int op_type,
- int *result, int eval)
+/*
+ * If 'eval' is 1, CheckFormula() looks for the next token in the
+ * formula given by 'g', 'clause' and 'i'. Usually this is the right
+ * side of an expression whose operator has precedence OpType(). If
+ * 'eval' is 0, just go to the end of an expression.
+ */
+int
+CheckFormula(game *g, int clause, int *i, int op_type, int *result, int eval)
{
- int token, ret, nextOp, lastPos;
- char *string = GetPlayersFormula (&parray[g->black], clause);
+ char *string = GetPlayersFormula(&parray[g->black], clause);
+ int token, ret, nextOp, lastPos;
- if (string == NULL)
- {
- *result = 1;
- return (ERR_NONE);
- }
- ret = ScanForNumber (g, clause, i, op_type, &token, eval);
- if (ret != ERR_NONE)
- return (ret);
- lastPos = *i;
- nextOp = ScanForOp (string, i);
- while (OpType(nextOp) > op_type) /* higher precedence. */
- {
- if (nextOp==OP_RTPAREN) return (ERR_PAREN);
- if (!eval)
- ret = CheckFormula(g, clause, i, OpType(nextOp), &token, 0);
- else ret = EvalBinaryOp (&token, nextOp, g, clause, i);
- if (ret != ERR_NONE) return (ret);
- lastPos = *i;
- nextOp = ScanForOp (string, i);
- }
- if (nextOp == OP_BAD) return(ERR_BADOP);
- *result = token;
-
- /* move back unless we're at the end or at a right paren, in which
- case we never went forward. */
- if (nextOp != OP_NONE && nextOp != OP_RTPAREN) *i=lastPos;
- return (ERR_NONE);
-} /* end of function CheckFormula. */
+ if (string == NULL) {
+ *result = 1;
+ return ERR_NONE;
+ }
+
+ ret = ScanForNumber(g, clause, i, op_type, &token, eval);
+
+ if (ret != ERR_NONE)
+ return ret;
+
+ lastPos = *i;
+ nextOp = ScanForOp(string, i);
+
+ while (OpType(nextOp) > op_type) { /* Higher precedence. */
+ if (nextOp == OP_RTPAREN)
+ return ERR_PAREN;
+ if (!eval) {
+ ret = CheckFormula(g, clause, i, OpType(nextOp),
+ &token, 0);
+ } else {
+ ret = EvalBinaryOp(&token, nextOp, g, clause,
+ i);
+ }
+
+ if (ret != ERR_NONE)
+ return ret;
+ lastPos = *i;
+ nextOp = ScanForOp(string, i);
+ }
+
+ if (nextOp == OP_BAD)
+ return ERR_BADOP;
+ *result = token;
+ /*
+ * Move back unless we're at the end or at a right paren, in
+ * which case we never went forward.
+ */
+ if (nextOp != OP_NONE && nextOp != OP_RTPAREN)
+ *i = lastPos;
+ return ERR_NONE;
+}
/*
* Which clauses are relevant for a player's formula.