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