(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.
This commit is contained in:
Markus Armbruster 2005-10-21 19:38:37 +00:00
parent 224cc6328a
commit 0ab9260151
4 changed files with 88 additions and 51 deletions

View file

@ -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. */

View file

@ -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; e<l && *e != '"' && *e != '\\' && isgraph(*e); ++e) ;
pr("%.*s", (int)(e-s), s);
@ -284,32 +258,30 @@ xditem(int type, char *arg)
/*
* Dump characteristics described by chr_camap[IDX].
* Return RET_OK on success, RET_SYN if IDX < 0.
* FIXME Merge into xditem() when nxtitem() is ready for it.
*/
static int
xdchr(int chridx)
{
struct camap *cm;
struct empfile *ef = &empfile[chridx];
struct castr *ca = ef->cadef;
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))) {

View file

@ -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)

View file

@ -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},
/* 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}
};