summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2007-06-21 11:33:46 +0000
committerSimon Howard2007-06-21 11:33:46 +0000
commited6191430b27a5447ef2675f2cfe19d8f0b88333 (patch)
treee7cd1d4d3d54a76717c6bc7f27050d865b4973bf
parentee2a6fda9fd817c191d74d0f1a00a4c05b4ed433 (diff)
downloadchocolate-doom-ed6191430b27a5447ef2675f2cfe19d8f0b88333.tar.gz
chocolate-doom-ed6191430b27a5447ef2675f2cfe19d8f0b88333.tar.bz2
chocolate-doom-ed6191430b27a5447ef2675f2cfe19d8f0b88333.zip
Add arrlen() macro as a clearer way of doing sizeof(array) /
sizeof(*array) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 922
-rw-r--r--setup/configfile.c5
-rw-r--r--setup/keyboard.c3
-rw-r--r--setup/mouse.c3
-rw-r--r--setup/multiplayer.c5
-rw-r--r--src/am_map.c14
-rw-r--r--src/d_iwad.c15
-rw-r--r--src/d_main.c2
-rw-r--r--src/deh_cheat.c2
-rw-r--r--src/deh_main.c10
-rw-r--r--src/deh_misc.c4
-rw-r--r--src/doomtype.h2
-rw-r--r--src/f_finale.c2
-rw-r--r--src/i_pcsound.c6
-rw-r--r--src/i_sdlmusic.c2
-rw-r--r--src/i_sdlsound.c2
-rw-r--r--src/m_misc.c4
-rw-r--r--src/wi_stuff.c6
17 files changed, 42 insertions, 45 deletions
diff --git a/setup/configfile.c b/setup/configfile.c
index d9b17af2..984df6b2 100644
--- 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_t doom_defaults_list[] =
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_t extra_defaults_list[] =
static default_collection_t extra_defaults =
{
extra_defaults_list,
- sizeof(extra_defaults_list) / sizeof(*extra_defaults_list),
+ arrlen(extra_defaults_list),
NULL,
};
diff --git a/setup/keyboard.c b/setup/keyboard.c
index e558840a..3a7ccb8f 100644
--- 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 @@ static void KeySetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
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)
{
diff --git a/setup/mouse.c b/setup/mouse.c
index bafccc87..147c6938 100644
--- 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 @@ static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
// 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)
diff --git a/setup/multiplayer.c b/setup/multiplayer.c
index e06fa6ab..5e35dbbc 100644
--- 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 @@ static iwad_t *GetIWADForDescription(char *description)
{
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 @@ static txt_widget_t *IWADSelector(void)
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)
{
diff --git a/src/am_map.c b/src/am_map.c
index 11f77c1e..347d592f 100644
--- a/src/am_map.c
+++ b/src/am_map.c
@@ -171,7 +171,6 @@ mline_t player_arrow[] = {
{ { -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 @@ mline_t cheat_player_arrow[] = {
{ { 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 @@ mline_t triangle_guy[] = {
{ { 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 @@ mline_t thintriangle_guy[] = {
{ { -.5*R, .7*R }, { -.5*R, -.7*R } }
};
#undef R
-#define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
@@ -800,7 +796,7 @@ void AM_updateLightLev(void)
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 @@ void AM_drawPlayers(void)
{
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 @@ void AM_drawPlayers(void)
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 @@ AM_drawThings
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;
}
diff --git a/src/d_iwad.c b/src/d_iwad.c
index 895b5afb..320ee835 100644
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -194,7 +194,7 @@ static void CheckUninstallStrings(void)
{
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 @@ static void CheckCollectorsEdition(void)
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 @@ static char *SearchDirectoryForIWAD(char *dir)
{
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 @@ static void IdentifyIWADByName(char *name)
gamemission = none;
- for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{
char *iwadname;
@@ -592,7 +591,7 @@ void D_SetSaveGameDir(void)
// 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 @@ static char *GetGameName(char *gamename)
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 @@ void D_FindInstalledIWADs(void)
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)
{
diff --git a/src/d_main.c b/src/d_main.c
index 6981b884..ca459022 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -631,7 +631,7 @@ void PrintDehackedBanners(void)
{
size_t i;
- for (i=0; i<sizeof(copyright_banners) / sizeof(char *); ++i)
+ for (i=0; i<arrlen(copyright_banners); ++i)
{
char *deh_s;
diff --git a/src/deh_cheat.c b/src/deh_cheat.c
index 6536ca3d..28f32572 100644
--- a/src/deh_cheat.c
+++ b/src/deh_cheat.c
@@ -64,7 +64,7 @@ static deh_cheat_t *FindCheatByName(char *name)
{
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];
diff --git a/src/deh_main.c b/src/deh_main.c
index ab205248..7d86e4b2 100644
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -77,8 +77,6 @@ static deh_section_t *section_types[] =
&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 @@ void DEH_Checksum(md5_digest_t digest)
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 @@ static void InitialiseSections(void)
{
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 @@ static deh_section_t *GetSectionByName(char *name)
{
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 @@ static boolean CheckSignatures(deh_context_t *context)
// 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))
{
diff --git a/src/deh_misc.c b/src/deh_misc.c
index 8f65afae..ea99fb12 100644
--- a/src/deh_misc.c
+++ b/src/deh_misc.c
@@ -206,7 +206,7 @@ static void DEH_MiscParseLine(deh_context_t *context, char *line, void *tag)
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 @@ static void DEH_MiscMD5Sum(md5_context_t *context)
{
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);
}
diff --git a/src/doomtype.h b/src/doomtype.h
index 5b2faf38..2c9680b3 100644
--- a/src/doomtype.h
+++ b/src/doomtype.h
@@ -71,5 +71,7 @@ typedef uint8_t byte;
#endif
+#define arrlen(array) (sizeof(array) / sizeof(*array))
+
#endif
diff --git a/src/f_finale.c b/src/f_finale.c
index c81649dd..7674f09f 100644
--- a/src/f_finale.c
+++ b/src/f_finale.c
@@ -132,7 +132,7 @@ void F_StartFinale (void)
// 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];
diff --git a/src/i_pcsound.c b/src/i_pcsound.c
index 08ba92e9..19d23cfb 100644
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -60,8 +60,6 @@ static float frequencies[] = {
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 @@ static void PCSCallbackFunc(int *duration, int *freq)
// 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 @@ static snddevice_t sound_pcsound_devices[] =
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,
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 4ece1555..28c8f60f 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -337,7 +337,7 @@ static snddevice_t music_sdl_devices[] =
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,
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index 920e74d2..8e10a932 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -434,7 +434,7 @@ static snddevice_t sound_sdl_devices[] =
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,
diff --git a/src/m_misc.c b/src/m_misc.c
index 92510734..451d9b31 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -401,7 +401,7 @@ static default_t doom_defaults_list[] =
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_t extra_defaults_list[] =
static default_collection_t extra_defaults =
{
extra_defaults_list,
- sizeof(extra_defaults_list) / sizeof(*extra_defaults_list),
+ arrlen(extra_defaults_list),
NULL,
};
diff --git a/src/wi_stuff.c b/src/wi_stuff.c
index 21809f45..c6e5c359 100644
--- a/src/wi_stuff.c
+++ b/src/wi_stuff.c
@@ -270,9 +270,9 @@ static anim_t epsd2animinfo[] =
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] =