cicon.pl 970 B

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