]> git.pond.sub.org Git - empserver/commitdiff
(EF_IS_GAME_STATE): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 28 Oct 2005 07:03:31 +0000 (07:03 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 28 Oct 2005 07:03:31 +0000 (07:03 +0000)
(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
src/lib/commands/xdump.c
src/util/files.c

index 2739558068eef4a8efefb8ae5e497b600b191d6d..ae592f0a2cf7c0c15bd8431e0305daa36958cb04 100644 (file)
@@ -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 allocated statically */
+#define EFF_STATIC     bit(3)
+/* Flags set when table contents is mapped */
 /* Table is entirely in memory */
-#define EFF_MEM                bit(3)
+#define EFF_MEM                bit(4)
 /* Table is read-only */
-#define EFF_RDONLY     bit(4)
+#define EFF_RDONLY     bit(5)
+/* Transient flags, just to control ef_open() */
 /* Create table file, clobbering any existing file */
-#define EFF_CREATE     bit(5)
-/* Table is allocated statically */
-#define EFF_STATIC     bit(6)
+#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_ */
index f13ae3ef2dec86fc2070ae83a13e6f2eb0e82f57..dac00d9ea7d1ff202a3124ac25297aae24030158 100644 (file)
 /* 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))) {
index 9a7d9340003cf5d92e2cda9e309e09081fd835d3..2261a82908b86d78c9d228227c8eed5d8d1d2386 100644 (file)
@@ -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);
     }