diff options
| author | Simon Tatham <anakin@pobox.com> | 2023-02-18 07:14:05 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2023-02-18 08:55:13 +0000 |
| commit | 873d613dd597f550b1b64946c4577b012d61d1c9 (patch) | |
| tree | e6c458a8dfc349ca4be8755f3bcc26658e0958d7 | |
| parent | dbced097ac16973f648ad2f024cc2302fa187578 (diff) | |
| download | puzzles-873d613dd597f550b1b64946c4577b012d61d1c9.zip puzzles-873d613dd597f550b1b64946c4577b012d61d1c9.tar.gz puzzles-873d613dd597f550b1b64946c4577b012d61d1c9.tar.bz2 puzzles-873d613dd597f550b1b64946c4577b012d61d1c9.tar.xz | |
Fix missing statics and #includes on variables.
After Ben fixed all the unwanted global functions by using gcc's
-Wmissing-declarations to spot any that were not predeclared, I
remembered that clang has -Wmissing-variable-declarations, which does
the same job for global objects. Enabled it in -DSTRICT=ON, and made
the code clean under it.
Mostly this was just a matter of sticking 'static' on the front of
things. One variable was outright removed ('verbose' in signpost.c)
because after I made it static clang was then able to spot that it was
also unused.
The more interesting cases were the ones where declarations had to be
_added_ to header files. In particular, in COMBINED builds, puzzles.h
now arranges to have predeclared each 'game' structure defined by a
puzzle backend. Also there's a new tiny header file gtk.h, containing
the declarations of xpm_icons and n_xpm_icons which are exported by
each puzzle's autogenerated icon source file and by no-icon.c. Happily
even the real XPM icon files were generated by our own Perl script
rather than being raw xpm output from ImageMagick, so there was no
difficulty adding the corresponding #include in there.
| -rw-r--r-- | cmake/platforms/unix.cmake | 2 | ||||
| -rw-r--r-- | dominosa.c | 4 | ||||
| -rw-r--r-- | galaxies.c | 4 | ||||
| -rw-r--r-- | gtk.c | 10 | ||||
| -rw-r--r-- | gtk.h | 7 | ||||
| -rwxr-xr-x | icons/cicon.pl | 1 | ||||
| -rw-r--r-- | latin.c | 2 | ||||
| -rw-r--r-- | lightup.c | 2 | ||||
| -rw-r--r-- | list.c | 4 | ||||
| -rw-r--r-- | magnets.c | 6 | ||||
| -rw-r--r-- | map.c | 2 | ||||
| -rw-r--r-- | no-icon.c | 2 | ||||
| -rw-r--r-- | pattern.c | 4 | ||||
| -rw-r--r-- | pearl.c | 2 | ||||
| -rw-r--r-- | penrose.c | 4 | ||||
| -rw-r--r-- | puzzles.h | 4 | ||||
| -rw-r--r-- | signpost.c | 3 | ||||
| -rw-r--r-- | singles.c | 2 | ||||
| -rw-r--r-- | slant.c | 2 | ||||
| -rw-r--r-- | solo.c | 2 | ||||
| -rw-r--r-- | tents.c | 2 | ||||
| -rw-r--r-- | tree234.c | 8 | ||||
| -rw-r--r-- | unequal.c | 4 | ||||
| -rw-r--r-- | unruly.c | 4 | ||||
| -rw-r--r-- | version.c | 1 |
25 files changed, 47 insertions, 41 deletions
diff --git a/cmake/platforms/unix.cmake b/cmake/platforms/unix.cmake index ca4be72..4a00b6c 100644 --- a/cmake/platforms/unix.cmake +++ b/cmake/platforms/unix.cmake @@ -63,7 +63,7 @@ if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "GNU")) endif() if(STRICT AND (CMAKE_C_COMPILER_ID MATCHES "Clang")) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes -Wmissing-variable-declarations") endif() add_compile_definitions(HELP_DIR="${CMAKE_INSTALL_PREFIX}/share/sgt-puzzles/help") @@ -259,9 +259,9 @@ static const char *validate_params(const game_params *params, bool full) #ifdef STANDALONE_SOLVER #define SOLVER_DIAGNOSTICS -bool solver_diagnostics = false; +static bool solver_diagnostics = false; #elif defined SOLVER_DIAGNOSTICS -const bool solver_diagnostics = true; +static const bool solver_diagnostics = true; #endif struct solver_domino; @@ -1278,7 +1278,7 @@ static bool generate_try_block(game_state *state, random_state *rs, } #ifdef STANDALONE_SOLVER -int maxtries; +static int maxtries; #define MAXTRIES maxtries #else #define MAXTRIES 50 @@ -3869,7 +3869,7 @@ const struct game thegame = { #ifdef STANDALONE_SOLVER -const char *quis; +static const char *quis; #include <time.h> @@ -30,6 +30,7 @@ #include <X11/Xatom.h> #include "puzzles.h" +#include "gtk.h" #if GTK_CHECK_VERSION(2,0,0) # define USE_PANGO @@ -2391,8 +2392,8 @@ static void menu_preset_event(GtkMenuItem *menuitem, gpointer data) midend_redraw(fe->me); } -GdkAtom compound_text_atom, utf8_string_atom; -bool paste_initialised = false; +static GdkAtom compound_text_atom, utf8_string_atom; +static bool paste_initialised = false; static void set_selection(frontend *fe, GdkAtom selection) { @@ -3076,9 +3077,6 @@ static void menu_about_event(GtkMenuItem *menuitem, gpointer data) "version", ver, \ "comments", "Part of Simon Tatham's Portable Puzzle Collection" - extern char *const *const xpm_icons[]; - extern const int n_xpm_icons; - if (n_xpm_icons) { GdkPixbuf *icon = gdk_pixbuf_new_from_xpm_data ((const gchar **)xpm_icons[0]); @@ -3193,8 +3191,6 @@ static frontend *new_window( GList *iconlist; int x, y, n; char errbuf[1024]; - extern char *const *const xpm_icons[]; - extern const int n_xpm_icons; struct preset_menu *preset_menu; fe = snew(frontend); @@ -0,0 +1,7 @@ +#ifndef PUZZLES_GTK_H +#define PUZZLES_GTK_H + +extern const char *const *const xpm_icons[]; +extern const int n_xpm_icons; + +#endif /* PUZZLES_GTK_H */ diff --git a/icons/cicon.pl b/icons/cicon.pl index a9f214e..4a5327a 100755 --- a/icons/cicon.pl +++ b/icons/cicon.pl @@ -21,6 +21,7 @@ foreach $f (@ARGV) { } # Now output. +print "#include \"gtk.h\"\n"; # for declarations of xpm_icons and n_xpm_icons foreach $line (@xpms) { print $line; } print "const char *const *const xpm_icons[] = {\n"; for ($i = 0; $i < $k; $i++) { print " xpm_icon_$i,\n"; } @@ -1321,7 +1321,7 @@ bool latin_check(digit *sq, int order) #include <stdio.h> #include <time.h> -const char *quis; +static const char *quis; static void latin_print(digit *sq, int order) { @@ -59,7 +59,7 @@ */ #if defined STANDALONE_SOLVER #define SOLVER_DIAGNOSTICS -int verbose = 0; +static int verbose = 0; #undef debug #define debug(x) printf x #elif defined SOLVER_DIAGNOSTICS @@ -8,10 +8,6 @@ #include "puzzles.h" -#define GAME(x) extern const game x; -#include "generated-games.h" -#undef GAME - #define GAME(x) &x, const game *gamelist[] = { #include "generated-games.h" @@ -42,7 +42,7 @@ #include "puzzles.h" #ifdef STANDALONE_SOLVER -bool verbose = 0; +static bool verbose = false; #endif enum { @@ -2489,8 +2489,8 @@ const struct game thegame = { #include <time.h> #include <stdarg.h> -const char *quis = NULL; -bool csv = false; +static const char *quis = NULL; +static bool csv = false; static void usage(FILE *out) { fprintf(out, "usage: %s [-v] [--print] <params>|<game id>\n", quis); @@ -26,7 +26,7 @@ */ #if defined STANDALONE_SOLVER #define SOLVER_DIAGNOSTICS -bool verbose = false; +static bool verbose = false; #elif defined SOLVER_DIAGNOSTICS #define verbose true #endif @@ -4,5 +4,7 @@ * `icons' subdirectory, when they're absent. */ +#include "gtk.h" + const char *const *const xpm_icons[] = { 0 }; const int n_xpm_icons = 0; @@ -363,7 +363,7 @@ static int compute_rowdata(int *ret, unsigned char *start, int len, int step) #define STILL_UNKNOWN 3 #ifdef STANDALONE_SOLVER -bool verbose = false; +static bool verbose = false; #endif static bool do_recurse(unsigned char *known, unsigned char *deduced, @@ -724,7 +724,7 @@ static unsigned char *generate_soluble(random_state *rs, int w, int h) #endif #ifdef STANDALONE_PICTURE_GENERATOR -unsigned char *picture; +static unsigned char *picture; #endif static char *new_game_desc(const game_params *params, random_state *rs, @@ -2753,7 +2753,7 @@ const struct game thegame = { #include <time.h> #include <stdarg.h> -const char *quis = NULL; +static const char *quis = NULL; static void usage(FILE *out) { fprintf(out, "usage: %s <params>\n", quis); @@ -509,8 +509,8 @@ void penrose_calculate_size(int which, int tilesize, int w, int h, #include <stdio.h> #include <string.h> -int show_recursion = 0; -int ntiles, nfinal; +static int show_recursion = 0; +static int ntiles, nfinal; static int test_cb(penrose_state *state, vector *vs, int n, int depth) { @@ -748,6 +748,10 @@ struct drawing_api { #ifdef COMBINED extern const game *gamelist[]; extern const int gamecount; +/* Also pre-declare every individual 'struct game' we expect */ +#define GAME(x) extern const game x; +#include "generated-games.h" +#undef GAME #else extern const game thegame; #endif @@ -2318,8 +2318,7 @@ const struct game thegame = { #include <time.h> #include <stdarg.h> -const char *quis = NULL; -int verbose = 0; +static const char *quis = NULL; static void usage(FILE *out) { fprintf(out, "usage: %s [--stdin] [--soak] [--seed SEED] <params>|<game id>\n", quis); @@ -64,7 +64,7 @@ #include "latin.h" #ifdef STANDALONE_SOLVER -bool verbose = false; +static bool verbose = false; #endif #define PREFERRED_TILE_SIZE 32 @@ -51,7 +51,7 @@ enum { */ #if defined STANDALONE_SOLVER #define SOLVER_DIAGNOSTICS -bool verbose = false; +static bool verbose = false; #elif defined SOLVER_DIAGNOSTICS #define verbose true #endif @@ -91,7 +91,7 @@ #ifdef STANDALONE_SOLVER #include <stdarg.h> -int solver_show_working, solver_recurse_depth; +static int solver_show_working, solver_recurse_depth; #endif #include "puzzles.h" @@ -230,7 +230,7 @@ */ #if defined STANDALONE_SOLVER #define SOLVER_DIAGNOSTICS -bool verbose = false; +static bool verbose = false; #elif defined SOLVER_DIAGNOSTICS #define verbose true #endif @@ -1501,12 +1501,12 @@ static void error(const char *fmt, ...) { } /* The array representation of the data. */ -void **array; -int arraylen, arraysize; -cmpfn234 cmp; +static void **array; +static int arraylen, arraysize; +static cmpfn234 cmp; /* The tree representation of the same data. */ -tree234 *tree; +static tree234 *tree; /* * Routines to provide a diagnostic printout of a tree. Currently @@ -1075,7 +1075,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin) } #ifdef STANDALONE_SOLVER -int maxtries; +static int maxtries; #define MAXTRIES maxtries #else #define MAXTRIES 50 @@ -2191,7 +2191,7 @@ const struct game thegame = { #include <time.h> #include <stdarg.h> -const char *quis = NULL; +static const char *quis = NULL; #if 0 /* currently unused */ @@ -52,7 +52,7 @@ #include "puzzles.h" #ifdef STANDALONE_SOLVER -bool solver_verbose = false; +static bool solver_verbose = false; #endif enum { @@ -2067,7 +2067,7 @@ const struct game thegame = { /* Most of the standalone solver code was copied from unequal.c and singles.c */ -const char *quis; +static const char *quis; static void usage_exit(const char *msg) { @@ -2,6 +2,7 @@ * Puzzles version numbering. */ +#include "puzzles.h" #include "version.h" char ver[] = VER; |