lyx_mirror/development/cmake/doc/ReplaceValues.pl
Kornel Benko 63f86623cc Backport of chanes made in trunk.
The main differecies to trunk is: Project name branchlyx.
        This is so, to be able to install trunk and branch (rpm or debian) package
        simultaneously. As they do not share the same directories it is
        now easy.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@28878 a592a061-630c-0410-9148-cb99ea01b6c8
2009-03-20 14:54:54 +00:00

43 lines
831 B
Perl

#! /usr/bin/env perl
use strict;
# Syntax: ReplaceValues.pl [<var1>=<Subst1> [<var2>=<Subst> ...]] <Inputfile> [<Inputfile> ...]
# Parse Arguments for strings to substitute
my %Subst = ();
for my $arg (@ARGV) {
if ($arg =~ /^([^=]+)=(.*)$/) {
$Subst{$1} = $2;
}
else {
# $arg should be filename here
&SubstituteDataInFile($arg);
}
}
exit(0);
#################################################################
sub SubstituteDataInFile($)
{ my ($InFile) = @_;
open(FI, '<', $InFile) || die("Could not read \"$InFile\"");
while (my $l = <FI>) {
print &SubstituteDataInLine($l);
}
close(FI);
}
sub SubstituteDataInLine($)
{my ($line) = @_;
my $result = $line;
for my $k (keys %Subst) {
while ($result =~ s/\b$k\b/$Subst{$k}/) {
}
}
return($result);
}