2012-07-18 15:25:19 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# palette.pl
|
|
|
|
#
|
|
|
|
# Converts your .Xdefault/.Xresources colors into a ready to paste palette
|
|
|
|
# for bar. It takes your foreground/background settings into account and if
|
|
|
|
# it cant find them it leaves COLOR0/COLOR1 undefined.
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
open (F, "<".$ARGV[0]) || die "Can't open!";
|
|
|
|
|
2013-08-31 15:36:32 +00:00
|
|
|
our %vars = ();
|
|
|
|
|
2012-07-18 15:25:19 +00:00
|
|
|
while (<F>) {
|
2013-08-31 15:36:32 +00:00
|
|
|
# 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);
|
2012-07-18 15:25:19 +00:00
|
|
|
}
|
2013-08-31 15:36:32 +00:00
|
|
|
elsif ($_ =~ m/^\s*\w*\*(background|foreground|color\d)\s*:\s*([\w\d#]+)/) {
|
|
|
|
my ($name, $value) = (uc $1, $2);
|
|
|
|
# Check if it's a color
|
2013-09-30 16:03:36 +00:00
|
|
|
if (substr($value, 0, 1) eq '#') {
|
2013-08-31 15:36:32 +00:00
|
|
|
$value = hex(substr($value, 1));
|
|
|
|
} else {
|
|
|
|
$value = $vars{"$value"};
|
|
|
|
}
|
|
|
|
printf "#define $name 0x%06x\n", $value;
|
2012-07-18 15:25:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-31 15:36:32 +00:00
|
|
|
|