diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2023-12-26 23:00:00 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2023-12-26 23:00:00 +0100 |
commit | 909d975eb8cec791e8e228792c825ac24b9b38ff (patch) | |
tree | bdfda3b3b3dad1336a58459b124f42c497afec20 | |
parent | 19e6186d1a8cb9cbdd99c8b9fc07010ea8f6df46 (diff) |
Reformatted ScanForOp()
-rw-r--r-- | FICS/formula.c | 96 |
1 files changed, 64 insertions, 32 deletions
diff --git a/FICS/formula.c b/FICS/formula.c index 69bf824..7f888c7 100644 --- a/FICS/formula.c +++ b/FICS/formula.c @@ -226,40 +226,72 @@ int VarToToken (game *g, int clause, char *string, int *i, int *tok, int eval) return (1); } /* end of function VarToToken. */ -/* ScanForOp checks for an operator at position *i in string[]. */ -int ScanForOp (char *string, int *i) +/* + * ScanForOp() checks for an operator at position 'i' in 'string'. + */ +int +ScanForOp(char *string, int *i) { - while (string[*i] != '\0' && isspace(string[*i])) (*i)++; + while (string[*i] != '\0' && isspace(string[*i])) + (*i)++; + + if (string[*i] == '\0') + return OP_NONE; + if (string[*i] == '#') + return OP_NONE; + if (string[*i] == ')') + return OP_RTPAREN; - if (string[*i] == '\0') return (OP_NONE); - if (string[*i] == '#') return (OP_NONE); - if (string[*i] == ')') return (OP_RTPAREN); - - /* Two char operators and longer first. */ - if (MoveIndexPastString(string, i, "and")) return (OP_AND); - if (MoveIndexPastString(string, i, "or")) return (OP_OR); - if (MoveIndexPastString(string, i, "||")) return (OP_OR); - if (MoveIndexPastString(string, i, "&&")) return (OP_AND); - if (MoveIndexPastString(string, i, "==")) return (OP_EQ); - if (MoveIndexPastString(string, i, "!=")) return (OP_NEQ); - if (MoveIndexPastString(string, i, "<>")) return (OP_NEQ); - if (MoveIndexPastString(string, i, ">=")) return (OP_GE); - if (MoveIndexPastString(string, i, "=>")) return (OP_GE); - if (MoveIndexPastString(string, i, "<=")) return (OP_LE); - if (MoveIndexPastString(string, i, "=<")) return (OP_LE); - - /* One char operators now. */ - if (MoveIndexPastString(string, i, "|")) return (OP_OR); - if (MoveIndexPastString(string, i, "&")) return (OP_AND); - if (MoveIndexPastString(string, i, ">")) return (OP_GT); - if (MoveIndexPastString(string, i, "<")) return (OP_LT); - if (MoveIndexPastString(string, i, "=")) return (OP_EQ); - if (MoveIndexPastString(string, i, "+")) return (OP_PLUS); - if (MoveIndexPastString(string, i, "-")) return (OP_MINUS); - if (MoveIndexPastString(string, i, "*")) return (OP_MULT); - if (MoveIndexPastString(string, i, "/")) return (OP_DIV); - return (OP_BAD); -} /* end of function ScanForOp. */ + /* + * Two char operators and longer first. + */ + if (MoveIndexPastString(string, i, "and")) + return OP_AND; + if (MoveIndexPastString(string, i, "or")) + return OP_OR; + if (MoveIndexPastString(string, i, "||")) + return OP_OR; + if (MoveIndexPastString(string, i, "&&")) + return OP_AND; + if (MoveIndexPastString(string, i, "==")) + return OP_EQ; + if (MoveIndexPastString(string, i, "!=")) + return OP_NEQ; + if (MoveIndexPastString(string, i, "<>")) + return OP_NEQ; + if (MoveIndexPastString(string, i, ">=")) + return OP_GE; + if (MoveIndexPastString(string, i, "=>")) + return OP_GE; + if (MoveIndexPastString(string, i, "<=")) + return OP_LE; + if (MoveIndexPastString(string, i, "=<")) + return OP_LE; + + /* + * One char operators now. + */ + if (MoveIndexPastString(string, i, "|")) + return OP_OR; + if (MoveIndexPastString(string, i, "&")) + return OP_AND; + if (MoveIndexPastString(string, i, ">")) + return OP_GT; + if (MoveIndexPastString(string, i, "<")) + return OP_LT; + if (MoveIndexPastString(string, i, "=")) + return OP_EQ; + if (MoveIndexPastString(string, i, "+")) + return OP_PLUS; + if (MoveIndexPastString(string, i, "-")) + return OP_MINUS; + if (MoveIndexPastString(string, i, "*")) + return OP_MULT; + if (MoveIndexPastString(string, i, "/")) + return OP_DIV; + + return OP_BAD; +} /* * OpType() returns the precedence of the operator 'op'. |