Fix ar9x compile/boot (#7102)
[opentx.git] / radio / util / addtr.py
blobadcc2b0b1fb4f54c8d6ea17ac703675ff7a89f58
1 #!/usr/bin/env python
3 from __future__ import print_function
5 import sys
6 import glob
9 def addLine(filename, newline, after):
10 print(filename, newline)
11 with open(filename, 'r') as f:
12 lines = f.readlines()
13 for i, line in enumerate(lines):
14 if after in line:
15 lines.insert(i + 1, newline + '\n')
16 break
17 with open(filename, 'w') as f:
18 f.writelines(lines)
21 def modifyTranslations(constant, translation, after):
22 for filename in glob.glob('translations/*.h.txt'):
23 newline = "#define " + constant + " " * max(1, 31 - len(constant)) + '"' + translation + '"'
24 addLine(filename, newline, after + " ")
27 def modifyDeclaration(constant, after):
28 newline = "extern const char S" + constant + "[];"
29 filename = "translations.h"
30 addLine(filename, newline, after + "[];")
33 def modifyDefinition(constant, after):
34 newline = "const char S" + constant + "[] = " + constant + ";"
35 filename = "translations.cpp"
36 addLine(filename, newline, after + "[] ")
39 after = sys.argv[-1]
40 for arg in sys.argv[1:-1]:
41 constant, translation = arg.split("=")
42 modifyTranslations(constant, translation, after)
43 modifyDeclaration(constant, after)
44 modifyDefinition(constant, after)
45 after = constant