minor improvement, strip newlines from end of code snippets

This commit is contained in:
Thibault Kruse 2016-09-10 09:16:57 +09:00
parent 1842b88c21
commit 084eb29d42

View File

@ -117,10 +117,24 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
text_filehandle.write('\n')
if (has_actual_code and not has_question_marks):
linebuffer = clean_trailing_newlines(linebuffer)
write_with_harness(codefile, sourcefile, start_linenum, linebuffer)
return (line, linenum)
def clean_trailing_newlines(linebuffer):
result = []
code_started = False
linebuffer.reverse()
for line in linebuffer:
if not code_started and line == '\n':
continue
code_started = True
result.append(line)
result.reverse()
return result
def write_with_harness(codefile, sourcefile, start_linenum, linebuffer):
'''write output with additional lines to make code likely compilable'''
# add commonly used headers, so that lines can likely compile.