#!/usr/bin/env python
from xml.etree.cElementTree import *
-from sys import argv
from os.path import basename
+import getopt
+import sys
import re
# Jump to the bottom of this file for the main routine
'new' : '_new',
'delete': '_delete'}
-_cardinal_types = ['CARD8', 'uint8_t',
- 'CARD16','uint16_t',
- 'CARD32','uint32_t',
- 'INT8', 'int8_t',
- 'INT16', 'int16_t',
- 'INT32', 'int32_t',
- 'BYTE',
- 'BOOL',
- 'char',
- 'void',
- 'float',
- 'double']
_hlines = []
_hlevel = 0
_clines = []
_ns = self.namespace
_ns.c_ext_global_name = _n(_ns.prefix + ('id',))
+ # Build the type-name collision avoidance table used by c_enum
+ build_collision_table()
+
_h_setlevel(0)
_c_setlevel(0)
for (n, h) in self.imports:
_hc('#include "%s.h"', h)
+ _h('')
+ _h('#ifdef __cplusplus')
+ _h('extern "C" {')
+ _h('#endif')
+
+ if _ns.is_ext:
_h('')
_h('#define XCB_%s_MAJOR_VERSION %s', _ns.ext_name.upper(), _ns.major_version)
_h('#define XCB_%s_MINOR_VERSION %s', _ns.ext_name.upper(), _ns.minor_version)
_h('extern xcb_extension_t %s;', _ns.c_ext_global_name)
_c('')
- _c('xcb_extension_t %s = { "%s" };', _ns.c_ext_global_name, _ns.ext_xname)
+ _c('xcb_extension_t %s = { "%s", 0 };', _ns.c_ext_global_name, _ns.ext_xname)
def c_close(self):
'''
_h_setlevel(2)
_c_setlevel(2)
_hc('')
+
+ _h('')
+ _h('#ifdef __cplusplus')
+ _h('}')
+ _h('#endif')
+
_h('')
_h('#endif')
_h('')
cfile.write('\n')
cfile.close()
+def build_collision_table():
+ global namecount
+ namecount = {}
+
+ for v in module.types.values():
+ name = _t(v[0])
+ namecount[name] = (namecount.get(name) or 0) + 1
+
def c_enum(self, name):
'''
Exported function that handles enum declarations.
'''
+
+ tname = _t(name)
+ if namecount[tname] > 1:
+ tname = _t(name + ('enum',))
+
_h_setlevel(0)
_h('')
- _h('typedef enum %s {', _t(name))
+ _h('typedef enum %s {', tname)
count = len(self.values)
comma = ',' if count > 0 else ''
_h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
- _h('} %s;', _t(name))
+ _h('} %s;', tname)
def _c_type_setup(self, name, postfix):
'''
return _c_iterator_get_end(field.type.last_varsized_field, accum)
if field.type.is_list:
# XXX we can always use the first way
- if field.type.c_type in _cardinal_types:
+ if field.type.member.is_simple:
return field.c_end_name + '(' + accum + ')'
else:
return field.type.member.c_end_name + '(' + field.c_iterator_name + '(' + accum + '))'
'''
Declares the accessor functions for a non-list field that follows a variable-length field.
'''
- if field.field_type[0] in _cardinal_types:
+ if field.type.is_simple:
_hc('')
_hc('')
_hc('/*****************************************************************************')
_c(' return %s;', _c_accessor_get_expr(field.type.expr, 'R'))
_c('}')
- if field.field_type[0] in _cardinal_types:
+ if field.type.member.is_simple:
_hc('')
_hc('')
_hc('/*****************************************************************************')
struct_fields = []
maxtypelen = 0
+ varfield = None
for field in self.fields:
if not field.type.fixed_size():
- break
+ varfield = field.c_field_name
+ continue
+ if varfield != None and not field.type.is_pad and field.wire:
+ errmsg = '%s: warning: variable field %s followed by fixed field %s\n' % (self.c_type, varfield, field.c_field_name)
+ sys.stderr.write(errmsg)
+ # sys.exit(1)
if field.wire:
struct_fields.append(field)
# Boilerplate below this point
+# Check for the argument that specifies path to the xcbgen python package.
+try:
+ opts, args = getopt.getopt(sys.argv[1:], 'p:')
+except getopt.GetoptError, err:
+ print str(err)
+ print 'Usage: c_client.py [-p path] file.xml'
+ sys.exit(1)
+
+for (opt, arg) in opts:
+ if opt == '-p':
+ sys.path.append(arg)
+
# Import the module class
try:
from xcbgen.state import Module
print ''
print 'Failed to load the xcbgen Python package!'
print 'Make sure that xcb/proto installed it on your Python path.'
- print 'If not, you will need to create a .pth file to extend the path.'
+ print 'If not, you will need to create a .pth file or define $PYTHONPATH'
+ print 'to extend the path.'
print 'Refer to the README file in xcb/proto for more info.'
print ''
raise
# Parse the xml header
-module = Module(argv[1], output)
+module = Module(args[0], output)
# Build type-registry and resolve type dependencies
module.register()