cicon.pl 864 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl
  2. # Given a list of input PNGs, create a C source file containing a
  3. # const array of XPMs, named by a given C identifier.
  4. $id = shift @ARGV;
  5. $k = 0;
  6. @xpms = ();
  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 ${id}_$k"."[] = {\n";
  17. $k++;
  18. push @xpms, @lines, "\n";
  19. }
  20. # Now output.
  21. foreach $line (@xpms) { print $line; }
  22. print "const char *const *const ${id}[] = {\n";
  23. for ($i = 0; $i < $k; $i++) { print " ${id}_$i,\n"; }
  24. print "};\n";
  25. print "const int n_${id} = $k;\n";