#!/usr/bin/perl -w
#
# xcolorchart: Make HTML file displays color chips.
#
# 2007-06-06: Written by Steven J. DeRose, sderose@acm.org.
# 2007-12-14 sjd: Getopt. Ignore header lines. Add -i, -gray.
use strict;
use Getopt::Long;
my $version = "2010-09-12";
my $dft_theFile = "/usr/X11/lib/X11/rgb.txt";
my $ignoreCase = 0;
my $gray = 1;
my $quiet = 0;
my $theFile = $dft_theFile;
my $verbose = 0;
# Process options
Getopt::Long::Configure ("ignore_case");
my $result = GetOptions(
"gray|grey!" => \$gray,
"h|help|?" => sub { system "perldoc makeXColorChart"; exit; },
"i" => \$ignoreCase,
"q|quiet!" => \$quiet,
"v|verbose+" => \$verbose,
"version" => sub {
die "Version of $version, by Steven J. DeRose.\n";
}
);
($result) || die "Bad options.\n";
###############################################################################
#
(-e $theFile) || die "Couldn't find file '$theFile'.\n";
open IN, "<$theFile";
print "
X Windows Color Chart
Colors from $theFile
";
if ($ignoreCase) {
print
"(color names differing only in case and spacing are not listed)
\n";
}
print "\n";
print "
Name |
On white |
On black |
Under black |
Under white |
";
my %seen = ();
while (my $l = ) {
if ($l =~ m/^!/) { next; }
my @tokens = split(/\s+/," $l");
#warn "Got: " . (scalar @tokens) . ": " . join(" ", @tokens) . "\n";
my $code = sprintf("%02x%02x%02x", $tokens[1], $tokens[2], $tokens[3]);
$tokens[0] = $tokens[1] = $tokens[2] = $tokens[3] = "";
my $name = join(" ",@tokens);
(my $iname = lc($name)) =~ s/\s//g;
$iname =~ s/grey/gray/g;
if ($ignoreCase && $seen{$iname}) { next; }
if (!$gray && $iname =~ m/gray/) { next; }
print "$name | \n";
print "$name | \n";
print "$name | \n";
print "$name | \n";
print "$name | \n";
print "
\n";
$seen{$iname}++;
}
print "
Generated by /home/deroses/xcolorchart
";
exit;
###############################################################################
#
sub showUsage() {
print "
=head1 Usage
xcolorchart [options] [>destination-file]
Generates an HTML file that nicely shows all the colors defined for
X11 in the file '$theFile'. Writes to stdout.
=head1 Options
=over
=item * B<-gray> (or -grey) Include shades of grey (gray0 to gray100).
(default; to turn off, use -nogray).
=item * B<-i> Discard entries that match prior ones except for case,
whitespace, and gray vs. grey spelling.
=item * B<-q> Suppress most messages.
=item * B<-v> Add more detailed messages.
=item * B<-version> Display version info and exit.
=back
=head1 Ownership
This work by Steven J. DeRose is licensed under a Creative Commons
Attribution-Share Alike 3.0 Unported License. For further information on
this license, see http://creativecommons.org/licenses/by-sa/3.0/.
The author's present email is sderose at acm.org.
For the most recent version, see http://www.derose.net/steve/utilities/.
=cut
";
}