Skip to content

Instantly share code, notes, and snippets.

@Krowemoh
Created Jul 27, 2022
Embed
What would you like to do?
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