def do_flags(self, flags):
        name = flags.getAttribute('plural') or flags.getAttribute('name')
        value_prefix = flags.getAttribute('singular') or \
                       flags.getAttribute('value-prefix') or \
                       flags.getAttribute('name')
        self.d("""\
/**
 *
%s:
""" % (self.prefix + name).replace('_', ''))
        for flag in get_by_path(flags, 'flag'):
            self.do_gtkdoc(flag, value_prefix)
        self.d(' *\n')
        docstrings = get_by_path(flags, 'docstring')
        if docstrings:
            self.d("""\
 * <![CDATA[%s]]>
 *
""" % get_descendant_text(docstrings).replace('\n', ' '))
        self.d("""\
 * Bitfield/set of flags generated from the Telepathy specification.
 */
""")

        self.write("typedef enum /*< flags >*/ {\n")

        for flag in get_by_path(flags, 'flag'):
            self.do_val(flag, value_prefix)
        self.write("""\
} %s;

""" % (self.prefix + name).replace('_', ''))
Beispiel #2
0
    def do_flags(self, flags):
        name = flags.getAttribute('plural') or flags.getAttribute('name')
        value_prefix = flags.getAttribute('singular') or \
                       flags.getAttribute('value-prefix') or \
                       flags.getAttribute('name')
        self.d("""\
/**
 * %s:
""" % (self.prefix + name).replace('_', ''))
        for flag in get_by_path(flags, 'flag'):
            self.do_gtkdoc(flag, value_prefix)
        self.d(' *\n')
        docstrings = get_by_path(flags, 'docstring')
        if docstrings:
            self.d("""\
 * <![CDATA[%s]]>
 *
""" % get_descendant_text(docstrings).replace('\n', ' '))
        self.d("""\
 * Bitfield/set of flags generated from the Telepathy specification.
 */
""")

        self.write("typedef enum /*< flags >*/ {\n")

        for flag in get_by_path(flags, 'flag'):
            self.do_val(flag, value_prefix)
        self.write("""\
} %s;

""" % (self.prefix + name).replace('_', ''))
    def do_enum(self, enum):
        name = enum.getAttribute('singular') or enum.getAttribute('name')
        value_prefix = enum.getAttribute('singular') or \
                       enum.getAttribute('value-prefix') or \
                       enum.getAttribute('name')
        name_plural = enum.getAttribute('plural') or \
                      enum.getAttribute('name') + 's'
        self.d("""\
/**
 * %s:
""" % (self.prefix + name).replace('_', ''))
        vals = get_by_path(enum, 'enumvalue')
        for val in vals:
            self.do_gtkdoc(val, value_prefix)
        self.d(' *\n')
        docstrings = get_by_path(enum, 'docstring')
        if docstrings:
            self.d("""\
 * <![CDATA[%s]]>
 *
""" % get_descendant_text(docstrings).replace('\n', ' '))
        self.d("""\
 * Bitfield/set of flags generated from the Telepathy specification.
 */
""")

        self.write("typedef enum {\n")

        for val in vals:
            self.do_val(val, value_prefix)
        self.write("} %s;\n" % (self.prefix + name).replace('_', ''))

        self.d("""\
/**
 * %(upper-prefix)sNUM_%(upper-plural)s:
 *
 * 1 higher than the highest valid value of #%(mixed-name)s.
 */

/**
 * NUM_%(upper-prefix)s%(upper-plural)s: (skip)
 *
 * 1 higher than the highest valid value of #%(mixed-name)s.
 * In new code, use %(upper-prefix)sNUM_%(upper-plural)s instead.
 */
""" % {'mixed-name' : (self.prefix + name).replace('_', ''),
       'upper-prefix' : self.prefix.upper(),
       'upper-plural' : name_plural.upper(),
       'last-val' : vals[-1].getAttribute('value')})

        self.write("""\
#define %(upper-prefix)sNUM_%(upper-plural)s (%(last-val)s+1)
#define NUM_%(upper-prefix)s%(upper-plural)s %(upper-prefix)sNUM_%(upper-plural)s

""" % {'mixed-name' : (self.prefix + name).replace('_', ''),
       'upper-prefix' : self.prefix.upper(),
       'upper-plural' : name_plural.upper(),
       'last-val' : vals[-1].getAttribute('value')})
    def do_enum(self, enum):
        name = enum.getAttribute('singular') or enum.getAttribute('name')
        value_prefix = enum.getAttribute('singular') or \
                       enum.getAttribute('value-prefix') or \
                       enum.getAttribute('name')
        name_plural = enum.getAttribute('plural') or \
                      enum.getAttribute('name') + 's'
        self.d("""\
/**
 *
%s:
""" % (self.prefix + name).replace('_', ''))
        vals = get_by_path(enum, 'enumvalue')
        for val in vals:
            self.do_gtkdoc(val, value_prefix)
        self.d(' *\n')
        docstrings = get_by_path(enum, 'docstring')
        if docstrings:
            self.d("""\
 * <![CDATA[%s]]>
 *
""" % get_descendant_text(docstrings).replace('\n', ' '))
        self.d("""\
 * Bitfield/set of flags generated from the Telepathy specification.
 */
""")

        self.write("typedef enum {\n")

        for val in vals:
            self.do_val(val, value_prefix)
        self.write("} %s;\n" % (self.prefix + name).replace('_', ''))

        self.d(
            """\
/**
 * NUM_%(upper-plural)s:
 *
 * 1 higher than the highest valid value of #%(mixed-name)s.
 */
""" % {
                'mixed-name': (self.prefix + name).replace('_', ''),
                'upper-plural': (self.prefix + name_plural).upper(),
                'last-val': vals[-1].getAttribute('value')
            })

        self.write(
            """\
#define NUM_%(upper-plural)s (%(last-val)s+1)

""" % {
                'mixed-name': (self.prefix + name).replace('_', ''),
                'upper-plural': (self.prefix + name_plural).upper(),
                'last-val': vals[-1].getAttribute('value')
            })
