Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / libpurple / dbus-analyze-signals.py
blobc357ebd4828c72069debb3b686ac1596136ec8ed
1 # This program takes a C source as the input and produces the list of
2 # all signals registered.
4 # Output is:
5 # <signal name="Changed">
6 # <arg name="new_value" type="b"/>
7 # </signal>
8 from __future__ import absolute_import, division, print_function
10 import argparse
11 import fileinput
12 import re
13 import sys
16 # List "excluded" contains signals that shouldn't be exported via
17 # DBus. If you remove a signal from this list, please make sure
18 # that it does not break "make" with the configure option
19 # "--enable-dbus" turned on.
21 excluded = [
22 # purple_dbus_signal_emit_purple prevents our "dbus-method-called"
23 # signal from being propagated to dbus.
24 "dbus-method-called",
27 registerregex = re.compile(
28 "purple_signal_register[^;]+\"([\w\-]+)\"[^;]+(purple_marshal_\w+)[^;]+;")
29 nameregex = re.compile('[-_][a-z]')
31 parser = argparse.ArgumentParser()
32 parser.add_argument('input', nargs='*',
33 help='Input files (or stdin if not specified)')
34 parser.add_argument('-o', '--output', type=argparse.FileType('w'),
35 help='Output to file instead of stdout')
36 cmd_args = parser.parse_args()
38 print("/* Generated by %s. Do not edit! */" % (sys.argv[0], ),
39 file=cmd_args.output)
40 print("const char *dbus_signals = ", file=cmd_args.output)
41 input = ''.join(list(fileinput.input(cmd_args.input)))
42 for match in registerregex.finditer(input):
43 signal = match.group(1)
44 marshal = match.group(2)
45 if signal in excluded:
46 continue
48 signal = nameregex.sub(lambda x: x.group()[1].upper(), '-' + signal)
49 print("\" <signal name='%s'>\\n\"" % (signal, ), file=cmd_args.output)
51 args = marshal.split('_')
52 # ['purple', 'marshal', <return type>, '', args...]
53 if len(args) > 4:
54 for arg in args[4:]:
55 if arg == "POINTER":
56 type = 'p'
57 elif arg == "ENUM":
58 type = 'i'
59 elif arg == "INT":
60 type = 'i'
61 elif arg == "UINT":
62 type = 'u'
63 elif arg == "INT64":
64 type = 'x'
65 elif arg == "UINT64":
66 type = 't'
67 elif arg == "BOOLEAN":
68 type = 'b'
69 print("\" <arg type='%s'/>\\n\"" % (type, ),
70 file=cmd_args.output)
72 print("\" </signal>\\n\"", file=cmd_args.output)
74 print(";", file=cmd_args.output)