]> git.lyx.org Git - lyx.git/blob - development/cmake/doc/ReplaceValues.py
* zh_TW.po: Update from Mingyi Wu
[lyx.git] / development / cmake / doc / ReplaceValues.py
1 #! /usr/bin/env python
2
3 # file ReplaceValues.py
4 #
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7 #
8 # author: Kornel Benko, kornel@lyx.org
9 #
10 # Syntax: ReplaceValues.py [<var1>=<Subst1> [<var2>=<Subst> ...]] <Inputfile> [<Inputfile> ...]
11
12 import sys
13 import re
14
15 Subst = {}  # map of desired substitutions
16 prog = re.compile("")
17
18 def createProg():
19     matchingS = "\\b|\\b".join(Subst.keys())
20     pattern = "".join(["(.*)(\\b", matchingS, "\\b)(.*)"])
21     return re.compile(pattern)
22
23 def SubstituteDataInLine(line):
24     result = line
25     m = prog.match(result)
26     if m:
27         return "".join([SubstituteDataInLine(m.group(1)),
28                         Subst[m.group(2)],
29                         SubstituteDataInLine(m.group(3))])
30     return line
31
32
33 def SubstituteDataInFile(InFile):
34     for line in open(InFile):
35         print SubstituteDataInLine(line[:-1])
36
37 ##########################################
38
39
40 args = sys.argv
41
42 del args[0] # we don't need the name ot this script
43 while len(args) > 0:
44     arg = args[0]
45     entry = args[0].split("=",1)
46     if len(entry) == 2:
47         key=entry[0]
48         val=entry[1]
49         if len(key) > 0:
50             Subst[key] = val
51     else:
52         prog = createProg()
53         SubstituteDataInFile(args[0])
54     del args[0]
55