3
# This perl script is intended to go through the fluxbox source
4
# code searching for the special NLS strings. It then dumps
5
# the requested details.
7
# I started trying to write it fairly generic, but it was difficult :-)
8
# Should be fairly adaptable though
10
# It doesn't currently handle more than one NLS define per line
11
# => If you get an "undefined" error, its probably 2 on one line
18
$Getopt::Std::STANDARD_HELP_VERSION = 1;
20
# the boolitem and focusitem is pretty dodgy, but it'll do for now
21
my $match_re = "(?:_FB(?:TK)?TEXT|_BOOLITEM|_FOCUSITEM)";
22
# regular expression for not a unquoted quote
23
my $noquote = q'(?:[^\"]|\\")';
25
my $fielddelim = "\0";
26
my $recorddelim = "\0";
28
#############################
29
# Parse and validate arguments
35
my $fullcommand = "$command " . join(" ", @ARGV);
37
if (!getopts("d:fhn:pr:vFHN:R", \%opts)) {
38
HELP_MESSAGE("error");
45
if (defined($arg) && $arg eq "error") {
49
print $FD "Usage: $command [options] directory\n";
50
print $FD " Where options can be:\n";
51
print $FD " -R\tDon't recurse into subdirectories.\n";
52
print $FD " -f\tThe argument is a file, not a directory\n";
53
print $FD " -F\tPrint full NLS names, not shorthand ones\n";
54
print $FD " -d delim\tUse delim as the default delimiter\n";
55
print $FD " -r delim\tUse delim as the record delimiter\n";
56
print $FD " -n\tHeader name, default FLUXBOX_NLS_HH\n";
57
print $FD " -N\tNamespace for header\n";
58
print $FD " -v\tverbose output\n";
59
print $FD " -h\tPrint this help message\n";
60
print $FD "\nPlus one of the following options that direct how to operate:\n";
61
print $FD " -H\tGenerate a header file for the strings encountered (-n implied).\n";
62
print $FD " -p\tPrint out a null-separated tuple of Set,String,Default,Description\n";
68
if (defined($opts{"h"})) {
79
return if (!defined($opts{$opt}));
84
mode_opt("H", "header");
85
mode_opt("p", "print");
87
if ($num_modes == 0) {
88
print STDERR "Must give one mode of operation!\n";
89
HELP_MESSAGE("error");
91
} elsif ($num_modes > 1) {
92
print STDERR "Too many modes of operation - must give exactly one!\n";
93
HELP_MESSAGE("error");
98
$recurse = 0 if (defined($opts{"R"}));
101
$fullnames = 1 if (defined($opts{"f"}) || $mode eq "header");
103
my $headername = "FLUXBOX_NLS_HH";
104
$headername = $opts{"n"} if (defined($opts{"n"}));
107
$namespace = $opts{"N"} if (defined($opts{"N"}));
110
$verbose = 1 if (defined($opts{"v"}));
112
if (defined($opts{"d"})) {
113
$fielddelim = $opts{"d"};
114
$recorddelim = $opts{"d"};
117
if (defined($opts{"r"})) {
118
$recorddelim = $opts{"r"};
122
if (scalar(@ARGV) == 0) {
123
print STDERR "Must give at least one more argument - the directory to scan\n";
129
if (!defined($opts{"f"})) {
130
foreach my $dir (@args) {
132
print STDERR "$dir is not a directory, aborting\n";
136
} elsif (defined($opts{"f"})) {
139
foreach my $file (@args) {
141
print STDERR "$file is not a readable file, aborting\n";
148
#############################
149
# Actually do stuff! (finally...)
153
if (defined($opts{"f"})) {
154
foreach my $file (@args) {
158
foreach my $dir (@args) {
163
# Now we have the data, we need to print it out
167
# this function is given the fbtext arguments
168
# But the first argument is the macro name...
170
my ($type, $set, $str, $default, $desc) = @_;
172
if ($type eq "_FBTKTEXT") {
176
if ($fullnames == 1) {
181
$sets{$set}->{$str}{"default"} = $default;
182
$sets{$set}->{$str}{"desc"} = $desc;
186
# C strings can just be a bunch of quoted strings adjacent to
187
# each other. This just puts them all together, removes the quotes
188
# and unquotes anything we want to.
189
# there may be newlines embedded... compare everything /s
193
# remove first and last quote
197
# now remove any inner quotes and intervening spaces
198
$str =~ s/([^\\])\"\s*\"/$1/sg;
200
# finally, unescape any remaining quotes
208
print STDERR "Processing directory '$dir'\n" if ($verbose == 1);
209
opendir(DIR, $dir) || die "can't opendir $dir: $!";
210
my @files = grep { ( /\.(cc|hh)$/ && -f "$dir/$_" ) ||
211
( -d "$dir/$_" && $_ !~ /^\.\.?$/ )
215
foreach my $file (@files) {
216
if (-d "$dir/$file") {
217
process_dir("$dir/$file") if ($recurse == 1);
219
process_file("$dir/$file");
224
# assumptions for now:
225
# - no more than one NLS thing on any single line
226
# - internal parenthesis are balanced
227
# - one nls thing can span several lines
231
print STDERR "Processing file '$file'\n" if ($verbose == 1);
232
open(FILE, "<$file") || die "Can't open file $file: $!";
236
if (/$match_re/ && $_ !~ /^\#(define|undef)/) {
238
# strip away leading stuff
239
# note that this doesn't work with more than one match on a line
240
$tail =~ s/^.*($match_re)/$1/;
241
# now we just need to find the end, looking out for any
246
# match the defined macro, plus the first 4 arguments
247
# (ignore any more), then handle them
248
if ($full =~ /^($match_re)\(([^,]+),\s*([^,]+),((?:\s*\"$noquote*\")+),((?:\s*"$noquote*")+)\s*(?:,.*)?\)/s ) {
249
store($1, $2, $3, squish($4), squish($5));
253
last if (!defined($extra));
264
foreach my $set (sort keys %sets) {
265
foreach my $str (sort keys %{$sets{$set}}) {
266
print $set . $fielddelim . $str . $fielddelim . $sets{$set}->{$str}{"default"} . $fielddelim . $sets{$set}->{$str}{"desc"} . $recorddelim;
272
print "// This file generated by $fullcommand, on " . localtime() . "\n\n";
273
print "#ifndef $headername\n";
274
print "#define $headername\n\n";
275
print "namespace $namespace {\n\n" if (defined($namespace));
279
foreach my $set (sort keys %sets) {
281
printf "\t%s = %d,\n", $set, $setnum;
284
foreach my $str (sort keys %{$sets{$set}}) {
286
printf "\t%s = %d,\n", $str, $strnum;
290
print "\tdummy_not_used = 0 // just for the end\n\n";
291
print "}; // end enum\n\n";
292
print "}; // end namespace $namespace\n\n" if (defined($namespace));
293
print "#endif // $headername\n";