Skip to content

Commit

Permalink
Get rid of trigraphs in string defaults when genereating config
Browse files Browse the repository at this point in the history
CL: Get rid of trigraphs in string defaults when genereating config
  • Loading branch information
rojer committed Jul 24, 2019
1 parent 4681825 commit 787ac38
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/mgos_gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ def GetHeaderLines(self):

return lines

@staticmethod
def EscapeCString(s):
# JSON encoder will provide acceptable escaping.
s = json.dumps(s)
# Get rid of trigraph sequences.
for a, b in ((r"??(", r"?\?("), (r"??)", r"?\?)"), (r"??<", r"?\?<"), (r"??>", r"?\?>"),
(r"??=", r"?\?="), (r"??/", r"?\?/"), (r"??'", r"?\?'"), (r"??!", r"?\?-")):
if a in s:
s = s.replace(a, b)
return s

# Returns array of lines to be pasted to the C source file.
def GetSourceLines(self):
lines = []
Expand All @@ -437,8 +448,7 @@ def GetSourceLines(self):
pass
elif e.vtype == SchemaEntry.V_STRING:
if e.default:
# JSON encoder will provide escaping.
lines.append(" .%s = %s," % (e.path, json.dumps(e.default)))
lines.append(" .%s = %s," % (e.path, self.EscapeCString(e.default)))
else:
lines.append(" .%s = NULL," % e.path)
elif e.vtype == SchemaEntry.V_BOOL:
Expand Down

0 comments on commit 787ac38

Please sign in to comment.