[[svn-to-darcs @ 13] dmorelli**20040410160001 This project now has support files and is in the rgbtable subdirectory. ] hunk ./trunk/rgbtable.pl 1 -#! /usr/local/bin/perl - -#-------------------------------------------------------------------------- -# $RCSfile$ -#-------------------------------------------------------------------------- -# $Revision: 4 $ -# $Date: 2004-02-25 13:19:39 -0500 (Wed, 25 Feb 2004) $ -# $Author: dmorelli $ -# -# Script to turn an rgb.txt file (from *nix) into an html table showing -# The color names, values and swatches. -#-------------------------------------------------------------------------- - - -main(); - -#-------------------------------------------------------------------------- -sub constructHeader -{ - my $strOrigFile = $_[0]; - - $strHeader = - "\n\t\n\t\trgb.txt listing\n\t"; - $strHeader .= "\n\n\t\n"; - $strHeader .= "\t\t

Constructed from ${strOrigFile}\n"; - $strHeader .= "\t\t
Running on: " . - qx/uname -a/ . "\n"; - $strHeader .= "\t\t
Constructed on " . localtime() . "\n"; - $strHeader .= "\t\t

\n"; - $strHeader .= "\t\t"; - $strHeader .= ""; - $strHeader .= ""; - $strHeader .= ""; - $strHeader .= "\n"; - - return $strHeader; -} # sub constructHeader - -#-------------------------------------------------------------------------- -# Take the decimal RGB values and color name and construct a table row. -sub constructTableRow -{ - # These three assingments perform a dec to hex conversion. - $nR = sprintf("%02x", $_[0]); - $nG = sprintf("%02x", $_[1]); - $nB = sprintf("%02x", $_[2]); - $strColorDec = "$_[0] $_[1] $_[2]"; - $strColorHex = "#${nR}${nG}${nB}"; - - $strName = $_[3]; - - $strRow = "\t\t\t"; - $strRow .= ""; - $strRow .= ""; - $strRow .= ""; - $strRow .= "\n"; - - return $strRow; -} # sub constructTableRow - -#-------------------------------------------------------------------------- -sub constructFooter -{ - return "\t\t
color nameswatch#rrggbb (hex)R G B (dec)
${strName}"; - $strRow .= " ${strColorHex}${strColorDec}
\n\t\n"; -} # sub constructFooter - -#-------------------------------------------------------------------------- -sub main -{ - my ($strFileIn, $strFileOut) = @ARGV; - - $strHtml = constructHeader($strFileIn); - - open(fileRgb, $strFileIn) - || die("Could not open file: $strFilePath\n"); - - # Skip the first line, it's always a comment. - $strLine = ; - - # Walk the remaining lines and extract the info we want. - while($strLine = ) - { - $strLine =~ m/[ \t]*([0-9]{1,3})[ \t]*([0-9]{1,3})[ \t]*([0-9]{1,3})[ \t]*(.*)/; - $strHtml .= constructTableRow($1, $2, $3, $4); - } - - close(fileRgb); - - $strHtml .= constructFooter(); - - # FIXME - # Instead of printing, how about we save the file. - #print("$strHtml\n"); - - open(fileOut, ">" . $strFileOut); - print(fileOut "$strHtml\n"); - close(fileOut); -} # sub main - rmfile ./trunk/rgbtable.pl