[[svn-to-darcs @ 12] dmorelli**20040410155902 New files added. ] adddir ./trunk/rgbtable addfile ./trunk/rgbtable/README addfile ./trunk/rgbtable/rgbtable.pl addfile ./trunk/rgbtable/rgbtable.tmpl hunk ./trunk/rgbtable/README 1 +Locations of the rgb.txt file + +Debian GNU/Linux: /usr/lib/X11/rgb.txt +SDF BSD: /usr/pkg/X11R6/lib/X11/rgb.txt + hunk ./trunk/rgbtable/rgbtable.pl 1 +#! /usr/bin/perl -w + +#-------------------------------------------------------------------------- +# $RCSfile$ +#-------------------------------------------------------------------------- +# $Revision: 12 $ +# $Date: 2004-04-10 11:59:02 -0400 (Sat, 10 Apr 2004) $ +# $Author: dmorelli $ +# +# Script to turn an rgb.txt file (from *nix) into an html table showing +# The color names, values and swatches. +#-------------------------------------------------------------------------- + +use HTML::Template; + + +main(); + +#-------------------------------------------------------------------------- +# Take the decimal RGB values and color name and construct a table row. +sub constructTableRow($$$$) +{ + my %rowData; # Get a fresh hash for the row data + + # These three assingments perform a dec to hex conversion. + $r = sprintf("%02x", $_[0]); + $g = sprintf("%02x", $_[1]); + $b = sprintf("%02x", $_[2]); + $colorDec = "$_[0] $_[1] $_[2]"; + $colorHex = "#${r}${g}${b}"; + + $rowData{colorName} = $_[3]; + $rowData{colorHex} = $colorHex; + $rowData{colorDec} = $colorDec; + + # Return a reference to the hash. + return { %rowData }; +} # sub constructTableRow + +#-------------------------------------------------------------------------- +sub main +{ + my $pathIn = shift @ARGV; + + # open the html template + my $template = HTML::Template->new(filename => 'rgbtable.tmpl'); + + $template->param(fileOrig => $pathIn); + $template->param(platform => qx/uname -a/); + $template->param(dateTime => scalar localtime()); + + open(fileRgb, $pathIn) + || die("Could not open file: $pathIn\n"); + + # initialize an array to hold your loop + my @loopData = (); + + # Skip the first line, it's always a comment. + $line = ; + + # Walk the remaining lines and extract the info we want. + while($line = ) + { + $line =~ m/[ \t]*([0-9]{1,3})[ \t]*([0-9]{1,3})[ \t]*([0-9]{1,3})[ \t]*(.*)/; + + # Push a reference to this row into the loop + push(@loopData, constructTableRow($1, $2, $3, $4)); + } + + close(fileRgb); + + $template->param(colors => \@loopData); + + # Output the result document. + print $template->output; +} # sub main + hunk ./trunk/rgbtable/rgbtable.tmpl 1 + + + + rgb.txt listing + + + +

Constructed from +
Running on +
Constructed on + +

+ + + + + + + + + + + + + + + + + +
color nameswatch#rrggbb (hex)R G B (dec)
+  
+ +