diff --git a/misc/scripts/png2c.py b/misc/scripts/png2c.py index aedb81e13f..d15ba811b0 100755 --- a/misc/scripts/png2c.py +++ b/misc/scripts/png2c.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # This script is a slightly modified version of the original found at # @@ -25,6 +25,9 @@ if len(sys.argv) < 2: r = re.compile("^([a-zA-Z._][a-zA-Z._0-9]*)[.][pP][nN][gG]$") +# Automatically replace some symbols in the filenames. +sanitize = str.maketrans('-@', '__') + with_size = 0 size_suffix = '' for path in sys.argv[1:]: @@ -32,12 +35,12 @@ for path in sys.argv[1:]: with_size = 1 continue - filename = os.path.basename(path).replace('-','_') + filename = os.path.basename(path).translate(sanitize) m = r.match(filename) # Allow only filenames that make sense as C variable names if not(m): - print("Skipped file (unsuitable filename): " + filename) + print("Skipped file (unsuitable filename): " + filename, file=sys.stderr) continue # Read PNG file as character array @@ -50,7 +53,7 @@ for path in sys.argv[1:]: # Each PNG file starts with a 8 byte signature that should be followed # by IHDR chunk which is always 13 bytes in length so the first 16 # bytes are fixed (or at least we expect them to be). - if bytes[0:16].tostring() != b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR': + if bytes[0:16].tobytes() != b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR': print('"%s" doesn\'t seem to be a valid PNG file.' % filename) continue