#!/usr/bin/env python
import re, sys
PAT_STR = re.compile("(STR_[^ ]*) *:(.*)")
files = sys.argv[1:]
for f in files:
railway = None
lines = []
for l in open(f):
l = l.strip()
lines.append(l)
m = PAT_STR.match(l)
if m and m.group(1) == "STR_RAIL_NAME_RAILROAD":
railway = m.group(2)
if railway:
with open(f, "w") as o:
for l in lines:
m = PAT_STR.match(l)
if m and (m.group(1).startswith("STR_LAI_RAIL_DESCRIPTION_TRACK") or m.group(1) == "STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT"):
l = l.replace("{STRING}", railway)
l = l.replace("{STRING.gen}", railway)
l = l.replace("{STRING.n}", railway)
l = l.replace("{STRING.ms}", railway)
o.write(l + "\n")