1 # This program takes a C header/source as the input and produces
3 # with --keyword=enum: the list of all enums
4 # with --keyword=struct: the list of all structs
8 # --enum DBUS_POINTER_NAME1,
17 from __future__
import absolute_import
, division
, print_function
25 def toprint(match
, line
):
29 return args
.pattern
% match
32 parser
= argparse
.ArgumentParser()
33 parser
.add_argument('input', nargs
='*',
34 help='Input files (or stdin if not specified)')
35 parser
.add_argument('-o', '--output', type=argparse
.FileType('w'),
36 help='Output to file instead of stdout')
37 parser
.add_argument('--keyword', default
='struct',
38 help='What keyword to search')
39 parser
.add_argument('--pattern', default
='%s',
40 help='String pattern used to print matches')
41 parser
.add_argument('--verbatim', action
='store_true',
42 help='Return full line of match instead of match itself')
43 args
= parser
.parse_args()
45 structregexp1
= re
.compile(
46 r
"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % (args
.keyword
, ))
47 structregexp2
= re
.compile(r
"^(typedef\s+)?%s" % (args
.keyword
, ))
48 structregexp3
= re
.compile(r
"^}\s+(\w+)\s*;")
50 print("/* Generated by %s. Do not edit! */" % (sys
.argv
[0], ),
53 myinput
= fileinput
.input(args
.input)
56 match
= structregexp1
.match(line
)
58 print(toprint(match
.group(2), line
), file=args
.output
)
61 match
= structregexp2
.match(line
)
65 print(line
.rstrip(), file=args
.output
)
67 match
= structregexp3
.match(line
)
69 print(toprint(match
.group(1), line
), file=args
.output
)
71 if line
[0] not in " \t{\n":
73 print(line
, file=args
.output
)