From 527f434cb701b10634073516ecc5f29401ab3145 Mon Sep 17 00:00:00 2001 From: piepie62 Date: Wed, 21 Nov 2018 13:07:18 -0700 Subject: [PATCH] Strip comments --- genScripts.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/genScripts.py b/genScripts.py index 28be684..a791baa 100755 --- a/genScripts.py +++ b/genScripts.py @@ -18,12 +18,24 @@ def main(args): data = f.read() data = data.replace("\r\n", "\n") + + # Get rid of all comments + commentIndex = data.find("/*") + while commentIndex != -1: + data = data[:commentIndex] + data[data.find("*/")+2:] + commentIndex = data.find("/*") + + commentIndex = data.find("//") + while commentIndex != -1: + data = data[:commentIndex] + data[data[commentIndex+2:].find("\n")+1 + commentIndex+2:] + commentIndex = data.find("//") + lines = data.split("\n") out = "" for line in lines: line = line.strip() - # preprocessor directives and comments - if "#" in line or "//" in line: + # preprocessor directives + if "#" in line: out += line + "\n" # just in case there are multiline strings/macros elif line[len(line) - 1:] == "\\":