]> git.pond.sub.org Git - empserver/commitdiff
Pass struct natstr * instead of natid to virtual selectors
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 25 Mar 2008 20:36:52 +0000 (21:36 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 26 Mar 2008 21:13:21 +0000 (22:13 +0100)
This is because we want to define them in src/lib/global/, and code
there can't use getnatp(), because that requires
src/lib/common/file.c.  Which renders a cnum parameter pretty useless.

Virtual selectors requiring code from common/ could well come up again
in the future, but let's not worry about that now.

include/nsc.h
src/lib/common/nstreval.c
src/lib/global/nsc.c

index 42b731ef70acd1518387e74c9903c492544b0763..f46ca6ccac7072723143e3ccbc1b11e17c93aed6 100644 (file)
@@ -103,11 +103,11 @@ enum nsc_cat {
  * in the context object.  I.e. the value is at sym.off + sym.idx *
  * SZ, where SZ is the size of the value.
  * If sym.get is not null, you obtain the value by calling get() like
- * VAL->get(VAL, CNUM, CTXO), where CNUM is the country to use for
- * coordinate translation and access control, and CTXO is the context
- * object.  get() either returns a null pointer and sets VAL->val_as
- * to the value, as appropriate for the type.  Or it returns another
- * context object and sets VAL->val_as.sym for it.
+ * VAL->get(VAL, NP, CTXO), where NP points to the country to use for
+ * coordinate translation and access control (null for none), and CTXO
+ * is the context object.  get() either returns a null pointer and
+ * sets VAL->val_as to the value, as appropriate for the type.  Or it
+ * returns another context object and sets VAL->val_as.sym for it.
  */
 struct valstr {
     enum nsc_type val_type;    /* type of value */
@@ -117,7 +117,7 @@ struct valstr {
            ptrdiff_t off;
            int len;
            int idx;
-           void *(*get)(struct valstr *, natid, void *);
+           void *(*get)(struct valstr *, struct natstr *, void *);
        } sym;
        double dbl;             /* cat NSC_VAL, type NSC_DOUBLE */
        struct {                /* cat NSC_VAL, type NSC_STRING, cat NSC_ID */
@@ -208,11 +208,11 @@ enum {
  * A datum of any other type is either a scalar of that type (if
  * ca_len is zero), or an array of ca_len elements of that type.
  * If ca_get is not null, the selector is virtual.  Values can be
- * obtained by calling ca_get(VAL, CNUM, CTXO), where VAL has been
+ * obtained by calling ca_get(VAL, NP, CTXO), where VAL has been
  * initialized my from the selector and an index by nstr_mksymval(),
- * CNUM is the country to use for coordinate translation and access
- * control, and CTXO is the context object.  See struct valstr for
- * details.
+ * NP points to the country to use for coordinate translation and
+ * access control (null for none), and CTXO is the context object.
+ * See struct valstr for details.
  * If flag NSC_DEITY is set, only to deities can use this selector.
  * If flag NSC_EXTRA is set, xdump ignores this selector.
  * If flag NSC_CONST is set, the datum can't be changed from its
@@ -227,7 +227,7 @@ struct castr {
     ptrdiff_t ca_off;
     enum nsc_type ca_type;
     unsigned short ca_len;
-    void *(*ca_get)(struct valstr *, natid, void *);
+    void *(*ca_get)(struct valstr *, struct natstr *, void *);
     int ca_table;
     int ca_flags;
 };
index 505407208aaede1c9ab21d6acece3ff4c52a7497..7c2f5e8bd2ee3aa2b355b25157f6c663b5f25be1 100644 (file)
@@ -87,8 +87,9 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
        break;
     case NSC_OFF:
        if (val->val_as.sym.get) {
+           natp = getnatp(cnum);
            do {
-               ptr = val->val_as.sym.get(val, cnum, ptr);
+               ptr = val->val_as.sym.get(val, natp, ptr);
            } while (ptr && val->val_as.sym.get);
            if (!ptr) {
                valtype = val->val_type;
index b85ad37b6f41bbf30666831403fcc22b274f9261..10efb4a104e6a8ea11209a29c5c28dc718690495 100644 (file)
 #include "nsc.h"
 #include "product.h"
 
-static void *nsc_ver(struct valstr *, natid, void *);
-static void *nsc_pln_att(struct valstr *, natid, void *);
-static void *nsc_pln_def(struct valstr *, natid, void *);
-static void *nsc_lnd_att(struct valstr *, natid, void *);
-static void *nsc_lnd_def(struct valstr *, natid, void *);
-static void *nsc_lnd_vul(struct valstr *, natid, void *);
-static void *nsc_lnd_spd(struct valstr *, natid, void *);
-static void *nsc_lnd_vis(struct valstr *, natid, void *);
-static void *nsc_lnd_frg(struct valstr *, natid, void *);
-static void *nsc_lnd_acc(struct valstr *, natid, void *);
-static void *nsc_lnd_dam(struct valstr *, natid, void *);
-static void *nsc_lnd_aaf(struct valstr *, natid, void *);
-static void *nsc_lchr(struct valstr *, natid, void *);
+static void *nsc_ver(struct valstr *, struct natstr *, void *);
+static void *nsc_pln_att(struct valstr *, struct natstr *, void *);
+static void *nsc_pln_def(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_att(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_def(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_vul(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_spd(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_vis(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_frg(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_acc(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *);
+static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
+static void *nsc_lchr(struct valstr *, struct natstr *, void *);
 
 /* Ugly hack to improve legibility by avoid long lines */
 #define fldoff(fld) offsetof(CURSTR, fld)
@@ -744,7 +744,7 @@ nsc_init(void)
  */
 
 static void *
-nsc_ver(struct valstr *val, natid cnum, void *ptr)
+nsc_ver(struct valstr *val, struct natstr *np, void *ptr)
 {
     struct keymatch *kp = &configkeys[val->val_as.sym.off];
     val->val_as.sym.off = 0;
@@ -753,84 +753,84 @@ nsc_ver(struct valstr *val, natid cnum, void *ptr)
 }
 
 static void *
-nsc_pln_def(struct valstr *val, natid cnum, void *ptr)
+nsc_pln_def(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = pln_def(ptr);;
     return NULL;
 }
 
 static void *
-nsc_pln_att(struct valstr *val, natid cnum, void *ptr)
+nsc_pln_att(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = pln_att(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_att(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_att(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.dbl = lnd_att(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_def(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_def(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.dbl = lnd_def(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_vul(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_vul(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_vul(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_spd(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_spd(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_spd(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_vis(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_vis(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_vis(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_frg(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_frg(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_frg(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_acc(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_acc(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_acc(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_dam(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_dam(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_dam(ptr);
     return NULL;
 }
 
 static void *
-nsc_lnd_aaf(struct valstr *val, natid cnum, void *ptr)
+nsc_lnd_aaf(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.lng = lnd_aaf(ptr);
     return NULL;
 }
 
 static void *
-nsc_lchr(struct valstr *val, natid cnum, void *ptr)
+nsc_lchr(struct valstr *val, struct natstr *np, void *ptr)
 {
     val->val_as.sym.get = NULL;
     return lchr + ((struct lndstr *)ptr)->lnd_type;