Created
May 8, 2019 18:34
-
-
Save Ivoah/10de6d6ebca7e5ea9ba9e8a6dd06e971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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