()
| 115 | |
| 116 | |
| 117 | def main(): |
| 118 | parser = argparse.ArgumentParser( |
| 119 | description="""Create a context file which can be used for decomp.me""" |
| 120 | ) |
| 121 | parser.add_argument( |
| 122 | "c_file", |
| 123 | help="""File from which to create context""", |
| 124 | ) |
| 125 | parser.add_argument( |
| 126 | "-o", |
| 127 | "--output", |
| 128 | help="""Output file""", |
| 129 | default="ctx.c", |
| 130 | ) |
| 131 | parser.add_argument( |
| 132 | "-d", |
| 133 | "--depfile", |
| 134 | help="""Dependency file""", |
| 135 | ) |
| 136 | parser.add_argument( |
| 137 | "-I", |
| 138 | "--include", |
| 139 | help="""Include directory""", |
| 140 | action="append", |
| 141 | ) |
| 142 | parser.add_argument( |
| 143 | "-x", |
| 144 | "--exclude", |
| 145 | help="""Excluded file name glob""", |
| 146 | action="append", |
| 147 | ) |
| 148 | parser.add_argument( |
| 149 | "-D", |
| 150 | "--define", |
| 151 | help="""Macro definition""", |
| 152 | action="append", |
| 153 | ) |
| 154 | args = parser.parse_args() |
| 155 | |
| 156 | if args.include is None: |
| 157 | exit("No include directories specified") |
| 158 | global include_dirs |
| 159 | include_dirs = args.include |
| 160 | global exclude_globs |
| 161 | exclude_globs = args.exclude or [] |
| 162 | prelude_defines = args.define or [] |
| 163 | output = generate_prelude(prelude_defines) |
| 164 | output += import_c_file(args.c_file) |
| 165 | |
| 166 | with open(os.path.join(root_dir, args.output), "w", encoding="utf-8") as f: |
| 167 | f.write(output) |
| 168 | |
| 169 | if args.depfile: |
| 170 | with open(os.path.join(root_dir, args.depfile), "w", encoding="utf-8") as f: |
| 171 | f.write(sanitize_path(args.output) + ":") |
| 172 | for dep in deps: |
| 173 | path = sanitize_path(dep) |
| 174 | f.write(f" \\\n\t{path}") |
no test coverage detected