]> git.pond.sub.org Git - empserver/commitdiff
Replace some typedef names by enum tags.
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 5 Mar 2008 05:09:48 +0000 (06:09 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:42 +0000 (20:25 +0100)
Also get rid of some mildly silly manual packing of enum types.

13 files changed:
include/item.h
include/nat.h
include/nsc.h
include/optlist.h
include/prototypes.h
include/sect.h
src/lib/commands/edit.c
src/lib/common/nstreval.c
src/lib/global/nsc.c
src/lib/subs/nstr.c
src/lib/subs/sarg.c
src/lib/update/deliver.c
src/lib/update/distribute.c

index 6122fd07c6cdb684de5bc5d52abe9a7c9301a393..1c9e4cd5babd9e89a23689fa4f82f0767a7b8613 100644 (file)
 
 #include "misc.h"
 
-typedef enum {
+enum i_packing {
     IPKG,                      /* "inefficient" packaging (eff<60) */
     NPKG,                      /* no special packaging */
     WPKG,                      /* "warehouse" packaging */
     UPKG,                      /* "urban" packaging */
     BPKG                       /* "bank" packaging */
-} i_packing;
+};
 
 enum {
     NUMPKG = BPKG + 1
index b54c8bf9ebde001422ccfa564bb8a97f68f07da9..828b3dd5d4f8b826fbf89dd8eba765e161fef422 100644 (file)
@@ -44,7 +44,7 @@
 #define        MAXNOR          50      /* max # realms */
 
 /* Nation status */
-typedef enum {
+enum nat_status {
     /*
      * Don't change order without checking inequality comparisons and
      * array initializers!
@@ -55,7 +55,7 @@ typedef enum {
     STAT_SANCT,                        /* still in sanctuary */
     STAT_ACTIVE,               /* active (sanctuary broken) */
     STAT_GOD                   /* deity powers */
-} nat_status;
+};
 
 
 /*
@@ -84,7 +84,7 @@ struct natstr {
     short nat_uid;             /* equals nat_cnum */
     natid nat_cnum;            /* our country number */
     /* end of part matching struct empobj */
-    nat_status nat_stat;
+    enum nat_status nat_stat;
     char nat_cnam[20];         /* country name */
     char nat_pnam[20];         /* representative */
     char nat_hostaddr[32];     /* host addr of last user */
index 59aa813a9b280e8dd2da7b1dec4e9eb6852d6a81..03af0206f91e387ddce82182dee245afcbf9aeeb 100644 (file)
@@ -43,7 +43,7 @@
 #define NS_NCOND       16
 
 /* Value type */
-typedef enum {
+enum nsc_type {
     NSC_NOTYPE,
     /* promoted types */
     NSC_LONG,                  /* long */
@@ -64,8 +64,7 @@ typedef enum {
     NSC_STRINGY,               /* char[], may be zero-terminated */
     /* aliases, must match typedefs */
     NSC_NATID = NSC_UCHAR      /* nation id */
-} nsc_type;
-typedef char packed_nsc_type;
+};
 
 /* Is TYPE a promoted value type?  */
 #define NSC_IS_PROMOTED(type) (NSC_LONG <= (type) && (type) <= NSC_STRING)
@@ -79,13 +78,12 @@ typedef char packed_nsc_type;
      : 1/0)
 
 /* Value category */
-typedef enum {
+enum nsc_cat {
     NSC_NOCAT,
     NSC_VAL,                   /* evaluated value */
     NSC_OFF,                   /* symbolic value: at offset in object */
     NSC_ID                     /* unresolved identifier (internal use) */
-} nsc_cat;
-typedef char packed_nsc_cat;
+};
 
 /*
  * Value, possibly symbolic
@@ -112,8 +110,8 @@ typedef char packed_nsc_cat;
  * context object and sets VAL->val_as.sym for it.
  */
 struct valstr {
-    packed_nsc_type val_type;  /* type of value */
-    packed_nsc_cat val_cat;    /* category of value */
+    enum nsc_type val_type;    /* type of value */
+    enum nsc_cat val_cat;      /* category of value */
     union {
        struct {                /* cat NSC_OFF */
            ptrdiff_t off;
@@ -133,13 +131,13 @@ struct valstr {
 /* Compiled condition */
 struct nscstr {
     char operator;             /* '<', '=', '>', '#' */
-    packed_nsc_type optype;    /* operator type */
+    enum nsc_type optype;      /* operator type */
     struct valstr lft;         /* left operand */
     struct valstr rgt;         /* right operand */
 };
 
 /* Selection type */
-typedef enum {
+enum ns_seltype {
     NS_UNDEF,                  /* error value */
     NS_LIST,                   /* list of IDs */
     NS_DIST,                   /* circular area */
@@ -147,14 +145,14 @@ typedef enum {
     NS_ALL,                    /* everything */
     NS_XY,                     /* one sector area */
     NS_GROUP                   /* group, i.e. fleet, wing, army */
-} ns_seltype;
+};
 
 /* Sector iterator */
 struct nstr_sect {
     coord x, y;                        /* current x-y */
     coord dx, dy;              /* accumlated x,y travel */
     int id;                    /* return value of sctoff */
-    ns_seltype type;           /* type of query */
+    enum ns_seltype type;              /* type of query */
     int curdist;               /* dist query: current range */
     struct range range;                /* area of coverage */
     int dist;                  /* dist query: range */
@@ -167,7 +165,7 @@ struct nstr_sect {
 /* Item iterator */
 struct nstr_item {
     int cur;                   /* current item */
-    ns_seltype sel;            /* selection type */
+    enum ns_seltype sel;       /* selection type */
     int type;                  /* item type being selected */
     int curdist;               /* if NS_DIST, current item's dist */
     struct range range;                /* NS_AREA/NS_DIST: range selector */
@@ -198,7 +196,6 @@ enum {
     NSC_CONST = bit(2),                /* field cannot be changed */
     NSC_BITS = bit(3)          /* value consists of flag bits */
 };
-typedef unsigned char nsc_flags;
 
 /*
  * Selector descriptor
@@ -228,11 +225,11 @@ typedef unsigned char nsc_flags;
 struct castr {
     char *ca_name;
     ptrdiff_t ca_off;
-    packed_nsc_type ca_type;
+    enum nsc_type ca_type;
     unsigned short ca_len;
     void *(*ca_get)(struct valstr *, natid, void *);
     int ca_table;
-    nsc_flags ca_flags;
+    int ca_flags;
 };
 
 /* variables using the above */
@@ -289,11 +286,11 @@ extern struct symbol sector_navigation[];
 /* src/lib/subs/nstr.c */
 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
 extern char *nstr_comp_val(char *, struct valstr*, int);
-extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
+extern int nstr_coerce_val(struct valstr *, enum nsc_type, char *);
 extern int nstr_exec(struct nscstr *, int, void *);
 /* src/lib/common/nstreval.c */
 extern struct valstr *nstr_mksymval(struct valstr *, struct castr *, int);
-extern struct valstr *nstr_exec_val(struct valstr *, natid, void *, nsc_type);
+extern struct valstr *nstr_exec_val(struct valstr *, natid, void *, enum nsc_type);
 extern int nstr_promote(int);
 extern char *symbol_by_value(int, struct symbol *);
 /* src/lib/global/nsc.c */
index 083dcd9b98ba4fcbfcb27b9225a0e373335189e1..b91a761e8fd842fe582cbc3ea849d1233de4ead6 100644 (file)
@@ -69,7 +69,7 @@ enum {
 
 struct keymatch {
     char *km_key;              /* the key */
-    nsc_type km_type;          /* type of associated data */
+    enum nsc_type km_type;     /* type of associated data */
     void *km_data;             /* pointer to associated data */
     int km_flags;              /* useful flags */
     char *km_comment;          /* Comment (hopefully useful) */
index 6f9cdb95c8efb9a4d0c21c359b70d8f0a6f617cb..42ac4464e105f68c7b851467b0af0ccf4aa082fa 100644 (file)
@@ -612,7 +612,7 @@ extern void retreat_land(struct lndstr *, char);
 extern int check_retreat_and_do_shipdamage(struct shpstr *, int);
 extern int check_retreat_and_do_landdamage(struct lndstr *, int);
 /* sarg.c */
-extern ns_seltype sarg_type(char *);
+extern enum ns_seltype sarg_type(char *);
 extern int sarg_xy(char *, coord *, coord *);
 extern int sarg_area(char *, struct range *);
 extern int sarg_range(char *, coord *, coord *, int *);
index 0ba02ee8afa093c89bef7e8f95afbb8045b673ff..15aca8b9d44ecba1577317a9391d05696abe0f44 100644 (file)
@@ -90,13 +90,13 @@ struct sctstr {
     time_t sct_timestamp;      /* Last time this sector was written to */
 };
 
-typedef enum {
+enum d_navigation {
     NAV_NONE,  /* ships can't navigate */
     NAVOK,     /* ships can always navigate */
     NAV_02,    /* requires 2% effic to navigate */
     NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
     NAV_60     /* requires 60% effic to navigate */
-} d_navigation;
+};
 
 struct dchrstr {
     unsigned char d_uid;
@@ -104,8 +104,8 @@ struct dchrstr {
     int d_prd;                 /* product type */
     int d_peffic;              /* process efficiency, in percent */
     float d_mob0, d_mob1;      /* movement cost at 0 and 100% eff */
-    d_navigation d_nav;                /* navigation capability */
-    i_packing d_pkg;           /* type of packaging in these sects */
+    enum d_navigation d_nav;   /* navigation capability */
+    enum i_packing d_pkg;      /* type of packaging in these sects */
     float d_ostr;              /* offensive strength */
     float d_dstr;              /* defensive strength */
     int d_value;               /* resale ("collect") value */
index 4f3c1c40e06e50981822db985279a613ab5baba5..52279b8414aa0f2f3c7020e43a31af1d1e9825b5 100644 (file)
@@ -700,7 +700,7 @@ docountry(char op, int arg, char *p, struct natstr *np)
        np->nat_yorg = newy;
        break;
     case 's':
-       np->nat_stat = (nat_status)errcheck(arg, STAT_UNUSED, STAT_GOD);
+       np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD);
        break;
     case 'u':
        arg = errcheck(arg, 0, m_m_p_d);
index 72269112eea42ebdbe3ba43b4fed1b6c4b078f4d..952626f2799f10e1d6f302858792fb6f1a56588c 100644 (file)
@@ -69,10 +69,10 @@ nstr_mksymval(struct valstr *val, struct castr *ca, int idx)
  * nstr_coerce_val(VAL, WANT, STR) succeeded.
  */
 struct valstr *
-nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
+nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
 {
     char *memb_ptr;
-    nsc_type valtype;
+    enum nsc_type valtype;
     int idx;
     struct natstr *natp;
 
index 6c03d3f93b3aa7f70f218a7d601d091bec42c2c3..71edc220b120a69744bb280b7aff5420b17ce584 100644 (file)
@@ -181,9 +181,10 @@ struct castr dchr_ca[] = {
     {"peffic", fldoff(d_peffic), NSC_INT, 0, NULL, EF_BAD, 0},
     {"mob0", fldoff(d_mob0), NSC_FLOAT, 0, NULL, EF_BAD, 0},
     {"mob1", fldoff(d_mob1), NSC_FLOAT, 0, NULL, EF_BAD, 0},
-    {"nav", fldoff(d_nav), NSC_SITYPE(d_navigation), 0, NULL,
+    {"nav", fldoff(d_nav), NSC_SITYPE(enum d_navigation), 0, NULL,
      EF_SECTOR_NAVIGATION, 0},
-    {"pkg", fldoff(d_pkg), NSC_SITYPE(i_packing), 0, NULL, EF_PACKING, 0},
+    {"pkg", fldoff(d_pkg), NSC_SITYPE(enum i_packing), 0, NULL,
+     EF_PACKING, 0},
     {"ostr", fldoff(d_ostr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
     {"dstr", fldoff(d_dstr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
     {"value", fldoff(d_value), NSC_INT, 0, NULL, EF_BAD, 0},
@@ -541,7 +542,7 @@ struct castr cou_ca[] = {
      * necessary for foreign levels.
      */
     {"cnum", fldoff(nat_cnum), NSC_NATID, 0, NULL, EF_NATION, 0},
-    {"stat", fldoff(nat_stat), NSC_SITYPE(nat_status), 0, NULL,
+    {"stat", fldoff(nat_stat), NSC_SITYPE(enum nat_status), 0, NULL,
      EF_NATION_STATUS, NSC_EXTRA},
     {"cname", fldoff(nat_cnam), NSC_STRINGY, 20, NULL, EF_BAD, NSC_EXTRA},
     {"passwd", fldoff(nat_pnam), NSC_STRINGY, 20, NULL,
index 493894b6d788b5669507f04f51c3584c17481c20..9170326892321d51d71a4cbf06ffed2a421e104c 100644 (file)
@@ -483,10 +483,10 @@ cond_type_mismatch(char *str)
  * messages if it is a null pointer.
  */
 int
-nstr_coerce_val(struct valstr *val, nsc_type to, char *str)
+nstr_coerce_val(struct valstr *val, enum nsc_type to, char *str)
 {
     /* FIXME get rid of promotion?  */
-    nsc_type from = nstr_promote(val->val_type);
+    enum nsc_type from = nstr_promote(val->val_type);
 
     if (from == NSC_NOTYPE)
        return 0;
index cc80ab9a4460248afeddc58e7de4fe5d1d29f296..56da9151331562fa223e29e6e299530c78af74ff 100644 (file)
@@ -55,7 +55,7 @@
  *
  * or 0 for none of the above.
  */
-ns_seltype
+enum ns_seltype
 sarg_type(char *str)
 {
     int c;
index 651251fdfcad0ec413666f84c9de863d9da0aacd..8ee140ec3555158c0035068c087bd259cc253ee1 100644 (file)
@@ -42,7 +42,7 @@
 
 static int
 deliver(struct sctstr *from, struct ichrstr *ip, int dir,
-       int thresh, int amt_src, int plague, i_packing packing)
+       int thresh, int amt_src, int plague, enum i_packing packing)
 {
     struct sctstr *to;
     i_type vtype;                      /* item vartype */
@@ -126,7 +126,7 @@ dodeliver(struct sctstr *sp)
     int thresh;
     int dir;
     int plague;
-    i_packing packing;
+    enum i_packing packing;
     int n;
 
     if (sp->sct_mobil <= 0)
index f9b267747aed466e2fa255d902024489dc6a6e3c..462346d7e3a2c1120695d1023836e0843db080d4 100644 (file)
@@ -55,7 +55,7 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
     int thresh;
     int amt_dist;
     int amt_sect;
-    i_packing sect_packing, dist_packing;
+    enum i_packing sect_packing, dist_packing;
     int pack;
     double mcost;
     int diff;