2022-03-29 11:06:35 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2002-09-05 17:31:37 +00:00
|
|
|
import re
|
|
|
|
|
import sys
|
|
|
|
|
|
2020-02-25 14:24:07 +01:00
|
|
|
repl = {"routine_name": "routineN", "module_name": "moduleN"}
|
2016-04-01 20:28:25 +00:00
|
|
|
specialRepl = None
|
2006-02-03 11:20:52 +00:00
|
|
|
# { re.compile(r"(.*:: *moduleN) *= *(['\"])[a-zA-Z_0-9]+\2",flags=re.IGNORECASE):r"character(len=*), parameter :: moduleN = '__MODULE_NAME__'" }
|
2002-09-05 17:31:37 +00:00
|
|
|
|
2016-04-01 20:28:25 +00:00
|
|
|
|
2020-02-25 14:24:07 +01:00
|
|
|
def replaceWords(infile, outfile, replacements=repl, specialReplacements=specialRepl):
|
2002-09-05 17:31:37 +00:00
|
|
|
"""Replaces the words in infile writing the output to outfile.
|
2016-03-10 12:38:52 +00:00
|
|
|
|
2002-09-05 17:31:37 +00:00
|
|
|
replacements is a dictionary with the words to replace.
|
|
|
|
|
specialReplacements is a dictionary with general regexp replacements.
|
|
|
|
|
"""
|
2016-04-01 20:28:25 +00:00
|
|
|
lineNr = 0
|
|
|
|
|
nonWordRe = re.compile(r"(\W+)")
|
2016-03-10 12:38:52 +00:00
|
|
|
|
2002-09-05 17:31:37 +00:00
|
|
|
while 1:
|
2016-04-01 20:28:25 +00:00
|
|
|
line = infile.readline()
|
|
|
|
|
lineNr = lineNr + 1
|
|
|
|
|
if not line:
|
|
|
|
|
break
|
2016-03-10 12:38:52 +00:00
|
|
|
|
2002-09-05 17:31:37 +00:00
|
|
|
if specialReplacements:
|
|
|
|
|
for subs in specialReplacements.keys():
|
2016-04-01 20:28:25 +00:00
|
|
|
line = subs.sub(specialReplacements[subs], line)
|
2016-03-10 12:38:52 +00:00
|
|
|
|
2016-04-01 20:28:25 +00:00
|
|
|
tokens = nonWordRe.split(line)
|
2002-09-05 17:31:37 +00:00
|
|
|
for token in tokens:
|
2016-04-18 14:27:43 +00:00
|
|
|
if token in replacements.keys():
|
2002-09-05 17:31:37 +00:00
|
|
|
outfile.write(replacements[token])
|
|
|
|
|
else:
|
|
|
|
|
outfile.write(token)
|
2020-02-25 14:24:07 +01:00
|
|
|
|
|
|
|
|
|
2016-04-01 20:28:25 +00:00
|
|
|
# EOF
|