f8668c1e |
1 | #!/usr/bin/perl |
2 | |
3 | # Given a list of input PNGs, create a C source file containing a |
4 | # const array of XPMs, named by a given C identifier. |
5 | |
6 | $id = shift @ARGV; |
7 | $k = 0; |
8 | @xpms = (); |
9 | foreach $f (@ARGV) { |
10 | # XPM format is generated directly by ImageMagick, so that's easy |
11 | # enough. We just have to adjust the declaration line so that it |
12 | # has the right name, linkage and storage class. |
13 | @lines = (); |
14 | open XPM, "convert $f xpm:- |"; |
15 | push @lines, $_ while <XPM>; |
16 | close XPM; |
17 | die "XPM from $f in unexpected format\n" unless $lines[1] =~ /^static.*\{$/; |
18 | $lines[1] = "static const char *const ${id}_$k"."[] = {\n"; |
19 | $k++; |
20 | push @xpms, @lines, "\n"; |
21 | } |
22 | |
23 | # Now output. |
24 | foreach $line (@xpms) { print $line; } |
25 | print "const char *const *const ${id}[] = {\n"; |
26 | for ($i = 0; $i < $k; $i++) { print " ${id}_$i,\n"; } |
27 | print "};\n"; |
28 | print "const int n_${id} = $k;\n"; |