Skip to content

Commit

Permalink
Strip comments
Browse files Browse the repository at this point in the history
  • Loading branch information
piepie62 committed Nov 21, 2018
1 parent adb81da commit 527f434
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions genScripts.py
Expand Up @@ -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:] == "\\":
Expand Down

0 comments on commit 527f434

Please sign in to comment.