Symbolic names for table entries in conditionals, closes #928376:
(ef_elt_byname): New. (nstr_match_val): Use it to generalize to arbitrary table with uniquely named elements. Use ca_type to find table, remove parameter type. Callers changed. (nstr_mkselval): Adapt sanity check accordingly. (NSC_TYPEID): No longer needed, remove, users changed to use appropriate integer type instead. This fixes signedness of sector selectors des and newdes. (meta_type): Remove entry for NSC_TYPEID. (nstr_coerce_val): Can't detect typeid - integer mismatch anymore. Was nice to have; perhaps revive it later.
This commit is contained in:
parent
15635c25ae
commit
c432e3107d
9 changed files with 72 additions and 42 deletions
|
@ -97,7 +97,7 @@ verify_row(int type, int row)
|
|||
val.val_as.sym.len = ca[i].ca_len;
|
||||
val.val_as.sym.idx = j;
|
||||
nstr_exec_val(&val, 0, row_ref, NSC_NOTYPE);
|
||||
if (val.val_type != NSC_LONG && val.val_type != NSC_TYPEID)
|
||||
if (val.val_type != NSC_LONG)
|
||||
continue;
|
||||
ca_sym = ef_cadef(ca[i].ca_table);
|
||||
if (ca[i].ca_flags & NSC_BITS) {
|
||||
|
|
|
@ -98,3 +98,53 @@ typematch(char *name, int type)
|
|||
}
|
||||
return M_NOTFOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search table TYPE for an element matching NAME, return its index.
|
||||
* Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
|
||||
* several.
|
||||
*/
|
||||
int
|
||||
ef_elt_byname(int type, char *name)
|
||||
{
|
||||
switch (type) {
|
||||
case EF_NATION:
|
||||
return cnumb(name);
|
||||
case EF_SECTOR_CHR:
|
||||
return sct_typematch(name);
|
||||
case EF_SHIP_CHR:
|
||||
return stmtch(name, mchr,
|
||||
offsetof(struct mchrstr, m_name),
|
||||
sizeof(mchr[0]));
|
||||
case EF_LAND_CHR:
|
||||
return stmtch(name, lchr,
|
||||
offsetof(struct lchrstr, l_name),
|
||||
sizeof(lchr[0]));
|
||||
case EF_PLANE_CHR:
|
||||
return stmtch(name, plchr,
|
||||
offsetof(struct plchrstr, pl_name),
|
||||
sizeof(plchr[0]));
|
||||
case EF_NUKE_CHR:
|
||||
return stmtch(name, nchr,
|
||||
offsetof(struct nchrstr, n_name),
|
||||
sizeof(nchr[0]));
|
||||
case EF_ITEM:
|
||||
return stmtch(name, ichr,
|
||||
offsetof(struct ichrstr, i_name),
|
||||
sizeof(ichr[0]));
|
||||
case EF_PRODUCT:
|
||||
return stmtch(name, pchr + 1,
|
||||
offsetof(struct pchrstr, p_sname),
|
||||
sizeof(pchr[0]));
|
||||
case EF_TABLE:
|
||||
return stmtch(name, empfile,
|
||||
offsetof(struct empfile, name),
|
||||
sizeof(empfile[0]));
|
||||
default:
|
||||
if (ef_cadef(type) == symbol_ca)
|
||||
return stmtch(name, ef_ptr(type, 0),
|
||||
offsetof(struct symbol, name),
|
||||
sizeof(struct symbol));
|
||||
}
|
||||
return M_NOTFOUND;
|
||||
}
|
||||
|
|
|
@ -447,7 +447,6 @@ setnum(int fldno, double dbl)
|
|||
|
||||
switch (ca->ca_type) {
|
||||
case NSC_CHAR:
|
||||
case NSC_TYPEID:
|
||||
old = ((signed char *)memb_ptr)[idx];
|
||||
((signed char *)memb_ptr)[idx] = (signed char)dbl;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue