#!/bin/perl
|
#!/bin/perl
|
|
|
# This is a little perl script that converts XPM colors from
|
# This is a little perl script that converts XPM colors from
|
# X colors to their true RGB format
|
# X colors to their true RGB format
|
|
|
# Change this first, if you rgb.txt file lives somewhere else
|
# Change this first, if you rgb.txt file lives somewhere else
|
$RFILE="/usr/X11R6/lib/X11/rgb.txt";
|
$RFILE="/usr/X11R6/lib/X11/rgb.txt";
|
|
|
# First, Open up the RGBFILE, and make a hash table
|
# First, Open up the RGBFILE, and make a hash table
|
|
|
open (RGBIN, $RFILE) || die "Can not file $RGBFILE!";
|
open (RGBIN, $RFILE) || die "Can not file $RGBFILE!";
|
|
|
while()
|
while()
|
{
|
{
|
chop($_);
|
chop($_);
|
|
|
$firstchar = substr($_, 0, 1);
|
$firstchar = substr($_, 0, 1);
|
|
|
if ($firstchar ne "!")
|
if ($firstchar ne "!")
|
{
|
{
|
($r, $g, $b, $val) = /\s*(\d*)\s*(\d*)\s*(\d*)\s*(\w*)/;
|
($r, $g, $b, $val) = /\s*(\d*)\s*(\d*)\s*(\d*)\s*(\w*)/;
|
$rgbvals{$val} = sprintf("#%2.2x%2.2x%2.2x", $r, $g, $b);
|
$rgbvals{$val} = sprintf("#%2.2x%2.2x%2.2x", $r, $g, $b);
|
}
|
}
|
}
|
}
|
|
|
close(RGBIN);
|
close(RGBIN);
|
|
|
# Ok then, are we in batch mode or individual mode?
|
# Ok then, are we in batch mode or individual mode?
|
|
|
if ($ARGV[0] eq "--batch")
|
if ($ARGV[0] eq "--batch")
|
{
|
{
|
$srcdir = $ARGV[1];
|
$srcdir = $ARGV[1];
|
$destdir = $ARGV[2];
|
$destdir = $ARGV[2];
|
|
|
# Batch mode, open up directory and fire
|
# Batch mode, open up directory and fire
|
opendir(INDIR, $srcdir) || die "Directory $ARGV[1] doesn't exist";
|
opendir(INDIR, $srcdir) || die "Directory $ARGV[1] doesn't exist";
|
my @xpms = readdir(INDIR);
|
my @xpms = readdir(INDIR);
|
closedir(INDIR);
|
closedir(INDIR);
|
|
|
foreach $xpmfile (@xpms)
|
foreach $xpmfile (@xpms)
|
{
|
{
|
if ($xpmfile =~ /\.xpm/g)
|
if ($xpmfile =~ /\.xpm/g)
|
{
|
{
|
print "Converting $srcdir/$xpmfile to $destdir/$xpmfile...\n"
|
print "Converting $srcdir/$xpmfile to $destdir/$xpmfile...\n"
|
&convert_xpm("$srcdir/$xpmfile", "$destdir/$xpmfile");
|
&convert_xpm("$srcdir/$xpmfile", "$destdir/$xpmfile");
|
}
|
}
|
}
|
}
|
}
|
}
|
else
|
else
|
{
|
{
|
# regular mode
|
# regular mode
|
&convert_xpm($ARGV[0], $ARGV[1]);
|
&convert_xpm($ARGV[0], $ARGV[1]);
|
}
|
}
|
|
|
|
|
sub convert_xpm
|
sub convert_xpm
|
{
|
{
|
# Open up the file to convert it
|
# Open up the file to convert it
|
|
|
$filea = $_[0];
|
$filea = $_[0];
|
$fileb = $_[1];
|
$fileb = $_[1];
|
|
|
print"Writing from $filea to $fileb...\n";
|
print"Writing from $filea to $fileb...\n";
|
|
|
open(XPMIN, $filea) || die "Could not file $filea for processing...\n";
|
open(XPMIN, $filea) || die "Could not file $filea for processing...\n";
|
open(XPMOUT,">$fileb") || die "Could not open file $fileb for writing...\n";
|
open(XPMOUT,">$fileb") || die "Could not open file $fileb for writing...\n";
|
|
|
$xpmline = ;
|
$xpmline = ;
|
|
|
die "$fila is Not an XPM file!\n" if (!($xpmline =~ /\/\* XPM \*\/\n/));
|
die "$fila is Not an XPM file!\n" if (!($xpmline =~ /\/\* XPM \*\/\n/));
|
|
|
$firstchar = substr($xpmline, 0, 1);
|
$firstchar = substr($xpmline, 0, 1);
|
|
|
while($firstchar ne "\"")
|
while($firstchar ne "\"")
|
{
|
{
|
print XPMOUT $xpmline;
|
print XPMOUT $xpmline;
|
$xpmline = ;
|
$xpmline = ;
|
$firstchar = substr($xpmline, 0, 1);
|
$firstchar = substr($xpmline, 0, 1);
|
}
|
}
|
|
|
# Now we have the numbers. Grab em!
|
# Now we have the numbers. Grab em!
|
|
|
($width, $height, $colors, $chars) = ($xpmline =~ /\"(\d*) (\d*) (\d*) (\d*)\",\n/);
|
($width, $height, $colors, $chars) = ($xpmline =~ /\"(\d*) (\d*) (\d*) (\d*)\",\n/);
|
|
|
print XPMOUT $xpmline;
|
print XPMOUT $xpmline;
|
|
|
# Now read in the appropriate number of colors
|
# Now read in the appropriate number of colors
|
|
|
for($i = 0; $i < $colors; $i++)
|
for($i = 0; $i < $colors; $i++)
|
{
|
{
|
$xpmline = ;
|
$xpmline = ;
|
chop($xpmline);
|
chop($xpmline);
|
|
|
($str, $val, $color) = ($xpmline =~ /\"(.+)\s+(\w*)\s+(.+)\"/);
|
($str, $val, $color) = ($xpmline =~ /\"(.+)\s+(\w*)\s+(.+)\"/);
|
|
|
$firstchar = substr($color, 0, 1);
|
$firstchar = substr($color, 0, 1);
|
|
|
if ($firstchar ne "#")
|
if ($firstchar ne "#")
|
{
|
{
|
$color = $rgbvals{$color} if ($color ne "None");
|
$color = $rgbvals{$color} if ($color ne "None");
|
}
|
}
|
|
|
print XPMOUT "\"$str $val $color\",\n";
|
print XPMOUT "\"$str $val $color\",\n";
|
}
|
}
|
|
|
while()
|
while()
|
{
|
{
|
print XPMOUT $_;
|
print XPMOUT $_;
|
}
|
}
|
|
|
close(XPMIN);
|
close(XPMIN);
|
close(XPMOUT);
|
close(XPMOUT);
|
}
|
}
|
|
|
|
|
|
|
|
|