]> git.pond.sub.org Git - empserver/commitdiff
(NS_UNDEF, NS_LIST, NS_DIST, NS_AREA, NS_ALL, NS_XY, NS_GROUP): Turn
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 6 Apr 2004 21:37:52 +0000 (21:37 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 6 Apr 2004 21:37:52 +0000 (21:37 +0000)
macros into enumeration constants.
(ns_seltype): New.  Use where appropriate.

include/nsc.h
include/prototypes.h
src/lib/commands/rada.c
src/lib/subs/sarg.c
src/scripts/indent-emp

index b5d241b6c3c17fb82b0b01549287cc29bc78b7f9..59aa51179a6ab3fc5e2fb48dca13e4a10159102a 100644 (file)
@@ -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.
index 9ccb2c491b74be4a2632ff7fd994d629f532eaed..f21940fcc9449ca8ad122cfdf54256b390959097 100644 (file)
@@ -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 *);
index 49f016e4c8b603afeb32332a02f83d202c71d9e7..5b9da325d510cf0cf3b4fdf39575f90d1799c3dc 100644 (file)
@@ -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
index d7ec1b83d86f005077de009d67f8cfe67f718a2f..ef2a149961b57ffecbf3216c2a3b631f830c0034 100644 (file)
@@ -53,7 +53,7 @@
  *
  * or 0 for none of the above.
  */
-int
+ns_seltype
 sarg_type(s_char *ptr)
 {
     int c;
index a16273fc7470907568397ceff58fb4f16eae1942..339d2886de8db29776c19b172195c93299aed0fb 100755 (executable)
@@ -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