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

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