From 0ab92601514db6b74ce8c2206c5ff348c6e62d05 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 21 Oct 2005 19:38:37 +0000 Subject: [PATCH] (empfile, chr_camap): Merge chr_camap[] into empfile[]. No existing user sees the new elements of empfile[]. (EF_SECTOR_CHR, EF_SHIP_CHR, EF_PLANE_CHR, EF_LAND_CHR, EF_NUKE_CHR) (EF_TREATY_CHR, EF_ITEM, EF_INFRASTRUCTURE, EF_PRODUCT): New. Not yet used. (my_ef_byname): Replacement for ef_byname() that sees the new elements. (xdchr): Work with empfile[] instead of chr_camap[]. (xdump): Use my_ef_byname() instead of ef_byname() and chridx_by_name(). (camap, chr_camap, chridx_by_name): Remove. --- include/file.h | 27 +++++++++++++++-- src/lib/commands/xdump.c | 64 +++++++++++----------------------------- src/lib/common/file.c | 4 +-- src/lib/global/file.c | 44 ++++++++++++++++++++++++++- 4 files changed, 88 insertions(+), 51 deletions(-) diff --git a/include/file.h b/include/file.h index 26562695..f9e01ada 100644 --- a/include/file.h +++ b/include/file.h @@ -66,8 +66,18 @@ struct empfile { #define EFF_OWNER bit(2) /* has concept of owner */ #define EFF_GROUP bit(3) /* has concept of group */ -/* file types, types 0..EF_MAX-1 are empfile[] indexes */ -#define EF_BAD -1 /* illegal file type */ +/* + * Empire `file types' + * These are really table IDs. Some tables are backed by files, some + * are compiled into the server. + * Historically, only table IDs 0..EF_MAX-1 existed. All the + * functions operating on table IDs still reject the new indexes >= + * EF_MAX. This needs to be rectified, carefully checking existing + * code, which could rely on unspoken assumptions about these tables. + */ +/* Error value */ +#define EF_BAD -1 +/* Dynamic game data tables: 0..EF_MAX-1 */ #define EF_SECTOR 0 #define EF_SHIP 1 #define EF_PLANE 2 @@ -84,6 +94,19 @@ struct empfile { #define EF_COMM 13 #define EF_LOST 14 #define EF_MAX 15 +/* Static game data (configuation): EF_MAX.. */ +#define EF_SECTOR_CHR 15 +#define EF_SHIP_CHR 16 +#define EF_PLANE_CHR 17 +#define EF_LAND_CHR 18 +#define EF_NUKE_CHR 19 +#if 0 /* doesn't exist yet */ +#define EF_NEWS_CHR +#endif +#define EF_TREATY_CHR 20 +#define EF_ITEM 21 +#define EF_INFRASTRUCTURE 22 +#define EF_PRODUCT 23 #define EF_NMAP 222 /* Kinda bogus, but used to describe a newdesmap instead of bmap or map. */ diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index 23025a35..9ddb0b62 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -80,44 +80,17 @@ /* FIXME document dump format */ /* FIXME don't dump stuff that's useless due to options */ -/* Selector descriptors for characteristics tables */ - -/* Characteristics table meta data */ -struct camap { - char *name; /* name for lookup */ - struct castr *ca; /* selector descriptors */ - void *chr; /* characteristics table */ - size_t size; /* size of characteristics table element */ -}; - -/* Table of characteristics tables */ -static struct camap chr_camap[] = { - {"sect chr", dchr_ca, dchr, sizeof(dchr[0])}, - {"ship chr", mchr_ca, mchr, sizeof(mchr[0])}, - {"plane chr", plchr_ca, plchr, sizeof(plchr[0])}, - {"land chr", lchr_ca, lchr, sizeof(lchr[0])}, - {"nuke chr", nchr_ca, nchr, sizeof(nchr[0])}, -#if 0 - /* FIXME rpt[] lacks sentinel, xdchr() doesn't terminate */ - {"news chr", rpt_ca, rpt, sizeof(rpt[0])}, -#endif - {"treaty chr", tchr_ca, tchr, sizeof(tchr[0])}, - {"item", ichr_ca, ichr, sizeof(ichr[0])}, - {"infrastructure", intrchr_ca, intrchr, sizeof(intrchr[0])}, - {"product", pchr_ca, pchr, sizeof(pchr[0])}, - {NULL, NULL, NULL, 0} -}; - /* - * Search chr_camap[] for element named NAME, return its index. + * Search empfile[] for element named NAME, return its index. * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are * several. + * FIXME Merge into ef_byname(). ef_byname() stops at EF_MAX! */ static int -chridx_by_name(char *name) +my_ef_byname(char *name) { - return stmtch(name, chr_camap, offsetof(struct camap, name), - sizeof(chr_camap[0])); + return stmtch(name, empfile, offsetof(struct empfile, name), + sizeof(empfile[0])); } /* @@ -157,6 +130,7 @@ xdprval(struct valstr *val, char *sep) if (s) { pr("%s\"", sep); l = s + val->val_as.str.maxsz; + /* FIXME maxsz == INT_MAX ! */ for (;;) { for (e=s; ecadef; char *p; struct valstr val; int n; - if (chridx < 0) - return RET_SYN; - cm = &chr_camap[chridx]; - - xdhdr(cm->name, cm->ca); + xdhdr(ef->name, ca); n = 0; - for (p = cm->chr; ; p += cm->size) { - val.val_type = cm->ca[0].ca_type; + for (p = ef->cache; ; p += ef->size) { + val.val_type = ca[0].ca_type; val.val_cat = NSC_OFF; - val.val_as.sym.off = cm->ca[0].ca_off; + val.val_as.sym.off = ca[0].ca_off; val.val_as.sym.idx = 0; nstr_exec_val(&val, player->cnum, p, NSC_STRING); if (!val.val_as.str.base || !*val.val_as.str.base) break; ++n; - xdflds(cm->ca, p); + xdflds(ca, p); pr("\n"); } @@ -391,11 +363,11 @@ xdump(void) if (!p) return RET_SYN; - type = ef_byname(p); - if (type >= 0) { + type = my_ef_byname(p); + if (type >= EF_MAX) + return xdchr(type); + else if (type >= 0) { return xditem(type, player->argp[2]); - } else if (!strncmp(p, "chr", strlen(p)) && player->argp[2]) { - return xdchr(chridx_by_name(player->argp[2])); } else if (!strncmp(p, "opt", strlen(p))) { return xdopt(); } else if (!strncmp(p, "ver", strlen(p))) { diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 271e00ae..13805a4f 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -362,8 +362,8 @@ ef_mtime(int type) } /* - * Return the filedescriptor used for the file containing objects of type - * 'type'. + * Search empfile[0..EF_MAX-1] for element named NAME. + * Return its index in empfile[] if found, else -1. */ int ef_byname(char *name) diff --git a/src/lib/global/file.c b/src/lib/global/file.c index 36a045bd..e64748cf 100644 --- a/src/lib/global/file.c +++ b/src/lib/global/file.c @@ -48,11 +48,13 @@ #include "news.h" #include "nat.h" #include "lost.h" +#include "product.h" #include "gamesdef.h" #include "commodity.h" struct empfile empfile[] = { + /* Dynamic game data */ {"sect", "sector", EFF_XY | EFF_OWNER, 0, sizeof(struct sctstr), NULL, NULL, NULL, -1, -1, 0, 0, NULL, 0, NULL}, @@ -97,5 +99,45 @@ struct empfile empfile[] = { -1, -1, 0, 0, NULL, 0, NULL}, {"lost", "lostitems", EFF_OWNER, 0, sizeof(struct loststr), NULL, NULL, NULL, - -1, -1, 0, 0, NULL, 0, NULL} + -1, -1, 0, 0, NULL, 0, NULL}, + + /* Static game data (configuation) */ + {"sect chr", NULL, EFF_MEM, + 0, sizeof(dchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)dchr, 0, dchr_ca}, + {"ship chr", NULL, EFF_MEM, + 0, sizeof(mchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)mchr, 0, mchr_ca}, + {"plane chr", NULL, EFF_MEM, + 0, sizeof(plchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)plchr, 0, plchr_ca}, + {"land chr", NULL, EFF_MEM, + 0, sizeof(lchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)lchr, 0, lchr_ca}, + {"nuke chr", NULL, EFF_MEM, + 0, sizeof(nchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)nchr, 0, nchr_ca}, +#if 0 + /* FIXME rpt[] lacks sentinel, xdchr() doesn't terminate */ + {"news chr", NULL, EFF_MEM, + 0, sizeof(rpt[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)rpt, 0, rpt_ca}, +#endif + {"treaty chr", NULL, EFF_MEM, + 0, sizeof(tchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)tchr, 0, tchr_ca}, + {"item", NULL, EFF_MEM, + 0, sizeof(ichr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)ichr, 0, ichr_ca}, + {"infrastructure", NULL, EFF_MEM, + 0, sizeof(intrchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)intrchr, 0, intrchr_ca}, + {"product", NULL, EFF_MEM, + 0, sizeof(pchr[0]), NULL, NULL, NULL, + -1, -1, 0, 0, (char *)pchr, 0, pchr_ca}, + + /* Sentinel */ + {NULL, NULL, 0, + 0, 0, NULL, NULL, NULL, + -1, -1, 0,0,NULL, 0, NULL} };