Skip to content

Instantly share code, notes, and snippets.

@Ivoah
Created May 8, 2019 18:34
Show Gist options
  • Save Ivoah/10de6d6ebca7e5ea9ba9e8a6dd06e971 to your computer and use it in GitHub Desktop.
Save Ivoah/10de6d6ebca7e5ea9ba9e8a6dd06e971 to your computer and use it in GitHub Desktop.
import subprocess
import re
CC = 'gcc'
FILE = 'main.c'
OUTPUT = 'fbcp'
error_re = re.compile(r'main\.c:(\d+):\d+: (?:(?:fatal )?error|warning)')
def comment_line(l):
with open(FILE) as f:
old_code = f.readlines()
if not old_code[l - 1].startswith('//'):
old_code[l - 1] = '// ' + old_code[l - 1]
with open(FILE, 'w') as f:
f.write(''.join(old_code))
fixed_error = True
while fixed_error:
output = subprocess.run([CC, FILE, '-o', OUTPUT], capture_output=True).stderr.decode('utf8')
fixed_error = False
for match in error_re.finditer(output):
comment_line(int(match.group(1)))
fixed_error = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment