#include "config.h" #include "mud.h" #include "u.h" #include "y.tab.h" /* "cast" a node as a true/false value */ int eval_castbool (Nod * n) { if (n->rv.t == NUM && n->rv.iv != 0) return (1); if (n->rv.t == STR && n->rv.cv != (char *) 0 && n->rv.cv[0] != '\0') return (1); if (n->rv.t == OID) return (cache_check (n->rv.cv)); return (0); } /* "cast" a node as an int */ int eval_castint (Nod * n) { switch (n->rv.t) { case STR: case OID: return (atoi (n->rv.cv)); case NUM: return (n->rv.iv); case VNULL: return (0); } return (0); } /* "cast" a node as a string */ char *eval_caststr (n) Nod *n; { switch (n->rv.t) { case STR: case OID: return (n->rv.cv); case NUM: { char nbuf[MAXOID]; return (tmpstr (itoa (n->rv.iv, nbuf, 10))); } case VNULL: return ("NULL"); } return (""); } /* adopt a node's rv into our nval or rv */ void eval_adopt (n1, n2, lrh) Nod *n1; Nod *n2; int lrh; { if (lrh) n2->nv.t = n1->rv.t; else n2->rv.t = n1->rv.t; switch (n1->rv.t) { case STR: case OID: if (lrh) n2->nv.cv = n1->rv.cv; else n2->rv.cv = n1->rv.cv; break; case NUM: case VNULL: if (lrh) n2->nv.iv = n1->rv.iv; else n2->rv.iv = n1->rv.iv; break; /* some types (like subtrees) we don't assign to! */ default: if (lrh) { n2->nv.t = VNULL; n2->nv.iv = UERR_ILLASGN; } else { n2->rv.t = VNULL; n2->rv.iv = UERR_ILLASGN; } } }