File: cicon.pl

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (28 lines) | stat: -rwxr-xr-x 864 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl

# Given a list of input PNGs, create a C source file containing a
# const array of XPMs, named by a given C identifier.

$id = shift @ARGV;
$k = 0;
@xpms = ();
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 ${id}_$k"."[] = {\n";
  $k++;
  push @xpms, @lines, "\n";
}

# Now output.
foreach $line (@xpms) { print $line; }
print "const char *const *const ${id}[] = {\n";
for ($i = 0; $i < $k; $i++) { print "    ${id}_$i,\n"; }
print "};\n";
print "const int n_${id} = $k;\n";