[Po4a-commits] "po4a po4a,1.45,1.46"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Sun Nov 27 15:59:30 UTC 2005


Update of /cvsroot/po4a/po4a
In directory haydn:/tmp/cvs-serv18531

Modified Files:
	po4a 
Log Message:
Add a --variable option.


Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- po4a	19 Nov 2005 21:51:34 -0000	1.45
+++ po4a	27 Nov 2005 15:59:28 -0000	1.46
@@ -238,6 +238,12 @@
 
 Remove the .po~ backup files (implies --no-backups).
 
+=item --variable I<var>=I<value>
+
+Define a variable that will be expanded in the po4a configuration file.
+Every occurrence of I<$(var)> will be replaced by I<value>.
+This option can be used multiple times.
+
 =back
 
 =head1 SHORTCOMINGS
@@ -312,6 +318,7 @@
     # temporary array for GetOptions
     my @verbose = ();
     my @options = ();
+    my @variables = ();
 
     my %opts = (
         "help"            => 0,
@@ -328,7 +335,8 @@
         "mastchar"        => "",
         "locchar"         => "",
         "addchar"         => "",
-        "options"         => {"verbose" => 0, "debug" => 0}
+        "options"         => {"verbose" => 0, "debug" => 0},
+        "variables"       => {}
     );
     Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
     GetOptions(
@@ -349,7 +357,8 @@
         'no-backups'            => \$opts{"no-backups"},
         'rm-backups'            => \$opts{"rm-backups"},
         'version|V'             => \&show_version,
-        'option|o=s'            => \@options
+        'option|o=s'            => \@options,
+        'variable=s'            => \@variables
     ) or pod2usage();
 
     $opts{"verbose"} = scalar @verbose;
@@ -369,6 +378,12 @@
         }
     }
 
+    foreach (@variables) {
+        if (m/^([^=]*)=(.*)$/) {
+            $opts{"variables"}{$1}="$2";
+        }
+    }
+
     # The rm- options imply the no-
     $opts{"no-translations"} = 1 if $opts{"rm-translations"};
     $opts{"no-backups"} = 1 if $opts{"rm-backups"};
@@ -445,6 +460,14 @@
     $line.=$_;
     $line =~ s/\t/ /g;
     $line =~ s/ +/ /g;
+    while ($line =~ m/\$\((\w+)\)/) {
+        if (defined $po4a_opts{"variables"}{$1}) {
+            $line =~ s/\$\((\Q$1\E)\)/$po4a_opts{"variables"}{$1}/g;
+        } else {
+           die wrap_ref_mod("$config_file:$nb", "",
+                            gettext("Unknown variable: %s"), $1);
+        }
+    }
     $line =~ s/^ //;
     $line =~ s/ $//;
     chomp($line);




More information about the Po4a-commits mailing list