Remove useless comparison
[pidgin-git.git] / libpurple / dbus-analyze-types.py
blob548a8797883052013a49029d06863a7918886f21
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
6 # the output styles:
8 # --enum DBUS_POINTER_NAME1,
9 # DBUS_POINTER_NAME2,
10 # DBUS_POINTER_NAME3,
12 # --list NAME1
13 # NAME2
14 # NAME3
17 from __future__ import print_function
18 import re
19 import sys
21 options = {}
23 def toprint(match, line):
24 if verbatim:
25 return line
26 else:
27 return pattern % match
29 for arg in sys.argv[1:]:
30 if arg[0:2] == "--":
31 mylist = arg[2:].split("=",1)
32 command = mylist[0]
33 if len(mylist) > 1:
34 options[command] = mylist[1]
35 else:
36 options[command] = None
38 keyword = options.get("keyword", "struct")
39 pattern = options.get("pattern", "%s")
40 verbatim = "verbatim" in options
42 structregexp1 = re.compile(r"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % keyword)
43 structregexp2 = re.compile(r"^(typedef\s+)?%s" % keyword)
44 structregexp3 = re.compile(r"^}\s+(\w+)\s*;")
46 print("/* Generated by %s. Do not edit! */" % sys.argv[0])
48 myinput = iter(sys.stdin)
50 for line in myinput:
51 match = structregexp1.match(line)
52 if match is not None:
53 print(toprint(match.group(2), line))
54 continue
56 match = structregexp2.match(line)
57 if match is not None:
58 while True:
59 if verbatim:
60 print(line.rstrip())
61 line = next(myinput)
62 match = structregexp3.match(line)
63 if match is not None:
64 print(toprint(match.group(1), line))
65 break
66 if line[0] not in [" ", "\t", "{", "\n"]:
67 if verbatim:
68 print(line)
69 break