summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/__init__.py0
-rwxr-xr-xTOOLS/file2string.py14
-rwxr-xr-xTOOLS/matroska.py21
3 files changed, 22 insertions, 13 deletions
diff --git a/TOOLS/__init__.py b/TOOLS/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/TOOLS/__init__.py
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
index 6cdd1a72ae..90c9e03368 100755
--- a/TOOLS/file2string.py
+++ b/TOOLS/file2string.py
@@ -5,23 +5,27 @@
# of every string, so code using the string may need to remove that to get
# the exact contents of the original file.
+from __future__ import unicode_literals
import sys
# Indexing a byte string yields int on Python 3.x, and a str on Python 2.x
def pord(c):
return ord(c) if type(c) == str else c
-def main(infile):
+def file2string(infilename, infile, outfile):
+ outfile.write("// Generated from %s\n\n" % infilename)
+
conv = ['\\' + ("%03o" % c) for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
"0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
+
for c in safe_chars:
conv[ord(c)] = c
for c, esc in ("\nn", "\tt", r"\\", '""'):
conv[ord(c)] = '\\' + esc
for line in infile:
- sys.stdout.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
+ outfile.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
-with open(sys.argv[1], 'rb') as infile:
- sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
- main(infile)
+if __name__ == "__main__":
+ with open(sys.argv[1], 'rb') as infile:
+ file2string(sys.argv[1], infile, sys.stdout)
diff --git a/TOOLS/matroska.py b/TOOLS/matroska.py
index 6e843560da..cf55db42a4 100755
--- a/TOOLS/matroska.py
+++ b/TOOLS/matroska.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
Generate C definitions for parsing Matroska files.
Can also be used to directly parse Matroska files and display their contents.
@@ -69,6 +69,12 @@ elements_matroska = (
'BlockDuration, 9b, uint',
'ReferenceBlock*, fb, sint',
'DiscardPadding, 75A2, sint',
+ 'BlockAdditions, 75A1, sub', (
+ 'BlockMore*, A6, sub', (
+ 'BlockAddID, EE, uint',
+ 'BlockAdditional, A5, binary',
+ ),
+ ),
),
'SimpleBlock*, a3, binary',
),
@@ -271,6 +277,7 @@ def parse_elems(l, namespace):
for el in l:
if isinstance(el, str):
name, hexid, eltype = [x.strip() for x in el.split(',')]
+ hexid = hexid.lower()
multiple = name.endswith('*')
name = name.strip('*')
new = MatroskaElement(name, hexid, eltype, namespace)
@@ -285,8 +292,8 @@ parse_elems(elements_ebml, 'EBML')
parse_elems(elements_matroska, 'MATROSKA')
def printf(out, *args):
- out.write(' '.join([str(x) for x in args]))
- out.write('\n')
+ out.write(u' '.join([str(x) for x in args]))
+ out.write(u'\n')
def generate_C_header(out):
printf(out, '// Generated by TOOLS/matroska.py, do not edit manually')
@@ -400,10 +407,6 @@ def read_float(s, length):
def parse_one(s, depth, parent, maxlen):
elid = hexlify(read_id(s)).decode('ascii')
elem = elementd.get(elid)
- if parent is not None and elid not in parent.subids and elid not in ('ec', 'bf'):
- print('Unexpected:', elid)
- if 1:
- raise NotImplementedError
size, length = read_vint(s)
this_length = len(elid) / 2 + size + length
if elem is not None:
@@ -442,7 +445,7 @@ def parse_one(s, depth, parent, maxlen):
else:
raise NotImplementedError
else:
- print(depth, 'Unknown element:', elid, 'size:', length)
+ print(" " * depth, '[' + elid + '] Unknown element! size:', length)
read(s, length)
return this_length
@@ -455,6 +458,8 @@ if __name__ == "__main__":
elif sys.argv[1] == '--generate-definitions':
generate_C_definitions(sys.stdout)
else:
+ if sys.version_info.major < 3:
+ raise Exception("Dumping requires Python 3.")
s = open(sys.argv[1], "rb")
while 1:
start = s.tell()