]> git.pond.sub.org Git - empserver/commitdiff
(NSC_STRINGY): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 21 Aug 2004 14:09:31 +0000 (14:09 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 21 Aug 2004 14:09:31 +0000 (14:09 +0000)
(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.

include/nsc.h
src/lib/global/nsc.c
src/lib/subs/nstr.c

index c5384b40def663096b6e3709bb8aaba65f4caef1..13511d904d89fe6d0162a991c9a2b3d9d0d35f84 100644 (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;
index eb6d79fbe20ec66a1910fcba6b25c5e51e746d2f..a019fb2c1ac0109e2a22c6b8e803e0e302d42933 100644 (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"},
index b829f18108399158701e9f83421c09232380acfb..07062185006da3173848be33837df12eddda143e 100644 (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: