11146
|
1 # This program takes a C header/source as the input and produces
|
|
2 #
|
|
3 # with --keyword=enum: the list of all enums
|
|
4 # with --keyword=struct: the list of all structs
|
|
5 #
|
|
6 # the output styles:
|
|
7 #
|
|
8 # --enum DBUS_POINTER_NAME1,
|
|
9 # DBUS_POINTER_NAME2,
|
|
10 # DBUS_POINTER_NAME3,
|
|
11 #
|
|
12 # --list NAME1
|
|
13 # NAME2
|
|
14 # NAME3
|
|
15 #
|
|
16
|
|
17
|
|
18 import re
|
|
19 import sys
|
|
20
|
|
21 keyword = "struct"
|
11171
|
22 pattern = "%s"
|
11146
|
23
|
|
24 for arg in sys.argv[1:]:
|
|
25 if arg[0:2] == "--":
|
11171
|
26 mylist = arg[2:].split("=",1)
|
11146
|
27 command = mylist[0]
|
|
28 if len(mylist) > 1:
|
|
29 value = mylist[1]
|
|
30 else:
|
|
31 value = None
|
|
32
|
11171
|
33 if command == "pattern":
|
|
34 pattern = value
|
11146
|
35 if command == "keyword":
|
|
36 keyword = value
|
|
37
|
|
38
|
|
39 structregexp1 = re.compile(r"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % keyword)
|
|
40 structregexp2 = re.compile(r"^(typedef\s+)?%s" % keyword)
|
|
41 structregexp3 = re.compile(r"^}\s+(\w+)\s*;")
|
|
42
|
11171
|
43 myinput = iter(sys.stdin)
|
|
44
|
11146
|
45 for line in myinput:
|
|
46 match = structregexp1.match(line)
|
|
47 if match is not None:
|
11171
|
48 print pattern % match.group(2)
|
11146
|
49 continue
|
|
50
|
|
51 match = structregexp2.match(line)
|
|
52 if match is not None:
|
|
53 while True:
|
|
54 line = myinput.next()
|
|
55 match = structregexp3.match(line)
|
|
56 if match is not None:
|
11171
|
57 print pattern % match.group(1)
|
11146
|
58 break
|
|
59 if line[0] not in [" ", "\t", "{", "\n"]:
|
|
60 break
|
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|