(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:
parent
7c4433c54b
commit
ba9748027b
3 changed files with 16 additions and 4 deletions
|
@ -59,6 +59,7 @@ typedef enum {
|
||||||
NSC_YCOORD, /* coord that needs y conversion */
|
NSC_YCOORD, /* coord that needs y conversion */
|
||||||
NSC_TIME, /* time_t */
|
NSC_TIME, /* time_t */
|
||||||
NSC_FLOAT, /* float */
|
NSC_FLOAT, /* float */
|
||||||
|
NSC_STRINGY, /* char[], zero-terminated string */
|
||||||
/* aliases, must match typedefs */
|
/* aliases, must match typedefs */
|
||||||
NSC_NATID = NSC_UCHAR /* nation id */
|
NSC_NATID = NSC_UCHAR /* nation id */
|
||||||
} nsc_type;
|
} nsc_type;
|
||||||
|
|
|
@ -143,7 +143,7 @@ struct castr ship_ca[] = {
|
||||||
{NSC_TIME, 0, 0, fldoff(shpstr, shp_access), "access"},
|
{NSC_TIME, 0, 0, fldoff(shpstr, shp_access), "access"},
|
||||||
{NSC_TIME, 0, 0, fldoff(shpstr, shp_timestamp), "timestamp"},
|
{NSC_TIME, 0, 0, fldoff(shpstr, shp_timestamp), "timestamp"},
|
||||||
/* FIXME sail stuff missing */
|
/* 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_fuel), "fuel"},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nchoppers), "nchoppers"},
|
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nchoppers), "nchoppers"},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nxlight), "nxlight"},
|
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nxlight), "nxlight"},
|
||||||
|
|
|
@ -148,7 +148,7 @@ nstr_comp(struct nscstr *np, int len, int type, char *str)
|
||||||
int
|
int
|
||||||
nstr_exec(struct nscstr *np, int ncond, void *ptr)
|
nstr_exec(struct nscstr *np, int ncond, void *ptr)
|
||||||
{
|
{
|
||||||
int i, op, optype;
|
int i, op, optype, cmp;
|
||||||
struct valstr lft, rgt;
|
struct valstr lft, rgt;
|
||||||
|
|
||||||
for (i = 0; i < ncond; ++i) {
|
for (i = 0; i < ncond; ++i) {
|
||||||
|
@ -171,7 +171,9 @@ nstr_exec(struct nscstr *np, int ncond, void *ptr)
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case NSC_STRING:
|
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;
|
return 0;
|
||||||
default:
|
default:
|
||||||
CANT_HAPPEN("bad OPTYPE");
|
CANT_HAPPEN("bad OPTYPE");
|
||||||
|
@ -297,6 +299,7 @@ nstr_comp_val(char *str, struct valstr*val, int type)
|
||||||
* Promote VALTYPE.
|
* Promote VALTYPE.
|
||||||
* If VALTYPE is an integer type, return NSC_LONG.
|
* If VALTYPE is an integer type, return NSC_LONG.
|
||||||
* If VALTYPE is a floating-point type, return NSC_DOUBLE.
|
* 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.
|
* If VALTYPE is NSC_NOTYPE, NSC_STRING or NSC_TYPEID, return VALTYPE.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
@ -322,6 +325,9 @@ nstr_promote(int valtype)
|
||||||
case NSC_FLOAT:
|
case NSC_FLOAT:
|
||||||
valtype = NSC_DOUBLE;
|
valtype = NSC_DOUBLE;
|
||||||
break;
|
break;
|
||||||
|
case NSC_STRINGY:
|
||||||
|
valtype = NSC_STRING;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
CANT_HAPPEN("bad VALTYPE");
|
CANT_HAPPEN("bad VALTYPE");
|
||||||
valtype = NSC_NOTYPE;
|
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];
|
val->val_as.dbl = ((double *)memb_ptr)[idx];
|
||||||
valtype = NSC_DOUBLE;
|
valtype = NSC_DOUBLE;
|
||||||
break;
|
break;
|
||||||
|
case NSC_STRINGY:
|
||||||
|
CANT_HAPPEN(idx);
|
||||||
|
val->val_as.str = (char *)memb_ptr;
|
||||||
|
valtype = NSC_STRING;
|
||||||
|
break;
|
||||||
case NSC_STRING:
|
case NSC_STRING:
|
||||||
val->val_as.str = *(char **)memb_ptr;
|
val->val_as.str = ((char **)memb_ptr)[idx];
|
||||||
valtype = NSC_STRING;
|
valtype = NSC_STRING;
|
||||||
break;
|
break;
|
||||||
case NSC_TIME:
|
case NSC_TIME:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue