Revamped palette.pl. Support separate colors for bg/fg.

This commit is contained in:
LemonBoy
2013-08-31 15:36:32 +00:00
parent 42ab142e74
commit 3a207cf9ba
3 changed files with 37 additions and 30 deletions

View File

@@ -12,16 +12,25 @@ use warnings;
open (F, "<".$ARGV[0]) || die "Can't open!";
our %vars = ();
while (<F>) {
if ($_ =~ m/^\s*(?:\w+\.|\*)(color|background|foreground)(\d+)?\s*:\s*#([0-9A-Fa-f]*)/) {
if ($1 eq "background") {
printf "#define COLOR0\t0x$3\n";
# Don't match comments
if ($_ !~ m/^\s*!/) {
# It's a define!
if ($_ =~ m/^\s*#define\s+(\w+)\s+#([0-9A-Fa-f]{1,6})/) {
$vars{"$1"} = hex($2);
}
elsif ($1 eq "foreground") {
printf "#define COLOR1\t0x$3\n"
}
elsif ($1 eq "color" && $2 < 8) {
printf "#define COLOR%i\t0x$3\n", $2 + 2;
elsif ($_ =~ m/^\s*\w*\*(background|foreground|color\d)\s*:\s*([\w\d#]+)/) {
my ($name, $value) = (uc $1, $2);
# Check if it's a color
if (substr($value, 1) eq '#') {
$value = hex(substr($value, 1));
} else {
$value = $vars{"$value"};
}
printf "#define $name 0x%06x\n", $value;
}
}
}