Fix _unserialize of reply headers
[free-sw/xcb/libxcb] / src / c-client.xsl
index 406e9b6..a15d824 100644 (file)
@@ -47,6 +47,8 @@ authorization from the authors.
 
   <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="'    '" />
@@ -68,9 +70,6 @@ authorization from the authors.
     <xsl:for-each select="/xcb/import">
       <path><xsl:value-of select="concat($extension-path, ., '.xml')" /></path>
     </xsl:for-each>
-    <xsl:if test="not($header='xproto')">
-      <path><xsl:value-of select="concat($base-path, 'xproto.xml')" /></path>
-    </xsl:if>
   </xsl:variable>
   <xsl:variable name="search-path" select="e:node-set($search-path-rtf)/path"/>
 
@@ -98,31 +97,19 @@ authorization from the authors.
     <xsl:param name="name" />
     <func:result>
       <xsl:text>xcb</xsl:text>
-      <xsl:choose>
-        <xsl:when test="/xcb/@extension-name = 'RandR'">
-          <xsl:text>_randr</xsl:text>
-        </xsl:when>
-        <xsl:when test="/xcb/@extension-name = 'ScreenSaver'">
-          <xsl:text>_screensaver</xsl:text>
-        </xsl:when>
-        <xsl:when test="/xcb/@extension-name = 'XF86Dri'">
-          <xsl:text>_xf86dri</xsl:text>
-        </xsl:when>
-        <xsl:when test="/xcb/@extension-name = 'XFixes'">
-          <xsl:text>_xfixes</xsl:text>
-        </xsl:when>
-        <xsl:when test="/xcb/@extension-name = 'XvMC'">
-          <xsl:text>_xvmc</xsl:text>
-        </xsl:when>
-        <xsl:when test="/xcb/@extension-name">
-          <xsl:text>_</xsl:text>
-          <xsl:call-template name="camelcase-to-underscore">
-            <xsl:with-param name="camelcase" select="/xcb/@extension-name" />
-          </xsl:call-template>
-        </xsl:when>
-        <xsl:otherwise>
-        </xsl:otherwise>
-      </xsl:choose>
+      <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">
@@ -343,9 +330,27 @@ authorization from the authors.
           <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="{$req/@opcode}"
+      <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>
@@ -361,6 +366,7 @@ authorization from the authors.
         <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">
@@ -390,6 +396,20 @@ authorization from the authors.
       </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">
@@ -590,7 +610,7 @@ authorization from the authors.
     </list>
   </xsl:template>
 
-  <xsl:template match="field|localfield" mode="param">
+  <xsl:template match="field" mode="param">
     <field>
       <xsl:attribute name="type">
         <xsl:call-template name="canonical-type-name" />
@@ -722,7 +742,11 @@ authorization from the authors.
     <l><xsl:value-of select="@ref" /> xcb_out;</l>
 
     <l />
-    <xsl:apply-templates select="$struct//*[(self::field or self::exprfield)
+    <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" />
 
@@ -781,6 +805,14 @@ authorization from the authors.
     </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" />
@@ -912,6 +944,14 @@ authorization from the authors.
     </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)]">
@@ -930,6 +970,15 @@ authorization from the authors.
         </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>
@@ -981,8 +1030,16 @@ authorization from the authors.
  * 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>
@@ -994,8 +1051,23 @@ authorization from the authors.
 <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:text>
+<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"
@@ -1007,6 +1079,10 @@ authorization from the authors.
 <xsl:if test="$h">
 <xsl:text>
 #endif
+
+/**
+ * @}
+ */
 </xsl:text>
 </xsl:if>
   </xsl:template>
@@ -1015,6 +1091,8 @@ authorization from the authors.
     <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>
@@ -1075,6 +1153,10 @@ authorization from the authors.
           <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>
@@ -1086,7 +1168,7 @@ authorization from the authors.
         <xsl:apply-templates select=".">
           <xsl:with-param name="type-lengths" select="$type-lengths" />
         </xsl:apply-templates>
-        <xsl:text>;
+        <xsl:text>; /**&lt; </xsl:text><xsl:text> */
 </xsl:text>
       </xsl:for-each>
       <xsl:text>} </xsl:text>
@@ -1131,8 +1213,35 @@ authorization from the authors.
       <xsl:call-template name="type-lengths">
         <xsl:with-param name="items" select="field/@type" />
       </xsl:call-template>
-    </xsl:variable>
-    <xsl:value-of select="@type" />
+  </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" />
@@ -1150,6 +1259,7 @@ authorization from the authors.
             <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>
@@ -1173,6 +1283,11 @@ authorization from the authors.
     </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>