Beispiel #5
0
    def __init__(self, prefix, dom, output_base):
        self.prefix = prefix + '_'
        self.spec = get_by_path(dom, "spec")[0]

        self.output_base = output_base
        self.__header = []
        self.__docs = []
    def __init__(self, prefix, dom, output_base):
        self.prefix = prefix + '_'
        self.spec = get_by_path(dom, "spec")[0]

        self.output_base = output_base
        self.__header = []
        self.__docs = []
 def do_gtkdoc(self, node, value_prefix):
     self.d(' * @')
     self.d((self.prefix + value_prefix + '_' +
         node.getAttribute('suffix')).upper())
     self.d(': <![CDATA[')
     docstring = get_by_path(node, 'docstring')
     self.d(get_descendant_text(docstring).replace('\n', ' '))
     self.d(']]>\n')
    def do_header(self, f):
        f('/* Generated from: ')
        f(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")
        if version:
            f(' version ' + get_descendant_text(version))
        f('\n\n')
        for copyright in get_by_path(self.spec, 'copyright'):
            f(get_descendant_text(copyright))
            f('\n')
        f('\n')
        f(get_descendant_text(get_by_path(self.spec, 'license')))
        f(get_descendant_text(get_by_path(self.spec, 'docstring')))
        f("""
 */

""")
    def do_header(self, f):
        f('/* Generated from: ')
        f(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")
        if version:
            f(' version ' + get_descendant_text(version))
        f('\n\n')
        for copyright in get_by_path(self.spec, 'copyright'):
            f(get_descendant_text(copyright))
            f('\n')
        f('\n')
        f(get_descendant_text(get_by_path(self.spec, 'license')))
        f(get_descendant_text(get_by_path(self.spec, 'docstring')))
        f("""
 */

""")
Beispiel #10
0
 def do_gtkdoc(self, node, value_prefix):
     self.d(' * @')
     self.d((self.prefix + value_prefix + '_' +
             node.getAttribute('suffix')).upper())
     self.d(': <![CDATA[')
     docstring = get_by_path(node, 'docstring')
     self.d(get_descendant_text(docstring).replace('\n', ' '))
     self.d(']]>\n')
    def __init__(self, prefix, implfile, declfile, dom):
        self.prefix = prefix + '_'

        assert declfile.endswith('.h')
        docfile = declfile[:-2] + '-gtk-doc.h'

        self.impls = open(implfile, 'w')
        self.decls = open(declfile, 'w')
        self.docs = open(docfile, 'w')
        self.spec = get_by_path(dom, "spec")[0]
    def __init__(self, prefix, implfile, declfile, dom):
        self.prefix = prefix + '_'

        assert declfile.endswith('.h')
        docfile = declfile[:-2] + '-gtk-doc.h'

        self.impls = open(implfile, 'w')
        self.decls = open(declfile, 'w')
        self.docs = open(docfile, 'w')
        self.spec = get_by_path(dom, "spec")[0]
Beispiel #13
0
    def do_header(self):
        self.write('/* Generated from ')
        self.write(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")
        if version:
            self.write(', version ' + get_descendant_text(version))
        self.write('\n\n')
        for copyright in get_by_path(self.spec, 'copyright'):
            self.write(get_descendant_text(copyright))
            self.write('\n')
        self.write(get_descendant_text(get_by_path(self.spec, 'license')))
        self.write('\n')
        self.write(get_descendant_text(get_by_path(self.spec, 'docstring')))
        self.write("""
 */

#ifdef __cplusplus
extern "C" {
#endif
\n""")
    def do_header(self):
        self.write('/* Generated from ')
        self.write(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")
        if version:
            self.write(', version ' + get_descendant_text(version))
        self.write('\n\n')
        for copyright in get_by_path(self.spec, 'copyright'):
            self.write(get_descendant_text(copyright))
            self.write('\n')
        self.write(get_descendant_text(get_by_path(self.spec, 'license')))
        self.write('\n')
        self.write(get_descendant_text(get_by_path(self.spec, 'docstring')))
        self.write("""
 */

#ifdef __cplusplus
extern "C" {
#endif
\n""")
    def do_iface(self, iface):
        parent_name = get_by_path(iface, '../@name')
        self.h("""\
/**
 * %(IFACE_DEFINE)s:
 *
 * The interface name "%(name)s"
 */
#define %(IFACE_DEFINE)s \\
"%(name)s"
""" % {'IFACE_DEFINE' : (self.prefix + 'IFACE_' + \
            parent_name).upper().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.h("""
/**
 * %(IFACE_QUARK_DEFINE)s:
 *
 * Expands to a call to a function that returns a quark for the interface \
name "%(name)s"
 */
#define %(IFACE_QUARK_DEFINE)s \\
  (%(iface_quark_func)s ())

GQuark %(iface_quark_func)s (void);

""" % {'IFACE_QUARK_DEFINE' : (self.prefix + 'IFACE_QUARK_' + \
            parent_name).upper().replace('/', ''),
       'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.c("""\
GQuark
%(iface_quark_func)s (void)
{
  static GQuark quark = 0;

  if (G_UNLIKELY (quark == 0))
    {
      quark = g_quark_from_static_string ("%(name)s");
    }

  return quark;
}

""" % {'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
       'name' : iface.getAttribute('name')})
    def do_iface(self, iface):
        parent_name = get_by_path(iface, '../@name')
        self.d("""\
/**
 * %(IFACE_DEFINE)s:
 *
 * The interface name "%(name)s"
 */
""" % {'IFACE_DEFINE' : (self.prefix + 'IFACE_' + \
            parent_name).upper().replace('/', ''),
        'name' : iface.getAttribute('name')})

        self.h("""
#define %(IFACE_DEFINE)s \\
"%(name)s"
""" % {'IFACE_DEFINE' : (self.prefix + 'IFACE_' + \
            parent_name).upper().replace('/', ''),
        'name' : iface.getAttribute('name')})

        self.d("""
/**
 * %(IFACE_QUARK_DEFINE)s:
 *
 * Expands to a call to a function that returns a quark for the interface \
name "%(name)s"
 */
""" % {'IFACE_QUARK_DEFINE' : (self.prefix + 'IFACE_QUARK_' + \
            parent_name).upper().replace('/', ''),
        'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
        'name' : iface.getAttribute('name')})

        self.h("""
#define %(IFACE_QUARK_DEFINE)s \\
  (%(iface_quark_func)s ())

GQuark %(iface_quark_func)s (void);

""" % {'IFACE_QUARK_DEFINE' : (self.prefix + 'IFACE_QUARK_' + \
            parent_name).upper().replace('/', ''),
        'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
        'name' : iface.getAttribute('name')})

        self.c("""\
GQuark
%(iface_quark_func)s (void)
{
  static GQuark quark = 0;

  if (G_UNLIKELY (quark == 0))
    {
      quark = g_quark_from_static_string ("%(name)s");
    }

  return quark;
}

""" % {'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
        'name' : iface.getAttribute('name')})

        for prop in iface.getElementsByTagNameNS(None, 'property'):
            self.d("""
/**
 * %(IFACE_PREFIX)s_%(PROP_UC)s:
 *
 * The fully-qualified property name "%(name)s.%(prop)s"
 */
""" % {'IFACE_PREFIX' : (self.prefix + 'PROP_' + \
                parent_name).upper().replace('/', ''),
            'PROP_UC': prop.getAttributeNS(NS_TP, "name-for-bindings").upper(),
            'name' : iface.getAttribute('name'),
            'prop' : prop.getAttribute('name'),
            })

            self.h("""
#define %(IFACE_PREFIX)s_%(PROP_UC)s \\
"%(name)s.%(prop)s"
""" % {'IFACE_PREFIX' : (self.prefix + 'PROP_' + \
                parent_name).upper().replace('/', ''),
            'PROP_UC': prop.getAttributeNS(NS_TP, "name-for-bindings").upper(),
            'name' : iface.getAttribute('name'),
            'prop' : prop.getAttribute('name'),
            })

        for prop in iface.getElementsByTagNameNS(NS_TP, 'contact-attribute'):
            self.d("""
/**
 * %(TOKEN_PREFIX)s_%(TOKEN_UC)s:
 *
 * The fully-qualified contact attribute token name "%(name)s/%(prop)s"
 */
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
            'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
            'name' : iface.getAttribute('name'),
            'prop' : prop.getAttribute('name'),
            })

            self.h("""
#define %(TOKEN_PREFIX)s_%(TOKEN_UC)s \\
"%(name)s/%(prop)s"
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
            'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
            'name' : iface.getAttribute('name'),
            'prop' : prop.getAttribute('name'),
            })

        for prop in iface.getElementsByTagNameNS(NS_TP, 'hct'):
            if (prop.getAttribute('is-family') != "yes"):
                self.d("""
/**
 * %(TOKEN_PREFIX)s_%(TOKEN_UC)s:
 *
 * The fully-qualified capability token name "%(name)s/%(prop)s"
 */
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
                'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
                'name' : iface.getAttribute('name'),
                'prop' : prop.getAttribute('name'),
                })

                self.h("""
#define %(TOKEN_PREFIX)s_%(TOKEN_UC)s \\
"%(name)s/%(prop)s"
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
                'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
                'name' : iface.getAttribute('name'),
                'prop' : prop.getAttribute('name'),
                })
    def do_iface(self, iface):
        parent_name = get_by_path(iface, '../@name')
        self.d("""\
/**
 * %(IFACE_DEFINE)s:
 *
 * The interface name "%(name)s"
 */
""" % {'IFACE_DEFINE' : (self.prefix + 'IFACE_' + \
            parent_name).upper().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.h("""
#define %(IFACE_DEFINE)s \\
"%(name)s"
""" % {'IFACE_DEFINE' : (self.prefix + 'IFACE_' + \
            parent_name).upper().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.d("""
/**
 * %(IFACE_QUARK_DEFINE)s:
 *
 * Expands to a call to a function that returns a quark for the interface \
name "%(name)s"
 */
""" % {'IFACE_QUARK_DEFINE' : (self.prefix + 'IFACE_QUARK_' + \
            parent_name).upper().replace('/', ''),
       'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.h("""
#define %(IFACE_QUARK_DEFINE)s \\
  (%(iface_quark_func)s ())

GQuark %(iface_quark_func)s (void);

""" % {'IFACE_QUARK_DEFINE' : (self.prefix + 'IFACE_QUARK_' + \
            parent_name).upper().replace('/', ''),
       'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
       'name' : iface.getAttribute('name')})

        self.c("""\
GQuark
%(iface_quark_func)s (void)
{
  static GQuark quark = 0;

  if (G_UNLIKELY (quark == 0))
    {
      quark = g_quark_from_static_string ("%(name)s");
    }

  return quark;
}

""" % {'iface_quark_func' : (self.prefix + 'iface_quark_' + \
            parent_name).lower().replace('/', ''),
       'name' : iface.getAttribute('name')})

        for prop in iface.getElementsByTagNameNS(None, 'property'):
            self.d("""
/**
 * %(IFACE_PREFIX)s_%(PROP_UC)s:
 *
 * The fully-qualified property name "%(name)s.%(prop)s"
 */
""" % {'IFACE_PREFIX' : (self.prefix + 'PROP_' + \
                parent_name).upper().replace('/', ''),
           'PROP_UC': prop.getAttributeNS(NS_TP, "name-for-bindings").upper(),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })

            self.h("""
#define %(IFACE_PREFIX)s_%(PROP_UC)s \\
"%(name)s.%(prop)s"
""" % {'IFACE_PREFIX' : (self.prefix + 'PROP_' + \
                parent_name).upper().replace('/', ''),
           'PROP_UC': prop.getAttributeNS(NS_TP, "name-for-bindings").upper(),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })


        for prop in iface.getElementsByTagNameNS(NS_TP, 'contact-attribute'):
            self.d("""
/**
 * %(TOKEN_PREFIX)s_%(TOKEN_UC)s:
 *
 * The fully-qualified contact attribute token name "%(name)s/%(prop)s"
 */
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
           'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })

            self.h("""
#define %(TOKEN_PREFIX)s_%(TOKEN_UC)s \\
"%(name)s/%(prop)s"
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
           'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })

        for prop in iface.getElementsByTagNameNS(NS_TP, 'hct'):
            if (prop.getAttribute('is-family') != "yes"):
                self.d("""
/**
 * %(TOKEN_PREFIX)s_%(TOKEN_UC)s:
 *
 * The fully-qualified capability token name "%(name)s/%(prop)s"
 */
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
           'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })

                self.h("""
#define %(TOKEN_PREFIX)s_%(TOKEN_UC)s \\
"%(name)s/%(prop)s"
""" % {'TOKEN_PREFIX' : (self.prefix + 'TOKEN_' + \
                parent_name).upper().replace('/', ''),
           'TOKEN_UC': prop.getAttributeNS(None, "name").upper().replace("-", "_").replace(".", "_"),
           'name' : iface.getAttribute('name'),
           'prop' : prop.getAttribute('name'),
           })
Beispiel #18
0
--- tools/glib-interfaces-gen.py.orig	2020-09-23 16:17:54 UTC
+++ tools/glib-interfaces-gen.py
@@ -3,7 +3,7 @@
 from sys import argv, stdout, stderr
 import xml.dom.minidom
 
-from libtpcodegen import file_set_contents
+from libtpcodegen import file_set_contents, u
 from libglibcodegen import NS_TP, get_docstring, \
         get_descendant_text, get_by_path
 
@@ -24,22 +24,22 @@ class Generator(object):
         self.spec = get_by_path(dom, "spec")[0]
 
     def h(self, code):
-        self.decls.append(code.encode('utf-8'))
+        self.decls.append(code)
 
     def c(self, code):
-        self.impls.append(code.encode('utf-8'))
+        self.impls.append(code)
 
     def d(self, code):
-        self.docs.append(code.encode('utf-8'))
+        self.docs.append(code)
 
     def __call__(self):
         for f in self.h, self.c:
             self.do_header(f)
         self.do_body()
 
 def __init__(self, prefix, dom):
     self.prefix = prefix + '_'
     self.spec = get_by_path(dom, "spec")[0]
Beispiel #20
0
 def __init__(self, prefix, dom):
     self.prefix = prefix + '_'
     self.spec = get_by_path(dom, "spec")[0]
 def __init__(self, prefix, implfile, declfile, dom):
     self.prefix = prefix + '_'
     self.impls = open(implfile, 'w')
     self.decls = open(declfile, 'w')
     self.spec = get_by_path(dom, "spec")[0]
Beispiel #22
0
    def __init__(self, prefix, dom, output_base):
        self.prefix = prefix + '_'
        self.spec = get_by_path(dom, "spec")[0]

        self.__header = open(output_base + '.h', 'w')
        self.__docs = open(output_base + '-gtk-doc.h', 'w')