diff --git a/include/nsc.h b/include/nsc.h index c5384b40..13511d90 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -59,6 +59,7 @@ typedef enum { NSC_YCOORD, /* coord that needs y conversion */ NSC_TIME, /* time_t */ NSC_FLOAT, /* float */ + NSC_STRINGY, /* char[], zero-terminated string */ /* aliases, must match typedefs */ NSC_NATID = NSC_UCHAR /* nation id */ } nsc_type; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index eb6d79fb..a019fb2c 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -143,7 +143,7 @@ struct castr ship_ca[] = { {NSC_TIME, 0, 0, fldoff(shpstr, shp_access), "access"}, {NSC_TIME, 0, 0, fldoff(shpstr, shp_timestamp), "timestamp"}, /* FIXME sail stuff missing */ - /* FIXME name missing */ + {NSC_STRINGY, 0, 0, fldoff(shpstr, shp_name), "name"}, {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_fuel), "fuel"}, {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nchoppers), "nchoppers"}, {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nxlight), "nxlight"}, diff --git a/src/lib/subs/nstr.c b/src/lib/subs/nstr.c index b829f181..07062185 100644 --- a/src/lib/subs/nstr.c +++ b/src/lib/subs/nstr.c @@ -148,7 +148,7 @@ nstr_comp(struct nscstr *np, int len, int type, char *str) int nstr_exec(struct nscstr *np, int ncond, void *ptr) { - int i, op, optype; + int i, op, optype, cmp; struct valstr lft, rgt; for (i = 0; i < ncond; ++i) { @@ -171,7 +171,9 @@ nstr_exec(struct nscstr *np, int ncond, void *ptr) return 0; break; case NSC_STRING: - CANT_HAPPEN("unimplemented OPTYPE"); /* FIXME */ + cmp = strcmp(lft.val_as.str, rgt.val_as.str); + if (!EVAL(op, cmp, 0)) + return 0; return 0; default: CANT_HAPPEN("bad OPTYPE"); @@ -297,6 +299,7 @@ nstr_comp_val(char *str, struct valstr*val, int type) * Promote VALTYPE. * If VALTYPE is an integer type, return NSC_LONG. * If VALTYPE is a floating-point type, return NSC_DOUBLE. + * If VALTYPE is NSC_STRINGY, return NSC_STRING. * If VALTYPE is NSC_NOTYPE, NSC_STRING or NSC_TYPEID, return VALTYPE. */ static int @@ -322,6 +325,9 @@ nstr_promote(int valtype) case NSC_FLOAT: valtype = NSC_DOUBLE; break; + case NSC_STRINGY: + valtype = NSC_STRING; + break; default: CANT_HAPPEN("bad VALTYPE"); valtype = NSC_NOTYPE; @@ -450,8 +456,13 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want) val->val_as.dbl = ((double *)memb_ptr)[idx]; valtype = NSC_DOUBLE; break; + case NSC_STRINGY: + CANT_HAPPEN(idx); + val->val_as.str = (char *)memb_ptr; + valtype = NSC_STRING; + break; case NSC_STRING: - val->val_as.str = *(char **)memb_ptr; + val->val_as.str = ((char **)memb_ptr)[idx]; valtype = NSC_STRING; break; case NSC_TIME: