summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2008-07-21 13:58:58 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2008-07-21 13:58:58 +0000
commit6da382dcab8bdf090c499cbcf82e6172b1fc61e5 (patch)
tree42a45c991578943aebf04770065efd24c35b028f /tools
parent840b9d157369f41d86803193ba37bf1731caced5 (diff)
downloadtelepathy-gabble-6da382dcab8bdf090c499cbcf82e6172b1fc61e5.tar.gz
Update code-gen tools from telepathy-glib 0.7.12
20080721135858-53eee-e543608d57731a947b8617c9446e02daa8ea6f22.gz
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am18
-rw-r--r--tools/c-constants-gen.py151
-rw-r--r--tools/c-constants-generator.xsl299
-rw-r--r--tools/c-interfaces-generator.xsl84
-rw-r--r--tools/glib-interfaces-body-generator.xsl47
-rw-r--r--tools/glib-interfaces-gen.py97
-rw-r--r--tools/glib-interfaces-generator.xsl55
-rw-r--r--tools/libglibcodegen.py6
-rw-r--r--tools/libtpcodegen.py41
9 files changed, 300 insertions, 498 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4d0cf1eaa..711a5ba36 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,6 +1,5 @@
EXTRA_DIST = \
- c-constants-generator.xsl \
- c-interfaces-generator.xsl \
+ c-constants-gen.py \
check-coding-style.mk \
check-c-style.sh \
check-misc.sh \
@@ -8,24 +7,23 @@ EXTRA_DIST = \
doc-generator.xsl \
glib-ginterface-gen.py \
glib-gtypes-generator.py \
- glib-interfaces-generator.xsl \
- glib-interfaces-body-generator.xsl \
+ glib-interfaces-gen.py \
glib-signals-marshal-gen.py \
identity.xsl \
libglibcodegen.py \
libtpcodegen.py \
xep.xsl
-libglibcodegen.py: libtpcodegen.py
- test -e $@
- touch $@
+CLEANFILES = *.pyc *.pyo
-glib-interfaces-generator.xsl glib-interfaces-body-generator.xsl: %: c-interfaces-generator.xsl
+all: $(EXTRA_DIST)
+
+libglibcodegen.py: libtpcodegen.py
test -e $@
touch $@
-glib-ginterface-gen.py glib-gtypes-generator.py glib-signals-marshal-gen.py: \
- %: libglibcodegen.py
+glib-ginterface-gen.py glib-gtypes-generator.py glib-interfaces-gen.py \
+glib-signals-marshal-gen.py c-constants-gen.py: %: libglibcodegen.py
test -e $@
touch $@
diff --git a/tools/c-constants-gen.py b/tools/c-constants-gen.py
new file mode 100644
index 000000000..f338257aa
--- /dev/null
+++ b/tools/c-constants-gen.py
@@ -0,0 +1,151 @@
+#!/usr/bin/python
+
+from sys import argv, stdout, stderr
+import xml.dom.minidom
+
+from libglibcodegen import NS_TP, camelcase_to_upper, get_docstring, \
+ get_descendant_text, get_by_path
+
+class Generator(object):
+ def __init__(self, prefix, dom):
+ self.prefix = prefix + '_'
+ self.spec = get_by_path(dom, "spec")[0]
+
+ def __call__(self):
+ self.do_header()
+ self.do_body()
+ self.do_footer()
+
+ # Header
+ def do_header(self):
+ stdout.write('/* Generated from ')
+ stdout.write(get_descendant_text(get_by_path(self.spec, 'title')))
+ version = get_by_path(self.spec, "version")
+ if version:
+ stdout.write(', version ' + get_descendant_text(version))
+ stdout.write('\n\n')
+ for copyright in get_by_path(self.spec, 'copyright'):
+ stdout.write(get_descendant_text(copyright))
+ stdout.write('\n')
+ stdout.write(get_descendant_text(get_by_path(self.spec, 'license')))
+ stdout.write('\n')
+ stdout.write(get_descendant_text(get_by_path(self.spec, 'docstring')))
+ stdout.write("""
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+\n""")
+
+ # Body
+ def do_body(self):
+ for elem in self.spec.getElementsByTagNameNS(NS_TP, '*'):
+ if elem.localName == 'flags':
+ self.do_flags(elem)
+ elif elem.localName == 'enum':
+ self.do_enum(elem)
+
+ 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')
+ stdout.write("""\
+/**
+ *
+%s:
+""" % (self.prefix + name).replace('_', ''))
+ for flag in get_by_path(flags, 'flag'):
+ self.do_gtkdoc(flag, value_prefix)
+ stdout.write(' *\n')
+ docstrings = get_by_path(flags, 'docstring')
+ if docstrings:
+ stdout.write("""\
+ * <![CDATA[%s]]>
+ *
+""" % get_descendant_text(docstrings).replace('\n', ' '))
+ stdout.write("""\
+ * Bitfield/set of flags generated from the Telepathy specification.
+ */
+typedef enum {
+""")
+ for flag in get_by_path(flags, 'flag'):
+ self.do_val(flag, value_prefix)
+ stdout.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'
+ stdout.write("""\
+/**
+ *
+%s:
+""" % (self.prefix + name).replace('_', ''))
+ vals = get_by_path(enum, 'enumvalue')
+ for val in vals:
+ self.do_gtkdoc(val, value_prefix)
+ stdout.write(' *\n')
+ docstrings = get_by_path(enum, 'docstring')
+ if docstrings:
+ stdout.write("""\
+ * <![CDATA[%s]]>
+ *
+""" % get_descendant_text(docstrings).replace('\n', ' '))
+ stdout.write("""\
+ * Bitfield/set of flags generated from the Telepathy specification.
+ */
+typedef enum {
+""")
+ for val in vals:
+ self.do_val(val, value_prefix)
+ stdout.write("""\
+} %(mixed-name)s;
+
+/**
+ * NUM_%(upper-plural)s:
+ *
+ * 1 higher than the highest valid value of #%(mixed-name)s.
+ */
+#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')})
+
+ def do_val(self, val, value_prefix):
+ name = val.getAttribute('name')
+ suffix = val.getAttribute('suffix')
+ use_name = (self.prefix + value_prefix + '_' + \
+ (suffix or name)).upper()
+ assert not (name and suffix) or name == suffix, \
+ 'Flag/enumvalue name %s != suffix %s' % (name, suffix)
+ stdout.write(' %s = %s,\n' % (use_name, val.getAttribute('value')))
+
+ def do_gtkdoc(self, node, value_prefix):
+ stdout.write(' * @')
+ stdout.write((self.prefix + value_prefix + '_' +
+ node.getAttribute('suffix')).upper())
+ stdout.write(': <![CDATA[')
+ docstring = get_by_path(node, 'docstring')
+ stdout.write(get_descendant_text(docstring).replace('\n', ' '))
+ stdout.write(']]>\n')
+
+ # Footer
+ def do_footer(self):
+ stdout.write("""
+#ifdef __cplusplus
+}
+#endif
+""")
+
+if __name__ == '__main__':
+ argv = argv[1:]
+ Generator(argv[0], xml.dom.minidom.parse(argv[1]))()
diff --git a/tools/c-constants-generator.xsl b/tools/c-constants-generator.xsl
deleted file mode 100644
index 18b2e495d..000000000
--- a/tools/c-constants-generator.xsl
+++ /dev/null
@@ -1,299 +0,0 @@
-<!-- Stylesheet to extract C enumerations from the Telepathy spec.
-The master copy of this stylesheet is in telepathy-glib - please make any
-changes there.
-
-Copyright (C) 2006, 2007 Collabora Limited
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--->
-
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
- exclude-result-prefixes="tp">
-
- <xsl:output method="text" indent="no" encoding="ascii"/>
-
- <xsl:param name="mixed-case-prefix" select="''"/>
-
- <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
- <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
-
- <xsl:variable name="upper-case-prefix" select="concat(translate($mixed-case-prefix, $lower, $upper), '_')"/>
- <xsl:variable name="lower-case-prefix" select="concat(translate($mixed-case-prefix, $upper, $lower), '_')"/>
-
-
- <xsl:template match="tp:flags">
- <xsl:variable name="name">
- <xsl:choose>
- <xsl:when test="@plural">
- <xsl:value-of select="@plural"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="value-prefix">
- <xsl:choose>
- <xsl:when test="@singular">
- <xsl:value-of select="@singular"/>
- </xsl:when>
- <xsl:when test="@value-prefix">
- <xsl:value-of select="@value-prefix"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:text>/**&#10;</xsl:text>
- <xsl:text> *&#10;</xsl:text>
- <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
- <xsl:text>:&#10;</xsl:text>
- <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
- <xsl:with-param name="value-prefix" select="$value-prefix"/>
- </xsl:apply-templates>
- <xsl:text> *&#10;</xsl:text>
- <xsl:if test="tp:docstring">
- <xsl:text> * &lt;![CDATA[</xsl:text>
- <xsl:value-of select="translate(string (tp:docstring), '&#13;&#10;', ' ')"/>
- <xsl:text>]]&gt;&#10;</xsl:text>
- <xsl:text> *&#10;</xsl:text>
- </xsl:if>
- <xsl:text> * Bitfield/set of flags generated from the Telepathy specification.&#10;</xsl:text>
- <xsl:text> */&#10;</xsl:text>
- <xsl:text>typedef enum {&#10;</xsl:text>
- <xsl:apply-templates>
- <xsl:with-param name="value-prefix" select="$value-prefix"/>
- </xsl:apply-templates>
- <xsl:text>} </xsl:text>
- <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
- <xsl:text>;&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="text()" mode="flag-or-enumvalue-gtkdoc"/>
-
- <xsl:template match="tp:enumvalue" mode="flag-or-enumvalue-gtkdoc">
- <xsl:param name="value-prefix"/>
- <xsl:text> * @</xsl:text>
- <xsl:value-of select="translate(concat($upper-case-prefix, $value-prefix, '_', @suffix), $lower, $upper)"/>
- <xsl:text>: &lt;![CDATA[</xsl:text>
- <xsl:value-of select="translate(string(tp:docstring), '&#13;&#10;', ' ')"/>
- <xsl:text>]]&gt;&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="tp:flag" mode="flag-or-enumvalue-gtkdoc">
- <xsl:param name="value-prefix"/>
- <xsl:text> * @</xsl:text>
- <xsl:value-of select="translate(concat($upper-case-prefix, $value-prefix, '_', @suffix), $lower, $upper)"/>
- <xsl:text>: &lt;![CDATA[</xsl:text>
- <xsl:value-of select="translate(string(tp:docstring), '&#13;&#10;', ' ')"/>
- <xsl:text>]]&gt;&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="tp:enum">
- <xsl:variable name="name">
- <xsl:choose>
- <xsl:when test="@singular">
- <xsl:value-of select="@singular"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="value-prefix">
- <xsl:choose>
- <xsl:when test="@singular">
- <xsl:value-of select="@singular"/>
- </xsl:when>
- <xsl:when test="@value-prefix">
- <xsl:value-of select="@value-prefix"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="name-plural">
- <xsl:choose>
- <xsl:when test="@plural">
- <xsl:value-of select="@plural"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/><xsl:text>s</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:text>/**&#10;</xsl:text>
- <xsl:text> *&#10;</xsl:text>
- <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
- <xsl:text>:&#10;</xsl:text>
- <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
- <xsl:with-param name="value-prefix" select="$value-prefix"/>
- </xsl:apply-templates>
- <xsl:text> *&#10;</xsl:text>
- <xsl:if test="tp:docstring">
- <xsl:text> * &lt;![CDATA[</xsl:text>
- <xsl:value-of select="translate(string (tp:docstring), '&#13;&#10;', ' ')"/>
- <xsl:text>]]&gt;&#10;</xsl:text>
- <xsl:text> *&#10;</xsl:text>
- </xsl:if>
- <xsl:text> * Bitfield/set of flags generated from the Telepathy specification.&#10;</xsl:text>
- <xsl:text> */&#10;</xsl:text>
- <xsl:text>typedef enum {&#10;</xsl:text>
- <xsl:apply-templates>
- <xsl:with-param name="value-prefix" select="$value-prefix"/>
- </xsl:apply-templates>
- <xsl:text>} </xsl:text>
- <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
- <xsl:text>;&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- <xsl:text>/**&#10;</xsl:text>
- <xsl:text> * NUM_</xsl:text>
- <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/>
- <xsl:text>:&#10;</xsl:text>
- <xsl:text> *&#10;</xsl:text>
- <xsl:text> * 1 higher than the highest valid value of #</xsl:text>
- <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
- <xsl:text>.&#10;</xsl:text>
- <xsl:text> */&#10;</xsl:text>
- <xsl:text>#define NUM_</xsl:text>
- <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/>
- <xsl:text> (</xsl:text>
- <xsl:value-of select="tp:enumvalue[position() = last()]/@value"/>
- <xsl:text>+1)&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="tp:flags/tp:flag">
- <xsl:param name="value-prefix"/>
- <xsl:variable name="suffix">
- <xsl:choose>
- <xsl:when test="@suffix">
- <xsl:value-of select="@suffix"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/>
-
- <xsl:if test="@name and @suffix and @name != @suffix">
- <xsl:message terminate="yes">
- <xsl:text>Flag name </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text> != suffix </xsl:text>
- <xsl:value-of select="@suffix"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:message>
- </xsl:if>
- <xsl:text> </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text> = </xsl:text>
- <xsl:value-of select="@value"/>
- <xsl:text>,&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="tp:enum/tp:enumvalue">
- <xsl:param name="value-prefix"/>
- <xsl:variable name="suffix">
- <xsl:choose>
- <xsl:when test="@suffix">
- <xsl:value-of select="@suffix"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/>
-
- <xsl:if test="@name and @suffix and @name != @suffix">
- <xsl:message terminate="yes">
- <xsl:text>Enumvalue name </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text> != suffix </xsl:text>
- <xsl:value-of select="@suffix"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:message>
- </xsl:if>
-
- <xsl:if test="preceding-sibling::tp:enumvalue and number(preceding-sibling::tp:enumvalue[1]/@value) > number(@value)">
- <xsl:message terminate="yes">
- <xsl:text>Enum values must be in ascending numeric order, but </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text> is less than the previous value</xsl:text>
- </xsl:message>
- </xsl:if>
-
- <xsl:text> </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text> = </xsl:text>
- <xsl:value-of select="@value"/>
- <xsl:text>,&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="tp:flag">
- <xsl:message terminate="yes">tp:flag found outside tp:flags&#10;</xsl:message>
- </xsl:template>
-
- <xsl:template match="tp:enumvalue">
- <xsl:message terminate="yes">tp:enumvalue found outside tp:enum&#10;</xsl:message>
- </xsl:template>
-
- <xsl:template match="text()"/>
-
- <xsl:template match="/tp:spec">
- <xsl:if test="$mixed-case-prefix = ''">
- <xsl:message terminate="yes">
- <xsl:text>mixed-case-prefix param must be set&#10;</xsl:text>
- </xsl:message>
- </xsl:if>
-
- <xsl:text>/* Generated from </xsl:text>
- <xsl:value-of select="tp:title"/>
- <xsl:if test="tp:version">
- <xsl:text>, version </xsl:text>
- <xsl:value-of select="tp:version"/>
- </xsl:if>
- <xsl:text>&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- <xsl:for-each select="tp:copyright">
- <xsl:value-of select="."/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:value-of select="tp:license"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:value-of select="tp:docstring"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:text> */&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- <xsl:text>#ifdef __cplusplus&#10;</xsl:text>
- <xsl:text>extern "C" {&#10;</xsl:text>
- <xsl:text>#endif&#10;</xsl:text>
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates/>
- <xsl:text>&#10;</xsl:text>
- <xsl:text>#ifdef __cplusplus&#10;</xsl:text>
- <xsl:text>}&#10;</xsl:text>
- <xsl:text>#endif&#10;</xsl:text>
- </xsl:template>
-
-</xsl:stylesheet>
-
-<!-- vim:set sw=2 sts=2 et noai noci: -->
diff --git a/tools/c-interfaces-generator.xsl b/tools/c-interfaces-generator.xsl
deleted file mode 100644
index f965a7051..000000000
--- a/tools/c-interfaces-generator.xsl
+++ /dev/null
@@ -1,84 +0,0 @@
-<!-- Stylesheet to extract C enumerations from the Telepathy spec.
-The master copy of this stylesheet is in telepathy-glib - please make any
-changes there.
-
-Copyright (C) 2006, 2007 Collabora Limited
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--->
-
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
- exclude-result-prefixes="tp">
-
- <xsl:param name="mixed-case-prefix" select="''"/>
-
- <xsl:variable name="PREFIX"
- select="translate($mixed-case-prefix, $lower, $upper)"/>
- <xsl:variable name="Prefix" select="$mixed-case-prefix"/>
- <xsl:variable name="prefix"
- select="translate($mixed-case-prefix, $upper, $lower)"/>
-
- <xsl:output method="text" indent="no" encoding="ascii"/>
-
- <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
- <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
-
- <xsl:template match="interface">
- <xsl:text>/**&#10; * </xsl:text>
- <xsl:value-of select="$PREFIX"/>
- <xsl:text>_IFACE_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($lower, '/'), $upper)"/>
- <xsl:text>:&#10; * &#10; * The interface name "</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>"&#10; */&#10;#define </xsl:text>
- <xsl:value-of select="$PREFIX"/>
- <xsl:text>_IFACE_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($lower, '/'), $upper)"/>
- <xsl:text> \&#10;"</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>"&#10;&#10;</xsl:text>
- </xsl:template>
-
- <xsl:template match="text()"/>
-
- <xsl:template match="/tp:spec">
- <xsl:if test="$mixed-case-prefix = ''">
- <xsl:message terminate="yes">
- <xsl:text>mixed-case-prefix param must be set&#10;</xsl:text>
- </xsl:message>
- </xsl:if>
-
- <xsl:text>/* Generated from: </xsl:text>
- <xsl:value-of select="tp:title"/>
- <xsl:if test="tp:version">
- <xsl:text> version </xsl:text>
- <xsl:value-of select="tp:version"/>
- </xsl:if>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:for-each select="tp:copyright">
- <xsl:value-of select="."/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:text>&#10;</xsl:text>
- <xsl:value-of select="tp:license"/>
- <xsl:value-of select="tp:docstring"/>
- <xsl:text>&#10; */&#10;&#10;</xsl:text>
- <xsl:apply-templates/>
- </xsl:template>
-
-</xsl:stylesheet>
-
-<!-- vim:set sw=2 sts=2 et noai noci: -->
diff --git a/tools/glib-interfaces-body-generator.xsl b/tools/glib-interfaces-body-generator.xsl
deleted file mode 100644
index caff8917a..000000000
--- a/tools/glib-interfaces-body-generator.xsl
+++ /dev/null
@@ -1,47 +0,0 @@
-<!-- Stylesheet to extract C interface names from the Telepathy spec.
-The master copy of this stylesheet is in telepathy-glib - please make any
-changes there.
-
-Copyright (C) 2006, 2007 Collabora Limited
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--->
-
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
- exclude-result-prefixes="tp">
-
- <xsl:import href="c-interfaces-generator.xsl"/>
-
- <xsl:template match="interface">
- <xsl:text>GQuark&#10;</xsl:text>
- <xsl:value-of select="$prefix"/>
- <xsl:text>_iface_quark_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($upper, '/'), $lower)"/>
- <xsl:text> (void)&#10;{&#10;</xsl:text>
- <xsl:text> static GQuark quark = 0;&#10;&#10;</xsl:text>
- <xsl:text> if (G_UNLIKELY (quark == 0))&#10;</xsl:text>
- <xsl:text> {&#10;</xsl:text>
- <xsl:text> quark = g_quark_from_static_string ("</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>");&#10;</xsl:text>
- <xsl:text> }&#10;&#10;</xsl:text>
- <xsl:text> return quark;&#10;</xsl:text>
- <xsl:text>}&#10;&#10;</xsl:text>
- </xsl:template>
-
-</xsl:stylesheet>
-
-<!-- vim:set sw=2 sts=2 et noai noci: -->
diff --git a/tools/glib-interfaces-gen.py b/tools/glib-interfaces-gen.py
new file mode 100644
index 000000000..741626ceb
--- /dev/null
+++ b/tools/glib-interfaces-gen.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+
+from sys import argv, stdout, stderr
+import xml.dom.minidom
+
+from libglibcodegen import NS_TP, camelcase_to_upper, get_docstring, \
+ get_descendant_text, get_by_path
+
+class Generator(object):
+ 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]
+
+ def __call__(self):
+ for file in self.decls, self.impls:
+ self.do_header(file)
+ self.do_body()
+
+ # Header
+ def do_header(self, file):
+ file.write('/* Generated from: ')
+ file.write(get_descendant_text(get_by_path(self.spec, 'title')))
+ version = get_by_path(self.spec, "version")
+ if version:
+ file.write(' version ' + get_descendant_text(version))
+ file.write('\n\n')
+ for copyright in get_by_path(self.spec, 'copyright'):
+ stdout.write(get_descendant_text(copyright))
+ stdout.write('\n')
+ file.write('\n')
+ file.write(get_descendant_text(get_by_path(self.spec, 'license')))
+ file.write(get_descendant_text(get_by_path(self.spec, 'docstring')))
+ file.write("""
+ */
+
+""")
+
+ # Body
+ def do_body(self):
+ for iface in self.spec.getElementsByTagName('interface'):
+ self.do_iface(iface)
+
+ def do_iface(self, iface):
+ parent_name = get_by_path(iface, '../@name')
+ self.decls.write("""\
+/**
+ * %(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.decls.write("""
+/**
+ * %(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.impls.write("""\
+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')})
+
+if __name__ == '__main__':
+ argv = argv[1:]
+ Generator(argv[0], argv[1], argv[2], xml.dom.minidom.parse(argv[3]))()
diff --git a/tools/glib-interfaces-generator.xsl b/tools/glib-interfaces-generator.xsl
deleted file mode 100644
index e703c407e..000000000
--- a/tools/glib-interfaces-generator.xsl
+++ /dev/null
@@ -1,55 +0,0 @@
-<!-- Stylesheet to extract C interface names from the Telepathy spec.
-The master copy of this stylesheet is in telepathy-glib - please make any
-changes there.
-
-Copyright (C) 2006, 2007 Collabora Limited
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--->
-
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
- exclude-result-prefixes="tp">
-
- <xsl:import href="c-interfaces-generator.xsl"/>
-
- <xsl:template match="interface">
- <xsl:apply-imports/>
-
- <xsl:text>/**&#10; * </xsl:text>
- <xsl:value-of select="$PREFIX"/>
- <xsl:text>_IFACE_QUARK_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($lower, '/'), $upper)"/>
- <xsl:text>:&#10; * &#10; * Expands to a call to a function that </xsl:text>
- <xsl:text>returns a quark for the interface name "</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>"&#10; */&#10;#define </xsl:text>
- <xsl:value-of select="$PREFIX"/>
- <xsl:text>_IFACE_QUARK_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($lower, '/'), $upper)"/>
- <xsl:text> \&#10; (</xsl:text>
- <xsl:value-of select="$prefix"/>
- <xsl:text>_iface_quark_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($upper, '/'), $lower)"/>
- <xsl:text> ())&#10;&#10;GQuark </xsl:text>
- <xsl:value-of select="$prefix"/>
- <xsl:text>_iface_quark_</xsl:text>
- <xsl:value-of select="translate(../@name, concat($upper, '/'), $lower)"/>
- <xsl:text> (void);&#10;&#10;</xsl:text>
- </xsl:template>
-
-</xsl:stylesheet>
-
-<!-- vim:set sw=2 sts=2 et noai noci: -->
diff --git a/tools/libglibcodegen.py b/tools/libglibcodegen.py
index 6a725c052..129c179e7 100644
--- a/tools/libglibcodegen.py
+++ b/tools/libglibcodegen.py
@@ -27,6 +27,7 @@ from libtpcodegen import NS_TP, \
camelcase_to_upper, \
cmp_by_name, \
escape_as_identifier, \
+ get_by_path, \
get_descendant_text, \
get_docstring, \
xml_escape
@@ -146,7 +147,10 @@ def type_to_gtype(s):
elif s == 'ab': #boolean array
return ("GArray *", "DBUS_TYPE_G_BOOLEAN_ARRAY", "BOXED", True)
elif s == 'ao': #object path array
- return ("GPtrArray *", "DBUS_TYPE_G_OBJECT_ARRAY", "BOXED", True)
+ return ("GPtrArray *",
+ 'dbus_g_type_get_collection ("GPtrArray",'
+ ' DBUS_TYPE_G_OBJECT_PATH)',
+ "BOXED", True)
elif s == 'a{ss}': #hash table of string to string
return ("GHashTable *", "DBUS_TYPE_G_STRING_STRING_HASHTABLE", "BOXED", False)
elif s[:2] == 'a{': #some arbitrary hash tables
diff --git a/tools/libtpcodegen.py b/tools/libtpcodegen.py
index e7527c8a9..6391f1a48 100644
--- a/tools/libtpcodegen.py
+++ b/tools/libtpcodegen.py
@@ -98,6 +98,39 @@ def escape_as_identifier(identifier):
return ''.join(ret)
+def get_by_path(element, path):
+ branches = path.split('/')
+ branch = branches[0]
+
+ # Is the current branch an attribute, if so, return the attribute value
+ if branch[0] == '@':
+ return element.getAttribute(branch[1:])
+
+ # Find matching children for the branch
+ children = []
+ if branch == '..':
+ children.append(element.parentNode)
+ else:
+ for x in element.childNodes:
+ if x.localName == branch:
+ children.append(x)
+
+ ret = []
+ # If this is not the last path element, recursively gather results from
+ # children
+ if len(branches) > 1:
+ for x in children:
+ add = get_by_path(x, '/'.join(branches[1:]))
+ if isinstance(add, list):
+ ret += add
+ else:
+ return add
+ else:
+ ret = children
+
+ return ret
+
+
def get_docstring(element):
docstring = None
for x in element.childNodes:
@@ -114,9 +147,13 @@ def get_docstring(element):
return docstring
-def get_descendant_text(element):
+def get_descendant_text(element_or_elements):
+ if not element_or_elements:
+ return ''
+ if isinstance(element_or_elements, list):
+ return ''.join(map(get_descendant_text, element_or_elements))
parts = []
- for x in element.childNodes:
+ for x in element_or_elements.childNodes:
if x.nodeType == x.TEXT_NODE:
parts.append(x.nodeValue)
elif x.nodeType == x.ELEMENT_NODE: