1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#!/usr/bin/perl -w
# make-gtkrc.pl -- Build gtkrc files from templates
# $Id: make-gtkrc.pl,v 1.10 2001/02/13 01:32:21 jsh Exp $
# make-gtkrc.pl SUBST-FILE... < INPUT > OUTPUT
use Getopt::Std;
# Default parameter values (from Eazel-Teal)
my %substs = (
focus_color => '"#508083"',
# focus_color gets set in <0>, so use it by default
menuitem_gradient => '{ vertical : <0,0.5> [3] <0> [10] <0> [2] <0,0.6> }',
insensitive_colors => '"#636563", "#cecfce"',
gradiented_menus => 'no',
prelight_check_buttons => 'yes',
lists_have_separators => 'no',
);
# Read any command line options
if (!getopts ('c:d:')) {
print "usage: make-gtkrc.pl [-c COLOR] [-d ENGINE-DIR] [SUBST-FILES..] <IN >OUT\n";
exit 1;
}
if (defined $opt_c) {
# opt_c sets the focus_color
$_ = $opt_c;
if (/^\#/) {
$_ = '"' . $_ . '"';
}
$substs{'focus_color'} = $_;
}
if (defined $opt_d) {
# opt_d sets the `@enginedir@' substitution
$substs{'enginedir'} = $opt_d;
}
# Read all substitutions into %substs hash
foreach my $subst_file (@ARGV) {
open (SUBST, $subst_file) or die "Can't open $subst_file for input: $!";
while (<SUBST>) {
# skip blank lines and comments
next if /^#/;
next if /^\s*$/;
chop;
if (! /^(\S+?)\s+(.*)$/) {
die "Malformed substitution: $_";
}
$substs{$1} = $2;
}
close SUBST;
}
# Then run through STDIN applying them..
print "# gtkrc generated automatically by make-gtkrc.pl\n\n";
my $if_state = 1;
my @if_stack = ();
while (<STDIN>) {
my @tokens = split (/\@/);
while (@tokens) {
# this is a verbatim token
my $text = shift (@tokens);
my $swallow_nl = 0;
if ($if_state) {
print ($text);
}
if (@tokens) {
# this is an @foo@ expression
my $expr = shift (@tokens);
if ($expr =~ /^\s*$/) {
# `@@' -> `@'
print '@';
} elsif ($expr =~ /^if\s+(\S+)$/) {
# if statement
push (@if_stack, $if_state);
$if_state = $substs{$1} ne 'no';
$swallow_nl = 1;
} elsif ($expr =~ /^\s*else\s*$/) {
# else statement
$if_state = ! $if_state;
$swallow_nl = 1;
} elsif ($expr =~ /^\s*endif\s*$/) {
# endif statement
$if_state = pop (@if_stack);
$swallow_nl = 1;
} elsif ($expr =~ /^\s*(\S+)\s*$/) {
# `@foo@' -> <value of foo>
my $word = $1;
if (!defined $substs{$word}) {
die "Undefined substitution: $word";
}
if ($if_state) {
print $substs{$word};
}
}
if ($swallow_nl && @tokens && $tokens[0] eq "\n") {
@tokens = ();
}
}
}
}
# End of make-gtkrc.pl
|