chiark / gitweb /
Add missing 'static' to game-internal declarations.
authorSimon Tatham <anakin@pobox.com>
Tue, 13 Nov 2018 22:06:19 +0000 (22:06 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 13 Nov 2018 22:06:19 +0000 (22:06 +0000)
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
galaxies.c
lightup.c
map.c
pearl.c
solo.c
tracks.c
undead.c
unequal.c

index 7ea7447b5d5ed4321e42a7c25da5b2a3c46bf85e..d12aa0bb6cd1460a9c27f3c8ffada65305ad18de 100644 (file)
--- 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 },
index e871e214c5f662c798af7bd03c84e5792a6019e1..0cc3198ae098da137436dfb2a64b8136fc4aae89 100644 (file)
@@ -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;
index 67916e4089f2983a8d567f0fae6960b0d98e02ee..90811d5475873b53e9eaac896a7d89710ad18d89 100644 (file)
--- 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 2e64479d1e77a54321b088dde3a0ce58ff002515..ac0bea1a5a23aa9ac5daf040766ec2c39ba5d227 100644 (file)
--- 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 e6f41a992c92d350d3fa979463835df3156c1735..ccbba5189791510079f384041050e697b4d81741 100644 (file)
--- 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 338aeeb7034b8cedee546a6aa41c9dfdfc0df485..cfe38c5bd916a6626320f09046e2b0187d93211e 100644 (file)
--- 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,
index dad8b9be8e3d68a01146f6c14e9c0c30ba2e6dd0..383a5d88918ca675bd1791d9484ec826676deaff 100644 (file)
--- 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)
index 3dceed889f74a194c8046863faabbbf02aa8e2d5..781c15d7916f81fd8d01f7a2b8ce4dd154491b3c 100644 (file)
--- 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 && 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 @@ 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;
index be1808bab2ae05fd2c8940811595159458faea49..d5b2bb1aa8c3b7ba4e6ab2de6109d1219c979819 100644 (file)
--- 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)