(NSC_OPMASK, NSC_ISNUM1, NSC_ISNUM2, nscstr, nstr_comp, nstr_exec):
Simplify encoding of struct ncstr member oper.
This commit is contained in:
parent
bd54488715
commit
3d0178b994
2 changed files with 12 additions and 10 deletions
|
@ -39,6 +39,12 @@
|
||||||
#define NS_LSIZE 128
|
#define NS_LSIZE 128
|
||||||
#define NS_NCOND 16
|
#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 {
|
struct nscstr {
|
||||||
long fld1; /* first commodity or number */
|
long fld1; /* first commodity or number */
|
||||||
long fld2; /* second commodity or number */
|
long fld2; /* second commodity or number */
|
||||||
|
|
|
@ -62,7 +62,6 @@ nstr_comp(struct nscstr *np, int *size, int type, s_char *str)
|
||||||
register int c;
|
register int c;
|
||||||
s_char ident[80];
|
s_char ident[80];
|
||||||
s_char arg[255];
|
s_char arg[255];
|
||||||
int op;
|
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
strncpy(arg, str, sizeof(arg) - 1);
|
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);
|
pr("'%s'? -- meaningless condition?\n", arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
op = c;
|
np[*size].oper = c & NSC_OPMASK;
|
||||||
np[*size].oper = op;
|
|
||||||
if ((val = encode(ident, &np[*size].fld1, type)) < 0)
|
if ((val = encode(ident, &np[*size].fld1, type)) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (val == 2)
|
if (val == 2)
|
||||||
np[*size].oper += 255;
|
np[*size].oper |= NSC_ISNUM1;
|
||||||
bp = ident;
|
bp = ident;
|
||||||
while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) {
|
while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) {
|
||||||
if (c == '&')
|
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)
|
if ((val = encode(ident, &np[*size].fld2, type)) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (val == 2)
|
if (val == 2)
|
||||||
np[*size].oper += 65535;
|
np[*size].oper |= NSC_ISNUM2;
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
cp--;
|
cp--;
|
||||||
(*size)++;
|
(*size)++;
|
||||||
|
@ -117,19 +115,17 @@ nstr_exec(struct nscstr *conds, register int ncond, void *ptr, int type)
|
||||||
|
|
||||||
for (nsc = conds; --ncond >= 0; nsc++) {
|
for (nsc = conds; --ncond >= 0; nsc++) {
|
||||||
oper = nsc->oper;
|
oper = nsc->oper;
|
||||||
if (oper > 65535) {
|
if (oper & NSC_ISNUM2) {
|
||||||
oper = oper - 65535;
|
|
||||||
rhs = nsc->fld2;
|
rhs = nsc->fld2;
|
||||||
} else
|
} else
|
||||||
rhs = decode(player->cnum, nsc->fld2, ptr, type);
|
rhs = decode(player->cnum, nsc->fld2, ptr, type);
|
||||||
|
|
||||||
if (oper > 255) {
|
if (oper & NSC_ISNUM1) {
|
||||||
oper = oper - 255;
|
|
||||||
lhs = nsc->fld1;
|
lhs = nsc->fld1;
|
||||||
} else
|
} else
|
||||||
lhs = decode(player->cnum, nsc->fld1, ptr, type);
|
lhs = decode(player->cnum, nsc->fld1, ptr, type);
|
||||||
|
|
||||||
op = oper;
|
op = oper & NSC_OPMASK;
|
||||||
if ((op == '<' && lhs >= rhs)
|
if ((op == '<' && lhs >= rhs)
|
||||||
|| (op == '=' && lhs != rhs)
|
|| (op == '=' && lhs != rhs)
|
||||||
|| (op == '>' && lhs <= rhs)
|
|| (op == '>' && lhs <= rhs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue