From 4f736752bbdf3bbf1a6325af7ad470198aa5a82a Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Sat, 20 Mar 2010 15:17:43 +0000
Subject: libxcb git update

---
 libxcb/src/Makefile.am  |   72 +--
 libxcb/src/c-client.xsl | 1551 +++++++++++++++++++++++++++++++++++++++++++++++
 libxcb/src/xcb.h        |   16 +
 libxcb/src/xcb_auth.c   |    4 +-
 libxcb/src/xcb_conn.c   |    4 +-
 libxcb/src/xcb_in.c     |  110 ++++
 libxcb/src/xcb_util.c   |   25 +-
 7 files changed, 1708 insertions(+), 74 deletions(-)
 create mode 100644 libxcb/src/c-client.xsl

(limited to 'libxcb/src')

diff --git a/libxcb/src/Makefile.am b/libxcb/src/Makefile.am
index 8bec61387..f0bdeaa46 100644
--- a/libxcb/src/Makefile.am
+++ b/libxcb/src/Makefile.am
@@ -1,14 +1,8 @@
 lib_LTLIBRARIES = libxcb.la
 
-EXTHEADERS =	xproto.h \
-		bigreq.h \
-		xc_misc.h
 EXTSOURCES =	xproto.c \
 		bigreq.c \
 		xc_misc.c
-EXTENSION_XML = xproto.xml \
-		bigreq.xml \
-		xc_misc.xml
 
 AM_CFLAGS = $(CWARNFLAGS) $(NEEDED_CFLAGS) $(XDMCP_CFLAGS)
 libxcb_la_LIBADD = $(NEEDED_LIBS) $(XDMCP_LIBS)
@@ -30,9 +24,7 @@ XCB_LIBS = libxcb.la
 
 # FIXME: find a way to autogenerate this from the XML files.
 
-EXTHEADERS += composite.h
 EXTSOURCES += composite.c
-EXTENSION_XML += composite.xml
 if BUILD_COMPOSITE
 lib_LTLIBRARIES += libxcb-composite.la
 libxcb_composite_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -40,9 +32,7 @@ libxcb_composite_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_composite_la_SOURCES = composite.c composite.h
 endif
 
-EXTHEADERS += damage.h
 EXTSOURCES += damage.c
-EXTENSION_XML += damage.xml
 if BUILD_DAMAGE
 lib_LTLIBRARIES += libxcb-damage.la
 libxcb_damage_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -50,9 +40,7 @@ libxcb_damage_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_damage_la_SOURCES = damage.c damage.h
 endif
 
-EXTHEADERS += dpms.h
 EXTSOURCES += dpms.c
-EXTENSION_XML += dpms.xml
 if BUILD_DPMS
 lib_LTLIBRARIES += libxcb-dpms.la
 libxcb_dpms_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -60,9 +48,7 @@ libxcb_dpms_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_dpms_la_SOURCES = dpms.c dpms.h
 endif
 
-EXTHEADERS += dri2.h
 EXTSOURCES += dri2.c
-EXTENSION_XML += dri2.xml
 if BUILD_DRI2
 lib_LTLIBRARIES += libxcb-dri2.la
 libxcb_dri2_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -70,9 +56,7 @@ libxcb_dri2_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_dri2_la_SOURCES = dri2.c dri2.h
 endif
 
-EXTHEADERS += glx.h
 EXTSOURCES += glx.c
-EXTENSION_XML += glx.xml
 if BUILD_GLX
 lib_LTLIBRARIES += libxcb-glx.la
 libxcb_glx_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -80,9 +64,7 @@ libxcb_glx_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_glx_la_SOURCES = glx.c glx.h
 endif
 
-EXTHEADERS += randr.h
 EXTSOURCES += randr.c
-EXTENSION_XML += randr.xml
 if BUILD_RANDR
 lib_LTLIBRARIES += libxcb-randr.la
 libxcb_randr_la_LDFLAGS = -version-info 1:0:1 -no-undefined
@@ -90,9 +72,7 @@ libxcb_randr_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_randr_la_SOURCES = randr.c randr.h
 endif
 
-EXTHEADERS += record.h
 EXTSOURCES += record.c
-EXTENSION_XML += record.xml
 if BUILD_RECORD
 lib_LTLIBRARIES += libxcb-record.la
 libxcb_record_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -100,9 +80,7 @@ libxcb_record_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_record_la_SOURCES = record.c record.h
 endif
 
-EXTHEADERS += render.h
 EXTSOURCES += render.c
-EXTENSION_XML += render.xml
 if BUILD_RENDER
 lib_LTLIBRARIES += libxcb-render.la
 libxcb_render_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -110,9 +88,7 @@ libxcb_render_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_render_la_SOURCES = render.c render.h
 endif
 
-EXTHEADERS += res.h
 EXTSOURCES += res.c
-EXTENSION_XML += res.xml
 if BUILD_RESOURCE
 lib_LTLIBRARIES += libxcb-res.la
 libxcb_res_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -120,9 +96,7 @@ libxcb_res_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_res_la_SOURCES = res.c res.h
 endif
 
-EXTHEADERS += screensaver.h
 EXTSOURCES += screensaver.c
-EXTENSION_XML += screensaver.xml
 if BUILD_SCREENSAVER
 lib_LTLIBRARIES += libxcb-screensaver.la
 libxcb_screensaver_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -130,9 +104,7 @@ libxcb_screensaver_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_screensaver_la_SOURCES = screensaver.c screensaver.h
 endif
 
-EXTHEADERS += shape.h
 EXTSOURCES += shape.c
-EXTENSION_XML += shape.xml
 if BUILD_SHAPE
 lib_LTLIBRARIES += libxcb-shape.la
 libxcb_shape_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -140,9 +112,7 @@ libxcb_shape_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_shape_la_SOURCES = shape.c shape.h
 endif
 
-EXTHEADERS += shm.h
 EXTSOURCES += shm.c
-EXTENSION_XML += shm.xml
 if BUILD_SHM
 lib_LTLIBRARIES += libxcb-shm.la
 libxcb_shm_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -150,9 +120,7 @@ libxcb_shm_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_shm_la_SOURCES = shm.c shm.h
 endif
 
-EXTHEADERS += sync.h
 EXTSOURCES += sync.c
-EXTENSION_XML += sync.xml
 if BUILD_SYNC
 lib_LTLIBRARIES += libxcb-sync.la
 libxcb_sync_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -160,9 +128,7 @@ libxcb_sync_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_sync_la_SOURCES = sync.c sync.h
 endif
 
-EXTHEADERS += xevie.h
 EXTSOURCES += xevie.c
-EXTENSION_XML += xevie.xml
 if BUILD_XEVIE
 lib_LTLIBRARIES += libxcb-xevie.la
 libxcb_xevie_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -170,9 +136,7 @@ libxcb_xevie_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xevie_la_SOURCES = xevie.c xevie.h
 endif
 
-EXTHEADERS += xf86dri.h
 EXTSOURCES += xf86dri.c
-EXTENSION_XML += xf86dri.xml
 if BUILD_XFREE86_DRI
 lib_LTLIBRARIES += libxcb-xf86dri.la
 libxcb_xf86dri_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -180,9 +144,7 @@ libxcb_xf86dri_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xf86dri_la_SOURCES = xf86dri.c xf86dri.h
 endif
 
-EXTHEADERS += xfixes.h
 EXTSOURCES += xfixes.c
-EXTENSION_XML += xfixes.xml
 if BUILD_XFIXES
 lib_LTLIBRARIES += libxcb-xfixes.la
 libxcb_xfixes_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -190,9 +152,7 @@ libxcb_xfixes_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xfixes_la_SOURCES = xfixes.c xfixes.h
 endif
 
-EXTHEADERS += xinerama.h
 EXTSOURCES += xinerama.c
-EXTENSION_XML += xinerama.xml
 if BUILD_XINERAMA
 lib_LTLIBRARIES += libxcb-xinerama.la
 libxcb_xinerama_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -200,9 +160,7 @@ libxcb_xinerama_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xinerama_la_SOURCES = xinerama.c xinerama.h
 endif
 
-EXTHEADERS += xinput.h
 EXTSOURCES += xinput.c
-EXTENSION_XML += xinput.xml
 if BUILD_XINPUT
 lib_LTLIBRARIES += libxcb-xinput.la
 libxcb_xinput_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -210,9 +168,7 @@ libxcb_xinput_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xinput_la_SOURCES = xinput.c xinput.h
 endif
 
-EXTHEADERS += xprint.h
 EXTSOURCES += xprint.c
-EXTENSION_XML += xprint.xml
 if BUILD_XPRINT
 lib_LTLIBRARIES += libxcb-xprint.la
 libxcb_xprint_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -220,9 +176,7 @@ libxcb_xprint_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xprint_la_SOURCES = xprint.c xprint.h
 endif
 
-EXTHEADERS += xselinux.h
 EXTSOURCES += xselinux.c
-EXTENSION_XML += xselinux.xml
 if BUILD_SELINUX
 lib_LTLIBRARIES += libxcb-xselinux.la
 libxcb_xselinux_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -230,9 +184,7 @@ libxcb_xselinux_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xselinux_la_SOURCES = xselinux.c xselinux.h
 endif
 
-EXTHEADERS += xtest.h
 EXTSOURCES += xtest.c
-EXTENSION_XML += xtest.xml
 if BUILD_XTEST
 lib_LTLIBRARIES += libxcb-xtest.la
 libxcb_xtest_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -240,9 +192,7 @@ libxcb_xtest_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xtest_la_SOURCES = xtest.c xtest.h
 endif
 
-EXTHEADERS += xv.h
 EXTSOURCES += xv.c
-EXTENSION_XML += xv.xml
 if BUILD_XV
 lib_LTLIBRARIES += libxcb-xv.la
 libxcb_xv_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -250,9 +200,7 @@ libxcb_xv_la_LIBADD = $(XCB_LIBS)
 nodist_libxcb_xv_la_SOURCES = xv.c xv.h
 endif
 
-EXTHEADERS += xvmc.h
 EXTSOURCES += xvmc.c
-EXTENSION_XML += xvmc.xml
 if BUILD_XVMC
 lib_LTLIBRARIES += libxcb-xvmc.la
 libxcb_xvmc_la_LDFLAGS = -version-info 0:0:0 -no-undefined
@@ -261,23 +209,13 @@ nodist_libxcb_xvmc_la_SOURCES = xvmc.c xvmc.h
 endif
 
 
-
+EXTHEADERS=$(EXTSOURCES:.c=.h)
 xcbinclude_HEADERS = xcb.h xcbext.h
 nodist_xcbinclude_HEADERS = $(EXTHEADERS)
 noinst_HEADERS = xcbint.h
 
-BUILT_SOURCES = $(EXTSOURCES) $(EXTHEADERS)
-CLEANFILES = $(EXTSOURCES) $(EXTHEADERS) $(EXTENSION_XML)
-
-$(EXTHEADERS) $(EXTSOURCES): c_client.py
-
-SUFFIXES = .xml
-
-.xml.h:
-	$(PYTHON) $(srcdir)/c_client.py -p $(XCBPROTO_XCBPYTHONDIR) $(XCBPROTO_XCBINCLUDEDIR)/$<
-
-.xml.c:
-	$(PYTHON) $(srcdir)/c_client.py -p $(XCBPROTO_XCBPYTHONDIR) $(XCBPROTO_XCBINCLUDEDIR)/$<
+BUILT_SOURCES = $(EXTSOURCES)
+CLEANFILES = $(EXTSOURCES) $(EXTHEADERS)
 
-$(EXTENSION_XML):
-	$(LN_S) -f $(XCBPROTO_XCBINCLUDEDIR)/$@ $@
+$(EXTSOURCES): c_client.py
+	$(PYTHON) $(srcdir)/c_client.py -p $(XCBPROTO_XCBPYTHONDIR) $(XCBPROTO_XCBINCLUDEDIR)/$(@:.c=.xml)
diff --git a/libxcb/src/c-client.xsl b/libxcb/src/c-client.xsl
new file mode 100644
index 000000000..a15d824a1
--- /dev/null
+++ b/libxcb/src/c-client.xsl
@@ -0,0 +1,1551 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (C) 2004 Josh Triplett.  All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors or their
+institutions shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from the authors.
+-->
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+               version="1.0"
+               xmlns:e="http://exslt.org/common"
+               xmlns:func="http://exslt.org/functions"
+               xmlns:str="http://exslt.org/strings"
+               xmlns:xcb="http://xcb.freedesktop.org"
+               extension-element-prefixes="func str xcb">
+  
+  <xsl:output method="text" />
+
+  <xsl:strip-space elements="*" />
+
+  <!-- "header" or "source" -->
+  <xsl:param name="mode" />
+
+  <!-- Path to the core protocol descriptions. -->
+  <xsl:param name="base-path" />
+
+  <!-- Path to the extension protocol descriptions. -->
+  <xsl:param name="extension-path" select="$base-path" />
+
+  <xsl:variable name="h" select="$mode = 'header'" />
+  <xsl:variable name="c" select="$mode = 'source'" />
+
+  <xsl:variable name="need-string-h" select="//request/pad[@bytes != 1]" />
+  
+  <!-- String used to indent lines of code. -->
+  <xsl:variable name="indent-string" select="'    '" />
+
+  <xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
+  <xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
+  <xsl:variable name="letters" select="concat($ucase, $lcase)" />
+  <xsl:variable name="digits" select="'0123456789'" />
+
+  <xsl:variable name="header" select="/xcb/@header" />
+  <xsl:variable name="ucase-header"
+                select="translate($header,$lcase,$ucase)" />
+
+  <xsl:variable name="ext" select="/xcb/@extension-name" />
+
+  <!-- Other protocol descriptions to search for types in, after checking the
+       current protocol description. -->
+  <xsl:variable name="search-path-rtf">
+    <xsl:for-each select="/xcb/import">
+      <path><xsl:value-of select="concat($extension-path, ., '.xml')" /></path>
+    </xsl:for-each>
+  </xsl:variable>
+  <xsl:variable name="search-path" select="e:node-set($search-path-rtf)/path"/>
+
+  <xsl:variable name="root" select="/" />
+  
+  <!-- First pass: Store everything in a variable. -->
+  <xsl:variable name="pass1-rtf">
+    <xsl:apply-templates select="/" mode="pass1" />
+  </xsl:variable>
+  <xsl:variable name="pass1" select="e:node-set($pass1-rtf)" />
+  
+  <xsl:template match="xcb" mode="pass1">
+    <xcb>
+      <xsl:copy-of select="@*" />
+      <xsl:if test="$ext">
+        <constant type="xcb_extension_t" name="{xcb:xcb-prefix()}_id">
+          <xsl:attribute name="value">{ "<xsl:value-of select="@extension-xname" />" }</xsl:attribute>
+        </constant>
+      </xsl:if>
+      <xsl:apply-templates mode="pass1" />
+    </xcb>
+  </xsl:template>
+
+  <func:function name="xcb:xcb-prefix">
+    <xsl:param name="name" />
+    <func:result>
+      <xsl:text>xcb</xsl:text>
+      <xsl:if test="/xcb/@extension-name">
+	<xsl:text>_</xsl:text>
+	<xsl:choose>
+	  <xsl:when test="/xcb/@extension-multiword = 'true' or /xcb/@extension-multiword = '1'">
+	    <xsl:call-template name="camelcase-to-underscore">
+	      <xsl:with-param name="camelcase" select="/xcb/@extension-name" />
+	    </xsl:call-template>
+	  </xsl:when>
+	  <xsl:otherwise>
+	    <xsl:value-of select="translate(/xcb/@extension-name, $ucase, $lcase)"/>
+	  </xsl:otherwise>
+	</xsl:choose>
+      </xsl:if>
+      <xsl:if test="$name">
+        <xsl:text>_</xsl:text>
+        <xsl:call-template name="camelcase-to-underscore">
+          <xsl:with-param name="camelcase" select="$name" />
+        </xsl:call-template>
+      </xsl:if>
+    </func:result>
+  </func:function>
+
+  <func:function name="xcb:lowercase">
+    <xsl:param name="name" />
+    <func:result>
+      <xsl:call-template name="camelcase-to-underscore">
+        <xsl:with-param name="camelcase" select="$name" />
+      </xsl:call-template>
+    </func:result>
+  </func:function>
+
+  <func:function name="xcb:get-char-void">
+    <xsl:param name="name" />
+    <xsl:variable name="ctype" select="substring-before($name, '_t')" />
+    <func:result>
+      <xsl:choose>
+        <xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
+          <xsl:value-of select="$ctype" />    
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$name" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </func:result>
+  </func:function>
+
+  <func:function name="xcb:remove-void">
+    <xsl:param name="name" />
+    <xsl:variable name="ctype" select="substring-before($name, '_t')" />
+    <func:result>
+      <xsl:choose>
+        <xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
+          <xsl:choose>
+            <xsl:when test="$ctype = 'void'">
+              <xsl:text>char</xsl:text>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:value-of select="$ctype" />
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$name" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </func:result>
+  </func:function>
+
+  <!-- split camel case into words and insert underscore -->
+  <xsl:template name="camelcase-to-underscore">
+    <xsl:param name="camelcase"/>
+    <xsl:choose>
+      <xsl:when test="$camelcase='CHAR2B' or $camelcase='INT64'
+                      or $camelcase='FLOAT32' or $camelcase='FLOAT64'
+                      or $camelcase='BOOL32' or $camelcase='STRING8'
+                      or $camelcase='Family_DECnet'">
+        <xsl:value-of select="translate($camelcase, $ucase, $lcase)"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:for-each select="str:split($camelcase, '')">
+          <xsl:variable name="a" select="."/>
+          <xsl:variable name="b" select="following::*[1]"/>
+          <xsl:variable name="c" select="following::*[2]"/>
+          <xsl:value-of select="translate(., $ucase, $lcase)"/>
+          <xsl:if test="($b and contains($lcase, $a) and contains($ucase, $b))
+                        or ($b and contains($digits, $a)
+                            and contains($letters, $b))
+                        or ($b and contains($letters, $a)
+                            and contains($digits, $b))
+                        or ($c and contains($ucase, $a)
+                            and contains($ucase, $b)
+                            and contains($lcase, $c))">
+            <xsl:text>_</xsl:text>
+          </xsl:if>
+        </xsl:for-each>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- Modify names that conflict with C++ keywords by prefixing them with an
+       underscore.  If the name parameter is not specified, it defaults to the
+       value of the name attribute on the context node. -->
+  <xsl:template name="canonical-var-name">
+    <xsl:param name="name" select="@name" />
+    <xsl:if test="$name='new' or $name='delete'
+                  or $name='class' or $name='operator'">
+      <xsl:text>_</xsl:text>
+    </xsl:if>
+    <xsl:value-of select="$name" />
+  </xsl:template>
+
+  <!-- List of core types, for use in canonical-type-name. -->
+  <xsl:variable name="core-types-rtf">
+    <type name="BOOL" newname="uint8" />
+    <type name="BYTE" newname="uint8" />
+    <type name="CARD8" newname="uint8" />
+    <type name="CARD16" newname="uint16" />
+    <type name="CARD32" newname="uint32" />
+    <type name="INT8" newname="int8" />
+    <type name="INT16" newname="int16" />
+    <type name="INT32" newname="int32" />
+
+    <type name="char" newname="char" />
+    <type name="void" newname="void" />
+    <type name="float" newname="float" />
+    <type name="double" newname="double" />
+  </xsl:variable>
+  <xsl:variable name="core-types" select="e:node-set($core-types-rtf)" />
+
+  <!--
+    Output the canonical name for a type.  This will be
+    xcb_{extension-containing-type-if-any}_type, wherever the type is found in
+    the search path, or just type if not found.  If the type parameter is not
+    specified, it defaults to the value of the type attribute on the context
+    node.
+  -->
+  <xsl:template name="canonical-type-name">
+    <xsl:param name="type" select="string(@type)" />
+
+    <xsl:variable name="is-unqualified" select="not(contains($type, ':'))"/>
+    <xsl:variable name="namespace" select="substring-before($type, ':')" />
+    <xsl:variable name="unqualified-type">
+      <xsl:choose>
+        <xsl:when test="$is-unqualified">
+          <xsl:value-of select="$type" />
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="substring-after($type, ':')" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:choose>
+      <xsl:when test="$is-unqualified and $core-types/type[@name=$type]">
+        <xsl:value-of select="$core-types/type[@name=$type]/@newname" />
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:variable name="type-definitions"
+                      select="(/xcb|document($search-path)/xcb
+                              )[$is-unqualified or @header=$namespace]
+                               /*[((self::struct or self::union or self::enum
+                                    or self::xidtype or self::xidunion
+                                    or self::event or self::eventcopy
+                                    or self::error or self::errorcopy)
+                                   and @name=$unqualified-type)
+                                  or (self::typedef
+                                      and @newname=$unqualified-type)]" />
+        <xsl:choose>
+          <xsl:when test="count($type-definitions) = 1">
+            <xsl:for-each select="$type-definitions">
+              <xsl:value-of select="xcb:xcb-prefix($unqualified-type)" />
+            </xsl:for-each>
+          </xsl:when>
+          <xsl:when test="count($type-definitions) > 1">
+            <xsl:message terminate="yes">
+              <xsl:text>Multiple definitions of type "</xsl:text>
+              <xsl:value-of select="$type" />
+              <xsl:text>" found.</xsl:text>
+              <xsl:if test="$is-unqualified">
+                <xsl:for-each select="$type-definitions">
+                  <xsl:text>
+    </xsl:text>
+                  <xsl:value-of select="concat(/xcb/@header, ':', $type)" />
+                </xsl:for-each>
+              </xsl:if>
+            </xsl:message>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:message terminate="yes">
+              <xsl:text>No definitions of type "</xsl:text>
+              <xsl:value-of select="$type" />
+              <xsl:text>" found</xsl:text>
+              <xsl:if test="$is-unqualified">
+                <xsl:text>, and it is not a known core type</xsl:text>
+              </xsl:if>
+              <xsl:text>.</xsl:text>
+            </xsl:message>
+          </xsl:otherwise>
+        </xsl:choose> 	
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  
+  <!-- Helper template for requests, that outputs the cookie type.  The
+       parameter "request" must be the request node, which defaults to the
+       context node. -->
+  <xsl:template name="cookie-type">
+    <xsl:param name="request" select="." />
+    <xsl:choose>
+      <xsl:when test="$request/reply">
+        <xsl:value-of select="xcb:xcb-prefix($request/@name)" />
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:text>xcb_void</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+    <xsl:text>_cookie_t</xsl:text>
+  </xsl:template>
+
+  <xsl:template name="request-function">
+    <xsl:param name="checked" />
+    <xsl:param name="req" />
+    <function>
+      <xsl:attribute name="name">
+        <xsl:value-of select="xcb:xcb-prefix($req/@name)" />
+        <xsl:if test="$checked='true' and not($req/reply)">_checked</xsl:if>
+        <xsl:if test="$checked='false' and $req/reply">_unchecked</xsl:if>
+      </xsl:attribute>
+      <xsl:attribute name="type">
+        <xsl:call-template name="cookie-type">
+          <xsl:with-param name="request" select="$req" />
+        </xsl:call-template>
+      </xsl:attribute>
+      <doc>/**</doc>
+      <doc> * Delivers a request to the X server</doc>
+      <doc> * @param c The connection</doc>
+      <doc> * @return A cookie</doc>
+      <doc> *</doc>
+      <doc> * Delivers a request to the X server.</doc>
+      <doc> * </doc>
+      <xsl:if test="$checked='true' and not($req/reply)">
+        <doc> * This form can be used only if the request will not cause</doc>
+        <doc> * a reply to be generated. Any returned error will be</doc>
+        <doc> * saved for handling by xcb_request_check().</doc>
+      </xsl:if>
+      <xsl:if test="$checked='false' and $req/reply">
+        <doc> * This form can be used only if the request will cause</doc>
+        <doc> * a reply to be generated. Any returned error will be</doc>
+        <doc> * placed in the event queue.</doc>
+      </xsl:if>
+      <doc> */</doc>
+      <field type="xcb_connection_t *" name="c" />
+      <xsl:apply-templates select="$req/*[not(self::reply)]" mode="param" />
+      <do-request ref="{xcb:xcb-prefix($req/@name)}_request_t" opcode="{translate(xcb:xcb-prefix($req/@name), $lcase, $ucase)}"
+                  checked="{$checked}">
+        <xsl:if test="$req/reply">
+          <xsl:attribute name="has-reply">true</xsl:attribute>
+        </xsl:if>
+      </do-request>
+    </function>
+  </xsl:template>
+  
+  <xsl:template match="request" mode="pass1">
+    <xsl:variable name="req" select="." />
+    <xsl:if test="reply">
+      <struct name="{xcb:xcb-prefix(@name)}_cookie_t">
+        <field type="unsigned int" name="sequence" />
+      </struct>
+    </xsl:if>
+    <constant type="number" name="{xcb:xcb-prefix($req/@name)}" value="{$req/@opcode}" />
+    <struct name="{xcb:xcb-prefix(@name)}_request_t">
+      <field type="uint8_t" name="major_opcode" no-assign="true" />
+      <xsl:if test="$ext">
+        <field type="uint8_t" name="minor_opcode" no-assign="true" />
+      </xsl:if>
+      <xsl:apply-templates select="*[not(self::reply)]" mode="field" />
+      <middle>
+        <field type="uint16_t" name="length" no-assign="true" />
+      </middle>
+    </struct>
+    <xsl:call-template name="request-function">
+      <xsl:with-param name="checked" select="'true'" />
+      <xsl:with-param name="req" select="$req" />
+    </xsl:call-template>
+    <xsl:call-template name="request-function">
+      <xsl:with-param name="checked" select="'false'" />
+      <xsl:with-param name="req" select="$req" />
+    </xsl:call-template>
+    <xsl:if test="reply">
+      <struct name="{xcb:xcb-prefix(@name)}_reply_t">
+        <field type="uint8_t" name="response_type" />
+        <xsl:apply-templates select="reply/*" mode="field" />
+        <middle>
+          <field type="uint16_t" name="sequence" />
+          <field type="uint32_t" name="length" />
+        </middle>
+      </struct>
+      <iterator-functions ref="{xcb:xcb-prefix(@name)}" kind="_reply" />
+      <function type="{xcb:xcb-prefix(@name)}_reply_t *" name="{xcb:xcb-prefix(@name)}_reply">
+        <doc>/**</doc>
+        <doc> * Return the reply</doc>
+        <doc> * @param c      The connection</doc>
+        <doc> * @param cookie The cookie</doc>
+        <doc> * @param e      The xcb_generic_error_t supplied</doc>
+        <doc> *</doc>
+        <doc> * Returns the reply of the request asked by</doc>
+        <doc> * </doc>
+        <doc> * The parameter @p e supplied to this function must be NULL if</doc>
+        <doc> * <xsl:value-of select="xcb:xcb-prefix(@name)" />_unchecked(). is used.</doc>
+        <doc> * Otherwise, it stores the error if any.</doc>
+        <doc> *</doc>
+        <doc> * The returned value must be freed by the caller using free().</doc>
+        <doc> */</doc>
+        <field type="xcb_connection_t *" name="c" />
+        <field name="cookie">
+          <xsl:attribute name="type">
+            <xsl:call-template name="cookie-type" />
+          </xsl:attribute>
+        </field>
+        <field type="xcb_generic_error_t **" name="e" />
+        <l>return (<xsl:value-of select="xcb:xcb-prefix(@name)" />_reply_t *)<!--
+        --> xcb_wait_for_reply(c, cookie.sequence, e);</l>
+      </function>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="xidtype|xidunion" mode="pass1">
+    <typedef oldname="uint32_t" newname="{xcb:xcb-prefix(@name)}_t" />
+    <iterator ref="{xcb:xcb-prefix(@name)}" />
+    <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
+  </xsl:template>
+
+  <xsl:template match="struct|union" mode="pass1">
+    <struct name="{xcb:xcb-prefix(@name)}_t">
+      <xsl:if test="self::union">
+        <xsl:attribute name="kind">union</xsl:attribute>
+      </xsl:if>
+      <xsl:apply-templates select="*" mode="field" />
+    </struct>
+    <iterator ref="{xcb:xcb-prefix(@name)}" />
+    <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
+  </xsl:template>
+
+  <xsl:template match="event|eventcopy|error|errorcopy" mode="pass1">
+    <xsl:variable name="suffix">
+      <xsl:choose>
+        <xsl:when test="self::event|self::eventcopy">
+          <xsl:text>_event_t</xsl:text>
+        </xsl:when>
+        <xsl:when test="self::error|self::errorcopy">
+          <xsl:text>_error_t</xsl:text>
+        </xsl:when>
+      </xsl:choose>
+    </xsl:variable>
+    <constant type="number" name="{xcb:xcb-prefix(@name)}" value="{@number}" />
+    <xsl:choose>
+      <xsl:when test="self::event|self::error">
+        <struct name="{xcb:xcb-prefix(@name)}{$suffix}">
+          <field type="uint8_t" name="response_type" />
+          <xsl:if test="self::error">
+            <field type="uint8_t" name="error_code" />
+          </xsl:if>
+          <xsl:apply-templates select="*" mode="field" />
+          <xsl:if test="not(self::event and boolean(@no-sequence-number))">
+            <middle>
+              <field type="uint16_t" name="sequence" />
+            </middle>
+          </xsl:if>
+        </struct>
+      </xsl:when>
+      <xsl:when test="self::eventcopy|self::errorcopy">
+        <typedef newname="{xcb:xcb-prefix(@name)}{$suffix}">
+          <xsl:attribute name="oldname">
+            <xsl:call-template name="canonical-type-name">
+              <xsl:with-param name="type" select="@ref" />
+            </xsl:call-template>
+            <xsl:value-of select="$suffix" />
+          </xsl:attribute>
+        </typedef>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="typedef" mode="pass1">
+    <typedef>
+      <xsl:attribute name="oldname">
+        <xsl:call-template name="canonical-type-name">
+          <xsl:with-param name="type" select="@oldname" />
+        </xsl:call-template>
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="newname">
+        <xsl:call-template name="canonical-type-name">
+          <xsl:with-param name="type" select="@newname" />
+        </xsl:call-template>
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+    </typedef>
+    <iterator ref="{xcb:xcb-prefix(@newname)}" />
+    <iterator-functions ref="{xcb:xcb-prefix(@newname)}" />
+  </xsl:template>
+
+  <xsl:template match="enum" mode="pass1">
+    <enum name="{xcb:xcb-prefix(@name)}_t">
+      <xsl:for-each select="item">
+        <item name="{translate(xcb:xcb-prefix(concat(../@name, concat('_', @name))), $lcase, $ucase)}">
+          <xsl:copy-of select="*" />
+        </item>
+      </xsl:for-each>
+    </enum>
+  </xsl:template>
+
+  <!--
+    Templates for processing fields.
+  -->
+
+  <xsl:template match="pad" mode="field">
+    <xsl:copy-of select="." />
+  </xsl:template>
+  
+  <xsl:template match="field|exprfield" mode="field">
+    <xsl:copy>
+      <xsl:attribute name="type">
+        <xsl:call-template name="canonical-type-name" />
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name" />
+      </xsl:attribute>
+      <xsl:copy-of select="*" />
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="list" mode="field">
+    <xsl:variable name="type"><!--
+      --><xsl:call-template name="canonical-type-name" />
+        <xsl:text>_t</xsl:text><!--
+    --></xsl:variable>
+    <list type="{$type}">
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name" />
+      </xsl:attribute>
+      <xsl:if test="not(parent::request) and node()
+                    and not(.//*[not(self::value or self::op)])">
+        <xsl:attribute name="fixed">true</xsl:attribute>
+      </xsl:if>
+      <!-- Handle lists with no length expressions. -->
+      <xsl:if test="not(node())">
+        <xsl:choose>
+          <!-- In a request, refer to an implicit localparam for length. -->
+          <xsl:when test="parent::request">
+            <fieldref>
+              <xsl:value-of select="concat(@name, '_len')" />
+            </fieldref>
+          </xsl:when>
+          <!-- In a reply, use the length of the reply to determine the length
+               of the list. -->
+          <xsl:when test="parent::reply">
+            <op op="/">
+              <op op="&lt;&lt;">
+                <fieldref>length</fieldref>
+                <value>2</value>
+              </op>
+              <function-call name="sizeof">
+                <param><xsl:value-of select="$type" /></param>
+              </function-call>
+            </op>
+          </xsl:when>
+          <!-- Other cases generate an error. -->
+          <xsl:otherwise>
+            <xsl:message terminate="yes"><!--
+              -->Encountered a list with no length expresssion outside a<!--
+              --> request or reply.<!--
+            --></xsl:message>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:if>
+      <xsl:copy-of select="*" />
+    </list>
+  </xsl:template>
+
+  <xsl:template match="valueparam" mode="field">
+    <field>
+      <xsl:attribute name="type">
+        <xsl:call-template name="canonical-type-name">
+          <xsl:with-param name="type" select="@value-mask-type" />
+        </xsl:call-template>
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name">
+          <xsl:with-param name="name" select="@value-mask-name" />
+        </xsl:call-template>
+      </xsl:attribute>
+    </field>
+    <list type="uint32_t">
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name">
+          <xsl:with-param name="name" select="@value-list-name" />
+        </xsl:call-template>
+      </xsl:attribute>
+      <function-call name="xcb_popcount">
+        <param>
+          <fieldref>
+            <xsl:call-template name="canonical-var-name">
+              <xsl:with-param name="name" select="@value-mask-name" />
+            </xsl:call-template>
+          </fieldref>
+        </param>
+      </function-call>
+    </list>
+  </xsl:template>
+
+  <xsl:template match="field" mode="param">
+    <field>
+      <xsl:attribute name="type">
+        <xsl:call-template name="canonical-type-name" />
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name" />
+      </xsl:attribute>
+    </field>
+  </xsl:template>
+
+  <xsl:template match="list" mode="param">
+    <!-- If no length expression is provided, use a CARD32 localfield. -->
+    <xsl:if test="not(node())">
+      <field type="uint32_t" name="{@name}_len" />
+    </xsl:if>
+    <field>
+      <xsl:variable name="ctype">
+        <xsl:call-template name="canonical-type-name" />
+      </xsl:variable>
+      <xsl:attribute name="type">
+        <xsl:text>const </xsl:text>
+        <xsl:call-template name="canonical-type-name" />
+        <xsl:if test="not($ctype='char') and not($ctype='void')">
+          <xsl:text>_t</xsl:text>
+        </xsl:if>
+        <xsl:text> *</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name" />
+      </xsl:attribute>
+    </field>
+  </xsl:template>
+
+  <xsl:template match="valueparam" mode="param">
+    <field>
+      <xsl:attribute name="type">
+        <xsl:call-template name="canonical-type-name">
+          <xsl:with-param name="type" select="@value-mask-type" />
+        </xsl:call-template>
+        <xsl:text>_t</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name">
+          <xsl:with-param name="name" select="@value-mask-name" />
+        </xsl:call-template>
+      </xsl:attribute>
+    </field>
+    <field type="const uint32_t *">
+      <xsl:attribute name="name">
+        <xsl:call-template name="canonical-var-name">
+          <xsl:with-param name="name" select="@value-list-name" />
+        </xsl:call-template>
+      </xsl:attribute>
+    </field>
+  </xsl:template>
+
+  <!-- Second pass: Process the variable. -->
+  <xsl:variable name="result-rtf">
+    <xsl:apply-templates select="$pass1/*" mode="pass2" />
+  </xsl:variable>
+  <xsl:variable name="result" select="e:node-set($result-rtf)" />
+
+  <xsl:template match="xcb" mode="pass2">
+    <xcb>
+      <xsl:copy-of select="@*" />
+      <xsl:apply-templates mode="pass2"
+                           select="constant|enum|struct|typedef|iterator" />
+      <xsl:apply-templates mode="pass2"
+                           select="function|iterator-functions" />
+    </xcb>
+  </xsl:template>
+
+  <!-- Generic rules for nodes that don't need further processing: copy node
+       with attributes, and recursively process the child nodes. -->
+  <xsl:template match="*" mode="pass2">
+    <xsl:copy>
+      <xsl:copy-of select="@*" />
+      <xsl:apply-templates mode="pass2" />
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="struct" mode="pass2">
+    <xsl:if test="@kind='union' and list[not(@fixed)]">
+      <xsl:message terminate="yes">Unions must be fixed length.</xsl:message>
+    </xsl:if>
+    <struct name="{@name}">
+      <xsl:if test="@kind">
+        <xsl:attribute name="kind">
+          <xsl:value-of select="@kind" />
+        </xsl:attribute>
+      </xsl:if>
+      <!-- FIXME: This should go by size, not number of fields. -->
+      <xsl:copy-of select="node()[not(self::middle)
+                   and position() &lt; 3]" />
+      <xsl:if test="middle and (count(*[not(self::middle)]) &lt; 2)">
+        <pad bytes="{2 - count(*[not(self::middle)])}" />
+      </xsl:if>
+      <xsl:copy-of select="middle/*" />
+      <xsl:copy-of select="node()[not(self::middle) and (position() > 2)]" />
+    </struct>
+  </xsl:template>
+
+  <xsl:template match="do-request" mode="pass2">
+    <xsl:variable name="struct"
+                  select="$pass1/xcb/struct[@name=current()/@ref]" />
+
+    <xsl:variable name="num-parts" select="(1+count($struct/list))*2" />
+
+    <l>static const xcb_protocol_request_t xcb_req = {</l>
+    <indent>
+      <l>/* count */ <xsl:value-of select="$num-parts" />,</l>
+      <l>/* ext */ <xsl:choose>
+                     <xsl:when test="$ext">
+                       <xsl:text>&amp;</xsl:text>
+                       <xsl:value-of select="xcb:xcb-prefix()" />
+                       <xsl:text>_id</xsl:text>
+                     </xsl:when>
+                     <xsl:otherwise>0</xsl:otherwise>
+                   </xsl:choose>,</l>
+      <l>/* opcode */ <xsl:value-of select="@opcode" />,</l>
+      <l>/* isvoid */ <xsl:value-of select="1-boolean(@has-reply)" /></l>
+    </indent>
+    <l>};</l>
+
+    <l />
+    <l>struct iovec xcb_parts[<xsl:value-of select="$num-parts+2" />];</l>
+    <l><xsl:value-of select="../@type" /> xcb_ret;</l>
+    <l><xsl:value-of select="@ref" /> xcb_out;</l>
+
+    <l />
+    <xsl:if test="not ($ext) and not($struct//*[(self::field or self::exprfield or self::pad)
+                                                and not(boolean(@no-assign))])">
+      <l>xcb_out.pad0 = 0;</l>
+    </xsl:if>
+    <xsl:apply-templates select="$struct//*[(self::field or self::exprfield or self::pad)
+                                            and not(boolean(@no-assign))]"
+                         mode="assign" />
+
+    <l />
+    <l>xcb_parts[2].iov_base = (char *) &amp;xcb_out;</l>
+    <l>xcb_parts[2].iov_len = sizeof(xcb_out);</l>
+    <l>xcb_parts[3].iov_base = 0;</l>
+    <l>xcb_parts[3].iov_len = -xcb_parts[2].iov_len &amp; 3;</l>
+
+    <xsl:for-each select="$struct/list">
+      <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_base = (char *) <!--
+      --><xsl:value-of select="@name" />;</l>
+      <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len = <!--
+      --><xsl:apply-templates mode="output-expression" />
+      <xsl:if test="not(@type = 'void_t')">
+        <xsl:text> * sizeof(</xsl:text>
+          <xsl:choose>
+          <xsl:when test="@type='char_t'">
+            <xsl:text>char</xsl:text>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="@type" />
+          </xsl:otherwise>
+        </xsl:choose>
+        <xsl:text>)</xsl:text>
+      </xsl:if>;</l>
+      <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_base = 0;</l>
+      <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_len = -xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len &amp; 3;</l>
+    </xsl:for-each>
+
+    <l>xcb_ret.sequence = xcb_send_request(c, <!--
+    --><xsl:choose>
+         <xsl:when test="@checked='true'">XCB_REQUEST_CHECKED</xsl:when>
+         <xsl:otherwise>0</xsl:otherwise>
+       </xsl:choose>, xcb_parts + 2, &amp;xcb_req);</l>
+    <l>return xcb_ret;</l>
+  </xsl:template>
+
+  <xsl:template match="field" mode="assign">
+    <l>
+      <xsl:text>xcb_out.</xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text> = </xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text>;</xsl:text>
+    </l>
+  </xsl:template>
+
+  <xsl:template match="exprfield" mode="assign">
+    <l>
+      <xsl:text>xcb_out.</xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text> = </xsl:text>
+      <xsl:apply-templates mode="output-expression" />
+      <xsl:text>;</xsl:text>
+    </l>
+  </xsl:template>
+
+  <xsl:template match="pad" mode="assign">
+    <xsl:variable name="padnum"><xsl:number /></xsl:variable>
+    <l><xsl:choose>
+        <xsl:when test="@bytes = 1">xcb_out.pad<xsl:value-of select="$padnum - 1" /> = 0;</xsl:when>
+        <xsl:otherwise>memset(xcb_out.pad<xsl:value-of select="$padnum - 1" />, 0, <xsl:value-of select="@bytes" />);</xsl:otherwise>
+    </xsl:choose></l>
+  </xsl:template>
+
+  <xsl:template match="iterator" mode="pass2">
+    <struct name="{@ref}_iterator_t">
+      <field type="{@ref}_t *" name="data" />
+      <field type="int" name="rem" />
+      <field type="int" name="index" />
+    </struct>
+  </xsl:template>
+
+  <xsl:template match="iterator-functions" mode="pass2">
+    <xsl:variable name="ref" select="@ref" />
+    <xsl:variable name="kind" select="@kind" />
+    <xsl:variable name="struct"
+                  select="$pass1/xcb/struct[@name=concat($ref, $kind, '_t')]" />
+    <xsl:variable name="nextfields-rtf">
+      <nextfield>R + 1</nextfield>
+      <xsl:for-each select="$struct/list[not(@fixed)]">
+        <xsl:choose>
+          <xsl:when test="substring(@type, 1, 3) = 'xcb'">
+            <nextfield><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_end(<!--
+            --><xsl:value-of select="$ref" />_<!--
+            --><xsl:value-of select="string(@name)" />_iterator(R))</nextfield>
+          </xsl:when>
+          <xsl:otherwise>
+            <nextfield><xsl:value-of select="$ref" />_<!--
+            --><xsl:value-of select="string(@name)" />_end(R)</nextfield>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:for-each>
+    </xsl:variable>
+    <xsl:variable name="nextfields" select="e:node-set($nextfields-rtf)" />
+    <xsl:for-each select="$struct/list[not(@fixed)]">
+      <xsl:variable name="number"
+                    select="1+count(preceding-sibling::list[not(@fixed)])" />
+      <xsl:variable name="nextfield" select="$nextfields/nextfield[$number]" />
+      <xsl:variable name="is-first"
+                    select="not(preceding-sibling::list[not(@fixed)])" />
+      <xsl:variable name="field-name" select="@name" />
+      <xsl:variable name="is-variable"
+                    select="$pass1/xcb/struct[@name=current()/@type]/list
+                            or document($search-path)/xcb
+                               /struct[concat(xcb:xcb-prefix(@name), '_t')
+                                       = current()/@type]
+                               /*[self::valueparam
+                                  or self::list[.//*[not(self::value
+                                                         or self::op)]]]" />
+      <xsl:if test="not($is-variable)">
+        <function type="{xcb:get-char-void(@type)} *" name="{$ref}_{xcb:lowercase($field-name)}">
+          <field type="const {$ref}{$kind}_t *" name="R" />
+          <xsl:choose>
+            <xsl:when test="$is-first">
+              <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
+              -->(<xsl:value-of select="$nextfield" />);</l>
+            </xsl:when>
+            <xsl:otherwise>
+              <l>xcb_generic_iterator_t prev = <!--
+              --><xsl:value-of select="$nextfield" />;</l>
+              <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
+              -->((char *) prev.data + XCB_TYPE_PAD(<!--
+              --><xsl:value-of select="xcb:get-char-void(@type)" />, prev.index));</l>
+            </xsl:otherwise>
+          </xsl:choose>
+        </function>
+      </xsl:if>
+      <function type="int" name="{$ref}_{xcb:lowercase($field-name)}_length">
+        <field type="const {$ref}{$kind}_t *" name="R" />
+        <l>return <xsl:apply-templates mode="output-expression">
+                    <xsl:with-param name="field-prefix" select="'R->'" />
+                  </xsl:apply-templates>;</l>
+      </function>
+      <xsl:choose>
+        <xsl:when test="substring(@type, 1, 3) = 'xcb'">
+          <function type="{substring(@type, 1, string-length(@type)-2)}_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_iterator">
+            <field type="const {$ref}{$kind}_t *" name="R" />
+            <l><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_iterator_t i;</l>
+            <xsl:choose>
+              <xsl:when test="$is-first">
+                <l>i.data = (<xsl:value-of select="@type" /> *) <!--
+                -->(<xsl:value-of select="$nextfield" />);</l>
+              </xsl:when>
+              <xsl:otherwise>
+                <l>xcb_generic_iterator_t prev = <!--
+                --><xsl:value-of select="$nextfield" />;</l>
+                <l>i.data = (<xsl:value-of select="@type" /> *) <!--
+                -->((char *) prev.data + XCB_TYPE_PAD(<!--
+                --><xsl:value-of select="@type" />, prev.index));</l>
+              </xsl:otherwise>
+            </xsl:choose>
+            <l>i.rem = <xsl:apply-templates mode="output-expression">
+                         <xsl:with-param name="field-prefix" select="'R->'" />
+                       </xsl:apply-templates>;</l>
+            <l>i.index = (char *) i.data - (char *) R;</l>
+            <l>return i;</l>
+          </function>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:variable name="cast">
+            <xsl:choose>
+              <xsl:when test="@type='void'">char</xsl:when>
+              <xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
+            </xsl:choose>
+          </xsl:variable>
+          <function type="xcb_generic_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_end">
+            <field type="const {$ref}{$kind}_t *" name="R" />
+            <l>xcb_generic_iterator_t i;</l>
+            <xsl:choose>
+              <xsl:when test="$is-first">
+                <l>i.data = ((<xsl:value-of select="xcb:remove-void($cast)" /> *) <!--
+                -->(<xsl:value-of select="$nextfield" />)) + (<!--
+                --><xsl:apply-templates mode="output-expression">
+                     <xsl:with-param name="field-prefix" select="'R->'" />
+                   </xsl:apply-templates>);</l>
+              </xsl:when>
+              <xsl:otherwise>
+                <l>xcb_generic_iterator_t child = <!--
+                --><xsl:value-of select="$nextfield" />;</l>
+                <l>i.data = ((<xsl:value-of select="xcb:get-char-void($cast)" /> *) <!--
+                -->child.data) + (<!--
+                --><xsl:apply-templates mode="output-expression">
+                     <xsl:with-param name="field-prefix" select="'R->'" />
+                   </xsl:apply-templates>);</l>
+              </xsl:otherwise>
+            </xsl:choose>
+            <l>i.rem = 0;</l>
+            <l>i.index = (char *) i.data - (char *) R;</l>
+            <l>return i;</l>
+          </function>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+    <xsl:if test="not($kind)">
+      <function type="void" name="{$ref}_next">
+        <doc>/**</doc>
+        <doc> * Get the next element of the iterator</doc>
+        <doc> * @param i Pointer to a <xsl:value-of select="$ref" />_iterator_t</doc>
+        <doc> *</doc>
+        <doc> * Get the next element in the iterator. The member rem is</doc>
+        <doc> * decreased by one. The member data points to the next</doc>
+        <doc> * element. The member index is increased by sizeof(<xsl:value-of select="$ref" />_t)</doc>
+        <doc> */</doc>
+        <field type="{$ref}_iterator_t *" name="i" />
+        <xsl:choose>
+          <xsl:when test="$struct/list[not(@fixed)]">
+            <l><xsl:value-of select="$ref" />_t *R = i->data;</l>
+            <l>xcb_generic_iterator_t child = <!--
+            --><xsl:value-of select="$nextfields/nextfield[last()]" />;</l>
+            <l>--i->rem;</l>
+            <l>i->data = (<xsl:value-of select="$ref" />_t *) child.data;</l>
+            <l>i->index = child.index;</l>
+          </xsl:when>
+          <xsl:otherwise>
+            <l>--i->rem;</l>
+            <l>++i->data;</l>
+            <l>i->index += sizeof(<xsl:value-of select="$ref" />_t);</l>
+          </xsl:otherwise>
+        </xsl:choose>
+      </function>
+      <function type="xcb_generic_iterator_t" name="{$ref}_end">
+        <doc>/**</doc>
+        <doc> * Return the iterator pointing to the last element</doc>
+        <doc> * @param i An <xsl:value-of select="$ref" />_iterator_t</doc>
+        <doc> * @return  The iterator pointing to the last element</doc>
+        <doc> *</doc>
+        <doc> * Set the current element in the iterator to the last element.</doc>
+        <doc> * The member rem is set to 0. The member data points to the</doc>
+        <doc> * last element.</doc>
+        <doc> */</doc>
+        <field type="{$ref}_iterator_t" name="i" />
+        <l>xcb_generic_iterator_t ret;</l>
+        <xsl:choose>
+          <xsl:when test="$struct/list[not(@fixed)]">
+            <l>while(i.rem > 0)</l>
+            <indent>
+              <l><xsl:value-of select="$ref" />_next(&amp;i);</l>
+            </indent>
+            <l>ret.data = i.data;</l>
+            <l>ret.rem = i.rem;</l>
+            <l>ret.index = i.index;</l>
+          </xsl:when>
+          <xsl:otherwise>
+            <l>ret.data = i.data + i.rem;</l>
+            <l>ret.index = i.index + ((char *) ret.data - (char *) i.data);</l>
+            <l>ret.rem = 0;</l>
+          </xsl:otherwise>
+        </xsl:choose>
+        <l>return ret;</l>
+      </function>
+    </xsl:if>
+  </xsl:template>
+
+  <!-- Output the results. -->
+  <xsl:template match="/">
+    <xsl:if test="not(function-available('e:node-set'))">
+      <xsl:message terminate="yes"><!--
+        -->Error: This stylesheet requires the EXSL node-set extension.<!--
+      --></xsl:message>
+    </xsl:if>
+
+    <xsl:if test="not($h) and not($c)">
+      <xsl:message terminate="yes"><!--
+        -->Error: Parameter "mode" must be "header" or "source".<!--
+      --></xsl:message>
+    </xsl:if>
+
+    <xsl:apply-templates select="$result/*" mode="output" />
+  </xsl:template>
+
+  <xsl:template match="xcb" mode="output">
+    <xsl:variable name="guard"><!--
+      -->__<xsl:value-of select="$ucase-header" />_H<!--
+    --></xsl:variable>
+
+<xsl:text>/*
+ * This file generated automatically from </xsl:text>
+<xsl:value-of select="$header" /><xsl:text>.xml by c-client.xsl using XSLT.
+ * Edit at your peril.
+ */
+</xsl:text>
+<xsl:if test="$h"><xsl:text>
+/**
+ * @defgroup XCB_</xsl:text><xsl:value-of select="$ext" /><xsl:text>_API XCB </xsl:text><xsl:value-of select="$ext" /><xsl:text> API
+ * @brief </xsl:text><xsl:value-of select="$ext" /><xsl:text> XCB Protocol Implementation.</xsl:text>
+<xsl:text>
+ * @{
+ **/
+</xsl:text>
+
+<xsl:text>
+#ifndef </xsl:text><xsl:value-of select="$guard" /><xsl:text>
+#define </xsl:text><xsl:value-of select="$guard" /><xsl:text>
+</xsl:text>
+#include "xcb.h"
+<xsl:for-each select="$root/xcb/import">
+<xsl:text>#include "</xsl:text><xsl:value-of select="." /><xsl:text>.h"
+</xsl:text>
+</xsl:for-each>
+<xsl:text>
+</xsl:text>
+</xsl:if>
+<xsl:if test="$h">
+    <xsl:choose>
+        <xsl:when test="string($ext)">
+  <xsl:text>#define XCB_</xsl:text><xsl:value-of select="translate($ext, $lcase, $ucase)"/><xsl:text>_MAJOR_VERSION </xsl:text><xsl:value-of select="/xcb/@major-version" /><xsl:text>
+</xsl:text>
+  <xsl:text>#define XCB_</xsl:text><xsl:value-of select="translate($ext, $lcase, $ucase)"/><xsl:text>_MINOR_VERSION </xsl:text><xsl:value-of select="/xcb/@minor-version" />
+  <xsl:text>
+  
+</xsl:text>
+    </xsl:when>
+  </xsl:choose>
+</xsl:if>
+
+<xsl:if test="$c">
+<xsl:if test="$need-string-h">
+#include &lt;string.h&gt;</xsl:if>
+<xsl:text>
+#include &lt;assert.h&gt;
+#include "xcbext.h"
+#include "</xsl:text><xsl:value-of select="$header" /><xsl:text>.h"
+
+</xsl:text></xsl:if>
+
+    <xsl:apply-templates mode="output" />
+
+<xsl:if test="$h">
+<xsl:text>
+#endif
+
+/**
+ * @}
+ */
+</xsl:text>
+</xsl:if>
+  </xsl:template>
+
+  <xsl:template match="constant" mode="output">
+    <xsl:choose>
+      <xsl:when test="@type = 'number'">
+        <xsl:if test="$h">
+          <xsl:text>/** Opcode for </xsl:text><xsl:value-of select="@name"/><xsl:text>. */
+</xsl:text>
+          <xsl:text>#define </xsl:text>
+          <xsl:value-of select="translate(@name, $lcase, $ucase)" />
+          <xsl:text> </xsl:text>
+          <xsl:value-of select="@value" />
+          <xsl:text>
+
+</xsl:text>
+        </xsl:if>
+      </xsl:when>
+      <xsl:when test="@type = 'string'">
+        <xsl:if test="$h">
+          <xsl:text>extern </xsl:text>
+        </xsl:if>
+        <xsl:text>const char </xsl:text>
+        <xsl:value-of select="@name" />
+        <xsl:text>[]</xsl:text>
+        <xsl:if test="$c">
+          <xsl:text> = "</xsl:text>
+          <xsl:value-of select="@value" />
+          <xsl:text>"</xsl:text>
+        </xsl:if>
+        <xsl:text>;
+
+</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:if test="$h">
+          <xsl:text>extern </xsl:text>
+        </xsl:if>
+        <xsl:call-template name="type-and-name" />
+        <xsl:if test="$c">
+          <xsl:text> = </xsl:text>
+          <xsl:value-of select="@value" />
+        </xsl:if>
+        <xsl:text>;
+
+</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="typedef" mode="output">
+    <xsl:if test="$h">
+      <xsl:text>typedef </xsl:text>
+      <xsl:value-of select="xcb:get-char-void(@oldname)" />
+      <xsl:text> </xsl:text>
+      <xsl:value-of select="@newname" />
+      <xsl:text>;
+
+</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="struct" mode="output">
+    <xsl:if test="$h">
+      <xsl:variable name="type-lengths">
+        <xsl:call-template name="type-lengths">
+          <xsl:with-param name="items" select="field/@type" />
+        </xsl:call-template>
+      </xsl:variable>
+      <xsl:text>/**
+ * @brief </xsl:text><xsl:value-of select="@name" /><xsl:text>
+ **/
+</xsl:text>
+      <xsl:text>typedef </xsl:text>
+      <xsl:if test="not(@kind)">struct</xsl:if><xsl:value-of select="@kind" />
+      <xsl:text> </xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text> {
+</xsl:text>
+      <xsl:for-each select="exprfield|field|list[@fixed]|pad">
+        <xsl:text>    </xsl:text>
+        <xsl:apply-templates select=".">
+          <xsl:with-param name="type-lengths" select="$type-lengths" />
+        </xsl:apply-templates>
+        <xsl:text>; /**&lt; </xsl:text><xsl:text> */
+</xsl:text>
+      </xsl:for-each>
+      <xsl:text>} </xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text>;
+
+</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="enum" mode="output">
+    <xsl:if test="$h">
+      <xsl:text>typedef enum </xsl:text>
+      <xsl:value-of select="@name" />
+      <xsl:text> {
+    </xsl:text>
+      <xsl:call-template name="list">
+        <xsl:with-param name="separator"><xsl:text>,
+    </xsl:text></xsl:with-param>
+        <xsl:with-param name="items">
+          <xsl:for-each select="item">
+            <item>
+              <xsl:value-of select="@name" />
+              <xsl:if test="node()"> <!-- If there is an expression -->
+                <xsl:text> = </xsl:text>
+                <xsl:apply-templates mode="output-expression" />
+              </xsl:if>
+            </item>
+          </xsl:for-each>
+        </xsl:with-param>
+      </xsl:call-template>
+      <xsl:text>
+} </xsl:text><xsl:value-of select="@name" /><xsl:text>;
+
+</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="function" mode="output">
+    <xsl:variable name="decl-open" select="concat(@name, ' (')" />
+    <xsl:variable name="type-lengths">
+      <xsl:call-template name="type-lengths">
+        <xsl:with-param name="items" select="field/@type" />
+      </xsl:call-template>
+  </xsl:variable>
+  <!-- Doxygen for functions in header. -->
+    <xsl:if test="$h">
+      <xsl:apply-templates select="doc" mode="function-doc">
+      </xsl:apply-templates>
+    </xsl:if>
+/*****************************************************************************
+ **
+ ** <xsl:value-of select="@type" />
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name" />
+ ** <xsl:call-template name="list">
+     <xsl:with-param name="items">
+         <xsl:for-each select="field">
+             <item>
+                 <xsl:text>
+ ** @param </xsl:text>
+                 <xsl:apply-templates select=".">
+                     <xsl:with-param name="type-lengths" select="$type-lengths" />
+                 </xsl:apply-templates>
+             </item>
+         </xsl:for-each>
+     </xsl:with-param>
+ </xsl:call-template>
+ ** @returns <xsl:value-of select="@type" />
+ **
+ *****************************************************************************/
+ 
+<xsl:value-of select="@type" />
+    <xsl:text>
+</xsl:text>
+    <xsl:value-of select="$decl-open" />
+    <xsl:call-template name="list">
+      <xsl:with-param name="separator">
+        <xsl:text>,
+</xsl:text>
+        <xsl:call-template name="repeat">
+          <xsl:with-param name="count" select="string-length($decl-open)" />
+        </xsl:call-template>
+      </xsl:with-param>
+      <xsl:with-param name="items">
+        <xsl:for-each select="field">
+          <item>
+            <xsl:apply-templates select=".">
+              <xsl:with-param name="type-lengths" select="$type-lengths" />
+            </xsl:apply-templates>
+            <xsl:text>  /**&lt; */</xsl:text>
+          </item>
+        </xsl:for-each>
+      </xsl:with-param>
+    </xsl:call-template>
+    <xsl:text>)</xsl:text>
+
+    <xsl:if test="$h"><xsl:text>;
+
+</xsl:text></xsl:if>
+
+    <xsl:if test="$c">
+      <xsl:text>
+{
+</xsl:text>
+      <xsl:apply-templates select="l|indent" mode="function-body">
+        <xsl:with-param name="indent" select="$indent-string" />
+      </xsl:apply-templates>
+      <xsl:text>}
+
+</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="doc" mode="function-doc">
+    <xsl:value-of select="." /><xsl:text>
+</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="l" mode="function-body">
+    <xsl:param name="indent" />
+    <xsl:value-of select="concat($indent, .)" /><xsl:text>
+</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="indent" mode="function-body">
+    <xsl:param name="indent" />
+    <xsl:apply-templates select="l|indent" mode="function-body">
+      <xsl:with-param name="indent" select="concat($indent, $indent-string)" />
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="value" mode="output-expression">
+    <xsl:value-of select="." />
+  </xsl:template>
+
+  <xsl:template match="fieldref" mode="output-expression">
+    <xsl:param name="field-prefix" />
+    <xsl:value-of select="concat($field-prefix, .)" />
+  </xsl:template>
+
+  <xsl:template match="op" mode="output-expression">
+    <xsl:param name="field-prefix" />
+    <xsl:text>(</xsl:text>
+    <xsl:apply-templates select="node()[1]" mode="output-expression">
+      <xsl:with-param name="field-prefix" select="$field-prefix" />
+    </xsl:apply-templates>
+    <xsl:text> </xsl:text>
+    <xsl:value-of select="@op" />
+    <xsl:text> </xsl:text>
+    <xsl:apply-templates select="node()[2]" mode="output-expression">
+      <xsl:with-param name="field-prefix" select="$field-prefix" />
+    </xsl:apply-templates>
+    <xsl:text>)</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="bit" mode="output-expression">
+    <xsl:text>(1 &lt;&lt; </xsl:text>
+    <xsl:value-of select="." />
+    <xsl:text>)</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="function-call" mode="output-expression">
+    <xsl:param name="field-prefix" />
+    <xsl:value-of select="@name" />
+    <xsl:text>(</xsl:text>
+    <xsl:call-template name="list">
+      <xsl:with-param name="separator" select="', '" />
+      <xsl:with-param name="items">
+        <xsl:for-each select="param">
+          <item><xsl:apply-templates mode="output-expression">
+            <xsl:with-param name="field-prefix" select="$field-prefix" />
+          </xsl:apply-templates></item>
+        </xsl:for-each>
+      </xsl:with-param>
+    </xsl:call-template>
+    <xsl:text>)</xsl:text>
+  </xsl:template>
+
+  <!-- Catch invalid elements in expressions. -->
+  <xsl:template match="*" mode="output-expression">
+    <xsl:message terminate="yes">
+      <xsl:text>Invalid element in expression: </xsl:text>
+      <xsl:value-of select="name()" />
+    </xsl:message>
+  </xsl:template>
+
+  <xsl:template match="field|exprfield">
+    <xsl:param name="type-lengths" select="0" />
+    <xsl:call-template name="type-and-name">
+      <xsl:with-param name="type-lengths" select="$type-lengths" />
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="list[@fixed]">
+    <xsl:param name="type-lengths" select="0" />
+    <xsl:call-template name="type-and-name">
+      <xsl:with-param name="type-lengths" select="$type-lengths" />
+    </xsl:call-template>
+    <xsl:text>[</xsl:text>
+    <xsl:apply-templates mode="output-expression" />
+    <xsl:text>]</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="pad">
+    <xsl:param name="type-lengths" select="0" />
+
+    <xsl:variable name="padnum"><xsl:number /></xsl:variable>
+
+    <xsl:call-template name="type-and-name">
+      <xsl:with-param name="type" select="'uint8_t'" />
+      <xsl:with-param name="name">
+        <xsl:text>pad</xsl:text>
+        <xsl:value-of select="$padnum - 1" />
+      </xsl:with-param>
+      <xsl:with-param name="type-lengths" select="$type-lengths" />
+    </xsl:call-template>
+    <xsl:if test="@bytes > 1">
+      <xsl:text>[</xsl:text>
+      <xsl:value-of select="@bytes" />
+      <xsl:text>]</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <!-- Output the given type and name (defaulting to the corresponding
+       attributes of the context node), with the appropriate spacing.  The
+       type must consist of a base type (which may contain spaces), then
+       optionally a single space and a suffix of one or more '*' characters.
+       If the type-lengths parameter is provided, use it to line up the base
+       types and suffixs of the type declarations. -->
+  <xsl:template name="type-and-name">
+    <xsl:param name="type" select="@type" />
+    <xsl:param name="name" select="@name" />
+    <xsl:param name="type-lengths">
+      <max-type-length>0</max-type-length>
+      <max-suffix-length>0</max-suffix-length>
+    </xsl:param>
+    
+    <xsl:variable name="type-lengths-ns" select="e:node-set($type-lengths)" />
+    <xsl:variable name="min-type-length"
+                  select="$type-lengths-ns/max-type-length" />
+    <xsl:variable name="min-suffix-length"
+                  select="$type-lengths-ns/max-suffix-length" />
+
+    <xsl:variable name="base-type">
+      <xsl:choose>
+        <xsl:when test="contains($type, ' *')">
+          <xsl:value-of select="substring-before($type, ' *')" />
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$type" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:variable name="suffix">
+      <xsl:if test="contains($type, ' *')">
+        <xsl:text>*</xsl:text>
+        <xsl:value-of select="substring-after($type, ' *')" />
+      </xsl:if>
+    </xsl:variable>
+
+    <xsl:value-of select="$base-type" />
+    <xsl:if test="string-length($base-type) &lt; $min-type-length">
+      <xsl:call-template name="repeat">
+        <xsl:with-param name="count" select="$min-type-length
+                                             - string-length($base-type)" />
+      </xsl:call-template>
+    </xsl:if>
+    <xsl:text> </xsl:text>
+    <xsl:if test="string-length($suffix) &lt; $min-suffix-length">
+      <xsl:call-template name="repeat">
+        <xsl:with-param name="count" select="$min-suffix-length
+                                             - string-length($suffix)" />
+      </xsl:call-template>
+    </xsl:if>
+    <xsl:value-of select="$suffix" />
+    <xsl:value-of select="$name" />
+  </xsl:template>
+
+  <!-- Output a list with a given separator.  Empty items are skipped. -->
+  <xsl:template name="list">
+    <xsl:param name="separator" />
+    <xsl:param name="items" />
+
+    <xsl:for-each select="e:node-set($items)/*">
+      <xsl:value-of select="." />
+      <xsl:if test="not(position() = last())">
+        <xsl:value-of select="$separator" />
+      </xsl:if>
+    </xsl:for-each>
+  </xsl:template>
+
+  <!-- Repeat a string (space by default) a given number of times. -->
+  <xsl:template name="repeat">
+    <xsl:param name="str" select="' '" />
+    <xsl:param name="count" />
+
+    <xsl:if test="$count &gt; 0">
+      <xsl:value-of select="$str" />
+      <xsl:call-template name="repeat">
+        <xsl:with-param name="str"   select="$str" />
+        <xsl:with-param name="count" select="$count - 1" />
+      </xsl:call-template>
+    </xsl:if>
+  </xsl:template>
+
+  <!-- Record the maximum type lengths of a set of types for use as the
+       max-type-lengths parameter of type-and-name. -->
+  <xsl:template name="type-lengths">
+    <xsl:param name="items" />
+    <xsl:variable name="type-lengths-rtf">
+      <xsl:for-each select="$items">
+        <item>
+          <xsl:choose>
+            <xsl:when test="contains(., ' *')">
+              <xsl:value-of select="string-length(
+                                    substring-before(., ' *'))" />
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:value-of select="string-length(.)" />
+            </xsl:otherwise>
+          </xsl:choose>
+        </item>
+      </xsl:for-each>
+    </xsl:variable>
+    <xsl:variable name="suffix-lengths-rtf">
+      <xsl:for-each select="$items">
+        <item>
+          <xsl:choose>
+            <xsl:when test="contains(., ' *')">
+              <xsl:value-of select="string-length(substring-after(., ' *'))
+                                    + 1" />
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:text>0</xsl:text>
+            </xsl:otherwise>
+          </xsl:choose>
+        </item>
+      </xsl:for-each>
+    </xsl:variable>
+    <max-type-length>
+      <xsl:call-template name="max">
+        <xsl:with-param name="items"
+                        select="e:node-set($type-lengths-rtf)/*" />
+      </xsl:call-template>
+    </max-type-length>
+    <max-suffix-length>
+      <xsl:call-template name="max">
+        <xsl:with-param name="items"
+                        select="e:node-set($suffix-lengths-rtf)/*" />
+      </xsl:call-template>
+    </max-suffix-length>
+  </xsl:template>
+
+  <!-- Return the maximum number in a set of numbers. -->
+  <xsl:template name="max">
+    <xsl:param name="items" />
+    <xsl:choose>
+      <xsl:when test="count($items) = 0">
+        <xsl:text>0</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:variable name="head" select="number($items[1])" />
+        <xsl:variable name="tail-max">
+          <xsl:call-template name="max">
+            <xsl:with-param name="items" select="$items[position() > 1]" />
+          </xsl:call-template>
+        </xsl:variable>
+        <xsl:choose>
+          <xsl:when test="$head > number($tail-max)">
+            <xsl:value-of select="$head" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$tail-max" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+</xsl:transform>
diff --git a/libxcb/src/xcb.h b/libxcb/src/xcb.h
index f95127665..35d876883 100644
--- a/libxcb/src/xcb.h
+++ b/libxcb/src/xcb.h
@@ -285,6 +285,22 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
  */
 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
 
+/**
+ * @brief Discards the reply for a request.
+ * @param c: The connection to the X server.
+ * @param sequence: The request sequence number from a cookie.
+ *
+ * Discards the reply for a request. Additionally, any error generated
+ * by the request is also discarded (unless it was an _unchecked request
+ * and the error has already arrived).
+ *
+ * This function will not block even if the reply is not yet available.
+ *
+ * Note that the sequence really does have to come from an xcb cookie;
+ * this function is not designed to operate on socket-handoff replies.
+ */
+void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence);
+
 
 /* xcb_ext.c */
 
diff --git a/libxcb/src/xcb_auth.c b/libxcb/src/xcb_auth.c
index 104f2f07b..00aad23c5 100644
--- a/libxcb/src/xcb_auth.c
+++ b/libxcb/src/xcb_auth.c
@@ -260,10 +260,10 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
      * case anyway.*/
     if (getpeername(fd, sockname, &socknamelen) == -1)
     {
-        if (sockname->sa_family != AF_UNIX)
-            return 0;   /* except for AF_UNIX, sockets should have peernames */
         if (getsockname(fd, sockname, &socknamelen) == -1)
             return 0;   /* can only authenticate sockets */
+        if (sockname->sa_family != AF_UNIX)
+            return 0;   /* except for AF_UNIX, sockets should have peernames */
         gotsockname = 1;
     }
 
diff --git a/libxcb/src/xcb_conn.c b/libxcb/src/xcb_conn.c
index 251d62e01..ed2153d27 100644
--- a/libxcb/src/xcb_conn.c
+++ b/libxcb/src/xcb_conn.c
@@ -211,8 +211,10 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
     xcb_connection_t* c;
 
     c = calloc(1, sizeof(xcb_connection_t));
-    if(!c)
+    if(!c) {
+        close(fd);
         return (xcb_connection_t *) &error_connection;
+    }
 
     c->fd = fd;
 
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c
index 26ab3581f..80f55232e 100644
--- a/libxcb/src/xcb_in.c
+++ b/libxcb/src/xcb_in.c
@@ -409,6 +409,116 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
     return ret;
 }
 
+static void insert_pending_discard(xcb_connection_t *c, pending_reply **prev_next, uint64_t seq)
+{
+    pending_reply *pend;
+    pend = malloc(sizeof(*pend));
+    if(!pend)
+    {
+        _xcb_conn_shutdown(c);
+        return;
+    }
+
+    pend->first_request = seq;
+    pend->last_request = seq;
+    pend->workaround = 0;
+    pend->flags = XCB_REQUEST_DISCARD_REPLY;
+    pend->next = *prev_next;
+    *prev_next = pend;
+
+    if(!pend->next)
+        c->in.pending_replies_tail = &pend->next;
+}
+
+static void discard_reply(xcb_connection_t *c, unsigned int request)
+{
+    pending_reply *pend = 0;
+    pending_reply **prev_pend;
+    uint64_t widened_request;
+
+    /* We've read requests past the one we want, so if it has replies we have
+     * them all and they're in the replies map. */
+    if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read))
+    {
+        struct reply_list *head;
+        head = _xcb_map_remove(c->in.replies, request);
+        while (head)
+        {
+            struct reply_list *next = head->next;
+            free(head->reply);
+            free(head);
+            head = next;
+        }
+        return;
+    }
+
+    /* We're currently processing the responses to the request we want, and we
+     * have a reply ready to return. Free it, and mark the pend to free any further
+     * replies. */
+    if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply)
+    {
+        struct reply_list *head;
+        head = c->in.current_reply;
+        c->in.current_reply = NULL;
+        c->in.current_reply_tail = &c->in.current_reply;
+        while (head)
+        {
+            struct reply_list *next = head->next;
+            free(head->reply);
+            free(head);
+            head = next;
+        }
+
+        pend = c->in.pending_replies;
+        if(pend &&
+            !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) &&
+             (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER ||
+              XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request))))
+            pend = 0;
+        if(pend)
+            pend->flags |= XCB_REQUEST_DISCARD_REPLY;
+        else
+            insert_pending_discard(c, &c->in.pending_replies, c->in.request_read);
+
+        return;
+    }
+
+    /* Walk the list of pending requests. Mark the first match for deletion. */
+    for(prev_pend = &c->in.pending_replies; *prev_pend; prev_pend = &(*prev_pend)->next)
+    {
+        if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, >, request))
+            break;
+
+        if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, ==, request))
+        {
+            /* Pending reply found. Mark for discard: */
+            (*prev_pend)->flags |= XCB_REQUEST_DISCARD_REPLY;
+            return;
+        }
+    }
+
+    /* Pending reply not found (likely due to _unchecked request). Create one: */
+    widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request;
+    if(widened_request > c->out.request)
+        widened_request -= UINT64_C(1) << 32;
+
+    insert_pending_discard(c, prev_pend, widened_request);
+}
+
+void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence)
+{
+    if(c->has_error)
+        return;
+
+    /* If an error occurred when issuing the request, fail immediately. */
+    if(!sequence)
+        return;
+
+    pthread_mutex_lock(&c->iolock);
+    discard_reply(c, sequence);
+    pthread_mutex_unlock(&c->iolock);
+}
+
 int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
 {
     int ret;
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index c3cbfa6c1..996ff2518 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <string.h>
 
 #include "xcb.h"
@@ -177,6 +178,22 @@ static int _xcb_open(char *host, char *protocol, const int display)
     return  _xcb_open_unix(protocol, file);
 }
 
+static int _xcb_socket(int family, int type, int proto)
+{
+    int fd;
+
+#ifdef SOCK_CLOEXEC
+    fd = socket(family, type | SOCK_CLOEXEC, proto);
+    if (fd == -1 && errno == EINVAL)
+#endif
+    {
+	fd = socket(family, type, proto);
+	if (fd >= 0)
+	    fcntl(fd, F_SETFD, FD_CLOEXEC);
+    }
+    return fd;
+}
+
 #ifdef DNETCONN
 static int _xcb_open_decnet(const char *host, const char *protocol, const unsigned short port)
 {
@@ -199,7 +216,7 @@ static int _xcb_open_decnet(const char *host, const char *protocol, const unsign
         return -1;
     addr.sdn_objnum = 0;
 
-    fd = socket(PF_DECnet, SOCK_STREAM, 0);
+    fd = _xcb_socket(PF_DECnet, SOCK_STREAM, 0);
     if(fd == -1)
         return -1;
 
@@ -256,7 +273,7 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
 
     for(addr = results; addr; addr = addr->ai_next)
     {
-        fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
+        fd = _xcb_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
         if(fd >= 0) {
             int on = 1;
             setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
@@ -285,7 +302,7 @@ static int _xcb_open_unix(char *protocol, const char *file)
 #ifdef HAVE_SOCKADDR_SUN_LEN
     addr.sun_len = SUN_LEN(&addr);
 #endif
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
     if(fd == -1)
         return -1;
     if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
@@ -311,7 +328,7 @@ static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
 #ifdef HAVE_SOCKADDR_SUN_LEN
     addr.sun_len = 1 + filelen;
 #endif
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
+    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
     if (fd == -1)
         return -1;
     if (connect(fd, (struct sockaddr *) &addr, namelen) == -1) {
-- 
cgit v1.2.3


From 6412df1b3df28c6213b43821c4a98cc3857d9a3f Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Thu, 15 Apr 2010 07:50:39 +0000
Subject: Git update 15/4/2010

---
 libxcb/src/xcb_conn.c | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'libxcb/src')

diff --git a/libxcb/src/xcb_conn.c b/libxcb/src/xcb_conn.c
index ed2153d27..1d3761452 100644
--- a/libxcb/src/xcb_conn.c
+++ b/libxcb/src/xcb_conn.c
@@ -210,6 +210,14 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
 {
     xcb_connection_t* c;
 
+#ifndef USE_POLL
+    if(fd >= FD_SETSIZE) /* would overflow in FD_SET */
+    {
+        close(fd);
+        return (xcb_connection_t *) &error_connection;
+    }
+#endif
+
     c = calloc(1, sizeof(xcb_connection_t));
     if(!c) {
         close(fd);
-- 
cgit v1.2.3


From a46e26df6103fb0e6e00d8d11d58c3f7a358208c Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Mon, 19 Apr 2010 12:25:24 +0000
Subject: libxcb update 19/4/2010

---
 libxcb/src/xcb_conn.c |  5 +----
 libxcb/src/xcb_in.c   | 28 +++++++++++++---------------
 libxcb/src/xcb_out.c  | 16 ++++++++--------
 libxcb/src/xcbint.h   |  4 +++-
 4 files changed, 25 insertions(+), 28 deletions(-)

(limited to 'libxcb/src')

diff --git a/libxcb/src/xcb_conn.c b/libxcb/src/xcb_conn.c
index 1d3761452..50a662bb2 100644
--- a/libxcb/src/xcb_conn.c
+++ b/libxcb/src/xcb_conn.c
@@ -102,10 +102,7 @@ static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
     assert(count <= (int) (sizeof(parts) / sizeof(*parts)));
 
     pthread_mutex_lock(&c->iolock);
-    {
-        struct iovec *parts_ptr = parts;
-        ret = _xcb_out_send(c, &parts_ptr, &count);
-    }
+    ret = _xcb_out_send(c, parts, count);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c
index 80f55232e..6dd358cbd 100644
--- a/libxcb/src/xcb_in.c
+++ b/libxcb/src/xcb_in.c
@@ -69,16 +69,6 @@ typedef struct reader_list {
     struct reader_list *next;
 } reader_list;
 
-static void wake_up_next_reader(xcb_connection_t *c)
-{
-    int pthreadret;
-    if(c->in.readers)
-        pthreadret = pthread_cond_signal(c->in.readers->data);
-    else
-        pthreadret = pthread_cond_signal(&c->in.event_cond);
-    assert(pthreadret == 0);
-}
-
 static int read_packet(xcb_connection_t *c)
 {
     xcb_generic_reply_t genrep;
@@ -154,9 +144,7 @@ static int read_packet(xcb_connection_t *c)
 
     /* XGE events may have sizes > 32 */
     if (genrep.response_type == XCB_XGE_EVENT)
-    {
-        eventlength = ((xcb_ge_event_t*)&genrep)->length * 4;
-    }
+        eventlength = genrep.length * 4;
 
     buf = malloc(length + eventlength +
             (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)));
@@ -404,7 +392,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
         pthread_cond_destroy(&cond);
     }
 
-    wake_up_next_reader(c);
+    _xcb_in_wake_up_next_reader(c);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
@@ -547,7 +535,7 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
         if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
             break;
 
-    wake_up_next_reader(c);
+    _xcb_in_wake_up_next_reader(c);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
@@ -631,6 +619,16 @@ void _xcb_in_destroy(_xcb_in *in)
     }
 }
 
+void _xcb_in_wake_up_next_reader(xcb_connection_t *c)
+{
+    int pthreadret;
+    if(c->in.readers)
+        pthreadret = pthread_cond_signal(c->in.readers->data);
+    else
+        pthreadret = pthread_cond_signal(&c->in.event_cond);
+    assert(pthreadret == 0);
+}
+
 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags)
 {
     pending_reply *pend = malloc(sizeof(pending_reply));
diff --git a/libxcb/src/xcb_out.c b/libxcb/src/xcb_out.c
index b3050fe3d..fbce7a0ea 100644
--- a/libxcb/src/xcb_out.c
+++ b/libxcb/src/xcb_out.c
@@ -52,7 +52,7 @@ static int write_block(xcb_connection_t *c, struct iovec *vector, int count)
     vector[0].iov_base = c->out.queue;
     vector[0].iov_len = c->out.queue_len;
     c->out.queue_len = 0;
-    return _xcb_out_send(c, &vector, &count);
+    return _xcb_out_send(c, vector, count);
 }
 
 static void get_socket_back(xcb_connection_t *c)
@@ -283,7 +283,7 @@ int xcb_writev(xcb_connection_t *c, struct iovec *vector, int count, uint64_t re
         return 0;
     pthread_mutex_lock(&c->iolock);
     c->out.request += requests;
-    ret = _xcb_out_send(c, &vector, &count);
+    ret = _xcb_out_send(c, vector, count);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
@@ -331,13 +331,14 @@ void _xcb_out_destroy(_xcb_out *out)
     pthread_mutex_destroy(&out->reqlenlock);
 }
 
-int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count)
+int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count)
 {
     int ret = 1;
-    while(ret && *count)
-        ret = _xcb_conn_wait(c, &c->out.cond, vector, count);
+    while(ret && count)
+        ret = _xcb_conn_wait(c, &c->out.cond, &vector, &count);
     c->out.request_written = c->out.request;
     pthread_cond_broadcast(&c->out.cond);
+    _xcb_in_wake_up_next_reader(c);
     return ret;
 }
 
@@ -348,12 +349,11 @@ int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request)
         return 1;
     if(c->out.queue_len)
     {
-        struct iovec vec, *vec_ptr = &vec;
-        int count = 1;
+        struct iovec vec;
         vec.iov_base = c->out.queue;
         vec.iov_len = c->out.queue_len;
         c->out.queue_len = 0;
-        return _xcb_out_send(c, &vec_ptr, &count);
+        return _xcb_out_send(c, &vec, 1);
     }
     while(c->out.writing)
         pthread_cond_wait(&c->out.cond, &c->iolock);
diff --git a/libxcb/src/xcbint.h b/libxcb/src/xcbint.h
index 154cca04a..f07add8b9 100644
--- a/libxcb/src/xcbint.h
+++ b/libxcb/src/xcbint.h
@@ -106,7 +106,7 @@ typedef struct _xcb_out {
 int _xcb_out_init(_xcb_out *out);
 void _xcb_out_destroy(_xcb_out *out);
 
-int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count);
+int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count);
 int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request);
 
 
@@ -137,6 +137,8 @@ typedef struct _xcb_in {
 int _xcb_in_init(_xcb_in *in);
 void _xcb_in_destroy(_xcb_in *in);
 
+void _xcb_in_wake_up_next_reader(xcb_connection_t *c);
+
 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags);
 void _xcb_in_replies_done(xcb_connection_t *c);
 
-- 
cgit v1.2.3


From e026745845d87ab4cd8b2a96b665d24b025644e1 Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Mon, 26 Apr 2010 09:39:43 +0000
Subject: libxcb git update 26/4/2010

---
 libxcb/src/xcb_util.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

(limited to 'libxcb/src')

diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 996ff2518..287f12fd9 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <limits.h>
 #include <sys/un.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -67,7 +68,14 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
         name = getenv("DISPLAY");
     if(!name)
         return 0;
+
+#ifdef HAVE_LAUNCHD
+    if(strncmp(name, "/tmp/launch", 11) == 0)
+        slash = NULL;
+    else
+#endif
     slash = strrchr(name, '/');
