Blame build-aux/gen-color-table.pl

Packit a4058c
#!/usr/bin/perl -w
Packit a4058c
Packit a4058c
if (@ARGV != 1) {
Packit a4058c
    die "Usage: gen-color-table.pl rgb.txt > xpm-color-table.h\n";
Packit a4058c
}
Packit a4058c
Packit a4058c
open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
Packit a4058c
Packit a4058c
@colors = ();
Packit a4058c
while (defined($_ = <IN>)) {
Packit a4058c
    next if /^!/;
Packit a4058c
    if (!/^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(.*\S)\s+$/) {
Packit a4058c
	die "Cannot parse line $_";
Packit a4058c
    }
Packit a4058c
Packit a4058c
    push @colors, [$1, $2, $3, $4];
Packit a4058c
}
Packit a4058c
Packit a4058c
@colors = sort { lc($a->[3]) cmp lc($b->[3]) } @colors;
Packit a4058c
Packit a4058c
$offset = 0;
Packit a4058c
Packit a4058c
$date = gmtime;
Packit a4058c
Packit a4058c
print <
Packit a4058c
/* xpm-color-table.h: Generated by gen-color-table.pl from rgb.txt
Packit a4058c
 *
Packit a4058c
 *  Date: $date
Packit a4058c
 *
Packit a4058c
 * Do not edit.   
Packit a4058c
 */
Packit a4058c
static const char color_names[] =
Packit a4058c
EOT
Packit a4058c
Packit a4058c
for $color (@colors) {
Packit a4058c
    $name = $color->[3];
Packit a4058c
Packit a4058c
    if ($offset != 0) {
Packit a4058c
	print qq(\n);
Packit a4058c
    }
Packit a4058c
    print qq(  "$name\\0");
Packit a4058c
Packit a4058c
    $color->[4] = $offset;
Packit a4058c
    $offset += length($name) + 1;
Packit a4058c
}
Packit a4058c
Packit a4058c
print ";\n\n";
Packit a4058c
Packit a4058c
print <
Packit a4058c
typedef struct {
Packit a4058c
    guint16 name_offset;
Packit a4058c
    guchar red;
Packit a4058c
    guchar green;
Packit a4058c
    guchar blue;
Packit a4058c
} XPMColorEntry;
Packit a4058c
Packit a4058c
static const XPMColorEntry xColors[] = {
Packit a4058c
EOT
Packit a4058c
Packit a4058c
$i = 0;
Packit a4058c
for $color (@colors) {
Packit a4058c
    $red = $color->[0];
Packit a4058c
    $green = $color->[1];
Packit a4058c
    $blue = $color->[2];
Packit a4058c
    $offset = $color->[4];
Packit a4058c
Packit a4058c
    if ($i != 0) {
Packit a4058c
	print ",\n";
Packit a4058c
    }
Packit a4058c
    print "  { $offset, $red, $green, $blue }";
Packit a4058c
    $i++;
Packit a4058c
}
Packit a4058c
Packit a4058c
print "\n};\n";