Skip to content

Commit 787ac38

Browse files
committed
Get rid of trigraphs in string defaults when genereating config
CL: Get rid of trigraphs in string defaults when genereating config
1 parent 4681825 commit 787ac38

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tools/mgos_gen_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ def GetHeaderLines(self):
424424

425425
return lines
426426

427+
@staticmethod
428+
def EscapeCString(s):
429+
# JSON encoder will provide acceptable escaping.
430+
s = json.dumps(s)
431+
# Get rid of trigraph sequences.
432+
for a, b in ((r"??(", r"?\?("), (r"??)", r"?\?)"), (r"??<", r"?\?<"), (r"??>", r"?\?>"),
433+
(r"??=", r"?\?="), (r"??/", r"?\?/"), (r"??'", r"?\?'"), (r"??!", r"?\?-")):
434+
if a in s:
435+
s = s.replace(a, b)
436+
return s
437+
427438
# Returns array of lines to be pasted to the C source file.
428439
def GetSourceLines(self):
429440
lines = []
@@ -437,8 +448,7 @@ def GetSourceLines(self):
437448
pass
438449
elif e.vtype == SchemaEntry.V_STRING:
439450
if e.default:
440-
# JSON encoder will provide escaping.
441-
lines.append(" .%s = %s," % (e.path, json.dumps(e.default)))
451+
lines.append(" .%s = %s," % (e.path, self.EscapeCString(e.default)))
442452
else:
443453
lines.append(" .%s = NULL," % e.path)
444454
elif e.vtype == SchemaEntry.V_BOOL:

0 commit comments

Comments
 (0)