aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/formula.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-26 19:00:03 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-26 19:00:03 +0100
commitc1815820f8c2341f7b8d3c9a535eb28b7ccc248d (patch)
tree19d2c8613d4dcd383d55dc63e6e8db4e6c05f677 /FICS/formula.c
parent16c26be10d1bd21d3088395e2f847c54878fb4c5 (diff)
Reformatted ScanForNumber()
Diffstat (limited to 'FICS/formula.c')
-rw-r--r--FICS/formula.c133
1 files changed, 72 insertions, 61 deletions
diff --git a/FICS/formula.c b/FICS/formula.c
index 24aa923..15dff2e 100644
--- a/FICS/formula.c
+++ b/FICS/formula.c
@@ -335,68 +335,79 @@ FUDGE_FACTOR);
}
} /* end of function EvalBinaryOp. */
-/* If eval is 1, ScanForNumber evaluates the number at position *i
- in the formula given by *g and clause, and place this value in
- *token. op_type is the precedence of the operator preceding the
- *i'th position. If we come to an operator of higher precedence,
- we must keep going before we can leave this function. If eval
- is 0, just move past the number we would evaluate. Returns 0 if
- no error; otherwise return code indicates the error.
-*/
-int ScanForNumber (game *g, int clause, int *i, int op_type,
- int *token, int eval)
+/*
+ * If 'eval' is 1, ScanForNumber() evaluates the number at position
+ * 'i' in the formula given by 'g' and 'clause', and places this value
+ * in 'token'. 'op_type' is the precedence of the operator preceding
+ * the i'th position. If we come to an operator of higher precedence
+ * we must keep going before we can leave this function. If 'eval' is
+ * 0, just move past the number we would evaluate. This function
+ * returns 0 on no error. Otherwise an error code is returned.
+ */
+int
+ScanForNumber(game *g, int clause, int *i, int op_type, int *token, int eval)
{
- char *string = GetPlayersFormula (&parray[g->black], clause);
- char c;
- int ret;
-
- while ((string[*i] != '\0') && (isspace(string[*i]))) (*i)++;
- switch (c = string[*i])
- {
- case '\0': case '#':
- if (op_type != OPTYPE_NONE) return (ERR_EOF);
- else *token=1;
- return (ERR_NONE);
-
- case ')':
- if (op_type != OPTYPE_PAREN) return (ERR_PAREN);
- else *token=1;
- return(ERR_NONE);
-
- case '(': return GetNumberInsideParens(g,clause,i,token,eval);
-
- case '-': case '!':
- ++(*i);
- if (c==string[*i]) return(ERR_UNARY);
- ret = ScanForNumber(g,clause,i,OPTYPE_UNARY,token,eval);
- if (ret != ERR_NONE)
- return (ret);
- if (c == '-') *token = -(*token);
- else if (c == '!') *token = !(*token);
- return (ERR_NONE);
-
- default:
- if (isdigit(string[*i]))
- {
- *token = 0;
-
- do *token = 10 * (*token) + string[(*i)++] - '0';
- while (isdigit(string[*i]));
-
- while (string[*i] != '\0' && isspace(string[*i])) (*i)++;
- if (MoveIndexPastString (string, i, "minutes"))
- *token *= 60;
- return (ERR_NONE);
- }
- else if (isalpha(string[*i]))
- {
- if (!VarToToken (g, clause, string, i, token, eval))
- return (ERR_BADVAR);
- return(ERR_NONE);
- }
- else return (ERR_NONESENSE);
- }
-} /* end of function ScanForNumber. */
+ char *string = GetPlayersFormula (&parray[g->black], clause);
+ char c;
+ int ret;
+
+ while (string[*i] != '\0' && isspace(string[*i]))
+ (*i)++;
+
+ switch (c = string[*i]) {
+ case '\0':
+ case '#':
+ if (op_type != OPTYPE_NONE)
+ return ERR_EOF;
+ else
+ *token = 1;
+ return ERR_NONE;
+ case ')':
+ if (op_type != OPTYPE_PAREN)
+ return ERR_PAREN;
+ else
+ *token = 1;
+ return ERR_NONE;
+ case '(':
+ return GetNumberInsideParens(g, clause, i, token, eval);
+ case '-':
+ case '!':
+ ++(*i);
+
+ if (c == string[*i])
+ return ERR_UNARY;
+
+ ret = ScanForNumber(g, clause, i, OPTYPE_UNARY, token, eval);
+
+ if (ret != ERR_NONE)
+ return ret;
+ if (c == '-')
+ *token = -(*token);
+ else if (c == '!')
+ *token = !(*token);
+ return ERR_NONE;
+ default:
+ if (isdigit(string[*i])) {
+ *token = 0;
+
+ do {
+ *token = (10 * (*token) + string[(*i)++] - '0');
+ } while (isdigit(string[*i]));
+
+ while (string[*i] != '\0' && isspace(string[*i]))
+ (*i)++;
+
+ if (MoveIndexPastString(string, i, "minutes"))
+ *token *= 60;
+ return ERR_NONE;
+ } else if (isalpha(string[*i])) {
+ if (!VarToToken(g, clause, string, i, token, eval))
+ return ERR_BADVAR;
+ return ERR_NONE;
+ } else
+ return ERR_NONESENSE;
+ } /* switch */
+}
/*
* If 'eval' is 1, CheckFormula() looks for the next token in the