include/file.h

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  file.h: Describes Empire tables (`files' for historical reasons)
00029  * 
00030  *  Known contributors to this file:
00031  *     Markus Armbruster, 2005
00032  */
00033 
00034 #ifndef FILE_H
00035 #define FILE_H
00036 
00037 #include <time.h>
00038 
00039 struct empfile {
00040     /* Members with immutable values */
00041     int uid;                    /* Table ID */
00042     char *name;                 /* Empire name (e.g., "treaty") */
00043     char *file;                 /* if backed by file, file name relative to
00044                                    data directory */
00045     struct castr *cadef;        /* table column selectors (column meta-data) */
00046     int size;                   /* size of a table entry */
00047     int flags;                  /* only EFF_IMMUTABLE immutable, see below
00048                                    for use of remaining bits */
00049     /* Members whose values are fixed when the cache is mapped */
00050     char *cache;                /* pointer to cache */
00051     int csize;                  /* cache size, in entries */
00052     /* and flags bit EFF_MEM */
00053     /* Members whose values may vary throughout operation */
00054     int baseid;                 /* id of first entry in cache */
00055     int cids;                   /* # entries in cache */
00056     int fids;                   /* # entries in table */
00057     int fd;                     /* file descriptor, -1 if not open */
00058     /* and flags bit EFF_RDONLY */
00059     /* User callbacks */
00060     void (*init)(int, void *);  /* called after entry creation, unless null */
00061     int (*postread)(int, void *); /* called after read, unless null */
00062     int (*prewrite)(int, void *); /* called before write, unless null */
00063 };
00064 
00065 /*
00066  * Flag bits for struct empfile member flags
00067  * Immutable flags are properties of the table and thus cannot change.
00068  * The remaining flags record how the table is being used.
00069  */
00070 /* Immutable flags, fixed at compile-time */
00071 /*
00072  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
00073  * group of such a table's entries can be safely obtained by
00074  * dereferencing entry address cast to struct empobj *.
00075  */
00076 #define EFF_XY          bit(0)
00077 #define EFF_OWNER       bit(1)
00078 #define EFF_GROUP       bit(2)
00079 /* Table is allocated statically */
00080 #define EFF_STATIC      bit(3)
00081 /* All the immutable flags */
00082 #define EFF_IMMUTABLE   (EFF_XY | EFF_OWNER | EFF_GROUP | EFF_STATIC)
00083 /* Flags set when table contents is mapped */
00084 /* Table is entirely in memory */
00085 #define EFF_MEM         bit(8)
00086 /* Table is read-only */
00087 #define EFF_RDONLY      bit(9)
00088 /* Table is customized (configuration tables only) */
00089 #define EFF_CUSTOM      bit(10)
00090 /* Transient flags, only occur in argument of ef_open() */
00091 /* Create table file, clobbering any existing file */
00092 #define EFF_CREATE      bit(11)
00093 
00094 /*
00095  * Empire `file types'
00096  * These are really table IDs.  Some tables are backed by files, some
00097  * are compiled into the server.
00098  */
00099 enum {
00100     /* Error value */
00101     EF_BAD = -1,
00102     /* Dynamic game data tables */
00103     EF_SECTOR,
00104     EF_SHIP,
00105     EF_PLANE,
00106     EF_LAND,
00107     EF_NUKE,
00108     EF_NEWS,
00109     EF_TREATY,
00110     EF_TRADE,
00111     EF_POWER,
00112     EF_NATION,
00113     EF_LOAN,
00114     EF_MAP,
00115     EF_BMAP,
00116     EF_COMM,
00117     EF_LOST,
00118     EF_REALM,
00119     EF_GAME,
00120     EF_DYNMAX = EF_GAME,
00121     /* Static game data (configuration) */
00122     /* Order is relevant; see read_builtin_tables() */
00123     EF_ITEM,
00124     EF_PRODUCT,
00125     EF_SECTOR_CHR,
00126     EF_SHIP_CHR,
00127     EF_PLANE_CHR,
00128     EF_LAND_CHR,
00129     EF_NUKE_CHR,
00130     EF_NEWS_CHR,
00131     EF_INFRASTRUCTURE,
00132     EF_UPDATES,                 /* not actually static */
00133     EF_TABLE,
00134     EF_META,
00135     /* Symbol tables */
00136     EF_AGREEMENT_STATUS,
00137     EF_LAND_CHR_FLAGS,
00138     EF_LEVEL,
00139     EF_META_FLAGS,
00140     EF_META_TYPE,
00141     EF_MISSIONS,
00142     EF_NATION_FLAGS,
00143     EF_NATION_REJECTS,
00144     EF_NATION_RELATIONS,
00145     EF_NATION_STATUS,
00146     EF_NUKE_CHR_FLAGS,
00147     EF_PACKING,
00148     EF_PAGE_HEADINGS,
00149     EF_PLAGUE_STAGES,
00150     EF_PLANE_CHR_FLAGS,
00151     EF_PLANE_FLAGS,
00152     EF_RESOURCES,
00153     EF_RETREAT_FLAGS,
00154     EF_SECTOR_NAVIGATION,
00155     EF_SHIP_CHR_FLAGS,
00156     EF_TREATY_FLAGS,
00157     /* Views */
00158     EF_COUNTRY,
00159     /* Number of types: */
00160     EF_MAX
00161 };
00162 
00163 #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_DYNMAX)
00164 #define EF_IS_VIEW(type) (EF_COUNTRY <= (type) && (type) < EF_MAX)
00165 
00166 extern struct castr *ef_cadef(int);
00167 extern int ef_read(int, int, void *);
00168 extern void *ef_ptr(int, int);
00169 extern char *ef_nameof(int);
00170 extern time_t ef_mtime(int);
00171 extern int ef_open(int, int);
00172 extern int ef_check(int);
00173 extern int ef_close(int);
00174 extern int ef_flush(int);
00175 extern int ef_write(int, int, void *);
00176 extern int ef_extend(int, int);
00177 extern int ef_ensure_space(int, int, int);
00178 extern int ef_nelem(int);
00179 extern int ef_flags(int);
00180 extern int ef_byname(char *);
00181 extern int ef_byname_from(char *, int *);
00182 extern void ef_init(void);
00183 extern int ef_verify(void);
00184 extern int ef_elt_byname(int, char *);
00185 
00186 extern struct empfile empfile[EF_MAX + 1];
00187 
00188 #endif

Generated on Fri Mar 28 11:01:10 2008 for empserver by  doxygen 1.5.2