Merge pull request #11592 from SaracenOne/header_generator_fix
Python header generator now generates strings with escape characters.
This commit is contained in:
commit
de9cc6ed96
1 changed files with 22 additions and 8 deletions
30
editor/SCsub
30
editor/SCsub
|
@ -6,6 +6,16 @@ env.editor_sources = []
|
||||||
import os
|
import os
|
||||||
from compat import encode_utf8, byte_to_str, open_utf8
|
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):
|
def make_certs_header(target, source, env):
|
||||||
|
|
||||||
|
@ -162,7 +172,7 @@ def make_authors_header(target, source, env):
|
||||||
for line in f:
|
for line in f:
|
||||||
if reading:
|
if reading:
|
||||||
if line.startswith(" "):
|
if line.startswith(" "):
|
||||||
g.write("\t\"" + line.strip() + "\",\n")
|
g.write("\t\"" + escape_string(line.strip()) + "\",\n")
|
||||||
continue
|
continue
|
||||||
if line.startswith("## "):
|
if line.startswith("## "):
|
||||||
if reading:
|
if reading:
|
||||||
|
@ -170,7 +180,7 @@ def make_authors_header(target, source, env):
|
||||||
reading = False
|
reading = False
|
||||||
for i in range(len(sections)):
|
for i in range(len(sections)):
|
||||||
if line.strip().endswith(sections[i]):
|
if line.strip().endswith(sections[i]):
|
||||||
current_section = sections_id[i]
|
current_section = escape_string(sections_id[i])
|
||||||
reading = True
|
reading = True
|
||||||
g.write("static const char *" + current_section + "[] = {\n")
|
g.write("static const char *" + current_section + "[] = {\n")
|
||||||
break
|
break
|
||||||
|
@ -204,7 +214,7 @@ def make_donors_header(target, source, env):
|
||||||
for line in f:
|
for line in f:
|
||||||
if reading >= 0:
|
if reading >= 0:
|
||||||
if line.startswith(" "):
|
if line.startswith(" "):
|
||||||
g.write("\t\"" + line.strip() + "\",\n")
|
g.write("\t\"" + escape_string(line.strip()) + "\",\n")
|
||||||
continue
|
continue
|
||||||
if line.startswith("## "):
|
if line.startswith("## "):
|
||||||
if reading:
|
if reading:
|
||||||
|
@ -212,7 +222,7 @@ def make_donors_header(target, source, env):
|
||||||
reading = False
|
reading = False
|
||||||
for i in range(len(sections)):
|
for i in range(len(sections)):
|
||||||
if line.strip().endswith(sections[i]):
|
if line.strip().endswith(sections[i]):
|
||||||
current_section = sections_id[i]
|
current_section = escape_string(sections_id[i])
|
||||||
reading = True
|
reading = True
|
||||||
g.write("static const char *" + current_section + "[] = {\n")
|
g.write("static const char *" + current_section + "[] = {\n")
|
||||||
break
|
break
|
||||||
|
@ -237,7 +247,8 @@ def make_license_header(target, source, env):
|
||||||
g.write("static const char *about_license =")
|
g.write("static const char *about_license =")
|
||||||
|
|
||||||
for line in f:
|
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")
|
g.write(";\n")
|
||||||
|
|
||||||
|
@ -322,11 +333,13 @@ def make_license_header(target, source, env):
|
||||||
for k in j[0].split("\n"):
|
for k in j[0].split("\n"):
|
||||||
if file_body != "":
|
if file_body != "":
|
||||||
file_body += "\\n\"\n"
|
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"):
|
for k in j[1].split("\n"):
|
||||||
if copyright_body != "":
|
if copyright_body != "":
|
||||||
copyright_body += "\\n\"\n"
|
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_file += "\t" + file_body + "\",\n"
|
||||||
about_tp_copyright += "\t" + copyright_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"):
|
for j in i[1].split("\n"):
|
||||||
if body != "":
|
if body != "":
|
||||||
body += "\\n\"\n"
|
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_name += "\t\"" + i[0] + "\",\n"
|
||||||
about_license_body += "\t" + body + "\",\n"
|
about_license_body += "\t" + body + "\",\n"
|
||||||
|
|
Loading…
Reference in a new issue