John Bates | 4a66e7b | 2017-05-17 15:31:56 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | import sys |
| 3 | import os |
| 4 | import argparse |
| 5 | |
| 6 | # Run this script to generate dvr_api.h in the current directory. |
| 7 | |
| 8 | def make_argument_parser(): |
| 9 | parser = argparse.ArgumentParser( |
| 10 | description='Process DVR API headers into exportable SDK files.') |
| 11 | return parser |
| 12 | |
| 13 | parser = make_argument_parser() |
| 14 | |
| 15 | in_file = open("include/dvr/dvr_api.h", "r") |
| 16 | out_file = open("./dvr_api.h", "w") |
| 17 | |
| 18 | h_filename = "" |
| 19 | for line in in_file: |
| 20 | if line.startswith("// dvr_") and line.endswith(".h\n"): |
| 21 | h_filename = "include/dvr/" + line[3:].strip() |
| 22 | if line.startswith("typedef ") and "(*Dvr" in line: |
| 23 | start = line.find("(*Dvr") + 5 |
| 24 | end = line.find("Ptr)") |
| 25 | if end != -1: |
| 26 | name = "dvr" + line[start:end] |
| 27 | # Find the comments for this function and insert into output. |
| 28 | with open(h_filename, 'r') as h_file: |
| 29 | h_lines = h_file.readlines() |
| 30 | i = 1 |
| 31 | while i < len(h_lines): |
| 32 | if name in h_lines[i]: |
| 33 | end_i = i |
| 34 | while h_lines[i - 1].startswith("//"): i -= 1 |
| 35 | while i < end_i: |
| 36 | out_file.write(h_lines[i]) |
| 37 | i += 1 |
| 38 | break |
| 39 | i += 1 |
| 40 | if line.startswith('#include "dvr_api_entries.h"'): |
| 41 | with open("include/dvr/dvr_api_entries.h") as f: |
| 42 | out_file.write(f.read()) |
| 43 | else: |
| 44 | out_file.write(line) |
| 45 | |
| 46 | in_file.close() |
| 47 | out_file.close() |