From 01c248cb59f17b537077884d5a0ab6858d61c79c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 28 Oct 2005 07:03:31 +0000 Subject: [PATCH] (EF_IS_GAME_STATE): New. (xdump, main): Use it. (EF_MAX): Change to largest table ID + 1. This is now possible because the changes above get rid of the assumption that empfile[0..EF_MAX-1] is only game state. Code can now work on any table using the advertized empfile interface, not just on game state. (my_ef_byname): Remove, use ef_byname(). --- include/file.h | 31 ++++++++++++++++--------------- src/lib/commands/xdump.c | 24 ++++++------------------ src/util/files.c | 4 ++++ 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/include/file.h b/include/file.h index 27395580..ae592f0a 100644 --- a/include/file.h +++ b/include/file.h @@ -58,6 +58,7 @@ struct empfile { /* * struct empfile flags */ +/* Immutable flags */ /* * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner / * group of such a table's entries can be safely obtained by @@ -66,14 +67,16 @@ struct empfile { #define EFF_XY bit(0) #define EFF_OWNER bit(1) #define EFF_GROUP bit(2) -/* Table is entirely in memory */ -#define EFF_MEM bit(3) -/* Table is read-only */ -#define EFF_RDONLY bit(4) -/* Create table file, clobbering any existing file */ -#define EFF_CREATE bit(5) /* Table is allocated statically */ -#define EFF_STATIC bit(6) +#define EFF_STATIC bit(3) +/* Flags set when table contents is mapped */ +/* Table is entirely in memory */ +#define EFF_MEM bit(4) +/* Table is read-only */ +#define EFF_RDONLY bit(5) +/* Transient flags, just to control ef_open() */ +/* Create table file, clobbering any existing file */ +#define EFF_CREATE bit(6) /* Flags that may be passed to ef_open() */ #define EFF_OPEN (EFF_MEM | EFF_RDONLY | EFF_CREATE) @@ -82,14 +85,10 @@ struct empfile { * 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 */ +/* Dynamic game data tables */ #define EF_SECTOR 0 #define EF_SHIP 1 #define EF_PLANE 2 @@ -105,8 +104,7 @@ struct empfile { #define EF_BMAP 12 #define EF_COMM 13 #define EF_LOST 14 -#define EF_MAX 15 -/* Static game data (configuration): EF_MAX.. */ +/* Static game data (configuration) */ #define EF_SECTOR_CHR 15 #define EF_SHIP_CHR 16 #define EF_PLANE_CHR 17 @@ -127,6 +125,9 @@ struct empfile { #define EF_META 29 #define EF_META_TYPE 30 #define EF_META_FLAGS 31 +#define EF_MAX 32 + +#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST) struct fileinit { int ef_type; @@ -152,6 +153,6 @@ extern int ef_flags(int); extern int ef_byname(char *); extern int ef_byname_from(char *, int *); -extern struct empfile empfile[]; +extern struct empfile empfile[EF_MAX]; #endif /* _FILE_H_ */ diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index f13ae3ef..dac00d9e 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -80,19 +80,6 @@ /* FIXME document dump format */ /* FIXME don't dump stuff that's useless due to options */ -/* - * 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 -my_ef_byname(char *name) -{ - return stmtch(name, empfile, offsetof(struct empfile, name), - sizeof(empfile[0])); -} - /* * Evaluate a attribute of an object into VAL, return VAL. * TYPE is the attribute's type. @@ -379,11 +366,12 @@ xdump(void) if (!p) return RET_SYN; - type = my_ef_byname(p); - if (type >= EF_MAX || (meta && type >=0)) - return xdchr(type, meta); - else if (type >= 0) { - return xditem(type, player->argp[2]); + type = ef_byname(p); + if (type >= 0) { + if (meta || !EF_IS_GAME_STATE(type)) + return xdchr(type, meta); + else + return xditem(type, player->argp[2]); } else if (!strncmp(p, "opt", strlen(p))) { return xdopt(); } else if (!strncmp(p, "ver", strlen(p))) { diff --git a/src/util/files.c b/src/util/files.c index 9a7d9340..2261a829 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -123,6 +123,8 @@ main(int argc, char *argv[]) exit(1); } for (i = 0; i < EF_MAX; i++) { + if (!EF_IS_GAME_STATE(i)) + continue; if (!ef_open(i, EFF_CREATE)) { perror("ef_open"); exit(1); @@ -180,6 +182,8 @@ main(int argc, char *argv[]) ef_write(EF_BMAP, i, map); } for (i = 0; i < EF_MAX; i++) { + if (!EF_IS_GAME_STATE(i)) + continue; ef_close(i); }