From e5ef3d48402e996d0414a4f10c8e0beb4e3fb6c0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 25 Mar 2008 21:36:52 +0100 Subject: [PATCH] Pass struct natstr * instead of natid to virtual selectors 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 | 22 ++++++++--------- src/lib/common/nstreval.c | 3 ++- src/lib/global/nsc.c | 52 +++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/include/nsc.h b/include/nsc.h index 42b731ef..f46ca6cc 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -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; }; diff --git a/src/lib/common/nstreval.c b/src/lib/common/nstreval.c index 50540720..7c2f5e8b 100644 --- a/src/lib/common/nstreval.c +++ b/src/lib/common/nstreval.c @@ -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; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index b85ad37b..10efb4a1 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -45,19 +45,19 @@ #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;