mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 07:31:30 -07:00
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.
This commit is contained in:
@ -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>
|
||||
|
||||
|
10
gtk.c
10
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 @@ 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);
|
||||
|
7
gtk.h
Normal file
7
gtk.h
Normal file
@ -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 */
|
@ -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"; }
|
||||
|
2
latin.c
2
latin.c
@ -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
|
||||
|
4
list.c
4
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"
|
||||
|
@ -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);
|
||||
|
2
map.c
2
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
|
||||
|
@ -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,
|
||||
|
2
pearl.c
2
pearl.c
@ -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
|
||||
|
2
slant.c
2
slant.c
@ -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
|
||||
|
2
solo.c
2
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"
|
||||
|
2
tents.c
2
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
|
||||
|
@ -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 */
|
||||
|
||||
|
4
unruly.c
4
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 @@ 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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user