]> git.pond.sub.org Git - empserver/commitdiff
New macro ARRAY_SIZE()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Dec 2020 05:15:40 +0000 (06:15 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 17 Jan 2021 20:24:28 +0000 (21:24 +0100)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/misc.h
src/lib/common/cargo.c
src/lib/common/filetable.c
src/lib/common/nsc.c
src/lib/subs/aircombat.c
src/lib/subs/fileinit.c
src/lib/subs/paths.c
src/lib/subs/show.c
src/lib/subs/snxtitem.c
src/lib/subs/snxtsct.c
src/server/update.c

index 7b428f091d39f21815f873d538e4497d2878ed48..b580633ae904759de6cc9dc60533a1f9d256655d 100644 (file)
@@ -29,7 +29,7 @@
  *
  *  Known contributors to this file:
  *     Doug Hay, 1998
- *     Markus Armbruster, 2004-2014
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef MISC_H
@@ -89,6 +89,11 @@ extern void (*oops_handler)(void);
 #define BUILD_ASSERT(cond) \
     ((void)BUILD_ASSERT_ONE(cond))
 
+/*
+ * Number of elements in ARRAY.
+ */
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+
 void exit_nomem(void) ATTRIBUTE((noreturn));
 
        /* return codes from command routines */
index a0d5948ec588909884d10c8065fdfafa659b30a2..e399a0b812746a19144b043a7862ac20861a8b8a 100644 (file)
@@ -27,7 +27,7 @@
  *  cargo.c: Cargo lists
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2009
+ *     Markus Armbruster, 2009-2020
  */
 
 #include <config.h>
@@ -94,7 +94,7 @@ clink_init(struct clink *cl)
     unsigned i;
 
     cl->next = -1;
-    for (i = 0; i < sizeof(cl->head) / sizeof(*cl->head); i++)
+    for (i = 0; i < ARRAY_SIZE(cl->head); i++)
        cl->head[i] = -1;
 }
 
index fd9fd39e423449bde15d47c78079e36222444c2c..bb123c3c369083492e559f3a6b7cc84165e40020 100644 (file)
@@ -27,7 +27,7 @@
  *  filetable.c: Empire game data file descriptions.
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2005-2016
+ *     Markus Armbruster, 2005-2020
  */
 
 #include <config.h>
@@ -70,9 +70,6 @@ static void nchr_oninit(void *);
 
 static char dummy_cache;
 
-/* Number of elements in ARRAY. */
-#define SZ(array) (sizeof(array) / sizeof((array)[0]))
-
 /* Initializers for members flags... */
 /* Unmapped cache */
 #define UNMAPPED_CACHE(type, nent, flags)      \
@@ -84,7 +81,7 @@ static char dummy_cache;
  */
 #define ARRAY_CACHE(array, flags) \
     sizeof(*(array)), -1, (flags), (char *)(array),    \
-    SZ((array)), 0, 0, 0, -1
+    ARRAY_SIZE((array)), 0, 0, 0, -1
 /*
  * Mapped cache, array with unknown size.
  * Member csize gets a bogus value, needs to be fixed up.
@@ -98,7 +95,7 @@ static char dummy_cache;
  */
 #define ARRAY_TABLE(array, nent, flags)                        \
     sizeof(*(array)), (nent), (flags), (char *)(array),        \
-    SZ((array)), 0, (nent), (nent), -1
+    ARRAY_SIZE((array)), 0, (nent), (nent), -1
 
 /* Common configuration table flags */
 #define EFF_CFG (EFF_PRIVATE | EFF_MEM | EFF_STATIC | EFF_SENTINEL)
