File indexing completed on 2024-04-28 15:35:16

0001 #!/usr/bin/perl
0002 
0003 # This script generated a color-file from a rgb.txt file that comes with
0004 # XFree86. This file contains all color names that libMXP recognizes.
0005 # Note that this list is probably bigger than what other implementations
0006 # support, so server MXP implementations should test with those before relying
0007 # on using all those color constants.
0008 #
0009 # Copyright (c) 2004 Tomas Mecir
0010 
0011 open (INFILE, "rgb.txt") or die "Cannot open rgb.txt: $!";
0012 open (OUTFILE, ">colorlist.h") or die "Cannot create output file colorlist.h: $!";
0013 
0014 print OUTFILE "/* Auto-generated from rgb.txt by mkcolors.pl */\n\n";
0015 print OUTFILE "#ifndef COLORLIST_H\n#define COLORLIST_H\n\n";
0016 print OUTFILE "#include \"libmxp.h\"\n\n";
0017 print OUTFILE "const char *COLOR_NAMES[] = { \n";
0018 
0019 while (<INFILE>)
0020 {
0021   # only colors whose names don't contain whitespaces
0022   if (/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+) *$/)
0023   {
0024     $cname = lc $4;
0025     print OUTFILE "  \"$cname\",\n";
0026   }
0027 }
0028 print OUTFILE "};\n\n";
0029 
0030 close INFILE;
0031 open (INFILE, "rgb.txt") or die "Cannot open rgb.txt: $!";
0032 
0033 print OUTFILE "RGB COLOR_DEF[] = {\n";
0034 
0035 $count = 0;
0036 
0037 while (<INFILE>)
0038 {
0039   if (/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+) *$/)
0040   {
0041     print OUTFILE "  {$1, $2, $3},\n";
0042 
0043     $count++;
0044   }
0045 }
0046 
0047 print OUTFILE "};\n\n";
0048 
0049 print OUTFILE "#define NUM_MXP_COLORS $count\n\n";
0050 
0051 print OUTFILE "#endif\n";
0052 
0053 close INFILE;
0054 close OUTFILE;
0055