X11 rgb.txt colors
$version
This utility reads the $rgbtxt file and converts it into color tiles.
Note that not all the colors will display correctly due the limitations
of the web.
EOF
$i = 0; # column counter
$row1 = ""; # colored cell row
$row2 = ""; # color names row
# read each line of the file and parse. convert from
# rrr ggg bbb color name
# to | | in hex
#
open(FILE,$rgbtxt) or die "cannot open $rgbtxt $!";
while() {
next if /^!/; # skip comment lines
$i++;
if($i == $columns) { # end row
print $row1,"
\n\n";
print $row2,"
\n\n";
$i = 0;
$row1 = "";
$row2 = "";
}
chomp;
($r,$g,$b,@fullname) = split; # parse colors and color name
$name = "";
foreach $n (@fullname) { $name .= " $n"; } # handle names with spaces
$row1 .= sprintf("| | \n",$r,$g,$b);
$row2 .= "$name | \n";
}
close(FILE);
# account for leftover cells in last row
# fill blank cells so they don't show up blank
#
for($i++;$i<$columns;$i++) {
$row1 .= " | \n";
$row2 .= " | \n";
}
# print last row
#
print $row1,"
\n\n";
print $row2,"
\n\n";
print <
EOF
#
#
#EOF
print `cat $footer`;
######################################################################
# eof: xrgb2html