Files
puzzles/icons/cicon.pl
Simon Tatham 873d613dd5 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.
2023-02-18 08:55:13 +00:00

30 lines
970 B
Prolog
Executable File

#!/usr/bin/perl
# Given a list of input PNGs, create a C source file file
# containing a const array of XPMs, under the name `xpm_icon'.
$k = 0;
@xpms = ();
$convert = shift @ARGV;
foreach $f (@ARGV) {
# XPM format is generated directly by ImageMagick, so that's easy
# enough. We just have to adjust the declaration line so that it
# has the right name, linkage and storage class.
@lines = ();
open XPM, "-|", $convert, $f, "xpm:-";
push @lines, $_ while <XPM>;
close XPM;
die "XPM from $f in unexpected format\n" unless $lines[1] =~ /^static.*\{$/;
$lines[1] = "static const char *const xpm_icon_$k"."[] = {\n";
$k++;
push @xpms, @lines, "\n";
}
# 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"; }
print "};\n";
print "const int n_xpm_icons = $k;\n";