| 63 | |
| 64 | # These get_header_* functions are ugly, but they work :) |
| 65 | def get_header_py(fp): |
| 66 | with open(fp, "r") as f: |
| 67 | lines = iter(l for l in f.readlines()) |
| 68 | |
| 69 | header = [] |
| 70 | rest = [] |
| 71 | in_multiline = False |
| 72 | multiline_type = None |
| 73 | |
| 74 | while (l := next(lines, None)) is not None: |
| 75 | l = l.strip() |
| 76 | if l.startswith(PY_ML_SINGLE) or l.startswith(PY_ML_DOUBLE): |
| 77 | # Detected multiline comment |
| 78 | if in_multiline and multiline_type == l[:3]: |
| 79 | # Ended a multiline comment |
| 80 | in_multiline = False |
| 81 | else: |
| 82 | # Started a multiline comment |
| 83 | in_multiline = True |
| 84 | multiline_type = l[:3] |
| 85 | if l.endswith(multiline_type) and len(l) >= 6: |
| 86 | # Opened and closed multiline comment on single line |
| 87 | in_multiline = False |
| 88 | elif in_multiline and l.endswith(multiline_type): |
| 89 | # Ended a multiline comment |
| 90 | in_multiline = False |
| 91 | elif not (in_multiline or l.startswith(PY_SL_COMMENT) or l == ""): |
| 92 | # Not in a comment |
| 93 | rest += [l + "\n"] |
| 94 | break |
| 95 | header.append(l) |
| 96 | |
| 97 | rest += list(lines) |
| 98 | |
| 99 | return header, rest |
| 100 | |
| 101 | |
| 102 | def get_header_c(fp): |