index d37936cc67614d68b29d2950c3b4532ab19f4380..d66493e64518f82ff000a0f2a3241341b9072a3e 100644 (file)
@@ -27,7 +27,7 @@
  *  nsc.c: Empire selection global structures
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 /*
@@ -640,7 +640,7 @@ struct castr cou_ca[] = {
 #undef CURSTR
 };
 
-struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
+struct castr nat_ca[ARRAY_SIZE(cou_ca)];
 /* initialized by nsc_init() */
 
 struct castr relat_ca[] = {
index daf99ea12e12733dcda9ab67199e29a32392cde7..e8cc5b85713542135c49552b98d3417b3c537f53 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1992
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2014
+ *     Markus Armbruster, 2006-2020
  */
 
 #include <config.h>
@@ -716,7 +716,7 @@ ac_flak_dam(int guns, int def, int pl_flags)
         0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
     /*    +5    +6     +7     +8    >+8 */
         0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
-    enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
+    enum { FLAK_MAX = ARRAY_SIZE(flaktable) - 1 };
 
     flak = guns - def;
     if ((pl_flags & P_T) == 0)
index c3247ab05873bad9698bc25ec88e8501c44ab04d..e0aeabfe441bbda1981c823046576e4db29c77a2 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2016
+ *     Markus Armbruster, 2005-2020
  */
 
 #include <config.h>
@@ -63,7 +63,7 @@ ef_init_srv(int force_bad_state)
 {
     unsigned i;
 
-    for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
+    for (i = 0; i < ARRAY_SIZE(fileinit); i++) {
        empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
        empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
        empfile[fileinit[i].ef_type].onresize = fileinit[i].onresize;
index 49adb7ba16845bdd8140441d3e8c57f131f5b554..23bd3bb5641cb9b69c4d7449a63ac7e29698921b 100644 (file)
@@ -27,7 +27,7 @@
  *  paths.c: Routines associated with paths, directions, etc.
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2005-2011
+ *     Markus Armbruster, 2005-2020
  */
 
 #include <config.h>
@@ -73,7 +73,7 @@ diridx(char dir)
 {
     unsigned i = dir - 'a';
 
-    if (CANT_HAPPEN(i >= sizeof(dirindex) / sizeof(*dirindex)
+    if (CANT_HAPPEN(i >= ARRAY_SIZE(dirindex)
                    || dirindex[i] < 0))
        return DIR_STOP;
     return dirindex[i];
index ce3395e72be0ce68741d2945b8d8b0fce8130c5a..e294e2d662d78b039a04f37d9c44fced182dd941 100644 (file)
@@ -31,7 +31,7 @@
  *     Jeff Bailey, 1990
  *     Steve McClure, 1996
  *     Ron Koenderink, 2005-2009
- *     Markus Armbruster, 2006-2017
+ *     Markus Armbruster, 2006-2020
  */
 
 #include <config.h>
@@ -187,7 +187,7 @@ show_nuke_stats(int tlev)
 void
 show_nuke_build(int tlev)
 {
-    struct chr_index chridx[sizeof(nchr) / sizeof(*nchr)];
+    struct chr_index chridx[ARRAY_SIZE(nchr)];
     int n = make_nchr_index(chridx, tlev);
     int i;
     struct nchrstr *np;
@@ -208,7 +208,7 @@ show_nuke_build(int tlev)
 void
 show_nuke_capab(int tlev)
 {
-    struct chr_index chridx[sizeof(nchr) / sizeof(*nchr)];
+    struct chr_index chridx[ARRAY_SIZE(nchr)];
     int n = make_nchr_index(chridx, tlev);
     int i;
     struct nchrstr *np;
@@ -230,7 +230,7 @@ show_nuke_capab(int tlev)
 void
 show_ship_build(int tlev)
 {
-    struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
+    struct chr_index chridx[ARRAY_SIZE(mchr)];
     int n = make_mchr_index(chridx, tlev);
     int i;
     struct mchrstr *mp;
@@ -247,7 +247,7 @@ show_ship_build(int tlev)
 void
 show_ship_stats(int tlev)
 {
-    struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
+    struct chr_index chridx[ARRAY_SIZE(mchr)];
     int n = make_mchr_index(chridx, tlev);
     int i;
     struct mchrstr *mp;
@@ -268,7 +268,7 @@ show_ship_stats(int tlev)
 void
 show_ship_capab(int tlev)
 {
-    struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
+    struct chr_index chridx[ARRAY_SIZE(mchr)];
     int n = make_mchr_index(chridx, tlev);
     int i;
     struct mchrstr *mp;
@@ -286,7 +286,7 @@ show_ship_capab(int tlev)
 void
 show_plane_stats(int tlev)
 {
-    struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
+    struct chr_index chridx[ARRAY_SIZE(plchr)];
     int n = make_plchr_index(chridx, tlev);
     int i;
     struct plchrstr *pp;
@@ -304,7 +304,7 @@ show_plane_stats(int tlev)
 void
 show_plane_capab(int tlev)
 {
-    struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
+    struct chr_index chridx[ARRAY_SIZE(plchr)];
     int n = make_plchr_index(chridx, tlev);
     int i;
     struct plchrstr *pp;
@@ -321,7 +321,7 @@ show_plane_capab(int tlev)
 void
 show_plane_build(int tlev)
 {
-    struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
+    struct chr_index chridx[ARRAY_SIZE(plchr)];
     int n = make_plchr_index(chridx, tlev);
     int i;
     struct plchrstr *pp;
@@ -339,7 +339,7 @@ show_plane_build(int tlev)
 void
 show_land_build(int tlev)
 {
-    struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
+    struct chr_index chridx[ARRAY_SIZE(lchr)];
     int n = make_lchr_index(chridx, tlev);
     int i;
     struct lchrstr *lp;
@@ -358,7 +358,7 @@ show_land_build(int tlev)
 void
 show_land_capab(int tlev)
 {
-    struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
+    struct chr_index chridx[ARRAY_SIZE(lchr)];
     int n = make_lchr_index(chridx, tlev);
     int i;
     struct lchrstr *lcp;
@@ -376,7 +376,7 @@ show_land_capab(int tlev)
 void
 show_land_stats(int tlev)
 {
-    struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
+    struct chr_index chridx[ARRAY_SIZE(lchr)];
     int n = make_lchr_index(chridx, tlev);
     int i;
     struct lchrstr *lcp;
index 858e45cb4b56299792e4ef4f38b42aaef976f3fe..6cdd02b8275f1335b0e07ea065ba6d38969b9582 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1989
- *     Markus Armbruster, 2009-2011
+ *     Markus Armbruster, 2009-2020
  */
 
 #include <config.h>
@@ -241,7 +241,7 @@ snxtitem_use_condarg(struct nstr_item *np)
 
     if (!player->condarg)
        return 1;
-    n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
+    n = nstr_comp(np->cond, ARRAY_SIZE(np->cond),
                  np->type, player->condarg);
     if (n < 0)
        return 0;
index c4beac747b2801281a6eadc1f1f8c981e521acd5..2a29d369c971049a65cca12f5819633364b4a872 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1989
- *     Markus Armbruster, 2006-2011
+ *     Markus Armbruster, 2006-2020
  */
 
 #include <config.h>
@@ -127,7 +127,7 @@ snxtsct_use_condarg(struct nstr_sect *np)
 
     if (!player->condarg)
        return 1;
-    n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
+    n = nstr_comp(np->cond, ARRAY_SIZE(np->cond),
                  EF_SECTOR, player->condarg);
     if (n < 0)
        return 0;
index 66c89f11320f68a07fd4a9254531eb981cb8dfb7..a9f3248cc86d31e87cc8a966e10a90e13e8c4bac 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1994
  *     Steve McClure, 1996
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2007-2012
+ *     Markus Armbruster, 2007-2020
  */
 
 #include <config.h>
@@ -83,7 +83,7 @@ static int
 update_get_schedule(void)
 {
     time_t now = time(NULL);
-    int n = sizeof(update_time) / sizeof(*update_time);
+    int n = ARRAY_SIZE(update_time);
     int i;
 
     ef_truncate(EF_UPDATES, 0);