| 35 | included = {} |
| 36 | total_line_count = 14 |
| 37 | def append(input_file_name, input_file, output_file, regex_includes, include_folder, line_directive_prefix, depth): |
| 38 | global total_line_count |
| 39 | inside_copyright = False |
| 40 | line_count = 1 |
| 41 | for line in input_file: |
| 42 | line_count += 1 |
| 43 | if 'Emil Dotchevski' in line: |
| 44 | inside_copyright = True |
| 45 | if inside_copyright: |
| 46 | if line.startswith('//') : |
| 47 | continue |
| 48 | if not line.strip(): |
| 49 | inside_copyright = False |
| 50 | if depth > 0: |
| 51 | output_file.write('%s#line %d "%s"\n' % (line_directive_prefix, line_count, input_file_name)) |
| 52 | continue |
| 53 | result = regex_includes.search(line) |
| 54 | if result: |
| 55 | next_input_file_name = result.group('include') |
| 56 | if next_input_file_name in included: |
| 57 | output_file.write('// %s // Expanded at line %d\n' % (line.strip(), included[next_input_file_name])) |
| 58 | total_line_count += 1 |
| 59 | else: |
| 60 | included[next_input_file_name] = total_line_count |
| 61 | print('%s (%d)' % (next_input_file_name, total_line_count)) |
| 62 | with open(os.path.join(include_folder, next_input_file_name), 'r') as next_input_file: |
| 63 | output_file.write('// >>> %s' % (line)) |
| 64 | total_line_count += 2 |
| 65 | append(next_input_file_name, next_input_file, output_file, regex_includes, include_folder, line_directive_prefix, depth + 1) |
| 66 | if depth > 0: |
| 67 | output_file.write('// <<< %s%s#line %d "%s"\n' % (line, line_directive_prefix, line_count, input_file_name)) |
| 68 | total_line_count += 2 |
| 69 | else: |
| 70 | output_file.write(line) |
| 71 | total_line_count += 1 |
| 72 | |
| 73 | def _main(): |
| 74 | parser = argparse.ArgumentParser( |