diff --git a/include/nsc.h b/include/nsc.h index b04d3f6e..44af2b29 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -39,6 +39,12 @@ #define NS_LSIZE 128 #define NS_NCOND 16 +enum { /* masks for struct nscstr member oper */ + NSC_OPMASK = 0x0ff, /* operator */ + NSC_ISNUM1 = 0x100, /* is left operand a number? */ + NSC_ISNUM2 = 0x200 /* is right operand a number? */ +}; + struct nscstr { long fld1; /* first commodity or number */ long fld2; /* second commodity or number */ diff --git a/src/lib/subs/nstr.c b/src/lib/subs/nstr.c index cab64dda..ff64e8df 100644 --- a/src/lib/subs/nstr.c +++ b/src/lib/subs/nstr.c @@ -62,7 +62,6 @@ nstr_comp(struct nscstr *np, int *size, int type, s_char *str) register int c; s_char ident[80]; s_char arg[255]; - int op; int val; strncpy(arg, str, sizeof(arg) - 1); @@ -79,12 +78,11 @@ nstr_comp(struct nscstr *np, int *size, int type, s_char *str) pr("'%s'? -- meaningless condition?\n", arg); return 0; } - op = c; - np[*size].oper = op; + np[*size].oper = c & NSC_OPMASK; if ((val = encode(ident, &np[*size].fld1, type)) < 0) return 0; if (val == 2) - np[*size].oper += 255; + np[*size].oper |= NSC_ISNUM1; bp = ident; while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) { if (c == '&') @@ -95,7 +93,7 @@ nstr_comp(struct nscstr *np, int *size, int type, s_char *str) if ((val = encode(ident, &np[*size].fld2, type)) < 0) return 0; if (val == 2) - np[*size].oper += 65535; + np[*size].oper |= NSC_ISNUM2; if (c == 0) cp--; (*size)++; @@ -117,19 +115,17 @@ nstr_exec(struct nscstr *conds, register int ncond, void *ptr, int type) for (nsc = conds; --ncond >= 0; nsc++) { oper = nsc->oper; - if (oper > 65535) { - oper = oper - 65535; + if (oper & NSC_ISNUM2) { rhs = nsc->fld2; } else rhs = decode(player->cnum, nsc->fld2, ptr, type); - if (oper > 255) { - oper = oper - 255; + if (oper & NSC_ISNUM1) { lhs = nsc->fld1; } else lhs = decode(player->cnum, nsc->fld1, ptr, type); - op = oper; + op = oper & NSC_OPMASK; if ((op == '<' && lhs >= rhs) || (op == '=' && lhs != rhs) || (op == '>' && lhs <= rhs)