-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
executable file
·36 lines (29 loc) · 966 Bytes
/
Copy pathparse.py
File metadata and controls
executable file
·36 lines (29 loc) · 966 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
34
35
36
#!/usr/bin/env python3
from textparser import TextParser
import json
import sys
def __printUsage():
print("Usage: parse.py <definition_file> [<text_file> --format] | [--stdinformat]")
sys.exit(1)
def main(args):
if len(args) < 2:
__printUsage()
parser = TextParser(args[0])
if len(args) == 2 and args[1] == "--stdinformat":
text = sys.stdin.read()
chars = parser.parseFormat(text)
print(chars.hex())
elif len(args) == 2:
with open(args[1], "rb") as f:
text = f.read().decode('latin-1', errors='ignore')
tree = parser.parse(text)
print(json.dumps(tree, indent=4))
elif len(args) == 3 and args[2] == "--format":
with open(args[1], "rb") as f:
text = f.read().decode('latin-1', errors='ignore')
chars = parser.parseFormat(text)
print(chars.hex())
else:
__printUsage()
if __name__ == "__main__":
main(sys.argv[1:])