]> git.lyx.org Git - lyx.git/blob - development/cmake/doc/ReplaceValues.pl
* zh_TW.po: Update from Mingyi Wu
[lyx.git] / development / cmake / doc / ReplaceValues.pl
1 #! /usr/bin/env perl
2
3 use strict;
4
5 # Syntax: ReplaceValues.pl [<var1>=<Subst1> [<var2>=<Subst> ...]] <Inputfile> [<Inputfile> ...]
6
7
8 # Parse Arguments for strings to substitute
9
10 my %Subst = ();
11
12 for my $arg (@ARGV) {
13     if ($arg =~ /^([^=]+)=(.*)$/) {
14         $Subst{$1} = $2;
15     }
16     else {
17         # $arg should be filename here
18         &SubstituteDataInFile($arg);
19     }
20 }
21
22 exit(0);
23
24 #################################################################
25 sub SubstituteDataInFile($)
26     { my ($InFile) = @_;
27       open(FI, '<', $InFile) || die("Could not read \"$InFile\"");
28       while (my $l = <FI>) {
29           print &SubstituteDataInLine($l);
30       }
31       close(FI);
32   }
33
34 sub SubstituteDataInLine($)
35         {my ($line) = @_;
36          my $result = $line;
37          for my $k (keys %Subst) {
38             while ($result =~ s/\b$k\b/$Subst{$k}/) {
39             }
40          }
41          return($result);
42      }