Skip to content

Instantly share code, notes, and snippets.

@Krowemoh
Created July 27, 2022 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krowemoh/29abe1b7096a04d166742b49abaac582 to your computer and use it in GitHub Desktop.
Save Krowemoh/29abe1b7096a04d166742b49abaac582 to your computer and use it in GitHub Desktop.
Remove ifdefs dependng on which defines are set
#!/usr/bin/env python3
import sys
f = open(sys.argv[1], "r")
lines = f.readlines()
symbolTable = { }
counter = 0
while counter < len(lines):
line = lines[counter]
counter = counter + 1
if "$DEFINE" in line:
line = line.strip()
print(line)
_, symbol = line.split(" ")
symbolTable[symbol] = True
continue
if "$IFDEF" in line:
line = line.strip()
_, symbol = line.split(" ")
if symbol in symbolTable:
continue
line = lines[counter]
stack = 1
while stack != 0:
if "$IFDEF" in line:
stack = stack + 1
if "$ENDIF" in line:
stack = stack - 1
counter = counter + 1
line = lines[counter]
continue
if "$ENDIF" in line:
continue
print(line[:-1])
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment