summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2009-12-02 18:06:32 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2009-12-02 18:06:35 +0000
commitc99c16a783104aa502c6cc3ef329f5b6d9ad11e8 (patch)
tree92f0f6f88d84736bbf90eff4b3a8a785f1b14b07
parent0d39564bdd5ec4fe83dd6e92203dbe9f063c70a8 (diff)
parentd84ccb1752b9487f4d20a511752eec9437d332fa (diff)
Merge remote branch 'wjt/cope-with-utf8-spec'
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--tools/c-constants-gen.py57
-rw-r--r--tools/glib-gtypes-generator.py166
-rw-r--r--tools/glib-interfaces-gen.py38
3 files changed, 138 insertions, 123 deletions
diff --git a/tools/c-constants-gen.py b/tools/c-constants-gen.py
index 341b4344..8969ffdc 100644
--- a/tools/c-constants-gen.py
+++ b/tools/c-constants-gen.py
@@ -16,21 +16,24 @@ class Generator(object):
self.do_body()
self.do_footer()
+ def write(self, code):
+ stdout.write(code.encode('utf-8'))
+
# Header
def do_header(self):
- stdout.write('/* Generated from ')
- stdout.write(get_descendant_text(get_by_path(self.spec, 'title')))
+ self.write('/* Generated from ')
+ self.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')
+ self.write(', version ' + get_descendant_text(version))
+ self.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("""
+ 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
@@ -51,28 +54,28 @@ extern "C" {
value_prefix = flags.getAttribute('singular') or \
flags.getAttribute('value-prefix') or \
flags.getAttribute('name')
- stdout.write("""\
+ self.write("""\
/**
*
%s:
""" % (self.prefix + name).replace('_', ''))
for flag in get_by_path(flags, 'flag'):
self.do_gtkdoc(flag, value_prefix)
- stdout.write(' *\n')
+ self.write(' *\n')
docstrings = get_by_path(flags, 'docstring')
if docstrings:
- stdout.write("""\
+ self.write("""\
* <![CDATA[%s]]>
*
""" % get_descendant_text(docstrings).replace('\n', ' '))
- stdout.write("""\
+ self.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("""\
+ self.write("""\
} %s;
""" % (self.prefix + name).replace('_', ''))
@@ -84,7 +87,7 @@ typedef enum {
enum.getAttribute('name')
name_plural = enum.getAttribute('plural') or \
enum.getAttribute('name') + 's'
- stdout.write("""\
+ self.write("""\
/**
*
%s:
@@ -92,21 +95,21 @@ typedef enum {
vals = get_by_path(enum, 'enumvalue')
for val in vals:
self.do_gtkdoc(val, value_prefix)
- stdout.write(' *\n')
+ self.write(' *\n')
docstrings = get_by_path(enum, 'docstring')
if docstrings:
- stdout.write("""\
+ self.write("""\
* <![CDATA[%s]]>
*
""" % get_descendant_text(docstrings).replace('\n', ' '))
- stdout.write("""\
+ self.write("""\
* Bitfield/set of flags generated from the Telepathy specification.
*/
typedef enum {
""")
for val in vals:
self.do_val(val, value_prefix)
- stdout.write("""\
+ self.write("""\
} %(mixed-name)s;
/**
@@ -127,20 +130,20 @@ typedef enum {
(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')))
+ self.write(' %s = %s,\n' % (use_name, val.getAttribute('value')))
def do_gtkdoc(self, node, value_prefix):
- stdout.write(' * @')
- stdout.write((self.prefix + value_prefix + '_' +
+ self.write(' * @')
+ self.write((self.prefix + value_prefix + '_' +
node.getAttribute('suffix')).upper())
- stdout.write(': <![CDATA[')
+ self.write(': <![CDATA[')
docstring = get_by_path(node, 'docstring')
- stdout.write(get_descendant_text(docstring).replace('\n', ' '))
- stdout.write(']]>\n')
+ self.write(get_descendant_text(docstring).replace('\n', ' '))
+ self.write(']]>\n')
# Footer
def do_footer(self):
- stdout.write("""
+ self.write("""
#ifdef __cplusplus
}
#endif
diff --git a/tools/glib-gtypes-generator.py b/tools/glib-gtypes-generator.py
index 29debf17..ebc2ad4c 100644
--- a/tools/glib-gtypes-generator.py
+++ b/tools/glib-gtypes-generator.py
@@ -64,6 +64,12 @@ class GTypesGenerator(object):
# values are the key escaped
self.need_other_arrays = {}
+ def h(self, code):
+ self.header.write(code.encode("utf-8"))
+
+ def c(self, code):
+ self.body.write(code.encode("utf-8"))
+
def do_mapping_header(self, mapping):
members = mapping.getElementsByTagNameNS(NS_TP, 'member')
assert len(members) == 2
@@ -79,43 +85,43 @@ class GTypesGenerator(object):
docstring = get_docstring(mapping) or '(Undocumented)'
- self.header.write('/**\n * %s:\n *\n' % name)
- self.header.write(' * %s\n' % xml_escape(docstring))
- self.header.write(' *\n')
- self.header.write(' * This macro expands to a call to a function\n')
- self.header.write(' * that returns the #GType of a #GHashTable\n')
- self.header.write(' * appropriate for representing a D-Bus\n')
- self.header.write(' * dictionary of signature\n')
- self.header.write(' * <literal>a{%s}</literal>.\n' % impl_sig)
- self.header.write(' *\n')
+ self.h('/**\n * %s:\n *\n' % name)
+ self.h(' * %s\n' % xml_escape(docstring))
+ self.h(' *\n')
+ self.h(' * This macro expands to a call to a function\n')
+ self.h(' * that returns the #GType of a #GHashTable\n')
+ self.h(' * appropriate for representing a D-Bus\n')
+ self.h(' * dictionary of signature\n')
+ self.h(' * <literal>a{%s}</literal>.\n' % impl_sig)
+ self.h(' *\n')
key, value = members
- self.header.write(' * Keys (D-Bus type <literal>%s</literal>,\n'
+ self.h(' * Keys (D-Bus type <literal>%s</literal>,\n'
% key.getAttribute('type'))
tp_type = key.getAttributeNS(NS_TP, 'type')
if tp_type:
- self.header.write(' * type <literal>%s</literal>,\n' % tp_type)
- self.header.write(' * named <literal>%s</literal>):\n'
+ self.h(' * type <literal>%s</literal>,\n' % tp_type)
+ self.h(' * named <literal>%s</literal>):\n'
% key.getAttribute('name'))
docstring = get_docstring(key) or '(Undocumented)'
- self.header.write(' * %s\n' % xml_escape(docstring))
- self.header.write(' *\n')
+ self.h(' * %s\n' % xml_escape(docstring))
+ self.h(' *\n')
- self.header.write(' * Values (D-Bus type <literal>%s</literal>,\n'
+ self.h(' * Values (D-Bus type <literal>%s</literal>,\n'
% value.getAttribute('type'))
tp_type = value.getAttributeNS(NS_TP, 'type')
if tp_type:
- self.header.write(' * type <literal>%s</literal>,\n' % tp_type)
- self.header.write(' * named <literal>%s</literal>):\n'
+ self.h(' * type <literal>%s</literal>,\n' % tp_type)
+ self.h(' * named <literal>%s</literal>):\n'
% value.getAttribute('name'))
docstring = get_docstring(value) or '(Undocumented)'
- self.header.write(' * %s\n' % xml_escape(docstring))
- self.header.write(' *\n')
+ self.h(' * %s\n' % xml_escape(docstring))
+ self.h(' *\n')
- self.header.write(' */\n')
+ self.h(' */\n')
- self.header.write('#define %s (%s ())\n\n' % (name, impl))
+ self.h('#define %s (%s ())\n\n' % (name, impl))
self.need_mappings[impl_sig] = esc_impl_sig
array_name = mapping.getAttribute('array-name')
@@ -124,12 +130,12 @@ class GTypesGenerator(object):
contents_sig = 'a{' + impl_sig + '}'
esc_contents_sig = escape_as_identifier(contents_sig)
impl = self.prefix_ + 'type_dbus_array_of_' + esc_contents_sig
- self.header.write('/**\n * %s:\n\n' % gtype_name)
- self.header.write(' * Expands to a call to a function\n')
- self.header.write(' * that returns the #GType of a #GPtrArray\n')
- self.header.write(' * of #%s.\n' % name)
- self.header.write(' */\n')
- self.header.write('#define %s (%s ())\n\n' % (gtype_name, impl))
+ self.h('/**\n * %s:\n\n' % gtype_name)
+ self.h(' * Expands to a call to a function\n')
+ self.h(' * that returns the #GType of a #GPtrArray\n')
+ self.h(' * of #%s.\n' % name)
+ self.h(' */\n')
+ self.h('#define %s (%s ())\n\n' % (gtype_name, impl))
self.need_other_arrays[contents_sig] = esc_contents_sig
def do_struct_header(self, struct):
@@ -151,42 +157,42 @@ class GTypesGenerator(object):
docstring = '(Undocumented)'
else:
docstring = '(Undocumented)'
- self.header.write('/**\n * %s:\n\n' % name)
- self.header.write(' * %s\n' % xml_escape(docstring))
- self.header.write(' *\n')
- self.header.write(' * This macro expands to a call to a function\n')
- self.header.write(' * that returns the #GType of a #GValueArray\n')
- self.header.write(' * appropriate for representing a D-Bus struct\n')
- self.header.write(' * with signature <literal>(%s)</literal>.\n'
+ self.h('/**\n * %s:\n\n' % name)
+ self.h(' * %s\n' % xml_escape(docstring))
+ self.h(' *\n')
+ self.h(' * This macro expands to a call to a function\n')
+ self.h(' * that returns the #GType of a #GValueArray\n')
+ self.h(' * appropriate for representing a D-Bus struct\n')
+ self.h(' * with signature <literal>(%s)</literal>.\n'
% impl_sig)
- self.header.write(' *\n')
+ self.h(' *\n')
for i, member in enumerate(members):
- self.header.write(' * Member %d (D-Bus type '
+ self.h(' * Member %d (D-Bus type '
'<literal>%s</literal>,\n'
% (i, member.getAttribute('type')))
tp_type = member.getAttributeNS(NS_TP, 'type')
if tp_type:
- self.header.write(' * type <literal>%s</literal>,\n' % tp_type)
- self.header.write(' * named <literal>%s</literal>):\n'
+ self.h(' * type <literal>%s</literal>,\n' % tp_type)
+ self.h(' * named <literal>%s</literal>):\n'
% member.getAttribute('name'))
docstring = get_docstring(member) or '(Undocumented)'
- self.header.write(' * %s\n' % xml_escape(docstring))
- self.header.write(' *\n')
+ self.h(' * %s\n' % xml_escape(docstring))
+ self.h(' *\n')
- self.header.write(' */\n')
- self.header.write('#define %s (%s ())\n\n' % (name, impl))
+ self.h(' */\n')
+ self.h('#define %s (%s ())\n\n' % (name, impl))
array_name = struct.getAttribute('array-name')
if array_name != '':
array_name = (self.PREFIX_ + 'ARRAY_TYPE_' + array_name.upper())
impl = self.prefix_ + 'type_dbus_array_' + esc_impl_sig
- self.header.write('/**\n * %s:\n\n' % array_name)
- self.header.write(' * Expands to a call to a function\n')
- self.header.write(' * that returns the #GType of a #GPtrArray\n')
- self.header.write(' * of #%s.\n' % name)
- self.header.write(' */\n')
- self.header.write('#define %s (%s ())\n\n' % (array_name, impl))
+ self.h('/**\n * %s:\n\n' % array_name)
+ self.h(' * Expands to a call to a function\n')
+ self.h(' * that returns the #GType of a #GPtrArray\n')
+ self.h(' * of #%s.\n' % name)
+ self.h(' */\n')
+ self.h('#define %s (%s ())\n\n' % (array_name, impl))
self.need_struct_arrays[impl_sig] = esc_impl_sig
self.need_structs[impl_sig] = esc_impl_sig
@@ -199,83 +205,83 @@ class GTypesGenerator(object):
self.do_mapping_header(mapping)
for sig in self.need_mappings:
- self.header.write('GType %stype_dbus_hash_%s (void);\n\n' %
+ self.h('GType %stype_dbus_hash_%s (void);\n\n' %
(self.prefix_, self.need_mappings[sig]))
- self.body.write('GType\n%stype_dbus_hash_%s (void)\n{\n' %
+ self.c('GType\n%stype_dbus_hash_%s (void)\n{\n' %
(self.prefix_, self.need_mappings[sig]))
- self.body.write(' static GType t = 0;\n\n')
- self.body.write(' if (G_UNLIKELY (t == 0))\n')
+ self.c(' static GType t = 0;\n\n')
+ self.c(' if (G_UNLIKELY (t == 0))\n')
# FIXME: translate sig into two GTypes
items = tuple(Signature(sig))
gtypes = types_to_gtypes(items)
- self.body.write(' t = dbus_g_type_get_map ("GHashTable", '
+ self.c(' t = dbus_g_type_get_map ("GHashTable", '
'%s, %s);\n' % (gtypes[0], gtypes[1]))
- self.body.write(' return t;\n')
- self.body.write('}\n\n')
+ self.c(' return t;\n')
+ self.c('}\n\n')
for struct in structs:
self.do_struct_header(struct)
for sig in self.need_structs:
- self.header.write('GType %stype_dbus_struct_%s (void);\n\n' %
+ self.h('GType %stype_dbus_struct_%s (void);\n\n' %
(self.prefix_, self.need_structs[sig]))
- self.body.write('GType\n%stype_dbus_struct_%s (void)\n{\n' %
+ self.c('GType\n%stype_dbus_struct_%s (void)\n{\n' %
(self.prefix_, self.need_structs[sig]))
- self.body.write(' static GType t = 0;\n\n')
- self.body.write(' if (G_UNLIKELY (t == 0))\n')
- self.body.write(' t = dbus_g_type_get_struct ("GValueArray",\n')
+ self.c(' static GType t = 0;\n\n')
+ self.c(' if (G_UNLIKELY (t == 0))\n')
+ self.c(' t = dbus_g_type_get_struct ("GValueArray",\n')
items = tuple(Signature(sig))
gtypes = types_to_gtypes(items)
for gtype in gtypes:
- self.body.write(' %s,\n' % gtype)
- self.body.write(' G_TYPE_INVALID);\n')
- self.body.write(' return t;\n')
- self.body.write('}\n\n')
+ self.c(' %s,\n' % gtype)
+ self.c(' G_TYPE_INVALID);\n')
+ self.c(' return t;\n')
+ self.c('}\n\n')
for sig in self.need_struct_arrays:
- self.header.write('GType %stype_dbus_array_%s (void);\n\n' %
+ self.h('GType %stype_dbus_array_%s (void);\n\n' %
(self.prefix_, self.need_struct_arrays[sig]))
- self.body.write('GType\n%stype_dbus_array_%s (void)\n{\n' %
+ self.c('GType\n%stype_dbus_array_%s (void)\n{\n' %
(self.prefix_, self.need_struct_arrays[sig]))
- self.body.write(' static GType t = 0;\n\n')
- self.body.write(' if (G_UNLIKELY (t == 0))\n')
- self.body.write(' t = dbus_g_type_get_collection ("GPtrArray", '
+ self.c(' static GType t = 0;\n\n')
+ self.c(' if (G_UNLIKELY (t == 0))\n')
+ self.c(' t = dbus_g_type_get_collection ("GPtrArray", '
'%stype_dbus_struct_%s ());\n' %
(self.prefix_, self.need_struct_arrays[sig]))
- self.body.write(' return t;\n')
- self.body.write('}\n\n')
+ self.c(' return t;\n')
+ self.c('}\n\n')
for sig in self.need_other_arrays:
- self.header.write('GType %stype_dbus_array_of_%s (void);\n\n' %
+ self.h('GType %stype_dbus_array_of_%s (void);\n\n' %
(self.prefix_, self.need_other_arrays[sig]))
- self.body.write('GType\n%stype_dbus_array_of_%s (void)\n{\n' %
+ self.c('GType\n%stype_dbus_array_of_%s (void)\n{\n' %
(self.prefix_, self.need_other_arrays[sig]))
- self.body.write(' static GType t = 0;\n\n')
- self.body.write(' if (G_UNLIKELY (t == 0))\n')
+ self.c(' static GType t = 0;\n\n')
+ self.c(' if (G_UNLIKELY (t == 0))\n')
if sig[:2] == 'a{' and sig[-1:] == '}':
# array of mappings
- self.body.write(' t = dbus_g_type_get_collection ('
+ self.c(' t = dbus_g_type_get_collection ('
'"GPtrArray", '
'%stype_dbus_hash_%s ());\n' %
(self.prefix_, escape_as_identifier(sig[2:-1])))
elif sig[:2] == 'a(' and sig[-1:] == ')':
# array of arrays of struct
- self.body.write(' t = dbus_g_type_get_collection ('
+ self.c(' t = dbus_g_type_get_collection ('
'"GPtrArray", '
'%stype_dbus_array_%s ());\n' %
(self.prefix_, escape_as_identifier(sig[2:-1])))
elif sig[:1] == 'a':
# array of arrays of non-struct
- self.body.write(' t = dbus_g_type_get_collection ('
+ self.c(' t = dbus_g_type_get_collection ('
'"GPtrArray", '
'%stype_dbus_array_of_%s ());\n' %
(self.prefix_, escape_as_identifier(sig[1:])))
else:
raise AssertionError("array of '%s' not supported" % sig)
- self.body.write(' return t;\n')
- self.body.write('}\n\n')
+ self.c(' return t;\n')
+ self.c('}\n\n')
if __name__ == '__main__':
argv = sys.argv[1:]
diff --git a/tools/glib-interfaces-gen.py b/tools/glib-interfaces-gen.py
index e573249b..95439687 100644
--- a/tools/glib-interfaces-gen.py
+++ b/tools/glib-interfaces-gen.py
@@ -13,26 +13,32 @@ class Generator(object):
self.decls = open(declfile, 'w')
self.spec = get_by_path(dom, "spec")[0]
+ def h(self, code):
+ self.decls.write(code.encode('utf-8'))
+
+ def c(self, code):
+ self.impls.write(code.encode('utf-8'))
+
def __call__(self):
- for file in self.decls, self.impls:
- self.do_header(file)
+ for f in self.h, self.c:
+ self.do_header(f)
self.do_body()
# Header
- def do_header(self, file):
- file.write('/* Generated from: ')
- file.write(get_descendant_text(get_by_path(self.spec, 'title')))
+ 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:
- file.write(' version ' + get_descendant_text(version))
- file.write('\n\n')
+ f(' version ' + get_descendant_text(version))
+ f('\n\n')
for copyright in get_by_path(self.spec, 'copyright'):
- file.write(get_descendant_text(copyright))
- file.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("""
+ 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("""
*/
""")
@@ -44,7 +50,7 @@ class Generator(object):
def do_iface(self, iface):
parent_name = get_by_path(iface, '../@name')
- self.decls.write("""\
+ self.h("""\
/**
* %(IFACE_DEFINE)s:
*
@@ -56,7 +62,7 @@ class Generator(object):
parent_name).upper().replace('/', ''),
'name' : iface.getAttribute('name')})
- self.decls.write("""
+ self.h("""
/**
* %(IFACE_QUARK_DEFINE)s:
*
@@ -74,7 +80,7 @@ GQuark %(iface_quark_func)s (void);
parent_name).lower().replace('/', ''),
'name' : iface.getAttribute('name')})
- self.impls.write("""\
+ self.c("""\
GQuark
%(iface_quark_func)s (void)
{