From: Jesse Natalie Date: Tue, 31 Mar 2020 21:51:26 +0000 (-0700) Subject: util: Make xxd.py output char array instead of string X-Git-Tag: upstream/21.0.0~4526 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82bbf4c3f2392e059ee1890e8c7644081ed8e906;p=platform%2Fupstream%2Fmesa.git util: Make xxd.py output char array instead of string This keeps us from hitting the 65k string limit on MSVC Part-of: --- diff --git a/src/util/xxd.py b/src/util/xxd.py index 23055ce..b9559bf 100644 --- a/src/util/xxd.py +++ b/src/util/xxd.py @@ -46,28 +46,7 @@ def filename_to_C_identifier(n): def emit_byte(f, b): - if ord(b) == ord('\n'): - f.write(b"\\n\"\n \"") - return - elif ord(b) == ord('\r'): - f.write(b"\\r\"\n \"") - return - elif ord(b) == ord('\t'): - f.write(b"\\t") - return - elif ord(b) == ord('"'): - f.write(b"\\\"") - return - elif ord(b) == ord('\\'): - f.write(b"\\\\") - return - - if ord(b) >= ord(' ') and ord(b) <= ord('~'): - f.write(b) - else: - hi = ord(b) >> 4 - lo = ord(b) & 0x0f - f.write("\\x{:x}{:x}".format(hi, lo).encode('utf-8')) + f.write("0x{:02x}, ".format(ord(b)).encode('utf-8')) def process_file(args): @@ -82,16 +61,21 @@ def process_file(args): else: name = filename_to_C_identifier(args.input) - outfile.write("static const char {}[] =\n \"".format(name).encode('utf-8')) + outfile.write("static const char {}[] = {{\n".format(name).encode('utf-8')) + linecount = 0 while True: byte = infile.read(1) if byte == b"": break emit_byte(outfile, byte) + linecount = linecount + 1 + if linecount > 20: + outfile.write(b"\n ") + linecount = 0 - outfile.write(b"\"\n ;\n") + outfile.write(b"\n0 };\n") except Exception: # In the event that anything goes wrong, delete the output file, # then re-raise the exception. Deleteing the output file should