libpurple/dbus-analyze-types.py

Thu, 01 Jun 2017 21:35:39 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Thu, 01 Jun 2017 21:35:39 -0500
changeset 38365
2ee19fb5fb0d
parent 37985
c3bab3be9695
child 38358
30ba44276e74
permissions
-rw-r--r--

libpurple: Use default marshaller for GObject signals

Since 2.30 it's been possible to use a default c_marshaller by
passing NULL to g_signal_new(). It has since become the recommended
way of creating signals.
https://developer.gnome.org/gobject/stable/howto-signals.html

This patch ports libpurple to use this method instead of generating
its own marshallers with glib-genmarshal.

# This program takes a C header/source as the input and produces
#
# with --keyword=enum: the list of all enums
# with --keyword=struct: the list of all structs
#
# the output styles:
#
# --enum    DBUS_POINTER_NAME1,
#           DBUS_POINTER_NAME2,
#           DBUS_POINTER_NAME3,
#
# --list    NAME1
#           NAME2
#           NAME3
#

from __future__ import absolute_import, division, print_function

import argparse
import fileinput
import re
import sys


def toprint(match, line):
    if args.verbatim:
        return line
    else:
        return args.pattern % match


parser = argparse.ArgumentParser()
parser.add_argument('input', nargs='*',
                    help='Input files (or stdin if not specified)')
parser.add_argument('-o', '--output', type=argparse.FileType('w'),
                    help='Output to file instead of stdout')
parser.add_argument('--keyword', default='struct',
                    help='What keyword to search')
parser.add_argument('--pattern', default='%s',
                    help='String pattern used to print matches')
parser.add_argument('--verbatim', action='store_true',
                    help='Return full line of match instead of match itself')
args = parser.parse_args()

structregexp1 = re.compile(
    r"^(typedef\s+)?%s\s+\w+\s+(\w+)\s*;" % (args.keyword, ))
structregexp2 = re.compile(r"^(typedef\s+)?%s" % (args.keyword, ))
structregexp3 = re.compile(r"^}\s+(\w+)\s*;")

print("/* Generated by %s.  Do not edit! */" % (sys.argv[0], ),
      file=args.output)

myinput = fileinput.input(args.input)

for line in myinput:
    match = structregexp1.match(line)
    if match is not None:
        print(toprint(match.group(2), line), file=args.output)
        continue

    match = structregexp2.match(line)
    if match is not None:
        while True:
            if args.verbatim:
                print(line.rstrip(), file=args.output)
            line = next(myinput)
            match = structregexp3.match(line)
            if match is not None:
                print(toprint(match.group(1), line), file=args.output)
                break
            if line[0] not in " \t{\n":
                if args.verbatim:
                    print(line, file=args.output)
                break

mercurial