blob: b3c2e4488f4b459a68d28c1d92a88c8aed5db609 [file] [log] [blame]
John Bates4a66e7b2017-05-17 15:31:56 -07001#!/usr/bin/python
2import sys
3import os
4import argparse
5
6# Run this script to generate dvr_api.h in the current directory.
7
8def make_argument_parser():
9 parser = argparse.ArgumentParser(
10 description='Process DVR API headers into exportable SDK files.')
11 return parser
12
13parser = make_argument_parser()
14
15in_file = open("include/dvr/dvr_api.h", "r")
16out_file = open("./dvr_api.h", "w")
17
18h_filename = ""
19for 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
46in_file.close()
47out_file.close()