(NSC_STRINGY): New.

(nstr_promote, nstr_exec_val): Implement.

(nstr_exec_val): Ignored IDX for NSC_STRING values.

(nstr_exec): Implement NSC_STRING.

(ship_ca): New selector name.
This commit is contained in:
Markus Armbruster 2004-08-21 14:09:31 +00:00
parent 7c4433c54b
commit ba9748027b
3 changed files with 16 additions and 4 deletions

View file

@ -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;

View file

@ -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"},

View file

@ -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: