diff options
Diffstat (limited to 'TOOLS/file2string.py')
-rwxr-xr-x | TOOLS/file2string.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py index b40317218c..5b1c4a95d1 100755 --- a/TOOLS/file2string.py +++ b/TOOLS/file2string.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/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 @@ -22,27 +22,23 @@ # License along with mpv. If not, see <http://www.gnu.org/licenses/>. # -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 file2string(infilename, infile, outfile): outfile.write("// Generated from %s\n\n" % infilename) - conv = ['\\' + ("%03o" % c) for c in range(256)] + conv = ["\\%03o" % c for c in range(256)] safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \ - "0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ " + "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: - outfile.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n') + outfile.write('"' + ''.join(conv[c] for c in line) + '"\n') if __name__ == "__main__": + outfile = open(sys.argv[2], "w") with open(sys.argv[1], 'rb') as infile: - file2string(sys.argv[1], infile, sys.stdout) + file2string(sys.argv[1], infile, outfile) |