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