#!/usr/bin/perl # # color_lookup colorname... # # Locate the RGB table (dbm or ascii) # Order here if from lowest to highest preference foreach $dir ( "/usr/openwin/lib", "/usr/lib/X11", "/usr/X11R6/lib/X11", "/usr/X11R6.1/lib/X11" ) { $RGB = "$dir/rgb" if -f "$dir/rgb.dir"; $RGBT = "$dir/rgb.txt" if -f "$dir/rgb.txt"; } # # what environment variable should this be? I have not found one. # $RGB = $ENV{'?????'} # if defined $ENV{'?????'} && -f $ENV{'?????'}; # die("RGB database not found!\n") unless $RGB || $RGBT; # this only should be done once in a program if ( defined $RGB ) { dbmopen(%RGB, $RGB, undef) || die "Unable to open RGB database\n"; } else { open(RGB, $RGBT) or die "Unable to open RGB text database, \"$RGBT\"\n"; } COLOR: while( $color = shift ) { if ( defined $RGB ) { $color_rgb = $RGB{ "\L$color" }; if ( defined $color_rgb ) { # $color_rgb = join('', unpack( "H12", $color_rgb)); # 16 bits/chan $color_rgb = join('', unpack( "H2xH2xH2x", $color_rgb)); # 8 printf "Color %-20s --> #%s\n", "\"$color\"", $color_rgb; exec( qw{ display -size 100x100 }, "xc:#$color", '&' ) if $ENV{DISPLAY}; next COLOR; } } else { seek(RGB, 0, 0); # rewind RGB text file while( ) { next if /^!/; # ignore rgb.txt comments s/^\s+//; # remove start spaces (if present) s/\s+$//; # remove end of line junk ($r,$g,$b,$c) = split(/\s+/,$_,4); if ( lc($color) eq lc($c) ) { printf "Color %-20s --> #%02x%02x%02x or %3d %3d %3d\n", "\"$color\"", $r, $g, $b, $r, $g, $b; exec( qw{ display -size 100x100 }, sprintf("xc:#%02x%02x%02x",$r, $g, $b), '&' ) if $ENV{DISPLAY}; next COLOR; } } } print "No such Color \"$color\" found\n"; }