diff options
Diffstat (limited to 'TOOLS')
-rwxr-xr-x | TOOLS/file2string.py | 23 | ||||
-rwxr-xr-x | TOOLS/matroska.py | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | TOOLS/vdpau_functions.py | 2 |
3 files changed, 26 insertions, 1 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py new file mode 100755 index 0000000000..002ba4ab60 --- /dev/null +++ b/TOOLS/file2string.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Convert the contents of a file into a C string constant. +# Note that the compiler will implicitly add an extra 0 byte at the end +# of every string, so code using the string may need to remove that to get +# the exact contents of the original file. + +import sys + +def main(infile): + conv = ['\\' + oct(c)[2:] 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[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) diff --git a/TOOLS/matroska.py b/TOOLS/matroska.py index 375fb8b279..ffa388e47b 100755 --- a/TOOLS/matroska.py +++ b/TOOLS/matroska.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 """ Generate C definitions for parsing Matroska files. Can also be used to directly parse Matroska files and display their contents. diff --git a/TOOLS/vdpau_functions.py b/TOOLS/vdpau_functions.py index 27d6ff45f3..39e38a8bbe 100644..100755 --- a/TOOLS/vdpau_functions.py +++ b/TOOLS/vdpau_functions.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + # Generate vdpau_template.c functions = """ |