+
     if (slash) {
         len = slash - name;
         if (protocol) {
@@ -135,12 +143,19 @@ static int _xcb_open(char *host, char *protocol, const int display)
 #ifdef HAVE_ABSTRACT_SOCKETS
     int fd;
 #endif
-    static const char base[] = "/tmp/.X11-unix/X";
-    char file[sizeof(base) + 20];
+    static const char unix_base[] = "/tmp/.X11-unix/X";
+    const char *base = unix_base;
+    char file[PATH_MAX + 1];
     int filelen;
 
     if(*host)
     {
+#ifdef HAVE_LAUNCHD
+        if(strncmp(host, "/tmp/launch", 11) == 0) {
+	    base = host;
+        } else {
+#endif
+
 #ifdef DNETCONN
         /* DECnet displays have two colons, so _xcb_parse_display will have
            left one at the end.  However, an IPv6 address can end with *two*
@@ -161,10 +176,18 @@ static int _xcb_open(char *host, char *protocol, const int display)
                 unsigned short port = X_TCP_PORT + display;
                 return _xcb_open_tcp(host, protocol, port);
             }
+#ifdef HAVE_LAUNCHD
+        }
+#endif
     }
 
     /* display specifies Unix socket */
-    filelen = snprintf(file, sizeof(file), "%s%d", base, display);
+#ifdef HAVE_LAUNCHD
+    if(base == host)
+        filelen = snprintf(file, sizeof(file), "%s:%d", base, display);
+    else
+#endif
+        filelen = snprintf(file, sizeof(file), "%s%d", base, display);
     if(filelen < 0)
         return -1;
     /* snprintf may truncate the file */
@@ -354,13 +377,6 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
 
     int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
     
-#ifdef HAVE_LAUNCHD
-    if(!displayname)
-        displayname = getenv("DISPLAY");
-    if(displayname && strlen(displayname)>11 && !strncmp(displayname, "/tmp/launch", 11))
-        fd = _xcb_open_unix(NULL, displayname);
-    else
-#endif
     if(!parsed)
         return (xcb_connection_t *) &error_connection;
     else
-- 
cgit v1.2.3


From bc18786a3d7b058bd2579ba1381e278a17fed40c Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Wed, 28 Apr 2010 14:37:15 +0000
Subject: Removed files not in the git repository

---
 libxcb/src/Makefile.in | 1037 ------------------------------------------------
 libxcb/src/config.h.in |   83 ----
 2 files changed, 1120 deletions(-)
 delete mode 100644 libxcb/src/Makefile.in
 delete mode 100644 libxcb/src/config.h.in

(limited to 'libxcb/src')

diff --git a/libxcb/src/Makefile.in b/libxcb/src/Makefile.in
deleted file mode 100644
index 256ebc2bc..000000000
--- a/libxcb/src/Makefile.in
+++ /dev/null
@@ -1,1037 +0,0 @@
-# Makefile.in generated by automake 1.11 from Makefile.am.
-# @configure_input@
-
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-@SET_MAKE@
-
-
-VPATH = @srcdir@
-pkgdatadir = $(datadir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkglibexecdir = $(libexecdir)/@PACKAGE@
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-install_sh_DATA = $(install_sh) -c -m 644
-install_sh_PROGRAM = $(install_sh) -c
-install_sh_SCRIPT = $(install_sh) -c
-INSTALL_HEADER = $(INSTALL_DATA)
-transform = $(program_transform_name)
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-build_triplet = @build@
-host_triplet = @host@
-@BUILD_COMPOSITE_TRUE@am__append_1 = libxcb-composite.la
-@BUILD_DAMAGE_TRUE@am__append_2 = libxcb-damage.la
-@BUILD_DPMS_TRUE@am__append_3 = libxcb-dpms.la
-@BUILD_DRI2_TRUE@am__append_4 = libxcb-dri2.la
-@BUILD_GLX_TRUE@am__append_5 = libxcb-glx.la
-@BUILD_RANDR_TRUE@am__append_6 = libxcb-randr.la
-@BUILD_RECORD_TRUE@am__append_7 = libxcb-record.la
-@BUILD_RENDER_TRUE@am__append_8 = libxcb-render.la
-@BUILD_RESOURCE_TRUE@am__append_9 = libxcb-res.la
-@BUILD_SCREENSAVER_TRUE@am__append_10 = libxcb-screensaver.la
-@BUILD_SHAPE_TRUE@am__append_11 = libxcb-shape.la
-@BUILD_SHM_TRUE@am__append_12 = libxcb-shm.la
-@BUILD_SYNC_TRUE@am__append_13 = libxcb-sync.la
-@BUILD_XEVIE_TRUE@am__append_14 = libxcb-xevie.la
-@BUILD_XFREE86_DRI_TRUE@am__append_15 = libxcb-xf86dri.la
-@BUILD_XFIXES_TRUE@am__append_16 = libxcb-xfixes.la
-@BUILD_XINERAMA_TRUE@am__append_17 = libxcb-xinerama.la
-@BUILD_XINPUT_TRUE@am__append_18 = libxcb-xinput.la
-@BUILD_XPRINT_TRUE@am__append_19 = libxcb-xprint.la
-@BUILD_SELINUX_TRUE@am__append_20 = libxcb-xselinux.la
-@BUILD_XTEST_TRUE@am__append_21 = libxcb-xtest.la
-@BUILD_XV_TRUE@am__append_22 = libxcb-xv.la
-@BUILD_XVMC_TRUE@am__append_23 = libxcb-xvmc.la
-subdir = src
-DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
-	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
-	$(xcbinclude_HEADERS)
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
-	$(top_srcdir)/configure.ac
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
-	$(ACLOCAL_M4)
-mkinstalldirs = $(install_sh) -d
-CONFIG_HEADER = config.h
-CONFIG_CLEAN_FILES =
-CONFIG_CLEAN_VPATH_FILES =
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
-am__vpath_adj = case $$p in \
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
-    *) f=$$p;; \
-  esac;
-am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
-am__install_max = 40
-am__nobase_strip_setup = \
-  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
-am__nobase_strip = \
-  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
-am__nobase_list = $(am__nobase_strip_setup); \
-  for p in $$list; do echo "$$p $$p"; done | \
-  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
-  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
-    if (++n[$$2] == $(am__install_max)) \
-      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
-    END { for (dir in files) print dir, files[dir] }'
-am__base_list = \
-  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
-  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
-am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(xcbincludedir)" \
-	"$(DESTDIR)$(xcbincludedir)"
-LTLIBRARIES = $(lib_LTLIBRARIES)
-@BUILD_COMPOSITE_TRUE@libxcb_composite_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_COMPOSITE_TRUE@nodist_libxcb_composite_la_OBJECTS =  \
-@BUILD_COMPOSITE_TRUE@	composite.lo
-libxcb_composite_la_OBJECTS = $(nodist_libxcb_composite_la_OBJECTS)
-libxcb_composite_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_composite_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_COMPOSITE_TRUE@am_libxcb_composite_la_rpath = -rpath $(libdir)
-@BUILD_DAMAGE_TRUE@libxcb_damage_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_DAMAGE_TRUE@nodist_libxcb_damage_la_OBJECTS = damage.lo
-libxcb_damage_la_OBJECTS = $(nodist_libxcb_damage_la_OBJECTS)
-libxcb_damage_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_damage_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_DAMAGE_TRUE@am_libxcb_damage_la_rpath = -rpath $(libdir)
-@BUILD_DPMS_TRUE@libxcb_dpms_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_DPMS_TRUE@nodist_libxcb_dpms_la_OBJECTS = dpms.lo
-libxcb_dpms_la_OBJECTS = $(nodist_libxcb_dpms_la_OBJECTS)
-libxcb_dpms_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_dpms_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_DPMS_TRUE@am_libxcb_dpms_la_rpath = -rpath $(libdir)
-@BUILD_DRI2_TRUE@libxcb_dri2_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_DRI2_TRUE@nodist_libxcb_dri2_la_OBJECTS = dri2.lo
-libxcb_dri2_la_OBJECTS = $(nodist_libxcb_dri2_la_OBJECTS)
-libxcb_dri2_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_dri2_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_DRI2_TRUE@am_libxcb_dri2_la_rpath = -rpath $(libdir)
-@BUILD_GLX_TRUE@libxcb_glx_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_GLX_TRUE@nodist_libxcb_glx_la_OBJECTS = glx.lo
-libxcb_glx_la_OBJECTS = $(nodist_libxcb_glx_la_OBJECTS)
-libxcb_glx_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_glx_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_GLX_TRUE@am_libxcb_glx_la_rpath = -rpath $(libdir)
-@BUILD_RANDR_TRUE@libxcb_randr_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_RANDR_TRUE@nodist_libxcb_randr_la_OBJECTS = randr.lo
-libxcb_randr_la_OBJECTS = $(nodist_libxcb_randr_la_OBJECTS)
-libxcb_randr_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_randr_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_RANDR_TRUE@am_libxcb_randr_la_rpath = -rpath $(libdir)
-@BUILD_RECORD_TRUE@libxcb_record_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_RECORD_TRUE@nodist_libxcb_record_la_OBJECTS = record.lo
-libxcb_record_la_OBJECTS = $(nodist_libxcb_record_la_OBJECTS)
-libxcb_record_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_record_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_RECORD_TRUE@am_libxcb_record_la_rpath = -rpath $(libdir)
-@BUILD_RENDER_TRUE@libxcb_render_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_RENDER_TRUE@nodist_libxcb_render_la_OBJECTS = render.lo
-libxcb_render_la_OBJECTS = $(nodist_libxcb_render_la_OBJECTS)
-libxcb_render_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_render_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_RENDER_TRUE@am_libxcb_render_la_rpath = -rpath $(libdir)
-@BUILD_RESOURCE_TRUE@libxcb_res_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_RESOURCE_TRUE@nodist_libxcb_res_la_OBJECTS = res.lo
-libxcb_res_la_OBJECTS = $(nodist_libxcb_res_la_OBJECTS)
-libxcb_res_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_res_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_RESOURCE_TRUE@am_libxcb_res_la_rpath = -rpath $(libdir)
-@BUILD_SCREENSAVER_TRUE@libxcb_screensaver_la_DEPENDENCIES =  \
-@BUILD_SCREENSAVER_TRUE@	$(XCB_LIBS)
-@BUILD_SCREENSAVER_TRUE@nodist_libxcb_screensaver_la_OBJECTS =  \
-@BUILD_SCREENSAVER_TRUE@	screensaver.lo
-libxcb_screensaver_la_OBJECTS =  \
-	$(nodist_libxcb_screensaver_la_OBJECTS)
-libxcb_screensaver_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_screensaver_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_SCREENSAVER_TRUE@am_libxcb_screensaver_la_rpath = -rpath \
-@BUILD_SCREENSAVER_TRUE@	$(libdir)
-@BUILD_SHAPE_TRUE@libxcb_shape_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_SHAPE_TRUE@nodist_libxcb_shape_la_OBJECTS = shape.lo
-libxcb_shape_la_OBJECTS = $(nodist_libxcb_shape_la_OBJECTS)
-libxcb_shape_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_shape_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_SHAPE_TRUE@am_libxcb_shape_la_rpath = -rpath $(libdir)
-@BUILD_SHM_TRUE@libxcb_shm_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_SHM_TRUE@nodist_libxcb_shm_la_OBJECTS = shm.lo
-libxcb_shm_la_OBJECTS = $(nodist_libxcb_shm_la_OBJECTS)
-libxcb_shm_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_shm_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_SHM_TRUE@am_libxcb_shm_la_rpath = -rpath $(libdir)
-@BUILD_SYNC_TRUE@libxcb_sync_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_SYNC_TRUE@nodist_libxcb_sync_la_OBJECTS = sync.lo
-libxcb_sync_la_OBJECTS = $(nodist_libxcb_sync_la_OBJECTS)
-libxcb_sync_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_sync_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_SYNC_TRUE@am_libxcb_sync_la_rpath = -rpath $(libdir)
-@BUILD_XEVIE_TRUE@libxcb_xevie_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XEVIE_TRUE@nodist_libxcb_xevie_la_OBJECTS = xevie.lo
-libxcb_xevie_la_OBJECTS = $(nodist_libxcb_xevie_la_OBJECTS)
-libxcb_xevie_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xevie_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XEVIE_TRUE@am_libxcb_xevie_la_rpath = -rpath $(libdir)
-@BUILD_XFREE86_DRI_TRUE@libxcb_xf86dri_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XFREE86_DRI_TRUE@nodist_libxcb_xf86dri_la_OBJECTS = xf86dri.lo
-libxcb_xf86dri_la_OBJECTS = $(nodist_libxcb_xf86dri_la_OBJECTS)
-libxcb_xf86dri_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xf86dri_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XFREE86_DRI_TRUE@am_libxcb_xf86dri_la_rpath = -rpath $(libdir)
-@BUILD_XFIXES_TRUE@libxcb_xfixes_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XFIXES_TRUE@nodist_libxcb_xfixes_la_OBJECTS = xfixes.lo
-libxcb_xfixes_la_OBJECTS = $(nodist_libxcb_xfixes_la_OBJECTS)
-libxcb_xfixes_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xfixes_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XFIXES_TRUE@am_libxcb_xfixes_la_rpath = -rpath $(libdir)
-@BUILD_XINERAMA_TRUE@libxcb_xinerama_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XINERAMA_TRUE@nodist_libxcb_xinerama_la_OBJECTS = xinerama.lo
-libxcb_xinerama_la_OBJECTS = $(nodist_libxcb_xinerama_la_OBJECTS)
-libxcb_xinerama_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xinerama_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XINERAMA_TRUE@am_libxcb_xinerama_la_rpath = -rpath $(libdir)
-@BUILD_XINPUT_TRUE@libxcb_xinput_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XINPUT_TRUE@nodist_libxcb_xinput_la_OBJECTS = xinput.lo
-libxcb_xinput_la_OBJECTS = $(nodist_libxcb_xinput_la_OBJECTS)
-libxcb_xinput_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xinput_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XINPUT_TRUE@am_libxcb_xinput_la_rpath = -rpath $(libdir)
-@BUILD_XPRINT_TRUE@libxcb_xprint_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XPRINT_TRUE@nodist_libxcb_xprint_la_OBJECTS = xprint.lo
-libxcb_xprint_la_OBJECTS = $(nodist_libxcb_xprint_la_OBJECTS)
-libxcb_xprint_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xprint_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XPRINT_TRUE@am_libxcb_xprint_la_rpath = -rpath $(libdir)
-@BUILD_SELINUX_TRUE@libxcb_xselinux_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_SELINUX_TRUE@nodist_libxcb_xselinux_la_OBJECTS = xselinux.lo
-libxcb_xselinux_la_OBJECTS = $(nodist_libxcb_xselinux_la_OBJECTS)
-libxcb_xselinux_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xselinux_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_SELINUX_TRUE@am_libxcb_xselinux_la_rpath = -rpath $(libdir)
-@BUILD_XTEST_TRUE@libxcb_xtest_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XTEST_TRUE@nodist_libxcb_xtest_la_OBJECTS = xtest.lo
-libxcb_xtest_la_OBJECTS = $(nodist_libxcb_xtest_la_OBJECTS)
-libxcb_xtest_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xtest_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XTEST_TRUE@am_libxcb_xtest_la_rpath = -rpath $(libdir)
-@BUILD_XV_TRUE@libxcb_xv_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XV_TRUE@nodist_libxcb_xv_la_OBJECTS = xv.lo
-libxcb_xv_la_OBJECTS = $(nodist_libxcb_xv_la_OBJECTS)
-libxcb_xv_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xv_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XV_TRUE@am_libxcb_xv_la_rpath = -rpath $(libdir)
-@BUILD_XVMC_TRUE@libxcb_xvmc_la_DEPENDENCIES = $(XCB_LIBS)
-@BUILD_XVMC_TRUE@nodist_libxcb_xvmc_la_OBJECTS = xvmc.lo
-libxcb_xvmc_la_OBJECTS = $(nodist_libxcb_xvmc_la_OBJECTS)
-libxcb_xvmc_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_xvmc_la_LDFLAGS) $(LDFLAGS) -o $@
-@BUILD_XVMC_TRUE@am_libxcb_xvmc_la_rpath = -rpath $(libdir)
-am__DEPENDENCIES_1 =
-libxcb_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
-am_libxcb_la_OBJECTS = xcb_conn.lo xcb_out.lo xcb_in.lo xcb_ext.lo \
-	xcb_xid.lo xcb_list.lo xcb_util.lo xcb_auth.lo
-nodist_libxcb_la_OBJECTS = xproto.lo bigreq.lo xc_misc.lo
-libxcb_la_OBJECTS = $(am_libxcb_la_OBJECTS) \
-	$(nodist_libxcb_la_OBJECTS)
-libxcb_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libxcb_la_LDFLAGS) $(LDFLAGS) -o $@
-DEFAULT_INCLUDES = -I.@am__isrc@
-depcomp = $(SHELL) $(top_srcdir)/depcomp
-am__depfiles_maybe = depfiles
-am__mv = mv -f
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
-	$(LDFLAGS) -o $@
-SOURCES = $(nodist_libxcb_composite_la_SOURCES) \
-	$(nodist_libxcb_damage_la_SOURCES) \
-	$(nodist_libxcb_dpms_la_SOURCES) \
-	$(nodist_libxcb_dri2_la_SOURCES) \
-	$(nodist_libxcb_glx_la_SOURCES) \
-	$(nodist_libxcb_randr_la_SOURCES) \
-	$(nodist_libxcb_record_la_SOURCES) \
-	$(nodist_libxcb_render_la_SOURCES) \
-	$(nodist_libxcb_res_la_SOURCES) \
-	$(nodist_libxcb_screensaver_la_SOURCES) \
-	$(nodist_libxcb_shape_la_SOURCES) \
-	$(nodist_libxcb_shm_la_SOURCES) \
-	$(nodist_libxcb_sync_la_SOURCES) \
-	$(nodist_libxcb_xevie_la_SOURCES) \
-	$(nodist_libxcb_xf86dri_la_SOURCES) \
-	$(nodist_libxcb_xfixes_la_SOURCES) \
-	$(nodist_libxcb_xinerama_la_SOURCES) \
-	$(nodist_libxcb_xinput_la_SOURCES) \
-	$(nodist_libxcb_xprint_la_SOURCES) \
-	$(nodist_libxcb_xselinux_la_SOURCES) \
-	$(nodist_libxcb_xtest_la_SOURCES) \
-	$(nodist_libxcb_xv_la_SOURCES) \
-	$(nodist_libxcb_xvmc_la_SOURCES) $(libxcb_la_SOURCES) \
-	$(nodist_libxcb_la_SOURCES)
-DIST_SOURCES = $(libxcb_la_SOURCES)
-HEADERS = $(nodist_xcbinclude_HEADERS) $(noinst_HEADERS) \
-	$(xcbinclude_HEADERS)
-ETAGS = etags
-CTAGS = ctags
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = @ACLOCAL@
-AMTAR = @AMTAR@
-AR = @AR@
-AUTOCONF = @AUTOCONF@
-AUTOHEADER = @AUTOHEADER@
-AUTOMAKE = @AUTOMAKE@
-AWK = @AWK@
-BUILD_DOCS = @BUILD_DOCS@
-CC = @CC@
-CCDEPMODE = @CCDEPMODE@
-CFLAGS = @CFLAGS@
-CHECK_CFLAGS = @CHECK_CFLAGS@
-CHECK_LIBS = @CHECK_LIBS@
-CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@
-CWARNFLAGS = @CWARNFLAGS@
-CYGPATH_W = @CYGPATH_W@
-DEFS = @DEFS@
-DEPDIR = @DEPDIR@
-DOT = @DOT@
-DOXYGEN = @DOXYGEN@
-DSYMUTIL = @DSYMUTIL@
-DUMPBIN = @DUMPBIN@
-ECHO_C = @ECHO_C@
-ECHO_N = @ECHO_N@
-ECHO_T = @ECHO_T@
-EGREP = @EGREP@
-EXEEXT = @EXEEXT@
-FGREP = @FGREP@
-GREP = @GREP@
-HTML_CHECK_RESULT = @HTML_CHECK_RESULT@
-INSTALL = @INSTALL@
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LAUNCHD = @LAUNCHD@
-LD = @LD@
-LDFLAGS = @LDFLAGS@
-LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
-LIBTOOL = @LIBTOOL@
-LIPO = @LIPO@
-LN_S = @LN_S@
-LTLIBOBJS = @LTLIBOBJS@
-MAKEINFO = @MAKEINFO@
-MKDIR_P = @MKDIR_P@
-NEEDED = @NEEDED@
-NEEDED_CFLAGS = @NEEDED_CFLAGS@
-NEEDED_LIBS = @NEEDED_LIBS@
-NM = @NM@
-NMEDIT = @NMEDIT@
-OBJDUMP = @OBJDUMP@
-OBJEXT = @OBJEXT@
-OTOOL = @OTOOL@
-OTOOL64 = @OTOOL64@
-PACKAGE = @PACKAGE@
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
-PACKAGE_NAME = @PACKAGE_NAME@
-PACKAGE_STRING = @PACKAGE_STRING@
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
-PACKAGE_URL = @PACKAGE_URL@
-PACKAGE_VERSION = @PACKAGE_VERSION@
-PATH_SEPARATOR = @PATH_SEPARATOR@
-PKG_CONFIG = @PKG_CONFIG@
-PYTHON = @PYTHON@
-PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
-PYTHON_PLATFORM = @PYTHON_PLATFORM@
-PYTHON_PREFIX = @PYTHON_PREFIX@
-PYTHON_VERSION = @PYTHON_VERSION@
-RANLIB = @RANLIB@
-SED = @SED@
-SET_MAKE = @SET_MAKE@
-SHELL = @SHELL@
-STRIP = @STRIP@
-VERSION = @VERSION@
-XCBPROTO_CFLAGS = @XCBPROTO_CFLAGS@
-XCBPROTO_LIBS = @XCBPROTO_LIBS@
-XCBPROTO_VERSION = @XCBPROTO_VERSION@
-XCBPROTO_XCBINCLUDEDIR = @XCBPROTO_XCBINCLUDEDIR@
-XCBPROTO_XCBPYTHONDIR = @XCBPROTO_XCBPYTHONDIR@
-XDMCP_CFLAGS = @XDMCP_CFLAGS@
-XDMCP_LIBS = @XDMCP_LIBS@
-XSLTPROC = @XSLTPROC@
-abs_builddir = @abs_builddir@
-abs_srcdir = @abs_srcdir@
-abs_top_builddir = @abs_top_builddir@
-abs_top_srcdir = @abs_top_srcdir@
-ac_ct_CC = @ac_ct_CC@
-ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
-am__include = @am__include@
-am__leading_dot = @am__leading_dot@
-am__quote = @am__quote@
-am__tar = @am__tar@
-am__untar = @am__untar@
-bindir = @bindir@
-build = @build@
-build_alias = @build_alias@
-build_cpu = @build_cpu@
-build_os = @build_os@
-build_vendor = @build_vendor@
-builddir = @builddir@
-datadir = @datadir@
-datarootdir = @datarootdir@
-docdir = @docdir@
-dvidir = @dvidir@
-exec_prefix = @exec_prefix@
-host = @host@
-host_alias = @host_alias@
-host_cpu = @host_cpu@
-host_os = @host_os@
-host_vendor = @host_vendor@
-htmldir = @htmldir@
-includedir = @includedir@
-infodir = @infodir@
-install_sh = @install_sh@
-libdir = @libdir@
-libexecdir = @libexecdir@
-localedir = @localedir@
-localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
-mandir = @mandir@
-mkdir_p = @mkdir_p@
-oldincludedir = @oldincludedir@
-pdfdir = @pdfdir@
-pkgpyexecdir = @pkgpyexecdir@
-pkgpythondir = @pkgpythondir@
-prefix = @prefix@
-program_transform_name = @program_transform_name@
-psdir = @psdir@
-pyexecdir = @pyexecdir@
-pythondir = @pythondir@
-sbindir = @sbindir@
-sharedstatedir = @sharedstatedir@
-srcdir = @srcdir@
-sysconfdir = @sysconfdir@
-target_alias = @target_alias@
-top_build_prefix = @top_build_prefix@
-top_builddir = @top_builddir@
-top_srcdir = @top_srcdir@
-xcbincludedir = @xcbincludedir@
-lib_LTLIBRARIES = libxcb.la $(am__append_1) $(am__append_2) \
-	$(am__append_3) $(am__append_4) $(am__append_5) \
-	$(am__append_6) $(am__append_7) $(am__append_8) \
-	$(am__append_9) $(am__append_10) $(am__append_11) \
-	$(am__append_12) $(am__append_13) $(am__append_14) \
-	$(am__append_15) $(am__append_16) $(am__append_17) \
-	$(am__append_18) $(am__append_19) $(am__append_20) \
-	$(am__append_21) $(am__append_22) $(am__append_23)
-
-# FIXME: find a way to autogenerate this from the XML files.
-EXTHEADERS = xproto.h bigreq.h xc_misc.h composite.h damage.h dpms.h \
-	dri2.h glx.h randr.h record.h render.h res.h screensaver.h \
-	shape.h shm.h sync.h xevie.h xf86dri.h xfixes.h xinerama.h \
-	xinput.h xprint.h xselinux.h xtest.h xv.h xvmc.h
-EXTSOURCES = xproto.c bigreq.c xc_misc.c composite.c damage.c dpms.c \
-	dri2.c glx.c randr.c record.c render.c res.c screensaver.c \
-	shape.c shm.c sync.c xevie.c xf86dri.c xfixes.c xinerama.c \
-	xinput.c xprint.c xselinux.c xtest.c xv.c xvmc.c
-EXTENSION_XML = xproto.xml bigreq.xml xc_misc.xml composite.xml \
-	damage.xml dpms.xml dri2.xml glx.xml randr.xml record.xml \
-	render.xml res.xml screensaver.xml shape.xml shm.xml sync.xml \
-	xevie.xml xf86dri.xml xfixes.xml xinerama.xml xinput.xml \
-	xprint.xml xselinux.xml xtest.xml xv.xml xvmc.xml
-AM_CFLAGS = $(CWARNFLAGS) $(NEEDED_CFLAGS) $(XDMCP_CFLAGS)
-libxcb_la_LIBADD = $(NEEDED_LIBS) $(XDMCP_LIBS)
-libxcb_la_SOURCES = \
-		xcb_conn.c xcb_out.c xcb_in.c xcb_ext.c xcb_xid.c \
-		xcb_list.c xcb_util.c xcb_auth.c c_client.py
-
-nodist_libxcb_la_SOURCES = xproto.c bigreq.c xc_misc.c
-
-# Explanation for -version-info:
-# -version-info current:revision:age
-# The library supports interface (current-age) to interface current.
-# * If you changed the source code at all, increment revision.
-# * If you add an interface, increment current and age and set revision to 0.
-# * If you change or remove an interface, increment current and set revision
-#   and age to 0.
-libxcb_la_LDFLAGS = -version-info 2:0:1 -no-undefined
-XCB_LIBS = libxcb.la
-@BUILD_COMPOSITE_TRUE@libxcb_composite_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_COMPOSITE_TRUE@libxcb_composite_la_LIBADD = $(XCB_LIBS)
-@BUILD_COMPOSITE_TRUE@nodist_libxcb_composite_la_SOURCES = composite.c composite.h
-@BUILD_DAMAGE_TRUE@libxcb_damage_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_DAMAGE_TRUE@libxcb_damage_la_LIBADD = $(XCB_LIBS)
-@BUILD_DAMAGE_TRUE@nodist_libxcb_damage_la_SOURCES = damage.c damage.h
-@BUILD_DPMS_TRUE@libxcb_dpms_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_DPMS_TRUE@libxcb_dpms_la_LIBADD = $(XCB_LIBS)
-@BUILD_DPMS_TRUE@nodist_libxcb_dpms_la_SOURCES = dpms.c dpms.h
-@BUILD_DRI2_TRUE@libxcb_dri2_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_DRI2_TRUE@libxcb_dri2_la_LIBADD = $(XCB_LIBS)
-@BUILD_DRI2_TRUE@nodist_libxcb_dri2_la_SOURCES = dri2.c dri2.h
-@BUILD_GLX_TRUE@libxcb_glx_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_GLX_TRUE@libxcb_glx_la_LIBADD = $(XCB_LIBS)
-@BUILD_GLX_TRUE@nodist_libxcb_glx_la_SOURCES = glx.c glx.h
-@BUILD_RANDR_TRUE@libxcb_randr_la_LDFLAGS = -version-info 1:0:1 -no-undefined
-@BUILD_RANDR_TRUE@libxcb_randr_la_LIBADD = $(XCB_LIBS)
-@BUILD_RANDR_TRUE@nodist_libxcb_randr_la_SOURCES = randr.c randr.h
-@BUILD_RECORD_TRUE@libxcb_record_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_RECORD_TRUE@libxcb_record_la_LIBADD = $(XCB_LIBS)
-@BUILD_RECORD_TRUE@nodist_libxcb_record_la_SOURCES = record.c record.h
-@BUILD_RENDER_TRUE@libxcb_render_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_RENDER_TRUE@libxcb_render_la_LIBADD = $(XCB_LIBS)
-@BUILD_RENDER_TRUE@nodist_libxcb_render_la_SOURCES = render.c render.h
-@BUILD_RESOURCE_TRUE@libxcb_res_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_RESOURCE_TRUE@libxcb_res_la_LIBADD = $(XCB_LIBS)
-@BUILD_RESOURCE_TRUE@nodist_libxcb_res_la_SOURCES = res.c res.h
-@BUILD_SCREENSAVER_TRUE@libxcb_screensaver_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_SCREENSAVER_TRUE@libxcb_screensaver_la_LIBADD = $(XCB_LIBS)
-@BUILD_SCREENSAVER_TRUE@nodist_libxcb_screensaver_la_SOURCES = screensaver.c screensaver.h
-@BUILD_SHAPE_TRUE@libxcb_shape_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_SHAPE_TRUE@libxcb_shape_la_LIBADD = $(XCB_LIBS)
-@BUILD_SHAPE_TRUE@nodist_libxcb_shape_la_SOURCES = shape.c shape.h
-@BUILD_SHM_TRUE@libxcb_shm_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_SHM_TRUE@libxcb_shm_la_LIBADD = $(XCB_LIBS)
-@BUILD_SHM_TRUE@nodist_libxcb_shm_la_SOURCES = shm.c shm.h
-@BUILD_SYNC_TRUE@libxcb_sync_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_SYNC_TRUE@libxcb_sync_la_LIBADD = $(XCB_LIBS)
-@BUILD_SYNC_TRUE@nodist_libxcb_sync_la_SOURCES = sync.c sync.h
-@BUILD_XEVIE_TRUE@libxcb_xevie_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XEVIE_TRUE@libxcb_xevie_la_LIBADD = $(XCB_LIBS)
-@BUILD_XEVIE_TRUE@nodist_libxcb_xevie_la_SOURCES = xevie.c xevie.h
-@BUILD_XFREE86_DRI_TRUE@libxcb_xf86dri_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XFREE86_DRI_TRUE@libxcb_xf86dri_la_LIBADD = $(XCB_LIBS)
-@BUILD_XFREE86_DRI_TRUE@nodist_libxcb_xf86dri_la_SOURCES = xf86dri.c xf86dri.h
-@BUILD_XFIXES_TRUE@libxcb_xfixes_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XFIXES_TRUE@libxcb_xfixes_la_LIBADD = $(XCB_LIBS)
-@BUILD_XFIXES_TRUE@nodist_libxcb_xfixes_la_SOURCES = xfixes.c xfixes.h
-@BUILD_XINERAMA_TRUE@libxcb_xinerama_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XINERAMA_TRUE@libxcb_xinerama_la_LIBADD = $(XCB_LIBS)
-@BUILD_XINERAMA_TRUE@nodist_libxcb_xinerama_la_SOURCES = xinerama.c xinerama.h
-@BUILD_XINPUT_TRUE@libxcb_xinput_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XINPUT_TRUE@libxcb_xinput_la_LIBADD = $(XCB_LIBS)
-@BUILD_XINPUT_TRUE@nodist_libxcb_xinput_la_SOURCES = xinput.c xinput.h
-@BUILD_XPRINT_TRUE@libxcb_xprint_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XPRINT_TRUE@libxcb_xprint_la_LIBADD = $(XCB_LIBS)
-@BUILD_XPRINT_TRUE@nodist_libxcb_xprint_la_SOURCES = xprint.c xprint.h
-@BUILD_SELINUX_TRUE@libxcb_xselinux_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_SELINUX_TRUE@libxcb_xselinux_la_LIBADD = $(XCB_LIBS)
-@BUILD_SELINUX_TRUE@nodist_libxcb_xselinux_la_SOURCES = xselinux.c xselinux.h
-@BUILD_XTEST_TRUE@libxcb_xtest_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XTEST_TRUE@libxcb_xtest_la_LIBADD = $(XCB_LIBS)
-@BUILD_XTEST_TRUE@nodist_libxcb_xtest_la_SOURCES = xtest.c xtest.h
-@BUILD_XV_TRUE@libxcb_xv_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XV_TRUE@libxcb_xv_la_LIBADD = $(XCB_LIBS)
-@BUILD_XV_TRUE@nodist_libxcb_xv_la_SOURCES = xv.c xv.h
-@BUILD_XVMC_TRUE@libxcb_xvmc_la_LDFLAGS = -version-info 0:0:0 -no-undefined
-@BUILD_XVMC_TRUE@libxcb_xvmc_la_LIBADD = $(XCB_LIBS)
-@BUILD_XVMC_TRUE@nodist_libxcb_xvmc_la_SOURCES = xvmc.c xvmc.h
-xcbinclude_HEADERS = xcb.h xcbext.h
-nodist_xcbinclude_HEADERS = $(EXTHEADERS)
-noinst_HEADERS = xcbint.h
-BUILT_SOURCES = $(EXTSOURCES) $(EXTHEADERS)
-CLEANFILES = $(EXTSOURCES) $(EXTHEADERS) $(EXTENSION_XML)
-SUFFIXES = .xml
-all: $(BUILT_SOURCES) config.h
-	$(MAKE) $(AM_MAKEFLAGS) all-am
-
-.SUFFIXES:
-.SUFFIXES: .xml .c .h .lo .o .obj
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
-	@for dep in $?; do \
-	  case '$(am__configure_deps)' in \
-	    *$$dep*) \
-	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
-	        && { if test -f $@; then exit 0; else break; fi; }; \
-	      exit 1;; \
-	  esac; \
-	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
-	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --foreign src/Makefile
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
-	@case '$?' in \
-	  *config.status*) \
-	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
-	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
-	esac;
-
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-
-$(top_srcdir)/configure:  $(am__configure_deps)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(am__aclocal_m4_deps):
-
-config.h: stamp-h1
-	@if test ! -f $@; then \
-	  rm -f stamp-h1; \
-	  $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
-	else :; fi
-
-stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
-	@rm -f stamp-h1
-	cd $(top_builddir) && $(SHELL) ./config.status src/config.h
-$(srcdir)/config.h.in:  $(am__configure_deps) 
-	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
-	rm -f stamp-h1
-	touch $@
-
-distclean-hdr:
-	-rm -f config.h stamp-h1
-install-libLTLIBRARIES: $(lib_LTLIBRARIES)
-	@$(NORMAL_INSTALL)
-	test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
-	@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
-	list2=; for p in $$list; do \
-	  if test -f $$p; then \
-	    list2="$$list2 $$p"; \
-	  else :; fi; \
-	done; \
-	test -z "$$list2" || { \
-	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
-	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
-	}
-
-uninstall-libLTLIBRARIES:
-	@$(NORMAL_UNINSTALL)
-	@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
-	for p in $$list; do \
-	  $(am__strip_dir) \
-	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
-	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
-	done
-
-clean-libLTLIBRARIES:
-	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
-	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
-	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
-	  test "$$dir" != "$$p" || dir=.; \
-	  echo "rm -f \"$${dir}/so_locations\""; \
-	  rm -f "$${dir}/so_locations"; \
-	done
-libxcb-composite.la: $(libxcb_composite_la_OBJECTS) $(libxcb_composite_la_DEPENDENCIES) 
-	$(libxcb_composite_la_LINK) $(am_libxcb_composite_la_rpath) $(libxcb_composite_la_OBJECTS) $(libxcb_composite_la_LIBADD) $(LIBS)
-libxcb-damage.la: $(libxcb_damage_la_OBJECTS) $(libxcb_damage_la_DEPENDENCIES) 
-	$(libxcb_damage_la_LINK) $(am_libxcb_damage_la_rpath) $(libxcb_damage_la_OBJECTS) $(libxcb_damage_la_LIBADD) $(LIBS)
-libxcb-dpms.la: $(libxcb_dpms_la_OBJECTS) $(libxcb_dpms_la_DEPENDENCIES) 
-	$(libxcb_dpms_la_LINK) $(am_libxcb_dpms_la_rpath) $(libxcb_dpms_la_OBJECTS) $(libxcb_dpms_la_LIBADD) $(LIBS)
-libxcb-dri2.la: $(libxcb_dri2_la_OBJECTS) $(libxcb_dri2_la_DEPENDENCIES) 
-	$(libxcb_dri2_la_LINK) $(am_libxcb_dri2_la_rpath) $(libxcb_dri2_la_OBJECTS) $(libxcb_dri2_la_LIBADD) $(LIBS)
-libxcb-glx.la: $(libxcb_glx_la_OBJECTS) $(libxcb_glx_la_DEPENDENCIES) 
-	$(libxcb_glx_la_LINK) $(am_libxcb_glx_la_rpath) $(libxcb_glx_la_OBJECTS) $(libxcb_glx_la_LIBADD) $(LIBS)
-libxcb-randr.la: $(libxcb_randr_la_OBJECTS) $(libxcb_randr_la_DEPENDENCIES) 
-	$(libxcb_randr_la_LINK) $(am_libxcb_randr_la_rpath) $(libxcb_randr_la_OBJECTS) $(libxcb_randr_la_LIBADD) $(LIBS)
-libxcb-record.la: $(libxcb_record_la_OBJECTS) $(libxcb_record_la_DEPENDENCIES) 
-	$(libxcb_record_la_LINK) $(am_libxcb_record_la_rpath) $(libxcb_record_la_OBJECTS) $(libxcb_record_la_LIBADD) $(LIBS)
-libxcb-render.la: $(libxcb_render_la_OBJECTS) $(libxcb_render_la_DEPENDENCIES) 
-	$(libxcb_render_la_LINK) $(am_libxcb_render_la_rpath) $(libxcb_render_la_OBJECTS) $(libxcb_render_la_LIBADD) $(LIBS)
-libxcb-res.la: $(libxcb_res_la_OBJECTS) $(libxcb_res_la_DEPENDENCIES) 
-	$(libxcb_res_la_LINK) $(am_libxcb_res_la_rpath) $(libxcb_res_la_OBJECTS) $(libxcb_res_la_LIBADD) $(LIBS)
-libxcb-screensaver.la: $(libxcb_screensaver_la_OBJECTS) $(libxcb_screensaver_la_DEPENDENCIES) 
-	$(libxcb_screensaver_la_LINK) $(am_libxcb_screensaver_la_rpath) $(libxcb_screensaver_la_OBJECTS) $(libxcb_screensaver_la_LIBADD) $(LIBS)
-libxcb-shape.la: $(libxcb_shape_la_OBJECTS) $(libxcb_shape_la_DEPENDENCIES) 
-	$(libxcb_shape_la_LINK) $(am_libxcb_shape_la_rpath) $(libxcb_shape_la_OBJECTS) $(libxcb_shape_la_LIBADD) $(LIBS)
-libxcb-shm.la: $(libxcb_shm_la_OBJECTS) $(libxcb_shm_la_DEPENDENCIES) 
-	$(libxcb_shm_la_LINK) $(am_libxcb_shm_la_rpath) $(libxcb_shm_la_OBJECTS) $(libxcb_shm_la_LIBADD) $(LIBS)
-libxcb-sync.la: $(libxcb_sync_la_OBJECTS) $(libxcb_sync_la_DEPENDENCIES) 
-	$(libxcb_sync_la_LINK) $(am_libxcb_sync_la_rpath) $(libxcb_sync_la_OBJECTS) $(libxcb_sync_la_LIBADD) $(LIBS)
-libxcb-xevie.la: $(libxcb_xevie_la_OBJECTS) $(libxcb_xevie_la_DEPENDENCIES) 
-	$(libxcb_xevie_la_LINK) $(am_libxcb_xevie_la_rpath) $(libxcb_xevie_la_OBJECTS) $(libxcb_xevie_la_LIBADD) $(LIBS)
-libxcb-xf86dri.la: $(libxcb_xf86dri_la_OBJECTS) $(libxcb_xf86dri_la_DEPENDENCIES) 
-	$(libxcb_xf86dri_la_LINK) $(am_libxcb_xf86dri_la_rpath) $(libxcb_xf86dri_la_OBJECTS) $(libxcb_xf86dri_la_LIBADD) $(LIBS)
-libxcb-xfixes.la: $(libxcb_xfixes_la_OBJECTS) $(libxcb_xfixes_la_DEPENDENCIES) 
-	$(libxcb_xfixes_la_LINK) $(am_libxcb_xfixes_la_rpath) $(libxcb_xfixes_la_OBJECTS) $(libxcb_xfixes_la_LIBADD) $(LIBS)
-libxcb-xinerama.la: $(libxcb_xinerama_la_OBJECTS) $(libxcb_xinerama_la_DEPENDENCIES) 
-	$(libxcb_xinerama_la_LINK) $(am_libxcb_xinerama_la_rpath) $(libxcb_xinerama_la_OBJECTS) $(libxcb_xinerama_la_LIBADD) $(LIBS)
-libxcb-xinput.la: $(libxcb_xinput_la_OBJECTS) $(libxcb_xinput_la_DEPENDENCIES) 
-	$(libxcb_xinput_la_LINK) $(am_libxcb_xinput_la_rpath) $(libxcb_xinput_la_OBJECTS) $(libxcb_xinput_la_LIBADD) $(LIBS)
-libxcb-xprint.la: $(libxcb_xprint_la_OBJECTS) $(libxcb_xprint_la_DEPENDENCIES) 
-	$(libxcb_xprint_la_LINK) $(am_libxcb_xprint_la_rpath) $(libxcb_xprint_la_OBJECTS) $(libxcb_xprint_la_LIBADD) $(LIBS)
-libxcb-xselinux.la: $(libxcb_xselinux_la_OBJECTS) $(libxcb_xselinux_la_DEPENDENCIES) 
-	$(libxcb_xselinux_la_LINK) $(am_libxcb_xselinux_la_rpath) $(libxcb_xselinux_la_OBJECTS) $(libxcb_xselinux_la_LIBADD) $(LIBS)
-libxcb-xtest.la: $(libxcb_xtest_la_OBJECTS) $(libxcb_xtest_la_DEPENDENCIES) 
-	$(libxcb_xtest_la_LINK) $(am_libxcb_xtest_la_rpath) $(libxcb_xtest_la_OBJECTS) $(libxcb_xtest_la_LIBADD) $(LIBS)
-libxcb-xv.la: $(libxcb_xv_la_OBJECTS) $(libxcb_xv_la_DEPENDENCIES) 
-	$(libxcb_xv_la_LINK) $(am_libxcb_xv_la_rpath) $(libxcb_xv_la_OBJECTS) $(libxcb_xv_la_LIBADD) $(LIBS)
-libxcb-xvmc.la: $(libxcb_xvmc_la_OBJECTS) $(libxcb_xvmc_la_DEPENDENCIES) 
-	$(libxcb_xvmc_la_LINK) $(am_libxcb_xvmc_la_rpath) $(libxcb_xvmc_la_OBJECTS) $(libxcb_xvmc_la_LIBADD) $(LIBS)
-libxcb.la: $(libxcb_la_OBJECTS) $(libxcb_la_DEPENDENCIES) 
-	$(libxcb_la_LINK) -rpath $(libdir) $(libxcb_la_OBJECTS) $(libxcb_la_LIBADD) $(LIBS)
-
-mostlyclean-compile:
-	-rm -f *.$(OBJEXT)
-
-distclean-compile:
-	-rm -f *.tab.c
-
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bigreq.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/composite.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/damage.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dpms.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dri2.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glx.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/randr.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/record.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/res.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/screensaver.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shape.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sync.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xc_misc.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_auth.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_conn.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_ext.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_in.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_list.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_out.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_util.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcb_xid.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xevie.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xf86dri.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xfixes.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xinerama.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xinput.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xprint.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xproto.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xselinux.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtest.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xv.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xvmc.Plo@am__quote@
-
-.c.o:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c $<
-
-.c.obj:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
-
-.c.lo:
-@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
-
-mostlyclean-libtool:
-	-rm -f *.lo
-
-clean-libtool:
-	-rm -rf .libs _libs
-install-nodist_xcbincludeHEADERS: $(nodist_xcbinclude_HEADERS)
-	@$(NORMAL_INSTALL)
-	test -z "$(xcbincludedir)" || $(MKDIR_P) "$(DESTDIR)$(xcbincludedir)"
-	@list='$(nodist_xcbinclude_HEADERS)'; test -n "$(xcbincludedir)" || list=; \
-	for p in $$list; do \
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-	  echo "$$d$$p"; \
-	done | $(am__base_list) | \
-	while read files; do \
-	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(xcbincludedir)'"; \
-	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(xcbincludedir)" || exit $$?; \
-	done
-
-uninstall-nodist_xcbincludeHEADERS:
-	@$(NORMAL_UNINSTALL)
-	@list='$(nodist_xcbinclude_HEADERS)'; test -n "$(xcbincludedir)" || list=; \
-	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-	test -n "$$files" || exit 0; \
-	echo " ( cd '$(DESTDIR)$(xcbincludedir)' && rm -f" $$files ")"; \
-	cd "$(DESTDIR)$(xcbincludedir)" && rm -f $$files
-install-xcbincludeHEADERS: $(xcbinclude_HEADERS)
-	@$(NORMAL_INSTALL)
-	test -z "$(xcbincludedir)" || $(MKDIR_P) "$(DESTDIR)$(xcbincludedir)"
-	@list='$(xcbinclude_HEADERS)'; test -n "$(xcbincludedir)" || list=; \
-	for p in $$list; do \
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-	  echo "$$d$$p"; \
-	done | $(am__base_list) | \
-	while read files; do \
-	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(xcbincludedir)'"; \
-	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(xcbincludedir)" || exit $$?; \
-	done
-
-uninstall-xcbincludeHEADERS:
-	@$(NORMAL_UNINSTALL)
-	@list='$(xcbinclude_HEADERS)'; test -n "$(xcbincludedir)" || list=; \
-	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-	test -n "$$files" || exit 0; \
-	echo " ( cd '$(DESTDIR)$(xcbincludedir)' && rm -f" $$files ")"; \
-	cd "$(DESTDIR)$(xcbincludedir)" && rm -f $$files
-
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
-	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	mkid -fID $$unique
-tags: TAGS
-
-TAGS:  $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	set x; \
-	here=`pwd`; \
-	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	shift; \
-	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
-	  test -n "$$unique" || unique=$$empty_fix; \
-	  if test $$# -gt 0; then \
-	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
-	      "$$@" $$unique; \
-	  else \
-	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
-	      $$unique; \
-	  fi; \
-	fi
-ctags: CTAGS
-CTAGS:  $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	test -z "$(CTAGS_ARGS)$$unique" \
-	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
-	     $$unique
-
-GTAGS:
-	here=`$(am__cd) $(top_builddir) && pwd` \
-	  && $(am__cd) $(top_srcdir) \
-	  && gtags -i $(GTAGS_ARGS) "$$here"
-
-distclean-tags:
-	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
-distdir: $(DISTFILES)
-	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
-	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
-	list='$(DISTFILES)'; \
-	  dist_files=`for file in $$list; do echo $$file; done | \
-	  sed -e "s|^$$srcdirstrip/||;t" \
-	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
-	case $$dist_files in \
-	  */*) $(MKDIR_P) `echo "$$dist_files" | \
-			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
-			   sort -u` ;; \
-	esac; \
-	for file in $$dist_files; do \
-	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
-	  if test -d $$d/$$file; then \
-	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
-	    if test -d "$(distdir)/$$file"; then \
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
-	    fi; \
-	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
-	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
-	    fi; \
-	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
-	  else \
-	    test -f "$(distdir)/$$file" \
-	    || cp -p $$d/$$file "$(distdir)/$$file" \
-	    || exit 1; \
-	  fi; \
-	done
-check-am: all-am
-check: $(BUILT_SOURCES)
-	$(MAKE) $(AM_MAKEFLAGS) check-am
-all-am: Makefile $(LTLIBRARIES) $(HEADERS) config.h
-installdirs:
-	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(xcbincludedir)" "$(DESTDIR)$(xcbincludedir)"; do \
-	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
-	done
-install: $(BUILT_SOURCES)
-	$(MAKE) $(AM_MAKEFLAGS) install-am
-install-exec: install-exec-am
-install-data: install-data-am
-uninstall: uninstall-am
-
-install-am: all-am
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-
-installcheck: installcheck-am
-install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
-mostlyclean-generic:
-
-clean-generic:
-	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
-
-distclean-generic:
-	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
-
-maintainer-clean-generic:
-	@echo "This command is intended for maintainers to use"
-	@echo "it deletes files that may require special tools to rebuild."
-	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
-clean: clean-am
-
-clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
-	mostlyclean-am
-
-distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
-	-rm -f Makefile
-distclean-am: clean-am distclean-compile distclean-generic \
-	distclean-hdr distclean-tags
-
-dvi: dvi-am
-
-dvi-am:
-
-html: html-am
-
-html-am:
-
-info: info-am
-
-info-am:
-
-install-data-am: install-nodist_xcbincludeHEADERS \
-	install-xcbincludeHEADERS
-
-install-dvi: install-dvi-am
-
-install-dvi-am:
-
-install-exec-am: install-libLTLIBRARIES
-
-install-html: install-html-am
-
-install-html-am:
-
-install-info: install-info-am
-
-install-info-am:
-
-install-man:
-
-install-pdf: install-pdf-am
-
-install-pdf-am:
-
-install-ps: install-ps-am
-
-install-ps-am:
-
-installcheck-am:
-
-maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
-	-rm -f Makefile
-maintainer-clean-am: distclean-am maintainer-clean-generic
-
-mostlyclean: mostlyclean-am
-
-mostlyclean-am: mostlyclean-compile mostlyclean-generic \
-	mostlyclean-libtool
-
-pdf: pdf-am
-
-pdf-am:
-
-ps: ps-am
-
-ps-am:
-
-uninstall-am: uninstall-libLTLIBRARIES \
-	uninstall-nodist_xcbincludeHEADERS uninstall-xcbincludeHEADERS
-
-.MAKE: all check install install-am install-strip
-
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
-	clean-libLTLIBRARIES clean-libtool ctags distclean \
-	distclean-compile distclean-generic distclean-hdr \
-	distclean-libtool distclean-tags distdir dvi dvi-am html \
-	html-am info info-am install install-am install-data \
-	install-data-am install-dvi install-dvi-am install-exec \
-	install-exec-am install-html install-html-am install-info \
-	install-info-am install-libLTLIBRARIES install-man \
-	install-nodist_xcbincludeHEADERS install-pdf install-pdf-am \
-	install-ps install-ps-am install-strip \
-	install-xcbincludeHEADERS installcheck installcheck-am \
-	installdirs maintainer-clean maintainer-clean-generic \
-	mostlyclean mostlyclean-compile mostlyclean-generic \
-	mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
-	uninstall-am uninstall-libLTLIBRARIES \
-	uninstall-nodist_xcbincludeHEADERS uninstall-xcbincludeHEADERS
-
-
-$(EXTHEADERS) $(EXTSOURCES): c_client.py
-
-.xml.h:
-	$(PYTHON) $(srcdir)/c_client.py -p $(XCBPROTO_XCBPYTHONDIR) $(XCBPROTO_XCBINCLUDEDIR)/$<
-
-.xml.c:
-	$(PYTHON) $(srcdir)/c_client.py -p $(XCBPROTO_XCBPYTHONDIR) $(XCBPROTO_XCBINCLUDEDIR)/$<
-
-$(EXTENSION_XML):
-	$(LN_S) -f $(XCBPROTO_XCBINCLUDEDIR)/$@ $@
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
diff --git a/libxcb/src/config.h.in b/libxcb/src/config.h.in
deleted file mode 100644
index 977ac8f7c..000000000
--- a/libxcb/src/config.h.in
+++ /dev/null
@@ -1,83 +0,0 @@
-/* src/config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Defined if GCC supports the visibility feature */
-#undef GCC_HAS_VISIBILITY
-
-/* Has Wraphelp.c needed for XDM AUTH protocols */
-#undef HASXDMAUTH
-
-/* Define if your platform supports abstract sockets */
-#undef HAVE_ABSTRACT_SOCKETS
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* launchd support available */
-#undef HAVE_LAUNCHD
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Have the sockaddr_un.sun_len member. */
-#undef HAVE_SOCKADDR_SUN_LEN
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
-   */
-#undef LT_OBJDIR
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* poll() function is available */
-#undef USE_POLL
-
-/* Version number of package */
-#undef VERSION
-
-/* XCB buffer queue size */
-#undef XCB_QUEUE_BUFFER_SIZE
-- 
cgit v1.2.3


From 567e9524c7a2fdabade9cdbb672a55f6a417ce15 Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Fri, 30 Apr 2010 14:06:28 +0000
Subject: libxcb git update 30/4/2010

---
 libxcb/src/xcb_auth.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-------
 libxcb/src/xcb_util.c | 29 +++++++++++++++------
 2 files changed, 83 insertions(+), 16 deletions(-)

(limited to 'libxcb/src')

diff --git a/libxcb/src/xcb_auth.c b/libxcb/src/xcb_auth.c
index 00aad23c5..d774d1069 100644
--- a/libxcb/src/xcb_auth.c
+++ b/libxcb/src/xcb_auth.c
@@ -89,8 +89,7 @@ static int authname_match(enum auth_protos kind, char *name, size_t namelen)
 
 #define SIN6_ADDR(s) (&((struct sockaddr_in6 *)s)->sin6_addr)
 
-static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
-                          int display)
+static Xauth *get_authptr(struct sockaddr *sockname, int display)
 {
     char *addr = 0;
     int addrlen = 0;
@@ -243,13 +242,55 @@ static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr *
     return 0;   /* Unknown authorization type */
 }
 
+/* `sockaddr_un.sun_path' typical size usually ranges between 92 and 108 */
+#define INITIAL_SOCKNAME_SLACK 108
+
+/* Return a dynamically allocated socket address structure according
+   to the value returned by either getpeername() or getsockname()
+   (according to POSIX, applications should not assume a particular
+   length for `sockaddr_un.sun_path') */
+static struct sockaddr *get_peer_sock_name(int (*socket_func)(int,
+							      struct sockaddr *,
+							      socklen_t *),
+					   int fd)
+{
+    socklen_t socknamelen = sizeof(struct sockaddr) + INITIAL_SOCKNAME_SLACK;
+    socklen_t actual_socknamelen = socknamelen;
+    struct sockaddr *sockname = malloc(socknamelen), *new_sockname = NULL;
+
+    if (sockname == NULL)
+        return NULL;
+
+    /* Both getpeername() and getsockname() truncates sockname if
+       there is not enough space and set the required length in
+       actual_socknamelen */
+    if (socket_func(fd, sockname, &actual_socknamelen) == -1)
+        goto sock_or_realloc_error;
+
+    if (actual_socknamelen > socknamelen)
+    {
+        socknamelen = actual_socknamelen;
+
+        if ((new_sockname = realloc(sockname, actual_socknamelen)) == NULL ||
+            socket_func(fd, new_sockname, &actual_socknamelen) == -1 ||
+            actual_socknamelen > socknamelen) 
+            goto sock_or_realloc_error;
+
+        sockname = new_sockname;
+    }
+
+    return sockname;
+
+ sock_or_realloc_error:
+    free(sockname);
+    return NULL;
+}
+
 int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
 {
     /* code adapted from Xlib/ConnDis.c, xtrans/Xtranssocket.c,
        xtrans/Xtransutils.c */
-    char sockbuf[sizeof(struct sockaddr) + MAXPATHLEN];
-    unsigned int socknamelen = sizeof(sockbuf);   /* need extra space */
-    struct sockaddr *sockname = (struct sockaddr *) &sockbuf;
+    struct sockaddr *sockname = NULL;
     int gotsockname = 0;
     Xauth *authptr = 0;
     int ret = 1;
@@ -258,24 +299,30 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
      * for UNIX Domain Sockets, but this is irrelevant,
      * since compute_auth() ignores the peer name in this
      * case anyway.*/
-    if (getpeername(fd, sockname, &socknamelen) == -1)
+    if ((sockname = get_peer_sock_name(getpeername, fd)) == NULL)
     {
-        if (getsockname(fd, sockname, &socknamelen) == -1)
+        if ((sockname = get_peer_sock_name(getsockname, fd)) == NULL)
             return 0;   /* can only authenticate sockets */
         if (sockname->sa_family != AF_UNIX)
+        {
+            free(sockname);
             return 0;   /* except for AF_UNIX, sockets should have peernames */
+        }
         gotsockname = 1;
     }
 
-    authptr = get_authptr(sockname, socknamelen, display);
+    authptr = get_authptr(sockname, display);
     if (authptr == 0)
+    {
+        free(sockname);
         return 0;   /* cannot find good auth data */
+    }
 
     info->namelen = memdup(&info->name, authptr->name, authptr->name_length);
     if (!info->namelen)
         goto no_auth;   /* out of memory */
 
-    if (!gotsockname && getsockname(fd, sockname, &socknamelen) == -1)
+    if (!gotsockname && (sockname = get_peer_sock_name(getsockname, fd)) == NULL)
     {
         free(info->name);
         goto no_auth;   /* can only authenticate sockets */
@@ -288,10 +335,15 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
         goto no_auth;   /* cannot build auth record */
     }
 
+    free(sockname);
+    sockname = NULL;
+
     XauDisposeAuth(authptr);
     return ret;
 
  no_auth:
+    free(sockname);
+
     info->name = 0;
     info->namelen = 0;
     XauDisposeAuth(authptr);
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 287f12fd9..cc4e24af2 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -145,8 +145,9 @@ static int _xcb_open(char *host, char *protocol, const int display)
 #endif
     static const char unix_base[] = "/tmp/.X11-unix/X";
     const char *base = unix_base;
-    char file[PATH_MAX + 1];
-    int filelen;
+    size_t filelen;
+    char *file = NULL;
+    int actual_filelen;
 
     if(*host)
     {
@@ -181,24 +182,38 @@ static int _xcb_open(char *host, char *protocol, const int display)
 #endif
     }
 
+    filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
+    file = malloc(filelen);
+    if(file == NULL)
+        return -1;
+
     /* display specifies Unix socket */
 #ifdef HAVE_LAUNCHD
     if(base == host)
-        filelen = snprintf(file, sizeof(file), "%s:%d", base, display);
+        actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
     else
 #endif
-        filelen = snprintf(file, sizeof(file), "%s%d", base, display);
-    if(filelen < 0)
+        actual_filelen = snprintf(file, filelen, "%s%d", base, display);
+    if(actual_filelen < 0)
+    {
+        free(file);
         return -1;
+    }
     /* snprintf may truncate the file */
-    filelen = MIN(filelen, sizeof(file) - 1);
+    filelen = MIN(actual_filelen, filelen - 1);
 #ifdef HAVE_ABSTRACT_SOCKETS
     fd = _xcb_open_abstract(protocol, file, filelen);
     if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+    {
+        free(file);
         return fd;
+    }
 
 #endif
-    return  _xcb_open_unix(protocol, file);
+    fd = _xcb_open_unix(protocol, file);
+    free(file);
+
+    return fd;
 }
 
 static int _xcb_socket(int family, int type, int proto)
