ref: ed6191430b27a5447ef2675f2cfe19d8f0b88333
parent: ee2a6fda9fd817c191d74d0f1a00a4c05b4ed433
author: Simon Howard <[email protected]>
date: Thu Jun 21 07:33:46 EDT 2007
Add arrlen() macro as a clearer way of doing sizeof(array) / sizeof(*array) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 922
--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -44,6 +44,7 @@
#include "doomfeatures.h"
#include "doomkeys.h"
+#include "doomtype.h"
#include "d_englsh.h"
#include "m_argv.h"
@@ -243,7 +244,7 @@
static default_collection_t doom_defaults =
{
doom_defaults_list,
- sizeof(doom_defaults_list) / sizeof(*doom_defaults_list),
+ arrlen(doom_defaults_list),
NULL,
};
@@ -282,7 +283,7 @@
static default_collection_t extra_defaults =
{
extra_defaults_list,
- sizeof(extra_defaults_list) / sizeof(*extra_defaults_list),
+ arrlen(extra_defaults_list),
NULL,
};
--- a/setup/keyboard.c
+++ b/setup/keyboard.c
@@ -19,6 +19,7 @@
// 02111-1307, USA.
//
#include "textscreen.h"
+#include "doomtype.h"
#include "execute.h"
#include "txt_keyinput.h"
@@ -72,7 +73,7 @@
TXT_CAST_ARG(int, variable);
unsigned int i;
- for (i=0; i<sizeof(allkeys) / sizeof(*allkeys); ++i)
+ for (i=0; i<arrlen(allkeys); ++i)
{
if (*variable == *allkeys[i] && allkeys[i] != variable)
{
--- a/setup/mouse.c
+++ b/setup/mouse.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include "textscreen.h"
+#include "doomtype.h"
#include "execute.h"
#include "txt_mouseinput.h"
@@ -64,7 +65,7 @@
// Check if the same mouse button is used for a different action
// If so, set the other action(s) to -1 (unset)
- for (i=0; i<sizeof(all_mouse_buttons) / sizeof(*all_mouse_buttons); ++i)
+ for (i=0; i<arrlen(all_mouse_buttons); ++i)
{
if (*all_mouse_buttons[i] == *variable
&& all_mouse_buttons[i] != variable)
--- a/setup/multiplayer.c
+++ b/setup/multiplayer.c
@@ -24,6 +24,7 @@
#include "d_englsh.h"
#include "textscreen.h"
+#include "doomtype.h"
#include "configfile.h"
@@ -112,7 +113,7 @@
{
int i;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
if (!strcmp(iwads[i].description, description))
{
@@ -405,7 +406,7 @@
num_iwads = 0;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
if (installed_iwads & iwads[i].mask)
{
--- a/src/am_map.c
+++ b/src/am_map.c
@@ -171,7 +171,6 @@
{ { -R+3*R/8, 0 }, { -R+R/8, -R/4 } }
};
#undef R
-#define NUMPLYRLINES (sizeof(player_arrow)/sizeof(mline_t))
#define R ((8*PLAYERRADIUS)/7)
mline_t cheat_player_arrow[] = {
@@ -193,7 +192,6 @@
{ { R/6+R/32, -R/7-R/32 }, { R/6+R/10, -R/7 } }
};
#undef R
-#define NUMCHEATPLYRLINES (sizeof(cheat_player_arrow)/sizeof(mline_t))
#define R (FRACUNIT)
mline_t triangle_guy[] = {
@@ -202,7 +200,6 @@
{ { 0, R }, { -.867*R, -.5*R } }
};
#undef R
-#define NUMTRIANGLEGUYLINES (sizeof(triangle_guy)/sizeof(mline_t))
#define R (FRACUNIT)
mline_t thintriangle_guy[] = {
@@ -211,7 +208,6 @@
{ { -.5*R, .7*R }, { -.5*R, -.7*R } }
};
#undef R
-#define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
@@ -800,7 +796,7 @@
if (amclock>nexttic)
{
lightlev = litelevels[litelevelscnt++];
- if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
+ if (litelevelscnt == arrlen(litelevels)) litelevelscnt = 0;
nexttic = amclock + 6 - (amclock % 6);
}
@@ -1262,11 +1258,11 @@
{
if (cheating)
AM_drawLineCharacter
- (cheat_player_arrow, NUMCHEATPLYRLINES, 0,
+ (cheat_player_arrow, arrlen(cheat_player_arrow), 0,
plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
else
AM_drawLineCharacter
- (player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
+ (player_arrow, arrlen(player_arrow), 0, plr->mo->angle,
WHITE, plr->mo->x, plr->mo->y);
return;
}
@@ -1288,7 +1284,7 @@
color = their_colors[their_color];
AM_drawLineCharacter
- (player_arrow, NUMPLYRLINES, 0, p->mo->angle,
+ (player_arrow, arrlen(player_arrow), 0, p->mo->angle,
color, p->mo->x, p->mo->y);
}
@@ -1308,7 +1304,7 @@
while (t)
{
AM_drawLineCharacter
- (thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
+ (thintriangle_guy, arrlen(thintriangle_guy),
16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
t = t->snext;
}
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -194,7 +194,7 @@
{
unsigned int i;
- for (i=0; i<sizeof(uninstall_values) / sizeof(*uninstall_values); ++i)
+ for (i=0; i<arrlen(uninstall_values); ++i)
{
char *val;
char *path;
@@ -237,8 +237,7 @@
return;
}
- for (i=0; i<sizeof(collectors_edition_subdirs)
- / sizeof(*collectors_edition_subdirs); ++i)
+ for (i=0; i<arrlen(collectors_edition_subdirs); ++i)
{
subpath = malloc(strlen(install_path)
+ strlen(collectors_edition_subdirs[i])
@@ -273,7 +272,7 @@
{
size_t i;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
char *filename;
char *iwadname;
@@ -312,7 +311,7 @@
gamemission = none;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
char *iwadname;
@@ -592,7 +591,7 @@
// This ensures that doom1.wad and doom.wad saves are stored
// in the same place.
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
if (gamemission == iwads[i].mission)
{
@@ -653,7 +652,7 @@
size_t i;
char *deh_sub;
- for (i=0; i<sizeof(banners) / sizeof(*banners); ++i)
+ for (i=0; i<arrlen(banners); ++i)
{
// Has the banner been replaced?
@@ -801,7 +800,7 @@
result = 0;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
if (D_FindWADByName(iwads[i].name) != NULL)
{
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -631,7 +631,7 @@
{
size_t i;
- for (i=0; i<sizeof(copyright_banners) / sizeof(char *); ++i)
+ for (i=0; i<arrlen(copyright_banners); ++i)
{
char *deh_s;
--- a/src/deh_cheat.c
+++ b/src/deh_cheat.c
@@ -64,7 +64,7 @@
{
size_t i;
- for (i=0; i<sizeof(allcheats) / sizeof(*allcheats); ++i)
+ for (i=0; i<arrlen(allcheats); ++i)
{
if (!strcasecmp(allcheats[i].name, name))
return &allcheats[i];
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -77,8 +77,6 @@
&deh_section_weapon,
};
-static int num_section_types = sizeof(section_types) / sizeof(*section_types);
-
void DEH_Checksum(md5_digest_t digest)
{
md5_context_t md5_context;
@@ -86,7 +84,7 @@
MD5_Init(&md5_context);
- for (i=0; i<num_section_types; ++i)
+ for (i=0; i<arrlen(section_types); ++i)
{
if (section_types[i]->md5_hash != NULL)
{
@@ -103,7 +101,7 @@
{
int i;
- for (i=0; i<num_section_types; ++i)
+ for (i=0; i<arrlen(section_types); ++i)
{
if (section_types[i]->init != NULL)
{
@@ -118,7 +116,7 @@
{
int i;
- for (i=0; i<num_section_types; ++i)
+ for (i=0; i<arrlen(section_types); ++i)
{
if (!strcasecmp(section_types[i]->name, name))
{
@@ -218,7 +216,7 @@
// Check all signatures to see if one matches
- for (i=0; i<sizeof(deh_signatures) / sizeof(*deh_signatures); ++i)
+ for (i=0; i<arrlen(deh_signatures); ++i)
{
if (!strcmp(deh_signatures[i], line))
{
--- a/src/deh_misc.c
+++ b/src/deh_misc.c
@@ -206,7 +206,7 @@
return;
}
- for (i=0; i<sizeof(misc_settings) / sizeof(*misc_settings); ++i)
+ for (i=0; i<arrlen(misc_settings); ++i)
{
if (!strcasecmp(variable_name, misc_settings[i].deh_name))
{
@@ -222,7 +222,7 @@
{
unsigned int i;
- for (i=0; i<sizeof(misc_settings) / sizeof(*misc_settings); ++i)
+ for (i=0; i<arrlen(misc_settings); ++i)
{
MD5_UpdateInt32(context, *misc_settings[i].value);
}
--- a/src/doomtype.h
+++ b/src/doomtype.h
@@ -71,5 +71,7 @@
#endif
+#define arrlen(array) (sizeof(array) / sizeof(*array))
+
#endif
--- a/src/f_finale.c
+++ b/src/f_finale.c
@@ -132,7 +132,7 @@
// Find the right screen and set the text and background
- for (i=0; i<sizeof(textscreens) / sizeof(textscreen_t); ++i)
+ for (i=0; i<arrlen(textscreens); ++i)
{
textscreen_t *screen = &textscreens[i];
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -60,8 +60,6 @@
2157.64, 2217.80, 2285.78, 2353.41, 2420.24, 2490.98, 2565.97, 2639.77,
};
-#define NUM_FREQUENCIES (sizeof(frequencies) / sizeof(*frequencies))
-
static void PCSCallbackFunc(int *duration, int *freq)
{
int tone;
@@ -84,7 +82,7 @@
// for a full discussion of this.
// Check we don't overflow the frequency table.
- if (tone < (int)NUM_FREQUENCIES)
+ if (tone < arrlen(frequencies))
{
*freq = (int) frequencies[tone];
}
@@ -286,7 +284,7 @@
sound_module_t sound_pcsound_module =
{
sound_pcsound_devices,
- sizeof(sound_pcsound_devices) / sizeof(*sound_pcsound_devices),
+ arrlen(sound_pcsound_devices),
I_PCS_InitSound,
I_PCS_ShutdownSound,
I_PCS_GetSfxLumpNum,
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -337,7 +337,7 @@
music_module_t music_sdl_module =
{
music_sdl_devices,
- sizeof(music_sdl_devices) / sizeof(*music_sdl_devices),
+ arrlen(music_sdl_devices),
I_SDL_InitMusic,
I_SDL_ShutdownMusic,
I_SDL_SetMusicVolume,
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -434,7 +434,7 @@
sound_module_t sound_sdl_module =
{
sound_sdl_devices,
- sizeof(sound_sdl_devices) / sizeof(*sound_sdl_devices),
+ arrlen(sound_sdl_devices),
I_SDL_InitSound,
I_SDL_ShutdownSound,
I_SDL_GetSfxLumpNum,
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -401,7 +401,7 @@
static default_collection_t doom_defaults =
{
doom_defaults_list,
- sizeof(doom_defaults_list) / sizeof(*doom_defaults_list),
+ arrlen(doom_defaults_list),
NULL,
};
@@ -444,7 +444,7 @@
static default_collection_t extra_defaults =
{
extra_defaults_list,
- sizeof(extra_defaults_list) / sizeof(*extra_defaults_list),
+ arrlen(extra_defaults_list),
NULL,
};
--- a/src/wi_stuff.c
+++ b/src/wi_stuff.c
@@ -270,9 +270,9 @@
static int NUMANIMS[NUMEPISODES] =
{
- sizeof(epsd0animinfo)/sizeof(anim_t),
- sizeof(epsd1animinfo)/sizeof(anim_t),
- sizeof(epsd2animinfo)/sizeof(anim_t)
+ arrlen(epsd0animinfo),
+ arrlen(epsd1animinfo),
+ arrlen(epsd2animinfo),
};
static anim_t *anims[NUMEPISODES] =