diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2023-12-26 16:17:35 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2023-12-26 16:17:35 +0100 |
commit | 08c22ff5c443c78fc0be9a3fea7df94edb54dda8 (patch) | |
tree | d5f9e10bce875a7d2eb6a9eaadb68534e7c48bb6 | |
parent | 9658109c5839ea672182046f418d0a0b5c0c7d63 (diff) |
Reformatted SetValidFormula()
-rw-r--r-- | FICS/formula.c | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/FICS/formula.c b/FICS/formula.c index 843f1b5..77cf89f 100644 --- a/FICS/formula.c +++ b/FICS/formula.c @@ -536,50 +536,56 @@ PUBLIC int GameMatchesFormula (int w, int b, int wTime, int wInc, int bTime, return (ret); } /* end of function GameMatchesFormula. */ -/* SetValidFormula sets a clause of player p and creates a game structure - to check whether that new formula is legitimate. If so, return 1; - otherwise, reset the formula and return 0. -*/ -int SetValidFormula (int p, int clause, char *string) +/* + * SetValidFormula() sets a clause of player 'p' and creates a game + * structure to check whether that new formula is legitimate. If so, + * return 1. Otherwise reset the formula and return 0. + */ +int +SetValidFormula(int p, int clause, char *string) { - game g; - int index=0, ret, err=ERR_NONE; - char *Old=NULL, **Cur; - player *me = &parray[p]; - - if (clause==MAX_FORMULA) - Cur = &me->formula; - else - Cur = &me->formulaLines[clause]; - - Old = *Cur; - - if (string != NULL) { - string = eatwhite(string); - *Cur = (*string != '\0' ? xstrdup (string) : NULL); - } - else *Cur = NULL; + char *Old = NULL, **Cur; + game g; + int index = 0, ret, err = ERR_NONE; + player *me = &parray[p]; + + if (clause == MAX_FORMULA) + Cur = &me->formula; + else + Cur = &me->formulaLines[clause]; + + Old = *Cur; + + if (string != NULL) { + string = eatwhite(string); + *Cur = (*string != '\0' ? xstrdup(string) : NULL); + } else + *Cur = NULL; + + if (*Cur == NULL) { + if (Old != NULL) + rfree(Old); + return 1; + } - if (*Cur==NULL) { - if (Old != NULL) rfree(Old); - return 1; - } + g.white = g.black = p; + g.wInitTime = g.bInitTime = me->d_time; + g.wIncrement = g.bIncrement = me->d_inc; + g.rated = me->rated; + g.type = TYPE_BLITZ; + + err = CheckFormula (&g, clause, &index, OPTYPE_NONE, &ret, 0); + + if (err != ERR_NONE) { + /* Bad formula -- reset it. */ + rfree(*Cur); + *Cur = Old; + } else { + if (Old != NULL) + rfree(Old); + } - g.white = g.black = p; - g.wInitTime = g.bInitTime = me->d_time; - g.wIncrement = g.bIncrement = me->d_inc; - g.rated = me->rated; - g.type = TYPE_BLITZ; - err = CheckFormula (&g, clause, &index, OPTYPE_NONE, &ret, 0); - - if (err != ERR_NONE) { - /* Bad formula; reset it. */ - rfree(*Cur); - *Cur = Old; - } else { - if (Old != NULL) rfree(Old); - } - return (err == ERR_NONE); + return (err == ERR_NONE); } PUBLIC void |