-- 
cgit v1.2.3


From 93041fdd8c52dc6ffe78516cd8955fe3d336c4b4 Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Tue, 4 May 2010 16:20:36 +0000
Subject: libxcb git update 4/5/2010

---
 libxcb/src/xcb_util.c | 2 --
 1 file changed, 2 deletions(-)

(limited to 'libxcb/src')

diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index cc4e24af2..3516186fa 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -140,9 +140,7 @@ static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
 
 static int _xcb_open(char *host, char *protocol, const int display)
 {
-#ifdef HAVE_ABSTRACT_SOCKETS
     int fd;
-#endif
     static const char unix_base[] = "/tmp/.X11-unix/X";
     const char *base = unix_base;
     size_t filelen;
-- 
cgit v1.2.3


From 0cc46df268cf3a3a3a2a25afe3a2415a4ec4193f Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Sat, 15 May 2010 16:38:43 +0000
Subject: libxcb git update 15/5/2010

---
 libxcb/src/c_client.py | 2084 ++++++++++++++++++++++++------------------------
 libxcb/src/xcb_util.c  |  836 +++++++++----------
 2 files changed, 1464 insertions(+), 1456 deletions(-)

(limited to 'libxcb/src')

diff --git a/libxcb/src/c_client.py b/libxcb/src/c_client.py
index d86d05e24..2d3d78a0b 100644
--- a/libxcb/src/c_client.py
+++ b/libxcb/src/c_client.py
@@ -1,1041 +1,1043 @@
-#!/usr/bin/env python
-from xml.etree.cElementTree import *
-from os.path import basename
-import getopt
-import sys
-import re
-
-# Jump to the bottom of this file for the main routine
-
-# Some hacks to make the API more readable, and to keep backwards compability
-_cname_re = re.compile('([A-Z0-9][a-z]+|[A-Z0-9]+(?![a-z])|[a-z]+)')
-_cname_special_cases = {'DECnet':'decnet'}
-
-_extension_special_cases = ['XPrint', 'XCMisc', 'BigRequests']
-
-_cplusplus_annoyances = {'class' : '_class',
-                         'new'   : '_new',
-                         'delete': '_delete'}
-
-_hlines = []
-_hlevel = 0
-_clines = []
-_clevel = 0
-_ns = None
-
-def _h(fmt, *args):
-    '''
-    Writes the given line to the header file.
-    '''
-    _hlines[_hlevel].append(fmt % args)
-    
-def _c(fmt, *args):
-    '''
-    Writes the given line to the source file.
-    '''
-    _clines[_clevel].append(fmt % args)
-    
-def _hc(fmt, *args):
-    '''
-    Writes the given line to both the header and source files.
-    '''
-    _h(fmt, *args)
-    _c(fmt, *args)
-
-# XXX See if this level thing is really necessary.
-def _h_setlevel(idx):
-    '''
-    Changes the array that header lines are written to.
-    Supports writing different sections of the header file.
-    '''
-    global _hlevel
-    while len(_hlines) <= idx:
-        _hlines.append([])
-    _hlevel = idx
-    
-def _c_setlevel(idx):
-    '''
-    Changes the array that source lines are written to.
-    Supports writing to different sections of the source file.
-    '''
-    global _clevel
-    while len(_clines) <= idx:
-        _clines.append([])
-    _clevel = idx
-    
-def _n_item(str):
-    '''
-    Does C-name conversion on a single string fragment.
-    Uses a regexp with some hard-coded special cases.
-    '''
-    if str in _cname_special_cases:
-        return _cname_special_cases[str]
-    else:
-        split = _cname_re.finditer(str)
-        name_parts = [match.group(0) for match in split]
-        return '_'.join(name_parts)
-    
-def _cpp(str):
-    '''
-    Checks for certain C++ reserved words and fixes them.
-    '''
-    if str in _cplusplus_annoyances:
-        return _cplusplus_annoyances[str]
-    else:
-        return str
-
-def _ext(str):
-    '''
-    Does C-name conversion on an extension name.
-    Has some additional special cases on top of _n_item.
-    '''
-    if str in _extension_special_cases:
-        return _n_item(str).lower()
-    else:
-        return str.lower()
-    
-def _n(list):
-    '''
-    Does C-name conversion on a tuple of strings.
-    Different behavior depending on length of tuple, extension/not extension, etc.
-    Basically C-name converts the individual pieces, then joins with underscores.
-    '''
-    if len(list) == 1:
-        parts = list
-    elif len(list) == 2:
-        parts = [list[0], _n_item(list[1])]
-    elif _ns.is_ext:
-        parts = [list[0], _ext(list[1])] + [_n_item(i) for i in list[2:]]
-    else:
-        parts = [list[0]] + [_n_item(i) for i in list[1:]]
-    return '_'.join(parts).lower()
-
-def _t(list):
-    '''
-    Does C-name conversion on a tuple of strings representing a type.
-    Same as _n but adds a "_t" on the end.
-    '''
-    if len(list) == 1:
-        parts = list
-    elif len(list) == 2:
-        parts = [list[0], _n_item(list[1]), 't']
-    elif _ns.is_ext:
-        parts = [list[0], _ext(list[1])] + [_n_item(i) for i in list[2:]] + ['t']
-    else:
-        parts = [list[0]] + [_n_item(i) for i in list[1:]] + ['t']
-    return '_'.join(parts).lower()
-        
-
-def c_open(self):
-    '''
-    Exported function that handles module open.
-    Opens the files and writes out the auto-generated comment, header file includes, etc.
-    '''
-    global _ns
-    _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)
-
-    _hc('/*')
-    _hc(' * This file generated automatically from %s by c_client.py.', _ns.file)
-    _hc(' * Edit at your peril.')
-    _hc(' */')
-    _hc('')
-
-    _h('/**')
-    _h(' * @defgroup XCB_%s_API XCB %s API', _ns.ext_name, _ns.ext_name)
-    _h(' * @brief %s XCB Protocol Implementation.', _ns.ext_name)
-    _h(' * @{')
-    _h(' **/')
-    _h('')
-    _h('#ifndef __%s_H', _ns.header.upper())
-    _h('#define __%s_H', _ns.header.upper())
-    _h('')
-    _h('#include "xcb.h"')
-
-    _c('#include <string.h>')
-    _c('#include <assert.h>')
-    _c('#include "xcbext.h"')
-    _c('#include "%s.h"', _ns.header)
-        
-    if _ns.is_ext:
-        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('  ') #XXX
-        _h('extern xcb_extension_t %s;', _ns.c_ext_global_name)
-
-        _c('')
-        _c('xcb_extension_t %s = { "%s", 0 };', _ns.c_ext_global_name, _ns.ext_xname)
-
-def c_close(self):
-    '''
-    Exported function that handles module close.
-    Writes out all the stored content lines, then closes the files.
-    '''
-    _h_setlevel(2)
-    _c_setlevel(2)
-    _hc('')
-
-    _h('')
-    _h('#ifdef __cplusplus')
-    _h('}')
-    _h('#endif')
-
-    _h('')
-    _h('#endif')
-    _h('')
-    _h('/**')
-    _h(' * @}')
-    _h(' */')
-
-    # Write header file
-    hfile = open('%s.h' % _ns.header, 'w')
-    for list in _hlines:
-        for line in list:
-            hfile.write(line)
-            hfile.write('\n')
-    hfile.close()
-
-    # Write source file
-    cfile = open('%s.c' % _ns.header, 'w')
-    for list in _clines:
-        for line in list:
-            cfile.write(line)
-            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 {', tname)
-
-    count = len(self.values)
-
-    for (enam, eval) in self.values:
-        count = count - 1
-        equals = ' = ' if eval != '' else ''
-        comma = ',' if count > 0 else ''
-        _h('    %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
-
-    _h('} %s;', tname)
-
-def _c_type_setup(self, name, postfix):
-    '''
-    Sets up all the C-related state by adding additional data fields to
-    all Field and Type objects.  Here is where we figure out most of our
-    variable and function names.
-
-    Recurses into child fields and list member types.
-    '''
-    # Do all the various names in advance
-    self.c_type = _t(name + postfix)
-    self.c_wiretype = 'char' if self.c_type == 'void' else self.c_type
-
-    self.c_iterator_type = _t(name + ('iterator',))
-    self.c_next_name = _n(name + ('next',))
-    self.c_end_name = _n(name + ('end',))
-
-    self.c_request_name = _n(name)
-    self.c_checked_name = _n(name + ('checked',))
-    self.c_unchecked_name = _n(name + ('unchecked',))
-    self.c_reply_name = _n(name + ('reply',))
-    self.c_reply_type = _t(name + ('reply',))
-    self.c_cookie_type = _t(name + ('cookie',))
-
-    if self.is_container:
-
-        self.c_container = 'union' if self.is_union else 'struct'
-        prev_varsized_field = None
-        prev_varsized_offset = 0
-        first_field_after_varsized = None
-
-        for field in self.fields:
-            _c_type_setup(field.type, field.field_type, ())
-            if field.type.is_list:
-                _c_type_setup(field.type.member, field.field_type, ())
-
-            field.c_field_type = _t(field.field_type)
-            field.c_field_const_type = ('' if field.type.nmemb == 1 else 'const ') + field.c_field_type
-            field.c_field_name = _cpp(field.field_name)
-            field.c_subscript = '[%d]' % field.type.nmemb if (field.type.nmemb > 1) else ''
-            field.c_pointer = ' ' if field.type.nmemb == 1 else '*'
-
-            field.c_iterator_type = _t(field.field_type + ('iterator',))      # xcb_fieldtype_iterator_t
-            field.c_iterator_name = _n(name + (field.field_name, 'iterator')) # xcb_container_field_iterator
-            field.c_accessor_name = _n(name + (field.field_name,))            # xcb_container_field
-            field.c_length_name = _n(name + (field.field_name, 'length'))     # xcb_container_field_length
-            field.c_end_name = _n(name + (field.field_name, 'end'))           # xcb_container_field_end
-
-            field.prev_varsized_field = prev_varsized_field
-            field.prev_varsized_offset = prev_varsized_offset
-
-            if prev_varsized_offset == 0:
-                first_field_after_varsized = field
-            field.first_field_after_varsized = first_field_after_varsized
-
-            if field.type.fixed_size():
-                prev_varsized_offset += field.type.size
-            else:
-                self.last_varsized_field = field
-                prev_varsized_field = field
-                prev_varsized_offset = 0
-
-def _c_iterator_get_end(field, accum):
-    '''
-    Figures out what C code is needed to find the end of a variable-length structure field.
-    For nested structures, recurses into its last variable-sized field.
-    For lists, calls the end function
-    '''
-    if field.type.is_container:
-        accum = field.c_accessor_name + '(' + accum + ')'
-        # XXX there could be fixed-length fields at the end
-        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.member.is_simple:
-            return field.c_end_name + '(' + accum + ')'
-        else:
-            return field.type.member.c_end_name + '(' + field.c_iterator_name + '(' + accum + '))'
-
-def _c_iterator(self, name):
-    '''
-    Declares the iterator structure and next/end functions for a given type.
-    '''
-    _h_setlevel(0)
-    _h('')
-    _h('/**')
-    _h(' * @brief %s', self.c_iterator_type)
-    _h(' **/')
-    _h('typedef struct %s {', self.c_iterator_type)
-    _h('    %s *data; /**<  */', self.c_type)
-    _h('    int%s rem; /**<  */', ' ' * (len(self.c_type) - 2))
-    _h('    int%s index; /**<  */', ' ' * (len(self.c_type) - 2))
-    _h('} %s;', self.c_iterator_type)
-
-    _h_setlevel(1)
-    _c_setlevel(1)
-    _h('')
-    _h('/**')
-    _h(' * Get the next element of the iterator')
-    _h(' * @param i Pointer to a %s', self.c_iterator_type)
-    _h(' *')
-    _h(' * Get the next element in the iterator. The member rem is')
-    _h(' * decreased by one. The member data points to the next')
-    _h(' * element. The member index is increased by sizeof(%s)', self.c_type)
-    _h(' */')
-    _c('')
-    _hc('')
-    _hc('/*****************************************************************************')
-    _hc(' **')
-    _hc(' ** void %s', self.c_next_name)
-    _hc(' ** ')
-    _hc(' ** @param %s *i', self.c_iterator_type)
-    _hc(' ** @returns void')
-    _hc(' **')
-    _hc(' *****************************************************************************/')
-    _hc(' ')
-    _hc('void')
-    _h('%s (%s *i  /**< */);', self.c_next_name, self.c_iterator_type)
-    _c('%s (%s *i  /**< */)', self.c_next_name, self.c_iterator_type)
-    _c('{')
-
-    if not self.fixed_size():
-        _c('    %s *R = i->data;', self.c_type)
-        _c('    xcb_generic_iterator_t child = %s;', _c_iterator_get_end(self.last_varsized_field, 'R'))
-        _c('    --i->rem;')
-        _c('    i->data = (%s *) child.data;', self.c_type)
-        _c('    i->index = child.index;')
-    else:
-        _c('    --i->rem;')
-        _c('    ++i->data;')
-        _c('    i->index += sizeof(%s);', self.c_type)
-
-    _c('}')
-
-    _h('')
-    _h('/**')
-    _h(' * Return the iterator pointing to the last element')
-    _h(' * @param i An %s', self.c_iterator_type)
-    _h(' * @return  The iterator pointing to the last element')
-    _h(' *')
-    _h(' * Set the current element in the iterator to the last element.')
-    _h(' * The member rem is set to 0. The member data points to the')
-    _h(' * last element.')
-    _h(' */')
-    _c('')
-    _hc('')
-    _hc('/*****************************************************************************')
-    _hc(' **')
-    _hc(' ** xcb_generic_iterator_t %s', self.c_end_name)
-    _hc(' ** ')
-    _hc(' ** @param %s i', self.c_iterator_type)
-    _hc(' ** @returns xcb_generic_iterator_t')
-    _hc(' **')
-    _hc(' *****************************************************************************/')
-    _hc(' ')
-    _hc('xcb_generic_iterator_t')
-    _h('%s (%s i  /**< */);', self.c_end_name, self.c_iterator_type)
-    _c('%s (%s i  /**< */)', self.c_end_name, self.c_iterator_type)
-    _c('{')
-    _c('    xcb_generic_iterator_t ret;')
-
-    if self.fixed_size():
-        _c('    ret.data = i.data + i.rem;')
-        _c('    ret.index = i.index + ((char *) ret.data - (char *) i.data);')
-        _c('    ret.rem = 0;')
-    else:
-        _c('    while(i.rem > 0)')
-        _c('        %s(&i);', self.c_next_name)
-        _c('    ret.data = i.data;')
-        _c('    ret.rem = i.rem;')
-        _c('    ret.index = i.index;')
-
-    _c('    return ret;')
-    _c('}')
-
-def _c_accessor_get_length(expr, prefix=''):
-    '''
-    Figures out what C code is needed to get a length field.
-    For fields that follow a variable-length field, use the accessor.
-    Otherwise, just reference the structure field directly.
-    '''
-    prefarrow = '' if prefix == '' else prefix + '->'
-
-    if expr.lenfield != None and expr.lenfield.prev_varsized_field != None:
-        return expr.lenfield.c_accessor_name + '(' + prefix + ')'
-    elif expr.lenfield_name != None:
-        return prefarrow + expr.lenfield_name
-    else:
-        return str(expr.nmemb)
-
-def _c_accessor_get_expr(expr, prefix=''):
-    '''
-    Figures out what C code is needed to get the length of a list field.
-    Recurses for math operations.
-    Returns bitcount for value-mask fields.
-    Otherwise, uses the value of the length field.
-    '''
-    lenexp = _c_accessor_get_length(expr, prefix)
-
-    if expr.op != None:
-        return '(' + _c_accessor_get_expr(expr.lhs, prefix) + ' ' + expr.op + ' ' + _c_accessor_get_expr(expr.rhs, prefix) + ')'
-    elif expr.bitfield:
-        return 'xcb_popcount(' + lenexp + ')'
-    else:
-        return lenexp
-
-def _c_accessors_field(self, field):
-    '''
-    Declares the accessor functions for a non-list field that follows a variable-length field.
-    '''
-    if field.type.is_simple:
-        _hc('')
-        _hc('')
-        _hc('/*****************************************************************************')
-        _hc(' **')
-        _hc(' ** %s %s', field.c_field_type, field.c_accessor_name)
-        _hc(' ** ')
-        _hc(' ** @param const %s *R', self.c_type)
-        _hc(' ** @returns %s', field.c_field_type)
-        _hc(' **')
-        _hc(' *****************************************************************************/')
-        _hc(' ')
-        _hc('%s', field.c_field_type)
-        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
-        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
-        _c('{')
-        _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
-        _c('    return * (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
-        _c('}')
-    else:
-        _hc('')
-        _hc('')
-        _hc('/*****************************************************************************')
-        _hc(' **')
-        _hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
-        _hc(' ** ')
-        _hc(' ** @param const %s *R', self.c_type)
-        _hc(' ** @returns %s *', field.c_field_type)
-        _hc(' **')
-        _hc(' *****************************************************************************/')
-        _hc(' ')
-        _hc('%s *', field.c_field_type)
-        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
-        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
-        _c('{')
-        _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
-        _c('    return (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
-        _c('}')
-    
-def _c_accessors_list(self, field):
-    '''
-    Declares the accessor functions for a list field.
-    Declares a direct-accessor function only if the list members are fixed size.
-    Declares length and get-iterator functions always.
-    '''
-    list = field.type
-
-    _h_setlevel(1)
-    _c_setlevel(1)
-    if list.member.fixed_size():
-        _hc('')
-        _hc('')
-        _hc('/*****************************************************************************')
-        _hc(' **')
-        _hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
-        _hc(' ** ')
-        _hc(' ** @param const %s *R', self.c_type)
-        _hc(' ** @returns %s *', field.c_field_type)
-        _hc(' **')
-        _hc(' *****************************************************************************/')
-        _hc(' ')
-        _hc('%s *', field.c_field_type)
-        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
-        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
-        _c('{')
-
-        if field.prev_varsized_field == None:
-            _c('    return (%s *) (R + 1);', field.c_field_type)
-        else:
-            _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
-            _c('    return (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
-
-        _c('}')
-
-    _hc('')
-    _hc('')
-    _hc('/*****************************************************************************')
-    _hc(' **')
-    _hc(' ** int %s', field.c_length_name)
-    _hc(' ** ')
-    _hc(' ** @param const %s *R', self.c_type)
-    _hc(' ** @returns int')
-    _hc(' **')
-    _hc(' *****************************************************************************/')
-    _hc(' ')
-    _hc('int')
-    _h('%s (const %s *R  /**< */);', field.c_length_name, self.c_type)
-    _c('%s (const %s *R  /**< */)', field.c_length_name, self.c_type)
-    _c('{')
-    _c('    return %s;', _c_accessor_get_expr(field.type.expr, 'R'))
-    _c('}')
-
-    if field.type.member.is_simple:
-        _hc('')
-        _hc('')
-        _hc('/*****************************************************************************')
-        _hc(' **')
-        _hc(' ** xcb_generic_iterator_t %s', field.c_end_name)
-        _hc(' ** ')
-        _hc(' ** @param const %s *R', self.c_type)
-        _hc(' ** @returns xcb_generic_iterator_t')
-        _hc(' **')
-        _hc(' *****************************************************************************/')
-        _hc(' ')
-        _hc('xcb_generic_iterator_t')
-        _h('%s (const %s *R  /**< */);', field.c_end_name, self.c_type)
-        _c('%s (const %s *R  /**< */)', field.c_end_name, self.c_type)
-        _c('{')
-        _c('    xcb_generic_iterator_t i;')
-
-        if field.prev_varsized_field == None:
-            _c('    i.data = ((%s *) (R + 1)) + (%s);', field.type.c_wiretype, _c_accessor_get_expr(field.type.expr, 'R'))
-        else:
-            _c('    xcb_generic_iterator_t child = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
-            _c('    i.data = ((%s *) child.data) + (%s);', field.type.c_wiretype, _c_accessor_get_expr(field.type.expr, 'R'))
-
-        _c('    i.rem = 0;')
-        _c('    i.index = (char *) i.data - (char *) R;')
-        _c('    return i;')
-        _c('}')
-
-    else:
-        _hc('')
-        _hc('')
-        _hc('/*****************************************************************************')
-        _hc(' **')
-        _hc(' ** %s %s', field.c_iterator_type, field.c_iterator_name)
-        _hc(' ** ')
-        _hc(' ** @param const %s *R', self.c_type)
-        _hc(' ** @returns %s', field.c_iterator_type)
-        _hc(' **')
-        _hc(' *****************************************************************************/')
-        _hc(' ')
-        _hc('%s', field.c_iterator_type)
-        _h('%s (const %s *R  /**< */);', field.c_iterator_name, self.c_type)
-        _c('%s (const %s *R  /**< */)', field.c_iterator_name, self.c_type)
-        _c('{')
-        _c('    %s i;', field.c_iterator_type)
-
-        if field.prev_varsized_field == None:
-            _c('    i.data = (%s *) (R + 1);', field.c_field_type)
-        else:
-            _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
-            _c('    i.data = (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index));', field.c_field_type, field.c_field_type)
-
-        _c('    i.rem = %s;', _c_accessor_get_expr(field.type.expr, 'R'))
-        _c('    i.index = (char *) i.data - (char *) R;')
-        _c('    return i;')
-        _c('}')
-
-def _c_accessors(self, name, base):
-    '''
-    Declares the accessor functions for the fields of a structure.
-    '''
-    for field in self.fields:
-        if field.type.is_list and not field.type.fixed_size():
-            _c_accessors_list(self, field)
-        elif field.prev_varsized_field != None:
-            _c_accessors_field(self, field)
-
-def c_simple(self, name):
-    '''
-    Exported function that handles cardinal type declarations.
-    These are types which are typedef'd to one of the CARDx's, char, float, etc.
-    '''
-    _c_type_setup(self, name, ())
-
-    if (self.name != name):
-        # Typedef
-        _h_setlevel(0)
-        my_name = _t(name)
-        _h('')
-        _h('typedef %s %s;', _t(self.name), my_name)
-
-        # Iterator
-        _c_iterator(self, name)
-
-def _c_complex(self):
-    '''
-    Helper function for handling all structure types.
-    Called for all structs, requests, replies, events, errors.
-    '''
-    _h_setlevel(0)
-    _h('')
-    _h('/**')
-    _h(' * @brief %s', self.c_type)
-    _h(' **/')
-    _h('typedef %s %s {', self.c_container, self.c_type)
-
-    struct_fields = []
-    maxtypelen = 0
-
-    varfield = None
-    for field in self.fields:
-        if not field.type.fixed_size():
-            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)
-        
-    for field in struct_fields:
-        if len(field.c_field_type) > maxtypelen:
-            maxtypelen = len(field.c_field_type)
-
-    for field in struct_fields:
-        spacing = ' ' * (maxtypelen - len(field.c_field_type))
-        _h('    %s%s %s%s; /**<  */', field.c_field_type, spacing, field.c_field_name, field.c_subscript)
-
-    _h('} %s;', self.c_type)
-
-def c_struct(self, name):
-    '''
-    Exported function that handles structure declarations.
-    '''
-    _c_type_setup(self, name, ())
-    _c_complex(self)
-    _c_accessors(self, name, name)
-    _c_iterator(self, name)
-
-def c_union(self, name):
-    '''
-    Exported function that handles union declarations.
-    '''
-    _c_type_setup(self, name, ())
-    _c_complex(self)
-    _c_iterator(self, name)
-
-def _c_request_helper(self, name, cookie_type, void, regular):
-    '''
-    Declares a request function.
-    '''
-
-    # Four stunningly confusing possibilities here:
-    #
-    #   Void            Non-void
-    # ------------------------------
-    # "req"            "req"
-    # 0 flag           CHECKED flag   Normal Mode
-    # void_cookie      req_cookie
-    # ------------------------------
-    # "req_checked"    "req_unchecked"
-    # CHECKED flag     0 flag         Abnormal Mode
-    # void_cookie      req_cookie
-    # ------------------------------
-
-
-    # Whether we are _checked or _unchecked
-    checked = void and not regular
-    unchecked = not void and not regular
-
-    # What kind of cookie we return
-    func_cookie = 'xcb_void_cookie_t' if void else self.c_cookie_type
-
-    # What flag is passed to xcb_request
-    func_flags = '0' if (void and regular) or (not void and not regular) else 'XCB_REQUEST_CHECKED'
-
-    # Global extension id variable or NULL for xproto
-    func_ext_global = '&' + _ns.c_ext_global_name if _ns.is_ext else '0'
-
-    # What our function name is
-    func_name = self.c_request_name
-    if checked:
-        func_name = self.c_checked_name
-    if unchecked:
-        func_name = self.c_unchecked_name
-
-    param_fields = []
-    wire_fields = []
-    maxtypelen = len('xcb_connection_t')
-
-    for field in self.fields:
-        if field.visible:
-            # The field should appear as a call parameter
-            param_fields.append(field)
-        if field.wire and not field.auto:
-            # We need to set the field up in the structure
-            wire_fields.append(field)
-        
-    for field in param_fields:
-        if len(field.c_field_const_type) > maxtypelen:
-            maxtypelen = len(field.c_field_const_type)
-
-    _h_setlevel(1)
-    _c_setlevel(1)
-    _h('')
-    _h('/**')
-    _h(' * Delivers a request to the X server')
-    _h(' * @param c The connection')
-    _h(' * @return A cookie')
-    _h(' *')
-    _h(' * Delivers a request to the X server.')
-    _h(' * ')
-    if checked:
-        _h(' * This form can be used only if the request will not cause')
-        _h(' * a reply to be generated. Any returned error will be')
-        _h(' * saved for handling by xcb_request_check().')
-    if unchecked:
-        _h(' * This form can be used only if the request will cause')
-        _h(' * a reply to be generated. Any returned error will be')
-        _h(' * placed in the event queue.')
-    _h(' */')
-    _c('')
-    _hc('')
-    _hc('/*****************************************************************************')
-    _hc(' **')
-    _hc(' ** %s %s', cookie_type, func_name)
-    _hc(' ** ')
-
-    spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
-    _hc(' ** @param xcb_connection_t%s *c', spacing)
-
-    for field in param_fields:
-        spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
-        _hc(' ** @param %s%s %s%s', field.c_field_const_type, spacing, field.c_pointer, field.c_field_name)
-
-    _hc(' ** @returns %s', cookie_type)
-    _hc(' **')
-    _hc(' *****************************************************************************/')
-    _hc(' ')
-    _hc('%s', cookie_type)
-
-    spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
-    comma = ',' if len(param_fields) else ');'
-    _h('%s (xcb_connection_t%s *c  /**< */%s', func_name, spacing, comma)
-    comma = ',' if len(param_fields) else ')'
-    _c('%s (xcb_connection_t%s *c  /**< */%s', func_name, spacing, comma)
-
-    func_spacing = ' ' * (len(func_name) + 2)
-    count = len(param_fields)
-    for field in param_fields:
-        count = count - 1
-        spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
-        comma = ',' if count else ');'
-        _h('%s%s%s %s%s  /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
-        comma = ',' if count else ')'
-        _c('%s%s%s %s%s  /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
-
-    count = 2
-    for field in param_fields:
-        if not field.type.fixed_size():
-            count = count + 2
-
-    _c('{')
-    _c('    static const xcb_protocol_request_t xcb_req = {')
-    _c('        /* count */ %d,', count)
-    _c('        /* ext */ %s,', func_ext_global)
-    _c('        /* opcode */ %s,', self.c_request_name.upper())
-    _c('        /* isvoid */ %d', 1 if void else 0)
-    _c('    };')
-    _c('    ')
-    _c('    struct iovec xcb_parts[%d];', count + 2)
-    _c('    %s xcb_ret;', func_cookie)
-    _c('    %s xcb_out;', self.c_type)
-    _c('    ')
-
-    for field in wire_fields:
-        if field.type.fixed_size():
-            if field.type.is_expr:
-                _c('    xcb_out.%s = %s;', field.c_field_name, _c_accessor_get_expr(field.type.expr))
-
-            elif field.type.is_pad:
-                if field.type.nmemb == 1:
-                    _c('    xcb_out.%s = 0;', field.c_field_name)
-                else:
-                    _c('    memset(xcb_out.%s, 0, %d);', field.c_field_name, field.type.nmemb)
-            else:
-                if field.type.nmemb == 1:
-                    _c('    xcb_out.%s = %s;', field.c_field_name, field.c_field_name)
-                else:
-                    _c('    memcpy(xcb_out.%s, %s, %d);', field.c_field_name, field.c_field_name, field.type.nmemb)
-
-    _c('    ')
-    _c('    xcb_parts[2].iov_base = (char *) &xcb_out;')
-    _c('    xcb_parts[2].iov_len = sizeof(xcb_out);')
-    _c('    xcb_parts[3].iov_base = 0;')
-    _c('    xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;')
-
-    count = 4
-    for field in param_fields:
-        if not field.type.fixed_size():
-            _c('    xcb_parts[%d].iov_base = (char *) %s;', count, field.c_field_name)
-            if field.type.is_list:
-                _c('    xcb_parts[%d].iov_len = %s * sizeof(%s);', count, _c_accessor_get_expr(field.type.expr), field.type.member.c_wiretype)
-            else:
-                _c('    xcb_parts[%d].iov_len = %s * sizeof(%s);', count, 'Uh oh', field.type.c_wiretype)
-            _c('    xcb_parts[%d].iov_base = 0;', count + 1)
-            _c('    xcb_parts[%d].iov_len = -xcb_parts[%d].iov_len & 3;', count + 1, count)
-            count = count + 2
-
-    _c('    xcb_ret.sequence = xcb_send_request(c, %s, xcb_parts + 2, &xcb_req);', func_flags)
-    _c('    return xcb_ret;')
-    _c('}')
-
-def _c_reply(self, name):
-    '''
-    Declares the function that returns the reply structure.
-    '''
-    spacing1 = ' ' * (len(self.c_cookie_type) - len('xcb_connection_t'))
-    spacing2 = ' ' * (len(self.c_cookie_type) - len('xcb_generic_error_t'))
-    spacing3 = ' ' * (len(self.c_reply_name) + 2)
-
-    _h('')
-    _h('/**')
-    _h(' * Return the reply')
-    _h(' * @param c      The connection')
-    _h(' * @param cookie The cookie')
-    _h(' * @param e      The xcb_generic_error_t supplied')
-    _h(' *')
-    _h(' * Returns the reply of the request asked by')
-    _h(' * ')
-    _h(' * The parameter @p e supplied to this function must be NULL if')
-    _h(' * %s(). is used.', self.c_unchecked_name)
-    _h(' * Otherwise, it stores the error if any.')
-    _h(' *')
-    _h(' * The returned value must be freed by the caller using free().')
-    _h(' */')
-    _c('')
-    _hc('')
-    _hc('/*****************************************************************************')
-    _hc(' **')
-    _hc(' ** %s * %s', self.c_reply_type, self.c_reply_name)
-    _hc(' ** ')
-    _hc(' ** @param xcb_connection_t%s  *c', spacing1)
-    _hc(' ** @param %s   cookie', self.c_cookie_type)
-    _hc(' ** @param xcb_generic_error_t%s **e', spacing2)
-    _hc(' ** @returns %s *', self.c_reply_type)
-    _hc(' **')
-    _hc(' *****************************************************************************/')
-    _hc(' ')
-    _hc('%s *', self.c_reply_type)
-    _hc('%s (xcb_connection_t%s  *c  /**< */,', self.c_reply_name, spacing1)
-    _hc('%s%s   cookie  /**< */,', spacing3, self.c_cookie_type)
-    _h('%sxcb_generic_error_t%s **e  /**< */);', spacing3, spacing2)
-    _c('%sxcb_generic_error_t%s **e  /**< */)', spacing3, spacing2)
-    _c('{')
-    _c('    return (%s *) xcb_wait_for_reply(c, cookie.sequence, e);', self.c_reply_type)
-    _c('}')
-
-def _c_opcode(name, opcode):
-    '''
-    Declares the opcode define for requests, events, and errors.
-    '''
-    _h_setlevel(0)
-    _h('')
-    _h('/** Opcode for %s. */', _n(name))
-    _h('#define %s %s', _n(name).upper(), opcode)
-    
-def _c_cookie(self, name):
-    '''
-    Declares the cookie type for a non-void request.
-    '''
-    _h_setlevel(0)
-    _h('')
-    _h('/**')
-    _h(' * @brief %s', self.c_cookie_type)
-    _h(' **/')
-    _h('typedef struct %s {', self.c_cookie_type)
-    _h('    unsigned int sequence; /**<  */')
-    _h('} %s;', self.c_cookie_type)
-
-def c_request(self, name):
-    '''
-    Exported function that handles request declarations.
-    '''
-    _c_type_setup(self, name, ('request',))
-
-    if self.reply:
-        # Cookie type declaration
-        _c_cookie(self, name)
-
-    # Opcode define
-    _c_opcode(name, self.opcode)
-
-    # Request structure declaration
-    _c_complex(self)
-
-    if self.reply:
-        _c_type_setup(self.reply, name, ('reply',))
-        # Reply structure definition
-        _c_complex(self.reply)
-        # Request prototypes
-        _c_request_helper(self, name, self.c_cookie_type, False, True)
-        _c_request_helper(self, name, self.c_cookie_type, False, False)
-        # Reply accessors
-        _c_accessors(self.reply, name + ('reply',), name)
-        _c_reply(self, name)
-    else:
-        # Request prototypes
-        _c_request_helper(self, name, 'xcb_void_cookie_t', True, False)
-        _c_request_helper(self, name, 'xcb_void_cookie_t', True, True)
-
-def c_event(self, name):
-    '''
-    Exported function that handles event declarations.
-    '''
-    _c_type_setup(self, name, ('event',))
-
-    # Opcode define
-    _c_opcode(name, self.opcodes[name])
-
-    if self.name == name:
-        # Structure definition
-        _c_complex(self)
-    else:
-        # Typedef
-        _h('')
-        _h('typedef %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
-
-def c_error(self, name):
-    '''
-    Exported function that handles error declarations.
-    '''
-    _c_type_setup(self, name, ('error',))
-
-    # Opcode define
-    _c_opcode(name, self.opcodes[name])
-
-    if self.name == name:
-        # Structure definition
-        _c_complex(self)
-    else:
-        # Typedef
-        _h('')
-        _h('typedef %s %s;', _t(self.name + ('error',)), _t(name + ('error',)))
-
-
-# Main routine starts here
-
-# Must create an "output" dictionary before any xcbgen imports.
-output = {'open'    : c_open,
-          'close'   : c_close,
-          'simple'  : c_simple,
-          'enum'    : c_enum,
-          'struct'  : c_struct,
-          'union'   : c_union,
-          'request' : c_request,
-          'event'   : c_event,
-          'error'   : c_error
-          }
-
-# 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
-except ImportError:
-    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 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(args[0], output)
-
-# Build type-registry and resolve type dependencies
-module.register()
-module.resolve()
-
-# Output the code
-module.generate()
+#!/usr/bin/env python
+from xml.etree.cElementTree import *
+from os.path import basename
+import getopt
+import sys
+import re
+
+# Jump to the bottom of this file for the main routine
+
+# Some hacks to make the API more readable, and to keep backwards compability
+_cname_re = re.compile('([A-Z0-9][a-z]+|[A-Z0-9]+(?![a-z])|[a-z]+)')
+_cname_special_cases = {'DECnet':'decnet'}
+
+_extension_special_cases = ['XPrint', 'XCMisc', 'BigRequests']
+
+_cplusplus_annoyances = {'class' : '_class',
+                         'new'   : '_new',
+                         'delete': '_delete'}
+
+_hlines = []
+_hlevel = 0
+_clines = []
+_clevel = 0
+_ns = None
+
+def _h(fmt, *args):
+    '''
+    Writes the given line to the header file.
+    '''
+    _hlines[_hlevel].append(fmt % args)
+    
+def _c(fmt, *args):
+    '''
+    Writes the given line to the source file.
+    '''
+    _clines[_clevel].append(fmt % args)
+    
+def _hc(fmt, *args):
+    '''
+    Writes the given line to both the header and source files.
+    '''
+    _h(fmt, *args)
+    _c(fmt, *args)
+
+# XXX See if this level thing is really necessary.
+def _h_setlevel(idx):
+    '''
+    Changes the array that header lines are written to.
+    Supports writing different sections of the header file.
+    '''
+    global _hlevel
+    while len(_hlines) <= idx:
+        _hlines.append([])
+    _hlevel = idx
+    
+def _c_setlevel(idx):
+    '''
+    Changes the array that source lines are written to.
+    Supports writing to different sections of the source file.
+    '''
+    global _clevel
+    while len(_clines) <= idx:
+        _clines.append([])
+    _clevel = idx
+    
+def _n_item(str):
+    '''
+    Does C-name conversion on a single string fragment.
+    Uses a regexp with some hard-coded special cases.
+    '''
+    if str in _cname_special_cases:
+        return _cname_special_cases[str]
+    else:
+        split = _cname_re.finditer(str)
+        name_parts = [match.group(0) for match in split]
+        return '_'.join(name_parts)
+    
+def _cpp(str):
+    '''
+    Checks for certain C++ reserved words and fixes them.
+    '''
+    if str in _cplusplus_annoyances:
+        return _cplusplus_annoyances[str]
+    else:
+        return str
+
+def _ext(str):
+    '''
+    Does C-name conversion on an extension name.
+    Has some additional special cases on top of _n_item.
+    '''
+    if str in _extension_special_cases:
+        return _n_item(str).lower()
+    else:
+        return str.lower()
+    
+def _n(list):
+    '''
+    Does C-name conversion on a tuple of strings.
+    Different behavior depending on length of tuple, extension/not extension, etc.
+    Basically C-name converts the individual pieces, then joins with underscores.
+    '''
+    if len(list) == 1:
+        parts = list
+    elif len(list) == 2:
+        parts = [list[0], _n_item(list[1])]
+    elif _ns.is_ext:
+        parts = [list[0], _ext(list[1])] + [_n_item(i) for i in list[2:]]
+    else:
+        parts = [list[0]] + [_n_item(i) for i in list[1:]]
+    return '_'.join(parts).lower()
+
+def _t(list):
+    '''
+    Does C-name conversion on a tuple of strings representing a type.
+    Same as _n but adds a "_t" on the end.
+    '''
+    if len(list) == 1:
+        parts = list
+    elif len(list) == 2:
+        parts = [list[0], _n_item(list[1]), 't']
+    elif _ns.is_ext:
+        parts = [list[0], _ext(list[1])] + [_n_item(i) for i in list[2:]] + ['t']
+    else:
+        parts = [list[0]] + [_n_item(i) for i in list[1:]] + ['t']
+    return '_'.join(parts).lower()
+        
+
+def c_open(self):
+    '''
+    Exported function that handles module open.
+    Opens the files and writes out the auto-generated comment, header file includes, etc.
+    '''
+    global _ns
+    _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)
+
+    _hc('/*')
+    _hc(' * This file generated automatically from %s by c_client.py.', _ns.file)
+    _hc(' * Edit at your peril.')
+    _hc(' */')
+    _hc('')
+
+    _h('/**')
+    _h(' * @defgroup XCB_%s_API XCB %s API', _ns.ext_name, _ns.ext_name)
+    _h(' * @brief %s XCB Protocol Implementation.', _ns.ext_name)
+    _h(' * @{')
+    _h(' **/')
+    _h('')
+    _h('#ifndef __%s_H', _ns.header.upper())
+    _h('#define __%s_H', _ns.header.upper())
+    _h('')
+    _h('#include "xcb.h"')
+
+    _c('#include <string.h>')
+    _c('#include <assert.h>')
+    _c('#include "xcbext.h"')
+    _c('#include "%s.h"', _ns.header)
+        
+    if _ns.is_ext:
+        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('  ') #XXX
+        _h('extern xcb_extension_t %s;', _ns.c_ext_global_name)
+
+        _c('')
+        _c('xcb_extension_t %s = { "%s", 0 };', _ns.c_ext_global_name, _ns.ext_xname)
+
+def c_close(self):
+    '''
+    Exported function that handles module close.
+    Writes out all the stored content lines, then closes the files.
+    '''
+    _h_setlevel(2)
+    _c_setlevel(2)
+    _hc('')
+
+    _h('')
+    _h('#ifdef __cplusplus')
+    _h('}')
+    _h('#endif')
+
+    _h('')
+    _h('#endif')
+    _h('')
+    _h('/**')
+    _h(' * @}')
+    _h(' */')
+
+    # Write header file
+    hfile = open('%s.h' % _ns.header, 'w')
+    for list in _hlines:
+        for line in list:
+            hfile.write(line)
+            hfile.write('\n')
+    hfile.close()
+
+    # Write source file
+    cfile = open('%s.c' % _ns.header, 'w')
+    for list in _clines:
+        for line in list:
+            cfile.write(line)
+            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 {', tname)
+
+    count = len(self.values)
+
+    for (enam, eval) in self.values:
+        count = count - 1
+        equals = ' = ' if eval != '' else ''
+        comma = ',' if count > 0 else ''
+        _h('    %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
+
+    _h('} %s;', tname)
+
+def _c_type_setup(self, name, postfix):
+    '''
+    Sets up all the C-related state by adding additional data fields to
+    all Field and Type objects.  Here is where we figure out most of our
+    variable and function names.
+
+    Recurses into child fields and list member types.
+    '''
+    # Do all the various names in advance
+    self.c_type = _t(name + postfix)
+    self.c_wiretype = 'char' if self.c_type == 'void' else self.c_type
+
+    self.c_iterator_type = _t(name + ('iterator',))
+    self.c_next_name = _n(name + ('next',))
+    self.c_end_name = _n(name + ('end',))
+
+    self.c_request_name = _n(name)
+    self.c_checked_name = _n(name + ('checked',))
+    self.c_unchecked_name = _n(name + ('unchecked',))
+    self.c_reply_name = _n(name + ('reply',))
+    self.c_reply_type = _t(name + ('reply',))
+    self.c_cookie_type = _t(name + ('cookie',))
+
+    if self.is_container:
+
+        self.c_container = 'union' if self.is_union else 'struct'
+        prev_varsized_field = None
+        prev_varsized_offset = 0
+        first_field_after_varsized = None
+
+        for field in self.fields:
+            _c_type_setup(field.type, field.field_type, ())
+            if field.type.is_list:
+                _c_type_setup(field.type.member, field.field_type, ())
+
+            field.c_field_type = _t(field.field_type)
+            field.c_field_const_type = ('' if field.type.nmemb == 1 else 'const ') + field.c_field_type
+            field.c_field_name = _cpp(field.field_name)
+            field.c_subscript = '[%d]' % field.type.nmemb if (field.type.nmemb > 1) else ''
+            field.c_pointer = ' ' if field.type.nmemb == 1 else '*'
+
+            field.c_iterator_type = _t(field.field_type + ('iterator',))      # xcb_fieldtype_iterator_t
+            field.c_iterator_name = _n(name + (field.field_name, 'iterator')) # xcb_container_field_iterator
+            field.c_accessor_name = _n(name + (field.field_name,))            # xcb_container_field
+            field.c_length_name = _n(name + (field.field_name, 'length'))     # xcb_container_field_length
+            field.c_end_name = _n(name + (field.field_name, 'end'))           # xcb_container_field_end
+
+            field.prev_varsized_field = prev_varsized_field
+            field.prev_varsized_offset = prev_varsized_offset
+
+            if prev_varsized_offset == 0:
+                first_field_after_varsized = field
+            field.first_field_after_varsized = first_field_after_varsized
+
+            if field.type.fixed_size():
+                prev_varsized_offset += field.type.size
+            else:
+                self.last_varsized_field = field
+                prev_varsized_field = field
+                prev_varsized_offset = 0
+
+def _c_iterator_get_end(field, accum):
+    '''
+    Figures out what C code is needed to find the end of a variable-length structure field.
+    For nested structures, recurses into its last variable-sized field.
+    For lists, calls the end function
+    '''
+    if field.type.is_container:
+        accum = field.c_accessor_name + '(' + accum + ')'
+        # XXX there could be fixed-length fields at the end
+        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.member.is_simple:
+            return field.c_end_name + '(' + accum + ')'
+        else:
+            return field.type.member.c_end_name + '(' + field.c_iterator_name + '(' + accum + '))'
+
+def _c_iterator(self, name):
+    '''
+    Declares the iterator structure and next/end functions for a given type.
+    '''
+    _h_setlevel(0)
+    _h('')
+    _h('/**')
+    _h(' * @brief %s', self.c_iterator_type)
+    _h(' **/')
+    _h('typedef struct %s {', self.c_iterator_type)
+    _h('    %s *data; /**<  */', self.c_type)
+    _h('    int%s rem; /**<  */', ' ' * (len(self.c_type) - 2))
+    _h('    int%s index; /**<  */', ' ' * (len(self.c_type) - 2))
+    _h('} %s;', self.c_iterator_type)
+
+    _h_setlevel(1)
+    _c_setlevel(1)
+    _h('')
+    _h('/**')
+    _h(' * Get the next element of the iterator')
+    _h(' * @param i Pointer to a %s', self.c_iterator_type)
+    _h(' *')
+    _h(' * Get the next element in the iterator. The member rem is')
+    _h(' * decreased by one. The member data points to the next')
+    _h(' * element. The member index is increased by sizeof(%s)', self.c_type)
+    _h(' */')
+    _c('')
+    _hc('')
+    _hc('/*****************************************************************************')
+    _hc(' **')
+    _hc(' ** void %s', self.c_next_name)
+    _hc(' ** ')
+    _hc(' ** @param %s *i', self.c_iterator_type)
+    _hc(' ** @returns void')
+    _hc(' **')
+    _hc(' *****************************************************************************/')
+    _hc(' ')
+    _hc('void')
+    _h('%s (%s *i  /**< */);', self.c_next_name, self.c_iterator_type)
+    _c('%s (%s *i  /**< */)', self.c_next_name, self.c_iterator_type)
+    _c('{')
+
+    if not self.fixed_size():
+        _c('    %s *R = i->data;', self.c_type)
+        _c('    xcb_generic_iterator_t child = %s;', _c_iterator_get_end(self.last_varsized_field, 'R'))
+        _c('    --i->rem;')
+        _c('    i->data = (%s *) child.data;', self.c_type)
+        _c('    i->index = child.index;')
+    else:
+        _c('    --i->rem;')
+        _c('    ++i->data;')
+        _c('    i->index += sizeof(%s);', self.c_type)
+
+    _c('}')
+
+    _h('')
+    _h('/**')
+    _h(' * Return the iterator pointing to the last element')
+    _h(' * @param i An %s', self.c_iterator_type)
+    _h(' * @return  The iterator pointing to the last element')
+    _h(' *')
+    _h(' * Set the current element in the iterator to the last element.')
+    _h(' * The member rem is set to 0. The member data points to the')
+    _h(' * last element.')
+    _h(' */')
+    _c('')
+    _hc('')
+    _hc('/*****************************************************************************')
+    _hc(' **')
+    _hc(' ** xcb_generic_iterator_t %s', self.c_end_name)
+    _hc(' ** ')
+    _hc(' ** @param %s i', self.c_iterator_type)
+    _hc(' ** @returns xcb_generic_iterator_t')
+    _hc(' **')
+    _hc(' *****************************************************************************/')
+    _hc(' ')
+    _hc('xcb_generic_iterator_t')
+    _h('%s (%s i  /**< */);', self.c_end_name, self.c_iterator_type)
+    _c('%s (%s i  /**< */)', self.c_end_name, self.c_iterator_type)
+    _c('{')
+    _c('    xcb_generic_iterator_t ret;')
+
+    if self.fixed_size():
+        _c('    ret.data = i.data + i.rem;')
+        _c('    ret.index = i.index + ((char *) ret.data - (char *) i.data);')
+        _c('    ret.rem = 0;')
+    else:
+        _c('    while(i.rem > 0)')
+        _c('        %s(&i);', self.c_next_name)
+        _c('    ret.data = i.data;')
+        _c('    ret.rem = i.rem;')
+        _c('    ret.index = i.index;')
+
+    _c('    return ret;')
+    _c('}')
+
+def _c_accessor_get_length(expr, prefix=''):
+    '''
+    Figures out what C code is needed to get a length field.
+    For fields that follow a variable-length field, use the accessor.
+    Otherwise, just reference the structure field directly.
+    '''
+    prefarrow = '' if prefix == '' else prefix + '->'
+
+    if expr.lenfield != None and expr.lenfield.prev_varsized_field != None:
+        return expr.lenfield.c_accessor_name + '(' + prefix + ')'
+    elif expr.lenfield_name != None:
+        return prefarrow + expr.lenfield_name
+    else:
+        return str(expr.nmemb)
+
+def _c_accessor_get_expr(expr, prefix=''):
+    '''
+    Figures out what C code is needed to get the length of a list field.
+    Recurses for math operations.
+    Returns bitcount for value-mask fields.
+    Otherwise, uses the value of the length field.
+    '''
+    lenexp = _c_accessor_get_length(expr, prefix)
+
+    if expr.op == '~':
+        return '(' + '~' + _c_accessor_get_expr(expr.rhs, prefix) + ')'
+    elif expr.op != None:
+        return '(' + _c_accessor_get_expr(expr.lhs, prefix) + ' ' + expr.op + ' ' + _c_accessor_get_expr(expr.rhs, prefix) + ')'
+    elif expr.bitfield:
+        return 'xcb_popcount(' + lenexp + ')'
+    else:
+        return lenexp
+
+def _c_accessors_field(self, field):
+    '''
+    Declares the accessor functions for a non-list field that follows a variable-length field.
+    '''
+    if field.type.is_simple:
+        _hc('')
+        _hc('')
+        _hc('/*****************************************************************************')
+        _hc(' **')
+        _hc(' ** %s %s', field.c_field_type, field.c_accessor_name)
+        _hc(' ** ')
+        _hc(' ** @param const %s *R', self.c_type)
+        _hc(' ** @returns %s', field.c_field_type)
+        _hc(' **')
+        _hc(' *****************************************************************************/')
+        _hc(' ')
+        _hc('%s', field.c_field_type)
+        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
+        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
+        _c('{')
+        _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
+        _c('    return * (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+        _c('}')
+    else:
+        _hc('')
+        _hc('')
+        _hc('/*****************************************************************************')
+        _hc(' **')
+        _hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
+        _hc(' ** ')
+        _hc(' ** @param const %s *R', self.c_type)
+        _hc(' ** @returns %s *', field.c_field_type)
+        _hc(' **')
+        _hc(' *****************************************************************************/')
+        _hc(' ')
+        _hc('%s *', field.c_field_type)
+        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
+        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
+        _c('{')
+        _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
+        _c('    return (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+        _c('}')
+    
+def _c_accessors_list(self, field):
+    '''
+    Declares the accessor functions for a list field.
+    Declares a direct-accessor function only if the list members are fixed size.
+    Declares length and get-iterator functions always.
+    '''
+    list = field.type
+
+    _h_setlevel(1)
+    _c_setlevel(1)
+    if list.member.fixed_size():
+        _hc('')
+        _hc('')
+        _hc('/*****************************************************************************')
+        _hc(' **')
+        _hc(' ** %s * %s', field.c_field_type, field.c_accessor_name)
+        _hc(' ** ')
+        _hc(' ** @param const %s *R', self.c_type)
+        _hc(' ** @returns %s *', field.c_field_type)
+        _hc(' **')
+        _hc(' *****************************************************************************/')
+        _hc(' ')
+        _hc('%s *', field.c_field_type)
+        _h('%s (const %s *R  /**< */);', field.c_accessor_name, self.c_type)
+        _c('%s (const %s *R  /**< */)', field.c_accessor_name, self.c_type)
+        _c('{')
+
+        if field.prev_varsized_field == None:
+            _c('    return (%s *) (R + 1);', field.c_field_type)
+        else:
+            _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
+            _c('    return (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+
+        _c('}')
+
+    _hc('')
+    _hc('')
+    _hc('/*****************************************************************************')
+    _hc(' **')
+    _hc(' ** int %s', field.c_length_name)
+    _hc(' ** ')
+    _hc(' ** @param const %s *R', self.c_type)
+    _hc(' ** @returns int')
+    _hc(' **')
+    _hc(' *****************************************************************************/')
+    _hc(' ')
+    _hc('int')
+    _h('%s (const %s *R  /**< */);', field.c_length_name, self.c_type)
+    _c('%s (const %s *R  /**< */)', field.c_length_name, self.c_type)
+    _c('{')
+    _c('    return %s;', _c_accessor_get_expr(field.type.expr, 'R'))
+    _c('}')
+
+    if field.type.member.is_simple:
+        _hc('')
+        _hc('')
+        _hc('/*****************************************************************************')
+        _hc(' **')
+        _hc(' ** xcb_generic_iterator_t %s', field.c_end_name)
+        _hc(' ** ')
+        _hc(' ** @param const %s *R', self.c_type)
+        _hc(' ** @returns xcb_generic_iterator_t')
+        _hc(' **')
+        _hc(' *****************************************************************************/')
+        _hc(' ')
+        _hc('xcb_generic_iterator_t')
+        _h('%s (const %s *R  /**< */);', field.c_end_name, self.c_type)
+        _c('%s (const %s *R  /**< */)', field.c_end_name, self.c_type)
+        _c('{')
+        _c('    xcb_generic_iterator_t i;')
+
+        if field.prev_varsized_field == None:
+            _c('    i.data = ((%s *) (R + 1)) + (%s);', field.type.c_wiretype, _c_accessor_get_expr(field.type.expr, 'R'))
+        else:
+            _c('    xcb_generic_iterator_t child = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
+            _c('    i.data = ((%s *) child.data) + (%s);', field.type.c_wiretype, _c_accessor_get_expr(field.type.expr, 'R'))
+
+        _c('    i.rem = 0;')
+        _c('    i.index = (char *) i.data - (char *) R;')
+        _c('    return i;')
+        _c('}')
+
+    else:
+        _hc('')
+        _hc('')
+        _hc('/*****************************************************************************')
+        _hc(' **')
+        _hc(' ** %s %s', field.c_iterator_type, field.c_iterator_name)
+        _hc(' ** ')
+        _hc(' ** @param const %s *R', self.c_type)
+        _hc(' ** @returns %s', field.c_iterator_type)
+        _hc(' **')
+        _hc(' *****************************************************************************/')
+        _hc(' ')
+        _hc('%s', field.c_iterator_type)
+        _h('%s (const %s *R  /**< */);', field.c_iterator_name, self.c_type)
+        _c('%s (const %s *R  /**< */)', field.c_iterator_name, self.c_type)
+        _c('{')
+        _c('    %s i;', field.c_iterator_type)
+
+        if field.prev_varsized_field == None:
+            _c('    i.data = (%s *) (R + 1);', field.c_field_type)
+        else:
+            _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
+            _c('    i.data = (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index));', field.c_field_type, field.c_field_type)
+
+        _c('    i.rem = %s;', _c_accessor_get_expr(field.type.expr, 'R'))
+        _c('    i.index = (char *) i.data - (char *) R;')
+        _c('    return i;')
+        _c('}')
+
+def _c_accessors(self, name, base):
+    '''
+    Declares the accessor functions for the fields of a structure.
+    '''
+    for field in self.fields:
+        if field.type.is_list and not field.type.fixed_size():
+            _c_accessors_list(self, field)
+        elif field.prev_varsized_field != None:
+            _c_accessors_field(self, field)
+
+def c_simple(self, name):
+    '''
+    Exported function that handles cardinal type declarations.
+    These are types which are typedef'd to one of the CARDx's, char, float, etc.
+    '''
+    _c_type_setup(self, name, ())
+
+    if (self.name != name):
+        # Typedef
+        _h_setlevel(0)
+        my_name = _t(name)
+        _h('')
+        _h('typedef %s %s;', _t(self.name), my_name)
+
+        # Iterator
+        _c_iterator(self, name)
+
+def _c_complex(self):
+    '''
+    Helper function for handling all structure types.
+    Called for all structs, requests, replies, events, errors.
+    '''
+    _h_setlevel(0)
+    _h('')
+    _h('/**')
+    _h(' * @brief %s', self.c_type)
+    _h(' **/')
+    _h('typedef %s %s {', self.c_container, self.c_type)
+
+    struct_fields = []
+    maxtypelen = 0
+
+    varfield = None
+    for field in self.fields:
+        if not field.type.fixed_size():
+            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)
+        
+    for field in struct_fields:
+        if len(field.c_field_type) > maxtypelen:
+            maxtypelen = len(field.c_field_type)
+
+    for field in struct_fields:
+        spacing = ' ' * (maxtypelen - len(field.c_field_type))
+        _h('    %s%s %s%s; /**<  */', field.c_field_type, spacing, field.c_field_name, field.c_subscript)
+
+    _h('} %s;', self.c_type)
+
+def c_struct(self, name):
+    '''
+    Exported function that handles structure declarations.
+    '''
+    _c_type_setup(self, name, ())
+    _c_complex(self)
+    _c_accessors(self, name, name)
+    _c_iterator(self, name)
+
+def c_union(self, name):
+    '''
+    Exported function that handles union declarations.
+    '''
+    _c_type_setup(self, name, ())
+    _c_complex(self)
+    _c_iterator(self, name)
+
+def _c_request_helper(self, name, cookie_type, void, regular):
+    '''
+    Declares a request function.
+    '''
+
+    # Four stunningly confusing possibilities here:
+    #
+    #   Void            Non-void
+    # ------------------------------
+    # "req"            "req"
+    # 0 flag           CHECKED flag   Normal Mode
+    # void_cookie      req_cookie
+    # ------------------------------
+    # "req_checked"    "req_unchecked"
+    # CHECKED flag     0 flag         Abnormal Mode
+    # void_cookie      req_cookie
+    # ------------------------------
+
+
+    # Whether we are _checked or _unchecked
+    checked = void and not regular
+    unchecked = not void and not regular
+
+    # What kind of cookie we return
+    func_cookie = 'xcb_void_cookie_t' if void else self.c_cookie_type
+
+    # What flag is passed to xcb_request
+    func_flags = '0' if (void and regular) or (not void and not regular) else 'XCB_REQUEST_CHECKED'
+
+    # Global extension id variable or NULL for xproto
+    func_ext_global = '&' + _ns.c_ext_global_name if _ns.is_ext else '0'
+
+    # What our function name is
+    func_name = self.c_request_name
+    if checked:
+        func_name = self.c_checked_name
+    if unchecked:
+        func_name = self.c_unchecked_name
+
+    param_fields = []
+    wire_fields = []
+    maxtypelen = len('xcb_connection_t')
+
+    for field in self.fields:
+        if field.visible:
+            # The field should appear as a call parameter
+            param_fields.append(field)
+        if field.wire and not field.auto:
+            # We need to set the field up in the structure
+            wire_fields.append(field)
+        
+    for field in param_fields:
+        if len(field.c_field_const_type) > maxtypelen:
+            maxtypelen = len(field.c_field_const_type)
+
+    _h_setlevel(1)
+    _c_setlevel(1)
+    _h('')
+    _h('/**')
+    _h(' * Delivers a request to the X server')
+    _h(' * @param c The connection')
+    _h(' * @return A cookie')
+    _h(' *')
+    _h(' * Delivers a request to the X server.')
+    _h(' * ')
+    if checked:
+        _h(' * This form can be used only if the request will not cause')
+        _h(' * a reply to be generated. Any returned error will be')
+        _h(' * saved for handling by xcb_request_check().')
+    if unchecked:
+        _h(' * This form can be used only if the request will cause')
+        _h(' * a reply to be generated. Any returned error will be')
+        _h(' * placed in the event queue.')
+    _h(' */')
+    _c('')
+    _hc('')
+    _hc('/*****************************************************************************')
+    _hc(' **')
+    _hc(' ** %s %s', cookie_type, func_name)
+    _hc(' ** ')
+
+    spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
+    _hc(' ** @param xcb_connection_t%s *c', spacing)
+
+    for field in param_fields:
+        spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
+        _hc(' ** @param %s%s %s%s', field.c_field_const_type, spacing, field.c_pointer, field.c_field_name)
+
+    _hc(' ** @returns %s', cookie_type)
+    _hc(' **')
+    _hc(' *****************************************************************************/')
+    _hc(' ')
+    _hc('%s', cookie_type)
+
+    spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
+    comma = ',' if len(param_fields) else ');'
+    _h('%s (xcb_connection_t%s *c  /**< */%s', func_name, spacing, comma)
+    comma = ',' if len(param_fields) else ')'
+    _c('%s (xcb_connection_t%s *c  /**< */%s', func_name, spacing, comma)
+
+    func_spacing = ' ' * (len(func_name) + 2)
+    count = len(param_fields)
+    for field in param_fields:
+        count = count - 1
+        spacing = ' ' * (maxtypelen - len(field.c_field_const_type))
+        comma = ',' if count else ');'
+        _h('%s%s%s %s%s  /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
+        comma = ',' if count else ')'
+        _c('%s%s%s %s%s  /**< */%s', func_spacing, field.c_field_const_type, spacing, field.c_pointer, field.c_field_name, comma)
+
+    count = 2
+    for field in param_fields:
+        if not field.type.fixed_size():
+            count = count + 2
+
+    _c('{')
+    _c('    static const xcb_protocol_request_t xcb_req = {')
+    _c('        /* count */ %d,', count)
+    _c('        /* ext */ %s,', func_ext_global)
+    _c('        /* opcode */ %s,', self.c_request_name.upper())
+    _c('        /* isvoid */ %d', 1 if void else 0)
+    _c('    };')
+    _c('    ')
+    _c('    struct iovec xcb_parts[%d];', count + 2)
+    _c('    %s xcb_ret;', func_cookie)
+    _c('    %s xcb_out;', self.c_type)
+    _c('    ')
+
+    for field in wire_fields:
+        if field.type.fixed_size():
+            if field.type.is_expr:
+                _c('    xcb_out.%s = %s;', field.c_field_name, _c_accessor_get_expr(field.type.expr))
+
+            elif field.type.is_pad:
+                if field.type.nmemb == 1:
+                    _c('    xcb_out.%s = 0;', field.c_field_name)
+                else:
+                    _c('    memset(xcb_out.%s, 0, %d);', field.c_field_name, field.type.nmemb)
+            else:
+                if field.type.nmemb == 1:
+                    _c('    xcb_out.%s = %s;', field.c_field_name, field.c_field_name)
+                else:
+                    _c('    memcpy(xcb_out.%s, %s, %d);', field.c_field_name, field.c_field_name, field.type.nmemb)
+
+    _c('    ')
+    _c('    xcb_parts[2].iov_base = (char *) &xcb_out;')
+    _c('    xcb_parts[2].iov_len = sizeof(xcb_out);')
+    _c('    xcb_parts[3].iov_base = 0;')
+    _c('    xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;')
+
+    count = 4
+    for field in param_fields:
+        if not field.type.fixed_size():
+            _c('    xcb_parts[%d].iov_base = (char *) %s;', count, field.c_field_name)
+            if field.type.is_list:
+                _c('    xcb_parts[%d].iov_len = %s * sizeof(%s);', count, _c_accessor_get_expr(field.type.expr), field.type.member.c_wiretype)
+            else:
+                _c('    xcb_parts[%d].iov_len = %s * sizeof(%s);', count, 'Uh oh', field.type.c_wiretype)
+            _c('    xcb_parts[%d].iov_base = 0;', count + 1)
+            _c('    xcb_parts[%d].iov_len = -xcb_parts[%d].iov_len & 3;', count + 1, count)
+            count = count + 2
+
+    _c('    xcb_ret.sequence = xcb_send_request(c, %s, xcb_parts + 2, &xcb_req);', func_flags)
+    _c('    return xcb_ret;')
+    _c('}')
+
+def _c_reply(self, name):
+    '''
+    Declares the function that returns the reply structure.
+    '''
+    spacing1 = ' ' * (len(self.c_cookie_type) - len('xcb_connection_t'))
+    spacing2 = ' ' * (len(self.c_cookie_type) - len('xcb_generic_error_t'))
+    spacing3 = ' ' * (len(self.c_reply_name) + 2)
+
+    _h('')
+    _h('/**')
+    _h(' * Return the reply')
+    _h(' * @param c      The connection')
+    _h(' * @param cookie The cookie')
+    _h(' * @param e      The xcb_generic_error_t supplied')
+    _h(' *')
+    _h(' * Returns the reply of the request asked by')
+    _h(' * ')
+    _h(' * The parameter @p e supplied to this function must be NULL if')
+    _h(' * %s(). is used.', self.c_unchecked_name)
+    _h(' * Otherwise, it stores the error if any.')
+    _h(' *')
+    _h(' * The returned value must be freed by the caller using free().')
+    _h(' */')
+    _c('')
+    _hc('')
+    _hc('/*****************************************************************************')
+    _hc(' **')
+    _hc(' ** %s * %s', self.c_reply_type, self.c_reply_name)
+    _hc(' ** ')
+    _hc(' ** @param xcb_connection_t%s  *c', spacing1)
+    _hc(' ** @param %s   cookie', self.c_cookie_type)
+    _hc(' ** @param xcb_generic_error_t%s **e', spacing2)
+    _hc(' ** @returns %s *', self.c_reply_type)
+    _hc(' **')
+    _hc(' *****************************************************************************/')
+    _hc(' ')
+    _hc('%s *', self.c_reply_type)
+    _hc('%s (xcb_connection_t%s  *c  /**< */,', self.c_reply_name, spacing1)
+    _hc('%s%s   cookie  /**< */,', spacing3, self.c_cookie_type)
+    _h('%sxcb_generic_error_t%s **e  /**< */);', spacing3, spacing2)
+    _c('%sxcb_generic_error_t%s **e  /**< */)', spacing3, spacing2)
+    _c('{')
+    _c('    return (%s *) xcb_wait_for_reply(c, cookie.sequence, e);', self.c_reply_type)
+    _c('}')
+
+def _c_opcode(name, opcode):
+    '''
+    Declares the opcode define for requests, events, and errors.
+    '''
+    _h_setlevel(0)
+    _h('')
+    _h('/** Opcode for %s. */', _n(name))
+    _h('#define %s %s', _n(name).upper(), opcode)
+    
+def _c_cookie(self, name):
+    '''
+    Declares the cookie type for a non-void request.
+    '''
+    _h_setlevel(0)
+    _h('')
+    _h('/**')
+    _h(' * @brief %s', self.c_cookie_type)
+    _h(' **/')
+    _h('typedef struct %s {', self.c_cookie_type)
+    _h('    unsigned int sequence; /**<  */')
+    _h('} %s;', self.c_cookie_type)
+
+def c_request(self, name):
+    '''
+    Exported function that handles request declarations.
+    '''
+    _c_type_setup(self, name, ('request',))
+
+    if self.reply:
+        # Cookie type declaration
+        _c_cookie(self, name)
+
+    # Opcode define
+    _c_opcode(name, self.opcode)
+
+    # Request structure declaration
+    _c_complex(self)
+
+    if self.reply:
+        _c_type_setup(self.reply, name, ('reply',))
+        # Reply structure definition
+        _c_complex(self.reply)
+        # Request prototypes
+        _c_request_helper(self, name, self.c_cookie_type, False, True)
+        _c_request_helper(self, name, self.c_cookie_type, False, False)
+        # Reply accessors
+        _c_accessors(self.reply, name + ('reply',), name)
+        _c_reply(self, name)
+    else:
+        # Request prototypes
+        _c_request_helper(self, name, 'xcb_void_cookie_t', True, False)
+        _c_request_helper(self, name, 'xcb_void_cookie_t', True, True)
+
+def c_event(self, name):
+    '''
+    Exported function that handles event declarations.
+    '''
+    _c_type_setup(self, name, ('event',))
+
+    # Opcode define
+    _c_opcode(name, self.opcodes[name])
+
+    if self.name == name:
+        # Structure definition
+        _c_complex(self)
+    else:
+        # Typedef
+        _h('')
+        _h('typedef %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
+
+def c_error(self, name):
+    '''
+    Exported function that handles error declarations.
+    '''
+    _c_type_setup(self, name, ('error',))
+
+    # Opcode define
+    _c_opcode(name, self.opcodes[name])
+
+    if self.name == name:
+        # Structure definition
+        _c_complex(self)
+    else:
+        # Typedef
+        _h('')
+        _h('typedef %s %s;', _t(self.name + ('error',)), _t(name + ('error',)))
+
+
+# Main routine starts here
+
+# Must create an "output" dictionary before any xcbgen imports.
+output = {'open'    : c_open,
+          'close'   : c_close,
+          'simple'  : c_simple,
+          'enum'    : c_enum,
+          'struct'  : c_struct,
+          'union'   : c_union,
+          'request' : c_request,
+          'event'   : c_event,
+          'error'   : c_error
+          }
+
+# 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
+except ImportError:
+    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 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(args[0], output)
+
+# Build type-registry and resolve type dependencies
+module.register()
+module.resolve()
+
+# Output the code
+module.generate()
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 3516186fa..53c05e0b8 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -1,415 +1,421 @@
-/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
- * Except as contained in this notice, the names of the authors or their
- * institutions shall not be used in advertising or otherwise to promote the
- * sale, use or other dealings in this Software without prior written
- * authorization from the authors.
- */
-
-/* Utility functions implementable using only public APIs. */
-
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <limits.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#ifdef DNETCONN
-#include <netdnet/dnetdb.h>
-#include <netdnet/dn.h>
-#endif
-#include <netdb.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-
-#include "xcb.h"
-#include "xcbext.h"
-#include "xcbint.h"
-
-static const int error_connection = 1;
-
-int xcb_popcount(uint32_t mask)
-{
-    uint32_t y;
-    y = (mask >> 1) & 033333333333;
-    y = mask - y - ((y >> 1) & 033333333333);
-    return ((y + (y >> 3)) & 030707070707) % 077;
-}
-
-static int _xcb_parse_display(const char *name, char **host, char **protocol,
-                      int *displayp, int *screenp)
-{
-    int len, display, screen;
-    char *slash, *colon, *dot, *end;
-    if(!name || !*name)
-        name = getenv("DISPLAY");
-    if(!name)
-        return 0;
-
-#ifdef HAVE_LAUNCHD
-    if(strncmp(name, "/tmp/launch", 11) == 0)
-        slash = NULL;
-    else
-#endif
-    slash = strrchr(name, '/');
-
-    if (slash) {
-        len = slash - name;
-        if (protocol) {
-            *protocol = malloc(len + 1);
-            if(!*protocol)
-                return 0;
-            memcpy(*protocol, name, len);
-            (*protocol)[len] = '\0';
-        }
-        name = slash + 1;
-    } else
-        if (protocol)
-            *protocol = NULL;
-
-    colon = strrchr(name, ':');
-    if(!colon)
-        return 0;
-    len = colon - name;
-    ++colon;
-    display = strtoul(colon, &dot, 10);
-    if(dot == colon)
-        return 0;
-    if(*dot == '\0')
-        screen = 0;
-    else
-    {
-        if(*dot != '.')
-            return 0;
-        ++dot;
-        screen = strtoul(dot, &end, 10);
-        if(end == dot || *end != '\0')
-            return 0;
-    }
-    /* At this point, the display string is fully parsed and valid, but
-     * the caller's memory is untouched. */
-
-    *host = malloc(len + 1);
-    if(!*host)
-        return 0;
-    memcpy(*host, name, len);
-    (*host)[len] = '\0';
-    *displayp = display;
-    if(screenp)
-        *screenp = screen;
-    return 1;
-}
-
-int xcb_parse_display(const char *name, char **host, int *displayp,
-                             int *screenp)
-{
-    return _xcb_parse_display(name, host, NULL, displayp, screenp);
-}
-
-static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
-static int _xcb_open_unix(char *protocol, const char *file);
-#ifdef DNETCONN
-static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
-#endif
-#ifdef HAVE_ABSTRACT_SOCKETS
-static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
-#endif
-
-static int _xcb_open(char *host, char *protocol, const int display)
-{
-    int fd;
-    static const char unix_base[] = "/tmp/.X11-unix/X";
-    const char *base = unix_base;
-    size_t filelen;
-    char *file = NULL;
-    int actual_filelen;
-
-    if(*host)
-    {
-#ifdef HAVE_LAUNCHD
-        if(strncmp(host, "/tmp/launch", 11) == 0) {
-	    base = host;
-        } else {
-#endif
-
-#ifdef DNETCONN
-        /* DECnet displays have two colons, so _xcb_parse_display will have
-           left one at the end.  However, an IPv6 address can end with *two*
-           colons, so only treat this as a DECnet display if host ends with
-           exactly one colon. */
-        char *colon = strchr(host, ':');
-        if(colon && *(colon+1) == '\0')
-        {
-            *colon = '\0';
-            return _xcb_open_decnet(host, protocol, display);
-        }
-        else
-#endif
-            if (protocol
-                || strcmp("unix",host)) { /* follow the old unix: rule */
-
-                /* display specifies TCP */
-                unsigned short port = X_TCP_PORT + display;
-                return _xcb_open_tcp(host, protocol, port);
-            }
-#ifdef HAVE_LAUNCHD
-        }
-#endif
-    }
-
-    filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
-    file = malloc(filelen);
-    if(file == NULL)
-        return -1;
-
-    /* display specifies Unix socket */
-#ifdef HAVE_LAUNCHD
-    if(base == host)
-        actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
-    else
-#endif
-        actual_filelen = snprintf(file, filelen, "%s%d", base, display);
-    if(actual_filelen < 0)
-    {
-        free(file);
-        return -1;
-    }
-    /* snprintf may truncate the file */
-    filelen = MIN(actual_filelen, filelen - 1);
-#ifdef HAVE_ABSTRACT_SOCKETS
-    fd = _xcb_open_abstract(protocol, file, filelen);
-    if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
-    {
-        free(file);
-        return fd;
-    }
-
-#endif
-    fd = _xcb_open_unix(protocol, file);
-    free(file);
-
-    return fd;
-}
-
-static int _xcb_socket(int family, int type, int proto)
-{
-    int fd;
-
-#ifdef SOCK_CLOEXEC
-    fd = socket(family, type | SOCK_CLOEXEC, proto);
-    if (fd == -1 && errno == EINVAL)
-#endif
-    {
-	fd = socket(family, type, proto);
-	if (fd >= 0)
-	    fcntl(fd, F_SETFD, FD_CLOEXEC);
-    }
-    return fd;
-}
-
-#ifdef DNETCONN
-static int _xcb_open_decnet(const char *host, const char *protocol, const unsigned short port)
-{
-    int fd;
-    struct sockaddr_dn addr;
-    struct accessdata_dn accessdata;
-    struct nodeent *nodeaddr = getnodebyname(host);
-
-    if(!nodeaddr)
-        return -1;
-    if (protocol && strcmp("dnet",protocol))
-        return -1;
-    addr.sdn_family = AF_DECnet;
-
-    addr.sdn_add.a_len = nodeaddr->n_length;
-    memcpy(addr.sdn_add.a_addr, nodeaddr->n_addr, addr.sdn_add.a_len);
-
-    addr.sdn_objnamel = sprintf((char *)addr.sdn_objname, "X$X%d", port);
-    if(addr.sdn_objnamel < 0)
-        return -1;
-    addr.sdn_objnum = 0;
-
-    fd = _xcb_socket(PF_DECnet, SOCK_STREAM, 0);
-    if(fd == -1)
-        return -1;
-
-    memset(&accessdata, 0, sizeof(accessdata));
-    accessdata.acc_accl = sprintf((char*)accessdata.acc_acc, "%d", getuid());
-    if(accessdata.acc_accl < 0)
-        return -1;
-    setsockopt(fd, DNPROTO_NSP, SO_CONACCESS, &accessdata, sizeof(accessdata));
-
-    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
-        close(fd);
-        return -1;
-    }
-    return fd;
-}
-#endif
-
-static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
-{
-    int fd = -1;
-    struct addrinfo hints;
-    char service[6]; /* "65535" with the trailing '\0' */
-    struct addrinfo *results, *addr;
-    char *bracket;
-
-    if (protocol && strcmp("tcp",protocol))
-        return -1;
-
-    memset(&hints, 0, sizeof(hints));
-#ifdef AI_ADDRCONFIG
-    hints.ai_flags |= AI_ADDRCONFIG;
-#endif
-#ifdef AI_NUMERICSERV
-    hints.ai_flags |= AI_NUMERICSERV;
-#endif
-    hints.ai_family = AF_UNSPEC;
-    hints.ai_socktype = SOCK_STREAM;
-
-#ifdef AF_INET6
-    /* Allow IPv6 addresses enclosed in brackets. */
-    if(host[0] == '[' && (bracket = strrchr(host, ']')) && bracket[1] == '\0')
-    {
-        *bracket = '\0';
-        ++host;
-        hints.ai_flags |= AI_NUMERICHOST;
-        hints.ai_family = AF_INET6;
-    }
-#endif
-
-    snprintf(service, sizeof(service), "%hu", port);
-    if(getaddrinfo(host, service, &hints, &results))
-        /* FIXME: use gai_strerror, and fill in error connection */
-        return -1;
-
-    for(addr = results; addr; addr = addr->ai_next)
-    {
-        fd = _xcb_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
-        if(fd >= 0) {
-            int on = 1;
-            setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
-	    setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
-
-            if (connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0)
-                break;
-            close(fd);
-            fd = -1;
-        }
-    }
-    freeaddrinfo(results);
-    return fd;
-}
-
-static int _xcb_open_unix(char *protocol, const char *file)
-{
-    int fd;
-    struct sockaddr_un addr;
-
-    if (protocol && strcmp("unix",protocol))
-        return -1;
-
-    strcpy(addr.sun_path, file);
-    addr.sun_family = AF_UNIX;
-#ifdef HAVE_SOCKADDR_SUN_LEN
-    addr.sun_len = SUN_LEN(&addr);
-#endif
-    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
-    if(fd == -1)
-        return -1;
-    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
-        close(fd);
-        return -1;
-    }
-    return fd;
-}
-
-#ifdef HAVE_ABSTRACT_SOCKETS
-static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
-{
-    int fd;
-    struct sockaddr_un addr = {0};
-    socklen_t namelen;
-
-    if (protocol && strcmp("unix",protocol))
-        return -1;
-
-    strcpy(addr.sun_path + 1, file);
-    addr.sun_family = AF_UNIX;
-    namelen = offsetof(struct sockaddr_un, sun_path) + 1 + filelen;
-#ifdef HAVE_SOCKADDR_SUN_LEN
-    addr.sun_len = 1 + filelen;
-#endif
-    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
-    if (fd == -1)
-        return -1;
-    if (connect(fd, (struct sockaddr *) &addr, namelen) == -1) {
-        close(fd);
-        return -1;
-    }
-    return fd;
-}
-#endif
-
-xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
-{
-    return xcb_connect_to_display_with_auth_info(displayname, NULL, screenp);
-}
-
-xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname, xcb_auth_info_t *auth, int *screenp)
-{
-    int fd, display = 0;
-    char *host;
-    char *protocol;
-    xcb_auth_info_t ourauth;
-    xcb_connection_t *c;
-
-    int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
-    
-    if(!parsed)
-        return (xcb_connection_t *) &error_connection;
-    else
-        fd = _xcb_open(host, protocol, display);
-    free(host);
-
-    if(fd == -1)
-        return (xcb_connection_t *) &error_connection;
-
-    if(auth)
-        return xcb_connect_to_fd(fd, auth);
-
-    if(_xcb_get_auth_info(fd, &ourauth, display))
-    {
-        c = xcb_connect_to_fd(fd, &ourauth);
-        free(ourauth.name);
-        free(ourauth.data);
-    }
-    else
-        c = xcb_connect_to_fd(fd, 0);
-
-    return c;
-}
+/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+/* Utility functions implementable using only public APIs. */
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <limits.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#ifdef DNETCONN
+#include <netdnet/dnetdb.h>
+#include <netdnet/dn.h>
+#endif
+#include <netdb.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "xcb.h"
+#include "xcbext.h"
+#include "xcbint.h"
+
+static const int error_connection = 1;
+
+int xcb_popcount(uint32_t mask)
+{
+    uint32_t y;
+    y = (mask >> 1) & 033333333333;
+    y = mask - y - ((y >> 1) & 033333333333);
+    return ((y + (y >> 3)) & 030707070707) % 077;
+}
+
+static int _xcb_parse_display(const char *name, char **host, char **protocol,
+                      int *displayp, int *screenp)
+{
+    int len, display, screen;
+    char *slash, *colon, *dot, *end;
+    if(!name || !*name)
+        name = getenv("DISPLAY");
+    if(!name)
+        return 0;
+
+#ifdef HAVE_LAUNCHD
+    if(strncmp(name, "/tmp/launch", 11) == 0)
+        slash = NULL;
+    else
+#endif
+    slash = strrchr(name, '/');
+
+    if (slash) {
+        len = slash - name;
+        if (protocol) {
+            *protocol = malloc(len + 1);
+            if(!*protocol)
+                return 0;
+            memcpy(*protocol, name, len);
+            (*protocol)[len] = '\0';
+        }
+        name = slash + 1;
+    } else
+        if (protocol)
+            *protocol = NULL;
+
+    colon = strrchr(name, ':');
+    if(!colon)
+        return 0;
+    len = colon - name;
+    ++colon;
+    display = strtoul(colon, &dot, 10);
+    if(dot == colon)
+        return 0;
+    if(*dot == '\0')
+        screen = 0;
+    else
+    {
+        if(*dot != '.')
+            return 0;
+        ++dot;
+        screen = strtoul(dot, &end, 10);
+        if(end == dot || *end != '\0')
+            return 0;
+    }
+    /* At this point, the display string is fully parsed and valid, but
+     * the caller's memory is untouched. */
+
+    *host = malloc(len + 1);
+    if(!*host)
+        return 0;
+    memcpy(*host, name, len);
+    (*host)[len] = '\0';
+    *displayp = display;
+    if(screenp)
+        *screenp = screen;
+    return 1;
+}
+
+int xcb_parse_display(const char *name, char **host, int *displayp,
+                             int *screenp)
+{
+    return _xcb_parse_display(name, host, NULL, displayp, screenp);
+}
+
+static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port);
+static int _xcb_open_unix(char *protocol, const char *file);
+#ifdef DNETCONN
+static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
+#endif
+#ifdef HAVE_ABSTRACT_SOCKETS
+static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
+#endif
+
+static int _xcb_open(const char *host, char *protocol, const int display)
+{
+    int fd;
+    static const char unix_base[] = "/tmp/.X11-unix/X";
+    const char *base = unix_base;
+    size_t filelen;
+    char *file = NULL;
+    int actual_filelen;
+
+#ifdef HAVE_LAUNCHD
+        if(strncmp(host, "/tmp/launch", 11) == 0) {
+		base = host;
+		host = "";
+		protocol = NULL;
+        }
+#endif
+
+    if(*host || protocol)
+    {
+#ifdef DNETCONN
+        /* DECnet displays have two colons, so _xcb_parse_display will have
+           left one at the end.  However, an IPv6 address can end with *two*
+           colons, so only treat this as a DECnet display if host ends with
+           exactly one colon. */
+        char *colon = strchr(host, ':');
+        if(colon && *(colon+1) == '\0')
+        {
+            *colon = '\0';
+            return _xcb_open_decnet(host, protocol, display);
+        }
+        else
+#endif
+            if (protocol
+                || strcmp("unix",host)) { /* follow the old unix: rule */
+
+                /* display specifies TCP */
+                unsigned short port = X_TCP_PORT + display;
+                return _xcb_open_tcp(host, protocol, port);
+            }
+    }
+
+    filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
+    file = malloc(filelen);
+    if(file == NULL)
+        return -1;
+
+    /* display specifies Unix socket */
+#ifdef HAVE_LAUNCHD
+    if(strncmp(base, "/tmp/launch", 11) == 0)
+        actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
+    else
+#endif
+        actual_filelen = snprintf(file, filelen, "%s%d", base, display);
+    if(actual_filelen < 0)
+    {
+        free(file);
+        return -1;
+    }
+    /* snprintf may truncate the file */
+    filelen = MIN(actual_filelen, filelen - 1);
+#ifdef HAVE_ABSTRACT_SOCKETS
+    fd = _xcb_open_abstract(protocol, file, filelen);
+    if (fd >= 0 || (errno != ENOENT && errno != ECONNREFUSED))
+    {
+        free(file);
+        return fd;
+    }
+
+#endif
+    fd = _xcb_open_unix(protocol, file);
+    free(file);
+
+    return fd;
+}
+
+static int _xcb_socket(int family, int type, int proto)
+{
+    int fd;
+
+#ifdef SOCK_CLOEXEC
+    fd = socket(family, type | SOCK_CLOEXEC, proto);
+    if (fd == -1 && errno == EINVAL)
+#endif
+    {
+	fd = socket(family, type, proto);
+	if (fd >= 0)
+	    fcntl(fd, F_SETFD, FD_CLOEXEC);
+    }
+    return fd;
+}
+
+#ifdef DNETCONN
+static int _xcb_open_decnet(const char *host, const char *protocol, const unsigned short port)
+{
+    int fd;
+    struct sockaddr_dn addr;
+    struct accessdata_dn accessdata;
+    struct nodeent *nodeaddr = getnodebyname(host);
+
+    if(!nodeaddr)
+        return -1;
+    if (protocol && strcmp("dnet",protocol))
+        return -1;
+    addr.sdn_family = AF_DECnet;
+
+    addr.sdn_add.a_len = nodeaddr->n_length;
+    memcpy(addr.sdn_add.a_addr, nodeaddr->n_addr, addr.sdn_add.a_len);
+
+    addr.sdn_objnamel = sprintf((char *)addr.sdn_objname, "X$X%d", port);
+    if(addr.sdn_objnamel < 0)
+        return -1;
+    addr.sdn_objnum = 0;
+
+    fd = _xcb_socket(PF_DECnet, SOCK_STREAM, 0);
+    if(fd == -1)
+        return -1;
+
+    memset(&accessdata, 0, sizeof(accessdata));
+    accessdata.acc_accl = sprintf((char*)accessdata.acc_acc, "%d", getuid());
+    if(accessdata.acc_accl < 0)
+        return -1;
+    setsockopt(fd, DNPROTO_NSP, SO_CONACCESS, &accessdata, sizeof(accessdata));
+
+    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
+        close(fd);
+        return -1;
+    }
+    return fd;
+}
+#endif
+
+static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port)
+{
+    int fd = -1;
+    struct addrinfo hints;
+    char service[6]; /* "65535" with the trailing '\0' */
+    struct addrinfo *results, *addr;
+    char *bracket;
+
+    if (protocol && strcmp("tcp",protocol) && strcmp("inet",protocol)
+#ifdef AF_INET6
+	         && strcmp("inet6",protocol)
+#endif
+	)
+        return -1;
+	
+    if (*host == '\0')
+	host = "localhost";
+
+    memset(&hints, 0, sizeof(hints));
+#ifdef AI_ADDRCONFIG
+    hints.ai_flags |= AI_ADDRCONFIG;
+#endif
+#ifdef AI_NUMERICSERV
+    hints.ai_flags |= AI_NUMERICSERV;
+#endif
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+
+#ifdef AF_INET6
+    /* Allow IPv6 addresses enclosed in brackets. */
+    if(host[0] == '[' && (bracket = strrchr(host, ']')) && bracket[1] == '\0')
+    {
+        *bracket = '\0';
+        ++host;
+        hints.ai_flags |= AI_NUMERICHOST;
+        hints.ai_family = AF_INET6;
+    }
+#endif
+
+    snprintf(service, sizeof(service), "%hu", port);
+    if(getaddrinfo(host, service, &hints, &results))
+        /* FIXME: use gai_strerror, and fill in error connection */
+        return -1;
+
+    for(addr = results; addr; addr = addr->ai_next)
+    {
+        fd = _xcb_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
+        if(fd >= 0) {
+            int on = 1;
+            setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+	    setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
+
+            if (connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0)
+                break;
+            close(fd);
+            fd = -1;
+        }
+    }
+    freeaddrinfo(results);
+    return fd;
+}
+
+static int _xcb_open_unix(char *protocol, const char *file)
+{
+    int fd;
+    struct sockaddr_un addr;
+
+    if (protocol && strcmp("unix",protocol))
+        return -1;
+
+    strcpy(addr.sun_path, file);
+    addr.sun_family = AF_UNIX;
+#ifdef HAVE_SOCKADDR_SUN_LEN
+    addr.sun_len = SUN_LEN(&addr);
+#endif
+    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
+    if(fd == -1)
+        return -1;
+    if(connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
+        close(fd);
+        return -1;
+    }
+    return fd;
+}
+
+#ifdef HAVE_ABSTRACT_SOCKETS
+static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
+{
+    int fd;
+    struct sockaddr_un addr = {0};
+    socklen_t namelen;
+
+    if (protocol && strcmp("unix",protocol))
+        return -1;
+
+    strcpy(addr.sun_path + 1, file);
+    addr.sun_family = AF_UNIX;
+    namelen = offsetof(struct sockaddr_un, sun_path) + 1 + filelen;
+#ifdef HAVE_SOCKADDR_SUN_LEN
+    addr.sun_len = 1 + filelen;
+#endif
+    fd = _xcb_socket(AF_UNIX, SOCK_STREAM, 0);
+    if (fd == -1)
+        return -1;
+    if (connect(fd, (struct sockaddr *) &addr, namelen) == -1) {
+        close(fd);
+        return -1;
+    }
+    return fd;
+}
+#endif
+
+xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
+{
+    return xcb_connect_to_display_with_auth_info(displayname, NULL, screenp);
+}
+
+xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname, xcb_auth_info_t *auth, int *screenp)
+{
+    int fd, display = 0;
+    char *host;
+    char *protocol;
+    xcb_auth_info_t ourauth;
+    xcb_connection_t *c;
+
+    int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
+    
+    if(!parsed)
+        return (xcb_connection_t *) &error_connection;
+    else
+        fd = _xcb_open(host, protocol, display);
+    free(host);
+
+    if(fd == -1)
+        return (xcb_connection_t *) &error_connection;
+
+    if(auth)
+        return xcb_connect_to_fd(fd, auth);
+
+    if(_xcb_get_auth_info(fd, &ourauth, display))
+    {
+        c = xcb_connect_to_fd(fd, &ourauth);
+        free(ourauth.name);
+        free(ourauth.data);
+    }
+    else
+        c = xcb_connect_to_fd(fd, 0);
+
+    return c;
+}
-- 
cgit v1.2.3