From 787ac38aae90231b9db9c71cf19dfc617ca58166 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Wed, 24 Jul 2019 15:29:33 +0100 Subject: [PATCH] Get rid of trigraphs in string defaults when genereating config CL: Get rid of trigraphs in string defaults when genereating config --- tools/mgos_gen_config.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/mgos_gen_config.py b/tools/mgos_gen_config.py index 68dd4f3ca..fabb80de0 100755 --- a/tools/mgos_gen_config.py +++ b/tools/mgos_gen_config.py @@ -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 = [] @@ -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: