Crossfire baudrate selection for X7 support ( fixes #4922 ) (#5194)
[opentx.git] / radio / util / parse.py
blobd4ea45f693462115eb32748544a1c98c8367fa87
1 #!/usr/bin/env python
3 from __future__ import print_function
5 import sys
7 filename = sys.argv[1]
8 print(filename)
9 fr = open(filename)
10 fw = open(filename + ".new", "w")
11 ew = open(filename + ".en", "w")
12 hw = open(filename + ".stringsh", "w")
13 cw = open(filename + ".stringsc", "w")
15 replacements = {}
17 for line in fr.readlines():
18 pos_pstr = line.find("PSTR(\"")
19 MENU = False
20 if pos_pstr < 0:
21 pos_pstr = line.find("MENU(\"")
22 MENU = True
23 while pos_pstr >= 0:
24 # print line,
25 if MENU:
26 pos_endparenthesis = line.find('"', pos_pstr + 7)
27 else:
28 pos_endparenthesis = line.find("\")", pos_pstr)
29 pstr = line[pos_pstr + 6:pos_endparenthesis]
31 str_rep = "STR_" + pstr.upper()
32 for s in (" ", ".", "[", "]", "-", "!", "/", ")", "(", "%", "+", ":"):
33 str_rep = str_rep.replace(s, "")
35 if "14" in pstr or "32" in pstr or "@" in pstr or len(str_rep) <= 5:
36 pos_pstr = -1
37 else:
38 if MENU:
39 glob_str = line[pos_pstr + 5:pos_endparenthesis + 1]
40 str_rep = "STR_MENU" + pstr.upper()
41 else:
42 glob_str = line[pos_pstr:pos_endparenthesis + 2]
43 str_rep = "STR_" + pstr.upper()
44 for s in (" ", ".", "[", "]", "-", "!", "/", ")", "(", "%", "+", ":"):
45 str_rep = str_rep.replace(s, "")
47 line = line.replace(glob_str, str_rep)
49 if str_rep in replacements.keys():
50 if replacements[str_rep] != pstr:
51 print("!!!!! NON !!!!!")
52 else:
53 replacements[str_rep] = pstr
54 print(glob_str, "=>", pstr, str_rep)
55 ew.write("#define " + str_rep[1:] + " " * (17 - len(str_rep)) + '"%s"\n' % pstr)
56 hw.write("extern const PROGMEM char %s[];\n" % str_rep)
57 cw.write("const prog_char APM %s[] = %s;\n" % (str_rep, str_rep[1:]))
59 pos_pstr = line.find("PSTR(\"")
61 fw.write(line)
63 fw.close()
64 ew.close()
65 hw.close()
66 cw.close()