summaryrefslogtreecommitdiffstats
path: root/TOOLS/file2string.py
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-16 07:30:30 +0200
committerwm4 <wm4@nowhere>2012-10-16 07:30:30 +0200
commit4e89851aa128a614f59ff4885af384a266cb24e6 (patch)
treec6ab9f34ef3e9c1d58f8ec837b93e249e79bdcf6 /TOOLS/file2string.py
parentf45eab6faea05834c1337175dbe51437707b8d7e (diff)
parent6557f206efeb4569a42f1e4810172bc97fd64619 (diff)
downloadmpv-4e89851aa128a614f59ff4885af384a266cb24e6.tar.bz2
mpv-4e89851aa128a614f59ff4885af384a266cb24e6.tar.xz
Merge branch 'master' into osd_changes
Conflicts: Makefile command.c libvo/gl_common.c libvo/vo_corevideo.m libvo/vo_opengl.c libvo/vo_opengl_old.c libvo/vo_opengl_shaders.glsl sub/ass_mp.c sub/osd_libass.c sub/sd_ass.c
Diffstat (limited to 'TOOLS/file2string.py')
-rwxr-xr-xTOOLS/file2string.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
index cb121e4884..6cdd1a72ae 100755
--- a/TOOLS/file2string.py
+++ b/TOOLS/file2string.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/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
@@ -7,6 +7,10 @@
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" \
@@ -16,7 +20,7 @@ def main(infile):
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')
+ 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])