ref: 873d613dd597f550b1b64946c4577b012d61d1c9
parent: dbced097ac16973f648ad2f024cc2302fa187578
author: Simon Tatham <anakin@pobox.com>
date: Sat Feb 18 02:14:05 EST 2023
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.
--- a/cmake/platforms/unix.cmake
+++ b/cmake/platforms/unix.cmake
@@ -63,7 +63,7 @@
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")
--- a/dominosa.c
+++ b/dominosa.c
@@ -259,9 +259,9 @@
#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;
--- a/galaxies.c
+++ b/galaxies.c
@@ -1278,7 +1278,7 @@
}
#ifdef STANDALONE_SOLVER
-int maxtries;
+static int maxtries;
#define MAXTRIES maxtries
#else
#define MAXTRIES 50
@@ -3869,7 +3869,7 @@
#ifdef STANDALONE_SOLVER
-const char *quis;
+static const char *quis;
#include <time.h>
--- a/gtk.c
+++ b/gtk.c
@@ -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 @@
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 @@
"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 @@
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);
--- /dev/null
+++ b/gtk.h
@@ -1,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 */
--- a/icons/cicon.pl
+++ b/icons/cicon.pl
@@ -21,6 +21,7 @@
}
# 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"; }
--- a/latin.c
+++ b/latin.c
@@ -1321,7 +1321,7 @@
#include <stdio.h>
#include <time.h>
-const char *quis;
+static const char *quis;
static void latin_print(digit *sq, int order)
{
--- a/lightup.c
+++ b/lightup.c
@@ -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
--- a/list.c
+++ b/list.c
@@ -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"
--- a/magnets.c
+++ b/magnets.c
@@ -42,7 +42,7 @@
#include "puzzles.h"
#ifdef STANDALONE_SOLVER
-bool verbose = 0;
+static bool verbose = false;
#endif
enum {
@@ -2489,8 +2489,8 @@
#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);
--- a/map.c
+++ b/map.c
@@ -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
--- a/no-icon.c
+++ b/no-icon.c
@@ -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;
--- a/pattern.c
+++ b/pattern.c
@@ -363,7 +363,7 @@
#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 @@
#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,
--- a/pearl.c
+++ b/pearl.c
@@ -2753,7 +2753,7 @@
#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);
--- a/penrose.c
+++ b/penrose.c
@@ -509,8 +509,8 @@
#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)
{
--- a/puzzles.h
+++ b/puzzles.h
@@ -748,6 +748,10 @@
#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
--- a/signpost.c
+++ b/signpost.c
@@ -2318,8 +2318,7 @@
#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);
--- a/singles.c
+++ b/singles.c
@@ -64,7 +64,7 @@
#include "latin.h"
#ifdef STANDALONE_SOLVER
-bool verbose = false;
+static bool verbose = false;
#endif
#define PREFERRED_TILE_SIZE 32
--- a/slant.c
+++ b/slant.c
@@ -51,7 +51,7 @@
*/
#if defined STANDALONE_SOLVER
#define SOLVER_DIAGNOSTICS
-bool verbose = false;
+static bool verbose = false;
#elif defined SOLVER_DIAGNOSTICS
#define verbose true
#endif
--- a/solo.c
+++ b/solo.c
@@ -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"
--- a/tents.c
+++ b/tents.c
@@ -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
--- a/tree234.c
+++ b/tree234.c
@@ -1501,12 +1501,12 @@
}
/* 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
--- a/unequal.c
+++ b/unequal.c
@@ -1075,7 +1075,7 @@
}
#ifdef STANDALONE_SOLVER
-int maxtries;
+static int maxtries;
#define MAXTRIES maxtries
#else
#define MAXTRIES 50
@@ -2191,7 +2191,7 @@
#include <time.h>
#include <stdarg.h>
-const char *quis = NULL;
+static const char *quis = NULL;
#if 0 /* currently unused */
--- a/unruly.c
+++ b/unruly.c
@@ -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 @@
/* 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)
{
--- a/version.c
+++ b/version.c
@@ -2,6 +2,7 @@
* Puzzles version numbering.
*/
+#include "puzzles.h"
#include "version.h"
char ver[] = VER;