diff options
author | Andreas Haas <Hinsbart@users.noreply.github.com> | 2017-10-02 23:31:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 23:31:40 +0200 |
commit | de9cc6ed96c79c70ca9cf22830b3e42cca4f244b (patch) | |
tree | 1a3bbd64b6f21a0a51af265f9013ab8af4931be1 /editor | |
parent | 29b44801b2e9693c5d19d3e4fbb708af367c4904 (diff) | |
parent | 07ccfa6a07baa8210f354aaf2098ee27a933734f (diff) |
Merge pull request #11592 from SaracenOne/header_generator_fix
Python header generator now generates strings with escape characters.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/SCsub | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/editor/SCsub b/editor/SCsub index bf88ebb1b5..11cdb471a8 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -6,6 +6,16 @@ env.editor_sources = [] import os from compat import encode_utf8, byte_to_str, open_utf8 +def escape_string(s, encoding='ascii'): + if isinstance(s, unicode): + s = s.encode(encoding) + result = '' + for c in s: + if not (32 <= ord(c) < 127) or c in ('\\', '"'): + result += '\\%03o' % ord(c) + else: + result += c + return result def make_certs_header(target, source, env): @@ -162,7 +172,7 @@ def make_authors_header(target, source, env): for line in f: if reading: if line.startswith(" "): - g.write("\t\"" + line.strip() + "\",\n") + g.write("\t\"" + escape_string(line.strip()) + "\",\n") continue if line.startswith("## "): if reading: @@ -170,7 +180,7 @@ def make_authors_header(target, source, env): reading = False for i in range(len(sections)): if line.strip().endswith(sections[i]): - current_section = sections_id[i] + current_section = escape_string(sections_id[i]) reading = True g.write("static const char *" + current_section + "[] = {\n") break @@ -204,7 +214,7 @@ def make_donors_header(target, source, env): for line in f: if reading >= 0: if line.startswith(" "): - g.write("\t\"" + line.strip() + "\",\n") + g.write("\t\"" + escape_string(line.strip()) + "\",\n") continue if line.startswith("## "): if reading: @@ -212,7 +222,7 @@ def make_donors_header(target, source, env): reading = False for i in range(len(sections)): if line.strip().endswith(sections[i]): - current_section = sections_id[i] + current_section = escape_string(sections_id[i]) reading = True g.write("static const char *" + current_section + "[] = {\n") break @@ -237,7 +247,8 @@ def make_license_header(target, source, env): g.write("static const char *about_license =") for line in f: - g.write("\n\t\"" + line.strip().replace("\"", "\\\"") + "\\n\"") + escaped_string = escape_string(line.strip().replace("\"", "\\\"")) + g.write("\n\t\"" + escaped_string + "\\n\"") g.write(";\n") @@ -322,11 +333,13 @@ def make_license_header(target, source, env): for k in j[0].split("\n"): if file_body != "": file_body += "\\n\"\n" - file_body += "\t\"" + k.strip().replace("\"", "\\\"") + escaped_string = escape_string(k.strip().replace("\"", "\\\"")) + file_body += "\t\"" + escaped_string for k in j[1].split("\n"): if copyright_body != "": copyright_body += "\\n\"\n" - copyright_body += "\t\"" + k.strip().replace("\"", "\\\"") + escaped_string = escape_string(k.strip().replace("\"", "\\\"")) + copyright_body += "\t\"" + escaped_string about_tp_file += "\t" + file_body + "\",\n" about_tp_copyright += "\t" + copyright_body + "\",\n" @@ -340,7 +353,8 @@ def make_license_header(target, source, env): for j in i[1].split("\n"): if body != "": body += "\\n\"\n" - body += "\t\"" + j.strip().replace("\"", "\\\"") + escaped_string = escape_string(j.strip().replace("\"", "\\\"")) + body += "\t\"" + escaped_string about_license_name += "\t\"" + i[0] + "\",\n" about_license_body += "\t" + body + "\",\n" |