-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsemsg.py
More file actions
executable file
·33 lines (28 loc) · 859 Bytes
/
Copy pathparsemsg.py
File metadata and controls
executable file
·33 lines (28 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import sys
import re
import json
MSG_RX = re.compile(r'^MessageId=([^ ]+) SymbolicName=([^\n]+)\n' +
r'Language=([^\n]+)\n(.*?)\n\.\n', re.M | re.S)
def main():
if len(sys.argv) < 2:
print("Usage: parsemsg.py <file>")
return 1
entries = []
for filename in sys.argv[1:]:
data = open(filename).read()
data = data.replace("\r\n", "\n")
entries += MSG_RX.findall(data)
print('#include "cmd.h"')
print('const cmdmsg_t g_cmdmsg[] = {')
N = 0
for entry in entries:
msgstr = json.dumps(entry[3])
if N > 0:
print(',', end=' ')
N += 1
print('{0x%08xL, "%s", %s}' % (int(entry[0]), entry[1], msgstr))
print(', {0xFFFFFFFF, "_END_", "_END_"}')
print('};')
if __name__ == "__main__":
sys.exit(main())