| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import os |
| 4 |
import sys |
| 5 |
import argparse |
| 6 |
|
| 7 |
parser = argparse.ArgumentParser() |
| 8 |
parser.add_argument('target_dir', |
| 9 |
help='the target dir') |
| 10 |
parser.add_argument('stem', |
| 11 |
help='the stem') |
| 12 |
parser.add_argument('input', |
| 13 |
help='the input file') |
| 14 |
|
| 15 |
options = parser.parse_args(sys.argv[1:]) |
| 16 |
|
| 17 |
with open(options.input) as f: |
| 18 |
content = f.read() |
| 19 |
|
| 20 |
|
| 21 |
output_c = os.path.join(options.target_dir, options.stem + ".tab.c") |
| 22 |
with open(output_c, 'w', encoding='utf-8') as f: |
| 23 |
f.write(content) |
| 24 |
|
| 25 |
|
| 26 |
output_h = os.path.join(options.target_dir, options.stem + ".tab.h") |
| 27 |
h_content = '''#pragma once |
| 28 |
|
| 29 |
int myfun(void); |
| 30 |
''' |
| 31 |
with open(output_h, 'w', encoding='utf-8') as f: |
| 32 |
f.write(h_content) |