From 543b0cba4f91b24d0a96ca3e4c75589a55136212 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 6 Apr 2004 21:37:52 +0000 Subject: [PATCH] (NS_UNDEF, NS_LIST, NS_DIST, NS_AREA, NS_ALL, NS_XY, NS_GROUP): Turn macros into enumeration constants. (ns_seltype): New. Use where appropriate. --- include/nsc.h | 39 +++++++++++++++++++++------------------ include/prototypes.h | 2 +- src/lib/commands/rada.c | 10 +++++----- src/lib/subs/sarg.c | 2 +- src/scripts/indent-emp | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/nsc.h b/include/nsc.h index b5d241b6c..59aa51179 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -42,7 +42,7 @@ #define NS_NCOND 16 /* Value type */ -enum nsc_type { +typedef enum { NSC_NOTYPE, /* promoted types */ NSC_LONG, /* long */ @@ -59,17 +59,15 @@ enum nsc_type { NSC_YCOORD, /* coord that needs y conversion */ NSC_TIME, /* time_t */ NSC_FLOAT /* float */ -}; -typedef enum nsc_type nsc_type; +} nsc_type; typedef char packed_nsc_type; /* Value category */ -enum nsc_cat { +typedef enum { NSC_NOCAT, NSC_VAL, /* evaluated value */ NSC_OFF /* symbolic value: at offset in object */ -}; -typedef enum nsc_cat nsc_cat; +} nsc_cat; typedef char packed_nsc_cat; enum { @@ -107,11 +105,23 @@ struct nscstr { struct valstr rgt; /* right operand */ }; +/* Selection type */ +typedef enum { + NS_UNDEF, /* error value */ + NS_LIST, /* list of IDs */ + NS_DIST, /* circular area */ + NS_AREA, /* rectangular area */ + 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 */ - int type; /* type of query */ + ns_seltype type; /* type of query */ int curdist; /* dist query: current range */ struct range range; /* area of coverage */ int dist; /* dist query: range */ @@ -121,9 +131,10 @@ struct nstr_sect { struct nscstr cond[NS_NCOND]; /* selection conditions */ }; +/* Item iterator */ struct nstr_item { int cur; /* current item */ - int sel; /* selection type */ + 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 */ @@ -134,19 +145,11 @@ struct nstr_item { int index; /* NS_LIST: index */ int list[NS_LSIZE]; /* NS_LIST: item list */ int (*read)(int type, int id, caddr_t ptr); /* read function */ - int flags; /* EFF_ flags */ + int flags; /* ef_flags(TYPE) */ int ncond; /* # of selection conditions */ - struct nscstr cond[NS_NCOND]; /* selection conditions */ + struct nscstr cond[NS_NCOND]; /* selection conditions */ }; -#define NS_UNDEF 0 -#define NS_LIST 1 -#define NS_DIST 2 -#define NS_AREA 3 -#define NS_ALL 4 -#define NS_XY 5 -#define NS_GROUP 6 - /* * Selector descriptor. * Value is at offset CA_OFF in the context object. diff --git a/include/prototypes.h b/include/prototypes.h index 9ccb2c491..f21940fcc 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -460,7 +460,7 @@ extern void retreat_land(struct lndstr *, s_char); extern int check_retreat_and_do_shipdamage(struct shpstr *, int); extern int check_retreat_and_do_landdamage(struct lndstr *, int); /* sarg.c */ -extern int sarg_type(s_char *); +extern ns_seltype sarg_type(s_char *); extern int sarg_xy(s_char *, coord *, coord *); extern int sarg_area(s_char *, register struct range *); extern int sarg_range(s_char *, coord *, coord *, int *); diff --git a/src/lib/commands/rada.c b/src/lib/commands/rada.c index 49f016e4c..5b9da325d 100644 --- a/src/lib/commands/rada.c +++ b/src/lib/commands/rada.c @@ -49,7 +49,6 @@ int rada(void) { s_char *cp; - int type; double tf; double tech; struct nstr_item ni; @@ -70,8 +69,8 @@ rada(void) "Radar from (unit # or sector(s)) : ", buf); if (cp == 0) return RET_SYN; - type = sarg_type(cp); - if (type == NS_AREA) { + switch (sarg_type(cp)) { + case NS_AREA: if (!snxtsct(&ns, cp)) return RET_SYN; tech = tfact(player->cnum, 8.0); @@ -87,7 +86,8 @@ rada(void) radmap(sect.sct_x, sect.sct_y, (int)sect.sct_effic, (int)(tech * 2.0), 0.0); } - } else if (type == NS_LIST || type == NS_GROUP) { + case NS_LIST: + case NS_GROUP: if (!from_unit) { /* assumes a NS_LIST return is a shipno */ if (!snxtitem(&ni, EF_SHIP, cp)) { @@ -139,7 +139,7 @@ rada(void) (int)tech, tf); } } - } else { + default: if (!from_unit) pr("Must use a ship or sector specifier\n"); else diff --git a/src/lib/subs/sarg.c b/src/lib/subs/sarg.c index d7ec1b83d..ef2a14996 100644 --- a/src/lib/subs/sarg.c +++ b/src/lib/subs/sarg.c @@ -53,7 +53,7 @@ * * or 0 for none of the above. */ -int +ns_seltype sarg_type(s_char *ptr) { int c; diff --git a/src/scripts/indent-emp b/src/scripts/indent-emp index a16273fc7..339d2886d 100755 --- a/src/scripts/indent-emp +++ b/src/scripts/indent-emp @@ -2,7 +2,7 @@ # indent needs to know type names do to a proper job. # Type names located with grep typedef, then extracted by hand: -types="bit_fdmask bit_mask caddr_t coord ef_fileinit emp_sig_t empth_sem_t empth_t intp iop_t iovec_t loc_Sem_t loc_Thread_t natid nsc_cat nsc_flags nsc_type packed_nsc_cat packed_nsc_type plate_e pointer qsort_func_t s_char stkalign_t u_char u_int u_short vf_ptr voidfunc" +types="bit_fdmask bit_mask caddr_t coord ef_fileinit emp_sig_t empth_sem_t empth_t intp iop_t iovec_t loc_Sem_t loc_Thread_t natid ns_seltype nsc_cat nsc_flags nsc_type packed_nsc_cat packed_nsc_type plate_e pointer qsort_func_t s_char stkalign_t u_char u_int u_short vf_ptr voidfunc" opts="-kr -cdw -cp8 -ncs -psl -ss" for t in $types -- 2.43.0