From 06a0036c63e5b16b8d5408e1935daf35b66700c7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 5 Mar 2008 06:09:48 +0100 Subject: [PATCH] Replace some typedef names by enum tags. Also get rid of some mildly silly manual packing of enum types. --- include/item.h | 4 ++-- include/nat.h | 6 +++--- include/nsc.h | 33 +++++++++++++++------------------ include/optlist.h | 2 +- include/prototypes.h | 2 +- include/sect.h | 8 ++++---- src/lib/commands/edit.c | 2 +- src/lib/common/nstreval.c | 4 ++-- src/lib/global/nsc.c | 7 ++++--- src/lib/subs/nstr.c | 4 ++-- src/lib/subs/sarg.c | 2 +- src/lib/update/deliver.c | 4 ++-- src/lib/update/distribute.c | 2 +- 13 files changed, 39 insertions(+), 41 deletions(-) diff --git a/include/item.h b/include/item.h index 6122fd07..1c9e4cd5 100644 --- a/include/item.h +++ b/include/item.h @@ -36,13 +36,13 @@ #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 diff --git a/include/nat.h b/include/nat.h index b54c8bf9..828b3dd5 100644 --- a/include/nat.h +++ b/include/nat.h @@ -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 */ diff --git a/include/nsc.h b/include/nsc.h index 59aa813a..03af0206 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -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 */ diff --git a/include/optlist.h b/include/optlist.h index 083dcd9b..b91a761e 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -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) */ diff --git a/include/prototypes.h b/include/prototypes.h index 6f9cdb95..42ac4464 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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 *); diff --git a/include/sect.h b/include/sect.h index 0ba02ee8..15aca8b9 100644 --- a/include/sect.h +++ b/include/sect.h @@ -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 */ diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 4f3c1c40..52279b84 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -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); diff --git a/src/lib/common/nstreval.c b/src/lib/common/nstreval.c index 72269112..952626f2 100644 --- a/src/lib/common/nstreval.c +++ b/src/lib/common/nstreval.c @@ -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; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 6c03d3f9..71edc220 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -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, diff --git a/src/lib/subs/nstr.c b/src/lib/subs/nstr.c index 493894b6..91703268 100644 --- a/src/lib/subs/nstr.c +++ b/src/lib/subs/nstr.c @@ -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; diff --git a/src/lib/subs/sarg.c b/src/lib/subs/sarg.c index cc80ab9a..56da9151 100644 --- a/src/lib/subs/sarg.c +++ b/src/lib/subs/sarg.c @@ -55,7 +55,7 @@ * * or 0 for none of the above. */ -ns_seltype +enum ns_seltype sarg_type(char *str) { int c; diff --git a/src/lib/update/deliver.c b/src/lib/update/deliver.c index 651251fd..8ee140ec 100644 --- a/src/lib/update/deliver.c +++ b/src/lib/update/deliver.c @@ -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) diff --git a/src/lib/update/distribute.c b/src/lib/update/distribute.c index f9b26774..462346d7 100644 --- a/src/lib/update/distribute.c +++ b/src/lib/update/distribute.c @@ -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;