From db3b531e2cab765a00475054d2e9046c9d0437d3 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 13 Nov 2018 22:06:19 +0000 Subject: [PATCH] Add missing 'static' to game-internal declarations. Another thing I spotted while trawling the whole source base was that a couple of games had omitted 'static' on a lot of their internal functions. Checking with nm, there turned out to be quite a few more than I'd spotted by eye, so this should fix them all. Also added one missing 'const', on the lookup table nbits[] in Tracks. --- bridges.c | 2 +- galaxies.c | 4 ++-- lightup.c | 2 +- map.c | 4 ++-- pearl.c | 8 ++++---- solo.c | 6 +++--- tracks.c | 21 +++++++++++++-------- undead.c | 30 +++++++++++++++--------------- unequal.c | 2 +- 9 files changed, 42 insertions(+), 37 deletions(-) diff --git a/bridges.c b/bridges.c index 7ea7447..d12aa0b 100644 --- a/bridges.c +++ b/bridges.c @@ -632,7 +632,7 @@ static bool island_impossible(struct island *is, bool strict) #define DEFAULT_PRESET 0 -const struct game_params bridges_presets[] = { +static const struct game_params bridges_presets[] = { { 7, 7, 2, 30, 10, 1, 0 }, { 7, 7, 2, 30, 10, 1, 1 }, { 7, 7, 2, 30, 10, 1, 2 }, diff --git a/galaxies.c b/galaxies.c index e871e21..0cc3198 100644 --- a/galaxies.c +++ b/galaxies.c @@ -49,7 +49,7 @@ #ifdef DEBUGGING #define solvep debug #else -bool solver_show_working; +static bool solver_show_working; #define solvep(x) do { if (solver_show_working) { printf x; } } while(0) #endif @@ -1605,7 +1605,7 @@ static game_state *new_game(midend *me, const game_params *params, * Solver and all its little wizards. */ -int solver_recurse_depth; +static int solver_recurse_depth; typedef struct solver_ctx { game_state *state; diff --git a/lightup.c b/lightup.c index 67916e4..90811d5 100644 --- a/lightup.c +++ b/lightup.c @@ -179,7 +179,7 @@ static void get_surrounds(const game_state *state, int ox, int oy, #define DEFAULT_PRESET 0 -const struct game_params lightup_presets[] = { +static const struct game_params lightup_presets[] = { { 7, 7, 20, SYMM_ROT4, 0 }, { 7, 7, 20, SYMM_ROT4, 1 }, { 7, 7, 20, SYMM_ROT4, 2 }, diff --git a/map.c b/map.c index 2e64479..ac0bea1 100644 --- a/map.c +++ b/map.c @@ -2624,7 +2624,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds, ds->bl = blitter_new(dr, TILESIZE+3, TILESIZE+3); } -const float map_colours[FOUR][3] = { +static const float map_colours[FOUR][3] = { #ifdef VIVID_COLOURS /* Use more vivid colours (e.g. on the Pocket PC) */ {0.75F, 0.25F, 0.25F}, @@ -2638,7 +2638,7 @@ const float map_colours[FOUR][3] = { {0.55F, 0.45F, 0.35F}, #endif }; -const int map_hatching[FOUR] = { +static const int map_hatching[FOUR] = { HATCH_VERT, HATCH_SLASH, HATCH_HORIZ, HATCH_BACKSLASH }; diff --git a/pearl.c b/pearl.c index e6f41a9..ccbba51 100644 --- a/pearl.c +++ b/pearl.c @@ -282,8 +282,8 @@ static const char *validate_params(const game_params *params, bool full) * Solver. */ -int pearl_solve(int w, int h, char *clues, char *result, - int difficulty, bool partial) +static int pearl_solve(int w, int h, char *clues, char *result, + int difficulty, bool partial) { int W = 2*w+1, H = 2*h+1; short *workspace; @@ -921,7 +921,7 @@ struct pearl_loopgen_bias_ctx { grid *g; }; -int pearl_loopgen_bias(void *vctx, char *board, int face) +static int pearl_loopgen_bias(void *vctx, char *board, int face) { struct pearl_loopgen_bias_ctx *ctx = (struct pearl_loopgen_bias_ctx *)vctx; grid *g = ctx->g; @@ -1048,7 +1048,7 @@ int pearl_loopgen_bias(void *vctx, char *board, int face) return ctx->score; } -void pearl_loopgen(int w, int h, char *lines, random_state *rs) +static void pearl_loopgen(int w, int h, char *lines, random_state *rs) { grid *g = grid_new(GRID_SQUARE, w-1, h-1, NULL); char *board = snewn(g->num_faces, char); diff --git a/solo.c b/solo.c index 338aeeb..cfe38c5 100644 --- a/solo.c +++ b/solo.c @@ -146,9 +146,9 @@ enum { #define MAX_2SUMS 5 #define MAX_3SUMS 8 #define MAX_4SUMS 12 -unsigned long sum_bits2[18][MAX_2SUMS]; -unsigned long sum_bits3[25][MAX_3SUMS]; -unsigned long sum_bits4[31][MAX_4SUMS]; +static unsigned long sum_bits2[18][MAX_2SUMS]; +static unsigned long sum_bits3[25][MAX_3SUMS]; +static unsigned long sum_bits4[31][MAX_4SUMS]; static int find_sum_bits(unsigned long *array, int idx, int value_left, int addends_left, int min_addend, diff --git a/tracks.c b/tracks.c index dad8b9b..383a5d8 100644 --- a/tracks.c +++ b/tracks.c @@ -228,7 +228,7 @@ static const char *validate_params(const game_params *params, bool full) #define BLANK 0 #define UNKNOWN 15 -int nbits[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; +static const int nbits[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; /* square grid flags */ #define S_TRACK 1 /* a track passes through this square (--> 2 edges) */ @@ -263,25 +263,28 @@ struct game_state { }; /* Return the four directions in which a particular edge flag is set, around a square. */ -int S_E_DIRS(const game_state *state, int sx, int sy, unsigned int eflag) { +static int S_E_DIRS(const game_state *state, int sx, int sy, + unsigned int eflag) { return (state->sflags[sy*state->p.w+sx] >> ((eflag == E_TRACK) ? S_TRACK_SHIFT : S_NOTRACK_SHIFT)) & ALLDIR; } /* Count the number of a particular edge flag around a grid square. */ -int S_E_COUNT(const game_state *state, int sx, int sy, unsigned int eflag) { +static int S_E_COUNT(const game_state *state, int sx, int sy, + unsigned int eflag) { return nbits[S_E_DIRS(state, sx, sy, eflag)]; } /* Return the two flags (E_TRACK and/or E_NOTRACK) set on a specific * edge of a square. */ -unsigned S_E_FLAGS(const game_state *state, int sx, int sy, int d) { +static unsigned S_E_FLAGS(const game_state *state, int sx, int sy, int d) { unsigned f = state->sflags[sy*state->p.w+sx]; int t = (f & (d << S_TRACK_SHIFT)), nt = (f & (d << S_NOTRACK_SHIFT)); return (t ? E_TRACK : 0) | (nt ? E_NOTRACK : 0); } -bool S_E_ADJ(const game_state *state, int sx, int sy, int d, int *ax, int *ay, unsigned int *ad) { +static bool S_E_ADJ(const game_state *state, int sx, int sy, int d, int *ax, + int *ay, unsigned int *ad) { if (d == L && sx > 0) { *ax = sx-1; *ay = sy; *ad = R; return true; } if (d == R && sx < state->p.w-1) { *ax = sx+1; *ay = sy; *ad = L; return true; } if (d == U && sy > 0) { *ax = sx; *ay = sy-1; *ad = D; return true; } @@ -291,7 +294,8 @@ bool S_E_ADJ(const game_state *state, int sx, int sy, int d, int *ax, int *ay, u } /* Sets flag (E_TRACK or E_NOTRACK) on a given edge of a square. */ -void S_E_SET(game_state *state, int sx, int sy, int d, unsigned int eflag) { +static void S_E_SET(game_state *state, int sx, int sy, int d, + unsigned int eflag) { unsigned shift = (eflag == E_TRACK) ? S_TRACK_SHIFT : S_NOTRACK_SHIFT, ad; int ax, ay; @@ -303,7 +307,8 @@ void S_E_SET(game_state *state, int sx, int sy, int d, unsigned int eflag) { } /* Clears flag (E_TRACK or E_NOTRACK) on a given edge of a square. */ -void S_E_CLEAR(game_state *state, int sx, int sy, int d, unsigned int eflag) { +static void S_E_CLEAR(game_state *state, int sx, int sy, int d, + unsigned int eflag) { unsigned shift = (eflag == E_TRACK) ? S_TRACK_SHIFT : S_NOTRACK_SHIFT, ad; int ax, ay; @@ -389,7 +394,7 @@ static void free_game(game_state *state) } #define NDIRS 4 -const unsigned int dirs_const[] = { U, D, L, R }; +static const unsigned int dirs_const[] = { U, D, L, R }; static unsigned int find_direction(game_state *state, random_state *rs, int x, int y) diff --git a/undead.c b/undead.c index 3dceed8..781c15d 100644 --- a/undead.c +++ b/undead.c @@ -397,7 +397,7 @@ enum { DIRECTION_DOWN }; -int range2grid(int rangeno, int width, int height, int *x, int *y) { +static int range2grid(int rangeno, int width, int height, int *x, int *y) { if (rangeno < 0) { *x = 0; *y = 0; return DIRECTION_NONE; @@ -421,7 +421,7 @@ int range2grid(int rangeno, int width, int height, int *x, int *y) { return DIRECTION_NONE; } -int grid2range(int x, int y, int w, int h) { +static int grid2range(int x, int y, int w, int h) { if (x>0 && x0 && yw+1 || y<0 || y>h+1) return -1; if ((x == 0 || x==w+1) && (y==0 || y==h+1)) return -1; @@ -431,7 +431,7 @@ int grid2range(int x, int y, int w, int h) { return 2*(w+h) - y; } -void make_paths(game_state *state) { +static void make_paths(game_state *state) { int i; int count = 0; @@ -529,7 +529,7 @@ struct guess { int *possible; }; -bool next_list(struct guess *g, int pos) { +static bool next_list(struct guess *g, int pos) { if (pos == 0) { if ((g->guess[pos] == 1 && g->possible[pos] == 1) || @@ -587,7 +587,7 @@ bool next_list(struct guess *g, int pos) { return false; } -void get_unique(game_state *state, int counter, random_state *rs) { +static void get_unique(game_state *state, int counter, random_state *rs) { int p,i,c,pathlimit,count_uniques; struct guess path_guess; @@ -765,8 +765,8 @@ void get_unique(game_state *state, int counter, random_state *rs) { return; } -int count_monsters(game_state *state, - int *cGhost, int *cVampire, int *cZombie) { +static int count_monsters(game_state *state, + int *cGhost, int *cVampire, int *cZombie) { int cNone; int i; @@ -782,7 +782,7 @@ int count_monsters(game_state *state, return cNone; } -bool check_numbers(game_state *state, int *guess) { +static bool check_numbers(game_state *state, int *guess) { bool valid; int i; int count_ghosts, count_vampires, count_zombies; @@ -803,7 +803,7 @@ bool check_numbers(game_state *state, int *guess) { return valid; } -bool check_solution(int *g, struct path path) { +static bool check_solution(int *g, struct path path) { int i; bool mirror; int count; @@ -835,7 +835,7 @@ bool check_solution(int *g, struct path path) { return true; } -bool solve_iterative(game_state *state, struct path *paths) { +static bool solve_iterative(game_state *state, struct path *paths) { bool solved; int p,i,j,count; @@ -908,7 +908,7 @@ bool solve_iterative(game_state *state, struct path *paths) { return solved; } -bool solve_bruteforce(game_state *state, struct path *paths) { +static bool solve_bruteforce(game_state *state, struct path *paths) { bool solved, correct; int number_solutions; int p,i; @@ -964,7 +964,7 @@ bool solve_bruteforce(game_state *state, struct path *paths) { return solved; } -int path_cmp(const void *a, const void *b) { +static int path_cmp(const void *a, const void *b) { const struct path *pa = (const struct path *)a; const struct path *pb = (const struct path *)b; return pa->num_monsters - pb->num_monsters; @@ -1307,7 +1307,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, return desc; } -void num2grid(int num, int width, int height, int *x, int *y) { +static void num2grid(int num, int width, int height, int *x, int *y) { *x = 1+(num%width); *y = 1+(num/width); return; @@ -1920,7 +1920,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, return NULL; } -bool check_numbers_draw(game_state *state, int *guess) { +static bool check_numbers_draw(game_state *state, int *guess) { bool valid, filled; int i,x,y,xy; int count_ghosts, count_vampires, count_zombies; @@ -1976,7 +1976,7 @@ bool check_numbers_draw(game_state *state, int *guess) { return valid; } -bool check_path_solution(game_state *state, int p) { +static bool check_path_solution(game_state *state, int p) { int i; bool mirror; int count; diff --git a/unequal.c b/unequal.c index be1808b..d5b2bb1 100644 --- a/unequal.c +++ b/unequal.c @@ -1009,7 +1009,7 @@ int maxtries; #else #define MAXTRIES 50 #endif -int gg_solved; +static int gg_solved; static int game_assemble(game_state *new, int *scratch, digit *latin, int difficulty)