ref: db3b531e2cab765a00475054d2e9046c9d0437d3
parent: 47cec547e59ac8c5012f6091394dcb4304d64fc3
author: Simon Tatham <anakin@pobox.com>
date: Tue Nov 13 17:06:19 EST 2018
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.
--- a/bridges.c
+++ b/bridges.c
@@ -632,7 +632,7 @@
#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 },
--- 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 @@
* Solver and all its little wizards.
*/
-int solver_recurse_depth;
+static int solver_recurse_depth;
typedef struct solver_ctx {
game_state *state;
--- a/lightup.c
+++ b/lightup.c
@@ -179,7 +179,7 @@
#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 },
--- a/map.c
+++ b/map.c
@@ -2624,7 +2624,7 @@
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 @@
{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
};
--- a/pearl.c
+++ b/pearl.c
@@ -282,8 +282,8 @@
* 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 @@
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 @@
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);
--- a/solo.c
+++ b/solo.c
@@ -146,9 +146,9 @@
#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,
--- a/tracks.c
+++ b/tracks.c
@@ -228,7 +228,7 @@
#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 @@
};
/* 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 @@
}
/* 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 @@
}
/* 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 @@
}
#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)
--- a/undead.c
+++ b/undead.c
@@ -397,7 +397,7 @@
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 @@
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 && x<w+1 && y>0 && y<h+1) return -1;
if (x<0 || x>w+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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
--- a/unequal.c
+++ b/unequal.c
@@ -1009,7 +1009,7 @@
#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)