summaryrefslogtreecommitdiffstats
path: root/TOOLS/file2string.py
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-12-17 13:24:05 +0100
committerwm4 <wm4@nowhere>2016-12-17 15:43:15 +0100
commitff9f5e06ff203c055d968087956026ef9204218b (patch)
tree883725191398913cc97bd441b7110bcf68237e28 /TOOLS/file2string.py
parent2b8b17402ed59815019b309051b277ba4de82f3b (diff)
downloadmpv-ff9f5e06ff203c055d968087956026ef9204218b.tar.bz2
mpv-ff9f5e06ff203c055d968087956026ef9204218b.tar.xz
Revert "Port several python scripts to Perl"
This reverts commit fae73079310eef9dce9737f2e37ff4b80c8830ee. Before the waf build system was used, we had a configure script written in shell. To drop the build dependency on Python, someone rewrote the Python scripts we had to Perl. Now the shell configure script is gone, and it makes no sense to have a build dependency on both Perl and Python. This isn't just a straight revert. It adds the new Matroska EBML elements to the old Python scripts, adjusts the waf build system, and of course doesn't add anything back needed by the old build system. It would be better if this used matroska.py/file2string.py directly by importing them as modules, instead of calling them via "python". But for now this is simpler.
Diffstat (limited to 'TOOLS/file2string.py')
-rwxr-xr-xTOOLS/file2string.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
new file mode 100755
index 0000000000..6cdd1a72ae
--- /dev/null
+++ b/TOOLS/file2string.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+# 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
+
+# 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):
+ 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')
+
+with open(sys.argv[1], 'rb') as infile:
+ sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
+ main(infile)