Mercurial > pidgin.yaz
comparison src/dbus-analyze-types.py @ 11331:64fadbf3810f
[gaim-migrate @ 13544]
General polishing of DBus code, improving examples, removing obsolete files.
committer: Tailor Script <tailor@pidgin.im>
author | Piotr Zielinski <zielaj> |
---|---|
date | Wed, 24 Aug 2005 02:34:40 +0000 |
parents | ebb02ea3c789 |
children |
comparison
equal
deleted
inserted
replaced
11330:d41a83d221b0 | 11331:64fadbf3810f |
---|---|
16 | 16 |
17 | 17 |
18 import re | 18 import re |
19 import sys | 19 import sys |
20 | 20 |
21 keyword = "struct" | 21 options = {} |
22 pattern = "%s" | 22 |
23 def toprint(match, line): | |
24 if verbatim: | |
25 return line | |
26 else: | |
27 return pattern % match | |
23 | 28 |
24 for arg in sys.argv[1:]: | 29 for arg in sys.argv[1:]: |
25 if arg[0:2] == "--": | 30 if arg[0:2] == "--": |
26 mylist = arg[2:].split("=",1) | 31 mylist = arg[2:].split("=",1) |
27 command = mylist[0] | 32 command = mylist[0] |
28 if len(mylist) > 1: | 33 if len(mylist) > 1: |
29 value = mylist[1] | 34 options[command] = mylist[1] |
30 else: | 35 else: |
31 value = None | 36 options[command] = None |
32 | 37 |
33 if command == "pattern": | 38 keyword = options.get("keyword", "struct") |
34 pattern = value | 39 pattern = options.get("pattern", "%s") |
35 if command == "keyword": | 40 verbatim = options.has_key("verbatim") |
36 keyword = value | |
37 | |
38 | 41 |
39 structregexp1 = re.compile(r"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % keyword) | 42 structregexp1 = re.compile(r"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % keyword) |
40 structregexp2 = re.compile(r"^(typedef\s+)?%s" % keyword) | 43 structregexp2 = re.compile(r"^(typedef\s+)?%s" % keyword) |
41 structregexp3 = re.compile(r"^}\s+(\w+)\s*;") | 44 structregexp3 = re.compile(r"^}\s+(\w+)\s*;") |
45 | |
46 print "/* Generated by %s. Do not edit! */" % sys.argv[0] | |
42 | 47 |
43 myinput = iter(sys.stdin) | 48 myinput = iter(sys.stdin) |
44 | 49 |
45 for line in myinput: | 50 for line in myinput: |
46 match = structregexp1.match(line) | 51 match = structregexp1.match(line) |
47 if match is not None: | 52 if match is not None: |
48 print pattern % match.group(2) | 53 print toprint(match.group(2), line) |
49 continue | 54 continue |
50 | 55 |
51 match = structregexp2.match(line) | 56 match = structregexp2.match(line) |
52 if match is not None: | 57 if match is not None: |
53 while True: | 58 while True: |
59 if verbatim: | |
60 print line.rstrip() | |
54 line = myinput.next() | 61 line = myinput.next() |
55 match = structregexp3.match(line) | 62 match = structregexp3.match(line) |
56 if match is not None: | 63 if match is not None: |
57 print pattern % match.group(1) | 64 print toprint(match.group(1), line) |
58 break | 65 break |
59 if line[0] not in [" ", "\t", "{", "\n"]: | 66 if line[0] not in [" ", "\t", "{", "\n"]: |
67 if verbatim: | |
68 print line | |
60 break | 69 break |
61 | 70 |
62 | 71 |
63 | 72 |
64 | 73 |