1 <?xml version="1.0" encoding="utf-8"?>
3 Copyright (C) 2004 Josh Triplett. All Rights Reserved.
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the names of the authors or their
23 institutions shall not be used in advertising or otherwise to promote the
24 sale, use or other dealings in this Software without prior written
25 authorization from the authors.
27 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29 xmlns:e="http://exslt.org/common"
30 xmlns:func="http://exslt.org/functions"
31 xmlns:str="http://exslt.org/strings"
32 xmlns:xcb="http://xcb.freedesktop.org"
33 extension-element-prefixes="func str xcb">
35 <xsl:output method="text" />
37 <xsl:strip-space elements="*" />
39 <!-- "header" or "source" -->
40 <xsl:param name="mode" />
42 <!-- Path to the core protocol descriptions. -->
43 <xsl:param name="base-path" />
45 <!-- Path to the extension protocol descriptions. -->
46 <xsl:param name="extension-path" select="$base-path" />
48 <xsl:variable name="h" select="$mode = 'header'" />
49 <xsl:variable name="c" select="$mode = 'source'" />
51 <!-- String used to indent lines of code. -->
52 <xsl:variable name="indent-string" select="' '" />
54 <xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
55 <xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
56 <xsl:variable name="letters" select="concat($ucase, $lcase)" />
57 <xsl:variable name="digits" select="'0123456789'" />
59 <xsl:variable name="header" select="/xcb/@header" />
60 <xsl:variable name="ucase-header"
61 select="translate($header,$lcase,$ucase)" />
63 <xsl:variable name="ext" select="/xcb/@extension-name" />
65 <!-- Other protocol descriptions to search for types in, after checking the
66 current protocol description. -->
67 <xsl:variable name="search-path-rtf">
68 <xsl:for-each select="/xcb/import">
69 <path><xsl:value-of select="concat($extension-path, ., '.xml')" /></path>
72 <xsl:variable name="search-path" select="e:node-set($search-path-rtf)/path"/>
74 <xsl:variable name="root" select="/" />
76 <!-- First pass: Store everything in a variable. -->
77 <xsl:variable name="pass1-rtf">
78 <xsl:apply-templates select="/" mode="pass1" />
80 <xsl:variable name="pass1" select="e:node-set($pass1-rtf)" />
82 <xsl:template match="xcb" mode="pass1">
84 <xsl:copy-of select="@*" />
86 <constant type="xcb_extension_t" name="{xcb:xcb-prefix()}_id">
87 <xsl:attribute name="value">{ "<xsl:value-of select="@extension-xname" />" }</xsl:attribute>
90 <xsl:apply-templates mode="pass1" />
94 <func:function name="xcb:xcb-prefix">
95 <xsl:param name="name" />
97 <xsl:text>xcb</xsl:text>
99 <xsl:when test="/xcb/@extension-name = 'RandR'">
100 <xsl:text>_randr</xsl:text>
102 <xsl:when test="/xcb/@extension-name = 'ScreenSaver'">
103 <xsl:text>_screensaver</xsl:text>
105 <xsl:when test="/xcb/@extension-name = 'XF86Dri'">
106 <xsl:text>_xf86dri</xsl:text>
108 <xsl:when test="/xcb/@extension-name = 'XFixes'">
109 <xsl:text>_xfixes</xsl:text>
111 <xsl:when test="/xcb/@extension-name = 'XvMC'">
112 <xsl:text>_xvmc</xsl:text>
114 <xsl:when test="/xcb/@extension-name">
115 <xsl:text>_</xsl:text>
116 <xsl:call-template name="camelcase-to-underscore">
117 <xsl:with-param name="camelcase" select="/xcb/@extension-name" />
123 <xsl:if test="$name">
124 <xsl:text>_</xsl:text>
125 <xsl:call-template name="camelcase-to-underscore">
126 <xsl:with-param name="camelcase" select="$name" />
132 <func:function name="xcb:lowercase">
133 <xsl:param name="name" />
135 <xsl:call-template name="camelcase-to-underscore">
136 <xsl:with-param name="camelcase" select="$name" />
141 <func:function name="xcb:get-char-void">
142 <xsl:param name="name" />
143 <xsl:variable name="ctype" select="substring-before($name, '_t')" />
146 <xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
147 <xsl:value-of select="$ctype" />
150 <xsl:value-of select="$name" />
156 <func:function name="xcb:remove-void">
157 <xsl:param name="name" />
158 <xsl:variable name="ctype" select="substring-before($name, '_t')" />
161 <xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
163 <xsl:when test="$ctype = 'void'">
164 <xsl:text>char</xsl:text>
167 <xsl:value-of select="$ctype" />
172 <xsl:value-of select="$name" />
178 <!-- split camel case into words and insert underscore -->
179 <xsl:template name="camelcase-to-underscore">
180 <xsl:param name="camelcase"/>
182 <xsl:when test="$camelcase='CHAR2B' or $camelcase='INT64'
183 or $camelcase='FLOAT32' or $camelcase='FLOAT64'
184 or $camelcase='BOOL32' or $camelcase='STRING8'
185 or $camelcase='Family_DECnet'">
186 <xsl:value-of select="translate($camelcase, $ucase, $lcase)"/>
189 <xsl:for-each select="str:split($camelcase, '')">
190 <xsl:variable name="a" select="."/>
191 <xsl:variable name="b" select="following::*[1]"/>
192 <xsl:variable name="c" select="following::*[2]"/>
193 <xsl:value-of select="translate(., $ucase, $lcase)"/>
194 <xsl:if test="($b and contains($lcase, $a) and contains($ucase, $b))
195 or ($b and contains($digits, $a)
196 and contains($letters, $b))
197 or ($b and contains($letters, $a)
198 and contains($digits, $b))
199 or ($c and contains($ucase, $a)
200 and contains($ucase, $b)
201 and contains($lcase, $c))">
202 <xsl:text>_</xsl:text>
209 <!-- Modify names that conflict with C++ keywords by prefixing them with an
210 underscore. If the name parameter is not specified, it defaults to the
211 value of the name attribute on the context node. -->
212 <xsl:template name="canonical-var-name">
213 <xsl:param name="name" select="@name" />
214 <xsl:if test="$name='new' or $name='delete'
215 or $name='class' or $name='operator'">
216 <xsl:text>_</xsl:text>
218 <xsl:value-of select="$name" />
221 <!-- List of core types, for use in canonical-type-name. -->
222 <xsl:variable name="core-types-rtf">
223 <type name="BOOL" newname="uint8" />
224 <type name="BYTE" newname="uint8" />
225 <type name="CARD8" newname="uint8" />
226 <type name="CARD16" newname="uint16" />
227 <type name="CARD32" newname="uint32" />
228 <type name="INT8" newname="int8" />
229 <type name="INT16" newname="int16" />
230 <type name="INT32" newname="int32" />
232 <type name="char" newname="char" />
233 <type name="void" newname="void" />
234 <type name="float" newname="float" />
235 <type name="double" newname="double" />
237 <xsl:variable name="core-types" select="e:node-set($core-types-rtf)" />
240 Output the canonical name for a type. This will be
241 xcb_{extension-containing-type-if-any}_type, wherever the type is found in
242 the search path, or just type if not found. If the type parameter is not
243 specified, it defaults to the value of the type attribute on the context
246 <xsl:template name="canonical-type-name">
247 <xsl:param name="type" select="string(@type)" />
249 <xsl:variable name="is-unqualified" select="not(contains($type, ':'))"/>
250 <xsl:variable name="namespace" select="substring-before($type, ':')" />
251 <xsl:variable name="unqualified-type">
253 <xsl:when test="$is-unqualified">
254 <xsl:value-of select="$type" />
257 <xsl:value-of select="substring-after($type, ':')" />
263 <xsl:when test="$is-unqualified and $core-types/type[@name=$type]">
264 <xsl:value-of select="$core-types/type[@name=$type]/@newname" />
267 <xsl:variable name="type-definitions"
268 select="(/xcb|document($search-path)/xcb
269 )[$is-unqualified or @header=$namespace]
270 /*[((self::struct or self::union or self::enum
271 or self::xidtype or self::xidunion
272 or self::event or self::eventcopy
273 or self::error or self::errorcopy)
274 and @name=$unqualified-type)
276 and @newname=$unqualified-type)]" />
278 <xsl:when test="count($type-definitions) = 1">
279 <xsl:for-each select="$type-definitions">
280 <xsl:value-of select="xcb:xcb-prefix($unqualified-type)" />
283 <xsl:when test="count($type-definitions) > 1">
284 <xsl:message terminate="yes">
285 <xsl:text>Multiple definitions of type "</xsl:text>
286 <xsl:value-of select="$type" />
287 <xsl:text>" found.</xsl:text>
288 <xsl:if test="$is-unqualified">
289 <xsl:for-each select="$type-definitions">
292 <xsl:value-of select="concat(/xcb/@header, ':', $type)" />
298 <xsl:message terminate="yes">
299 <xsl:text>No definitions of type "</xsl:text>
300 <xsl:value-of select="$type" />
301 <xsl:text>" found</xsl:text>
302 <xsl:if test="$is-unqualified">
303 <xsl:text>, and it is not a known core type</xsl:text>
305 <xsl:text>.</xsl:text>
313 <!-- Helper template for requests, that outputs the cookie type. The
314 parameter "request" must be the request node, which defaults to the
316 <xsl:template name="cookie-type">
317 <xsl:param name="request" select="." />
319 <xsl:when test="$request/reply">
320 <xsl:value-of select="xcb:xcb-prefix($request/@name)" />
323 <xsl:text>xcb_void</xsl:text>
326 <xsl:text>_cookie_t</xsl:text>
329 <xsl:template name="request-function">
330 <xsl:param name="checked" />
331 <xsl:param name="req" />
333 <xsl:attribute name="name">
334 <xsl:value-of select="xcb:xcb-prefix($req/@name)" />
335 <xsl:if test="$checked='true' and not($req/reply)">_checked</xsl:if>
336 <xsl:if test="$checked='false' and $req/reply">_unchecked</xsl:if>
338 <xsl:attribute name="type">
339 <xsl:call-template name="cookie-type">
340 <xsl:with-param name="request" select="$req" />
343 <field type="xcb_connection_t *" name="c" />
344 <xsl:apply-templates select="$req/*[not(self::reply)]" mode="param" />
345 <do-request ref="{xcb:xcb-prefix($req/@name)}_request_t" opcode="{translate(xcb:xcb-prefix($req/@name), $lcase, $ucase)}"
346 checked="{$checked}">
347 <xsl:if test="$req/reply">
348 <xsl:attribute name="has-reply">true</xsl:attribute>
354 <xsl:template match="request" mode="pass1">
355 <xsl:variable name="req" select="." />
356 <xsl:if test="reply">
357 <struct name="{xcb:xcb-prefix(@name)}_cookie_t">
358 <field type="unsigned int" name="sequence" />
361 <constant type="number" name="{xcb:xcb-prefix($req/@name)}" value="{$req/@opcode}" />
362 <struct name="{xcb:xcb-prefix(@name)}_request_t">
363 <field type="uint8_t" name="major_opcode" no-assign="true" />
365 <field type="uint8_t" name="minor_opcode" no-assign="true" />
367 <xsl:apply-templates select="*[not(self::reply)]" mode="field" />
369 <field type="uint16_t" name="length" no-assign="true" />
372 <xsl:call-template name="request-function">
373 <xsl:with-param name="checked" select="'true'" />
374 <xsl:with-param name="req" select="$req" />
376 <xsl:call-template name="request-function">
377 <xsl:with-param name="checked" select="'false'" />
378 <xsl:with-param name="req" select="$req" />
380 <xsl:if test="reply">
381 <struct name="{xcb:xcb-prefix(@name)}_reply_t">
382 <field type="uint8_t" name="response_type" />
383 <xsl:apply-templates select="reply/*" mode="field" />
385 <field type="uint16_t" name="sequence" />
386 <field type="uint32_t" name="length" />
389 <iterator-functions ref="{xcb:xcb-prefix(@name)}" kind="_reply" />
390 <function type="{xcb:xcb-prefix(@name)}_reply_t *" name="{xcb:xcb-prefix(@name)}_reply">
391 <field type="xcb_connection_t *" name="c" />
392 <field name="cookie">
393 <xsl:attribute name="type">
394 <xsl:call-template name="cookie-type" />
397 <field type="xcb_generic_error_t **" name="e" />
398 <l>return (<xsl:value-of select="xcb:xcb-prefix(@name)" />_reply_t *)<!--
399 --> xcb_wait_for_reply(c, cookie.sequence, e);</l>
404 <xsl:template match="xidtype|xidunion" mode="pass1">
405 <typedef oldname="uint32_t" newname="{xcb:xcb-prefix(@name)}_t" />
406 <iterator ref="{xcb:xcb-prefix(@name)}" />
407 <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
410 <xsl:template match="struct|union" mode="pass1">
411 <struct name="{xcb:xcb-prefix(@name)}_t">
412 <xsl:if test="self::union">
413 <xsl:attribute name="kind">union</xsl:attribute>
415 <xsl:apply-templates select="*" mode="field" />
417 <iterator ref="{xcb:xcb-prefix(@name)}" />
418 <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
421 <xsl:template match="event|eventcopy|error|errorcopy" mode="pass1">
422 <xsl:variable name="suffix">
424 <xsl:when test="self::event|self::eventcopy">
425 <xsl:text>_event_t</xsl:text>
427 <xsl:when test="self::error|self::errorcopy">
428 <xsl:text>_error_t</xsl:text>
432 <constant type="number" name="{xcb:xcb-prefix(@name)}" value="{@number}" />
434 <xsl:when test="self::event|self::error">
435 <struct name="{xcb:xcb-prefix(@name)}{$suffix}">
436 <field type="uint8_t" name="response_type" />
437 <xsl:if test="self::error">
438 <field type="uint8_t" name="error_code" />
440 <xsl:apply-templates select="*" mode="field" />
441 <xsl:if test="not(self::event and boolean(@no-sequence-number))">
443 <field type="uint16_t" name="sequence" />
448 <xsl:when test="self::eventcopy|self::errorcopy">
449 <typedef newname="{xcb:xcb-prefix(@name)}{$suffix}">
450 <xsl:attribute name="oldname">
451 <xsl:call-template name="canonical-type-name">
452 <xsl:with-param name="type" select="@ref" />
454 <xsl:value-of select="$suffix" />
461 <xsl:template match="typedef" mode="pass1">
463 <xsl:attribute name="oldname">
464 <xsl:call-template name="canonical-type-name">
465 <xsl:with-param name="type" select="@oldname" />
467 <xsl:text>_t</xsl:text>
469 <xsl:attribute name="newname">
470 <xsl:call-template name="canonical-type-name">
471 <xsl:with-param name="type" select="@newname" />
473 <xsl:text>_t</xsl:text>
476 <iterator ref="{xcb:xcb-prefix(@newname)}" />
477 <iterator-functions ref="{xcb:xcb-prefix(@newname)}" />
480 <xsl:template match="enum" mode="pass1">
481 <enum name="{xcb:xcb-prefix(@name)}_t">
482 <xsl:for-each select="item">
483 <item name="{translate(xcb:xcb-prefix(concat(../@name, concat('_', @name))), $lcase, $ucase)}">
484 <xsl:copy-of select="*" />
491 Templates for processing fields.
494 <xsl:template match="pad" mode="field">
495 <xsl:copy-of select="." />
498 <xsl:template match="field|exprfield" mode="field">
500 <xsl:attribute name="type">
501 <xsl:call-template name="canonical-type-name" />
502 <xsl:text>_t</xsl:text>
504 <xsl:attribute name="name">
505 <xsl:call-template name="canonical-var-name" />
507 <xsl:copy-of select="*" />
511 <xsl:template match="list" mode="field">
512 <xsl:variable name="type"><!--
513 --><xsl:call-template name="canonical-type-name" />
514 <xsl:text>_t</xsl:text><!--
516 <list type="{$type}">
517 <xsl:attribute name="name">
518 <xsl:call-template name="canonical-var-name" />
520 <xsl:if test="not(parent::request) and node()
521 and not(.//*[not(self::value or self::op)])">
522 <xsl:attribute name="fixed">true</xsl:attribute>
524 <!-- Handle lists with no length expressions. -->
525 <xsl:if test="not(node())">
527 <!-- In a request, refer to an implicit localparam for length. -->
528 <xsl:when test="parent::request">
530 <xsl:value-of select="concat(@name, '_len')" />
533 <!-- In a reply, use the length of the reply to determine the length
535 <xsl:when test="parent::reply">
538 <fieldref>length</fieldref>
541 <function-call name="sizeof">
542 <param><xsl:value-of select="$type" /></param>
546 <!-- Other cases generate an error. -->
548 <xsl:message terminate="yes"><!--
549 -->Encountered a list with no length expresssion outside a<!--
550 --> request or reply.<!--
555 <xsl:copy-of select="*" />
559 <xsl:template match="valueparam" mode="field">
561 <xsl:attribute name="type">
562 <xsl:call-template name="canonical-type-name">
563 <xsl:with-param name="type" select="@value-mask-type" />
565 <xsl:text>_t</xsl:text>
567 <xsl:attribute name="name">
568 <xsl:call-template name="canonical-var-name">
569 <xsl:with-param name="name" select="@value-mask-name" />
573 <list type="uint32_t">
574 <xsl:attribute name="name">
575 <xsl:call-template name="canonical-var-name">
576 <xsl:with-param name="name" select="@value-list-name" />
579 <function-call name="xcb_popcount">
582 <xsl:call-template name="canonical-var-name">
583 <xsl:with-param name="name" select="@value-mask-name" />
591 <xsl:template match="field|localfield" mode="param">
593 <xsl:attribute name="type">
594 <xsl:call-template name="canonical-type-name" />
595 <xsl:text>_t</xsl:text>
597 <xsl:attribute name="name">
598 <xsl:call-template name="canonical-var-name" />
603 <xsl:template match="list" mode="param">
604 <!-- If no length expression is provided, use a CARD32 localfield. -->
605 <xsl:if test="not(node())">
606 <field type="uint32_t" name="{@name}_len" />
609 <xsl:variable name="ctype">
610 <xsl:call-template name="canonical-type-name" />
612 <xsl:attribute name="type">
613 <xsl:text>const </xsl:text>
614 <xsl:call-template name="canonical-type-name" />
615 <xsl:if test="not($ctype='char') and not($ctype='void')">
616 <xsl:text>_t</xsl:text>
618 <xsl:text> *</xsl:text>
620 <xsl:attribute name="name">
621 <xsl:call-template name="canonical-var-name" />
626 <xsl:template match="valueparam" mode="param">
628 <xsl:attribute name="type">
629 <xsl:call-template name="canonical-type-name">
630 <xsl:with-param name="type" select="@value-mask-type" />
632 <xsl:text>_t</xsl:text>
634 <xsl:attribute name="name">
635 <xsl:call-template name="canonical-var-name">
636 <xsl:with-param name="name" select="@value-mask-name" />
640 <field type="const uint32_t *">
641 <xsl:attribute name="name">
642 <xsl:call-template name="canonical-var-name">
643 <xsl:with-param name="name" select="@value-list-name" />
649 <!-- Second pass: Process the variable. -->
650 <xsl:variable name="result-rtf">
651 <xsl:apply-templates select="$pass1/*" mode="pass2" />
653 <xsl:variable name="result" select="e:node-set($result-rtf)" />
655 <xsl:template match="xcb" mode="pass2">
657 <xsl:copy-of select="@*" />
658 <xsl:apply-templates mode="pass2"
659 select="constant|enum|struct|typedef|iterator" />
660 <xsl:apply-templates mode="pass2"
661 select="function|iterator-functions" />
665 <!-- Generic rules for nodes that don't need further processing: copy node
666 with attributes, and recursively process the child nodes. -->
667 <xsl:template match="*" mode="pass2">
669 <xsl:copy-of select="@*" />
670 <xsl:apply-templates mode="pass2" />
674 <xsl:template match="struct" mode="pass2">
675 <xsl:if test="@kind='union' and list[not(@fixed)]">
676 <xsl:message terminate="yes">Unions must be fixed length.</xsl:message>
678 <struct name="{@name}">
679 <xsl:if test="@kind">
680 <xsl:attribute name="kind">
681 <xsl:value-of select="@kind" />
684 <!-- FIXME: This should go by size, not number of fields. -->
685 <xsl:copy-of select="node()[not(self::middle)
686 and position() < 3]" />
687 <xsl:if test="middle and (count(*[not(self::middle)]) < 2)">
688 <pad bytes="{2 - count(*[not(self::middle)])}" />
690 <xsl:copy-of select="middle/*" />
691 <xsl:copy-of select="node()[not(self::middle) and (position() > 2)]" />
695 <xsl:template match="do-request" mode="pass2">
696 <xsl:variable name="struct"
697 select="$pass1/xcb/struct[@name=current()/@ref]" />
699 <xsl:variable name="num-parts" select="(1+count($struct/list))*2" />
701 <l>static const xcb_protocol_request_t xcb_req = {</l>
703 <l>/* count */ <xsl:value-of select="$num-parts" />,</l>
704 <l>/* ext */ <xsl:choose>
705 <xsl:when test="$ext">
706 <xsl:text>&</xsl:text>
707 <xsl:value-of select="xcb:xcb-prefix()" />
708 <xsl:text>_id</xsl:text>
710 <xsl:otherwise>0</xsl:otherwise>
712 <l>/* opcode */ <xsl:value-of select="@opcode" />,</l>
713 <l>/* isvoid */ <xsl:value-of select="1-boolean(@has-reply)" /></l>
718 <l>struct iovec xcb_parts[<xsl:value-of select="$num-parts+2" />];</l>
719 <l><xsl:value-of select="../@type" /> xcb_ret;</l>
720 <l><xsl:value-of select="@ref" /> xcb_out;</l>
723 <xsl:apply-templates select="$struct//*[(self::field or self::exprfield)
724 and not(boolean(@no-assign))]"
728 <l>xcb_parts[2].iov_base = (char *) &xcb_out;</l>
729 <l>xcb_parts[2].iov_len = sizeof(xcb_out);</l>
730 <l>xcb_parts[3].iov_base = 0;</l>
731 <l>xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;</l>
733 <xsl:for-each select="$struct/list">
734 <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_base = (char *) <!--
735 --><xsl:value-of select="@name" />;</l>
736 <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len = <!--
737 --><xsl:apply-templates mode="output-expression" />
738 <xsl:if test="not(@type = 'void_t')">
739 <xsl:text> * sizeof(</xsl:text>
741 <xsl:when test="@type='char_t'">
742 <xsl:text>char</xsl:text>
745 <xsl:value-of select="@type" />
748 <xsl:text>)</xsl:text>
750 <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_base = 0;</l>
751 <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_len = -xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len & 3;</l>
754 <l>xcb_ret.sequence = xcb_send_request(c, <!--
756 <xsl:when test="@checked='true'">XCB_REQUEST_CHECKED</xsl:when>
757 <xsl:otherwise>0</xsl:otherwise>
758 </xsl:choose>, xcb_parts + 2, &xcb_req);</l>
759 <l>return xcb_ret;</l>
762 <xsl:template match="field" mode="assign">
764 <xsl:text>xcb_out.</xsl:text>
765 <xsl:value-of select="@name" />
766 <xsl:text> = </xsl:text>
767 <xsl:value-of select="@name" />
768 <xsl:text>;</xsl:text>
772 <xsl:template match="exprfield" mode="assign">
774 <xsl:text>xcb_out.</xsl:text>
775 <xsl:value-of select="@name" />
776 <xsl:text> = </xsl:text>
777 <xsl:apply-templates mode="output-expression" />
778 <xsl:text>;</xsl:text>
782 <xsl:template match="iterator" mode="pass2">
783 <struct name="{@ref}_iterator_t">
784 <field type="{@ref}_t *" name="data" />
785 <field type="int" name="rem" />
786 <field type="int" name="index" />
790 <xsl:template match="iterator-functions" mode="pass2">
791 <xsl:variable name="ref" select="@ref" />
792 <xsl:variable name="kind" select="@kind" />
793 <xsl:variable name="struct"
794 select="$pass1/xcb/struct[@name=concat($ref, $kind, '_t')]" />
795 <xsl:variable name="nextfields-rtf">
796 <nextfield>R + 1</nextfield>
797 <xsl:for-each select="$struct/list[not(@fixed)]">
799 <xsl:when test="substring(@type, 1, 3) = 'xcb'">
800 <nextfield><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_end(<!--
801 --><xsl:value-of select="$ref" />_<!--
802 --><xsl:value-of select="string(@name)" />_iterator(R))</nextfield>
805 <nextfield><xsl:value-of select="$ref" />_<!--
806 --><xsl:value-of select="string(@name)" />_end(R)</nextfield>
811 <xsl:variable name="nextfields" select="e:node-set($nextfields-rtf)" />
812 <xsl:for-each select="$struct/list[not(@fixed)]">
813 <xsl:variable name="number"
814 select="1+count(preceding-sibling::list[not(@fixed)])" />
815 <xsl:variable name="nextfield" select="$nextfields/nextfield[$number]" />
816 <xsl:variable name="is-first"
817 select="not(preceding-sibling::list[not(@fixed)])" />
818 <xsl:variable name="field-name" select="@name" />
819 <xsl:variable name="is-variable"
820 select="$pass1/xcb/struct[@name=current()/@type]/list
821 or document($search-path)/xcb
822 /struct[concat(xcb:xcb-prefix(@name), '_t')
825 or self::list[.//*[not(self::value
827 <xsl:if test="not($is-variable)">
828 <function type="{xcb:get-char-void(@type)} *" name="{$ref}_{xcb:lowercase($field-name)}">
829 <field type="const {$ref}{$kind}_t *" name="R" />
831 <xsl:when test="$is-first">
832 <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
833 -->(<xsl:value-of select="$nextfield" />);</l>
836 <l>xcb_generic_iterator_t prev = <!--
837 --><xsl:value-of select="$nextfield" />;</l>
838 <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
839 -->((char *) prev.data + XCB_TYPE_PAD(<!--
840 --><xsl:value-of select="xcb:get-char-void(@type)" />, prev.index));</l>
845 <function type="int" name="{$ref}_{xcb:lowercase($field-name)}_length">
846 <field type="const {$ref}{$kind}_t *" name="R" />
847 <l>return <xsl:apply-templates mode="output-expression">
848 <xsl:with-param name="field-prefix" select="'R->'" />
849 </xsl:apply-templates>;</l>
852 <xsl:when test="substring(@type, 1, 3) = 'xcb'">
853 <function type="{substring(@type, 1, string-length(@type)-2)}_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_iterator">
854 <field type="const {$ref}{$kind}_t *" name="R" />
855 <l><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_iterator_t i;</l>
857 <xsl:when test="$is-first">
858 <l>i.data = (<xsl:value-of select="@type" /> *) <!--
859 -->(<xsl:value-of select="$nextfield" />);</l>
862 <l>xcb_generic_iterator_t prev = <!--
863 --><xsl:value-of select="$nextfield" />;</l>
864 <l>i.data = (<xsl:value-of select="@type" /> *) <!--
865 -->((char *) prev.data + XCB_TYPE_PAD(<!--
866 --><xsl:value-of select="@type" />, prev.index));</l>
869 <l>i.rem = <xsl:apply-templates mode="output-expression">
870 <xsl:with-param name="field-prefix" select="'R->'" />
871 </xsl:apply-templates>;</l>
872 <l>i.index = (char *) i.data - (char *) R;</l>
877 <xsl:variable name="cast">
879 <xsl:when test="@type='void'">char</xsl:when>
880 <xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
883 <function type="xcb_generic_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_end">
884 <field type="const {$ref}{$kind}_t *" name="R" />
885 <l>xcb_generic_iterator_t i;</l>
887 <xsl:when test="$is-first">
888 <l>i.data = ((<xsl:value-of select="xcb:remove-void($cast)" /> *) <!--
889 -->(<xsl:value-of select="$nextfield" />)) + (<!--
890 --><xsl:apply-templates mode="output-expression">
891 <xsl:with-param name="field-prefix" select="'R->'" />
892 </xsl:apply-templates>);</l>
895 <l>xcb_generic_iterator_t child = <!--
896 --><xsl:value-of select="$nextfield" />;</l>
897 <l>i.data = ((<xsl:value-of select="xcb:get-char-void($cast)" /> *) <!--
898 -->child.data) + (<!--
899 --><xsl:apply-templates mode="output-expression">
900 <xsl:with-param name="field-prefix" select="'R->'" />
901 </xsl:apply-templates>);</l>
905 <l>i.index = (char *) i.data - (char *) R;</l>
911 <xsl:if test="not($kind)">
912 <function type="void" name="{$ref}_next">
913 <field type="{$ref}_iterator_t *" name="i" />
915 <xsl:when test="$struct/list[not(@fixed)]">
916 <l><xsl:value-of select="$ref" />_t *R = i->data;</l>
917 <l>xcb_generic_iterator_t child = <!--
918 --><xsl:value-of select="$nextfields/nextfield[last()]" />;</l>
920 <l>i->data = (<xsl:value-of select="$ref" />_t *) child.data;</l>
921 <l>i->index = child.index;</l>
926 <l>i->index += sizeof(<xsl:value-of select="$ref" />_t);</l>
930 <function type="xcb_generic_iterator_t" name="{$ref}_end">
931 <field type="{$ref}_iterator_t" name="i" />
932 <l>xcb_generic_iterator_t ret;</l>
934 <xsl:when test="$struct/list[not(@fixed)]">
935 <l>while(i.rem > 0)</l>
937 <l><xsl:value-of select="$ref" />_next(&i);</l>
939 <l>ret.data = i.data;</l>
940 <l>ret.rem = i.rem;</l>
941 <l>ret.index = i.index;</l>
944 <l>ret.data = i.data + i.rem;</l>
945 <l>ret.index = i.index + ((char *) ret.data - (char *) i.data);</l>
954 <!-- Output the results. -->
955 <xsl:template match="/">
956 <xsl:if test="not(function-available('e:node-set'))">
957 <xsl:message terminate="yes"><!--
958 -->Error: This stylesheet requires the EXSL node-set extension.<!--
962 <xsl:if test="not($h) and not($c)">
963 <xsl:message terminate="yes"><!--
964 -->Error: Parameter "mode" must be "header" or "source".<!--
968 <xsl:apply-templates select="$result/*" mode="output" />
971 <xsl:template match="xcb" mode="output">
972 <xsl:variable name="guard"><!--
973 -->__<xsl:value-of select="$ucase-header" />_H<!--
977 * This file generated automatically from </xsl:text>
978 <xsl:value-of select="$header" /><xsl:text>.xml by c-client.xsl using XSLT.
979 * Edit at your peril.
983 <xsl:if test="$h"><xsl:text>
984 #ifndef </xsl:text><xsl:value-of select="$guard" /><xsl:text>
985 #define </xsl:text><xsl:value-of select="$guard" /><xsl:text>
988 <xsl:for-each select="$root/xcb/import">
989 <xsl:text>#include "</xsl:text><xsl:value-of select="." /><xsl:text>.h"
996 <xsl:if test="$c"><xsl:text>
997 #include <assert.h>
999 #include "</xsl:text><xsl:value-of select="$header" /><xsl:text>.h"
1001 </xsl:text></xsl:if>
1003 <xsl:apply-templates mode="output" />
1012 <xsl:template match="constant" mode="output">
1014 <xsl:when test="@type = 'number'">
1016 <xsl:text>#define </xsl:text>
1017 <xsl:value-of select="translate(@name, $lcase, $ucase)" />
1018 <xsl:text> </xsl:text>
1019 <xsl:value-of select="@value" />
1025 <xsl:when test="@type = 'string'">
1027 <xsl:text>extern </xsl:text>
1029 <xsl:text>const char </xsl:text>
1030 <xsl:value-of select="@name" />
1031 <xsl:text>[]</xsl:text>
1033 <xsl:text> = "</xsl:text>
1034 <xsl:value-of select="@value" />
1035 <xsl:text>"</xsl:text>
1043 <xsl:text>extern </xsl:text>
1045 <xsl:call-template name="type-and-name" />
1047 <xsl:text> = </xsl:text>
1048 <xsl:value-of select="@value" />
1057 <xsl:template match="typedef" mode="output">
1059 <xsl:text>typedef </xsl:text>
1060 <xsl:value-of select="xcb:get-char-void(@oldname)" />
1061 <xsl:text> </xsl:text>
1062 <xsl:value-of select="@newname" />
1069 <xsl:template match="struct" mode="output">
1071 <xsl:variable name="type-lengths">
1072 <xsl:call-template name="type-lengths">
1073 <xsl:with-param name="items" select="field/@type" />
1074 </xsl:call-template>
1076 <xsl:text>typedef </xsl:text>
1077 <xsl:if test="not(@kind)">struct</xsl:if><xsl:value-of select="@kind" />
1078 <xsl:text> </xsl:text>
1079 <xsl:value-of select="@name" />
1082 <xsl:for-each select="exprfield|field|list[@fixed]|pad">
1083 <xsl:text> </xsl:text>
1084 <xsl:apply-templates select=".">
1085 <xsl:with-param name="type-lengths" select="$type-lengths" />
1086 </xsl:apply-templates>
1090 <xsl:text>} </xsl:text>
1091 <xsl:value-of select="@name" />
1098 <xsl:template match="enum" mode="output">
1100 <xsl:text>typedef enum </xsl:text>
1101 <xsl:value-of select="@name" />
1104 <xsl:call-template name="list">
1105 <xsl:with-param name="separator"><xsl:text>,
1106 </xsl:text></xsl:with-param>
1107 <xsl:with-param name="items">
1108 <xsl:for-each select="item">
1110 <xsl:value-of select="@name" />
1111 <xsl:if test="node()"> <!-- If there is an expression -->
1112 <xsl:text> = </xsl:text>
1113 <xsl:apply-templates mode="output-expression" />
1118 </xsl:call-template>
1120 } </xsl:text><xsl:value-of select="@name" /><xsl:text>;
1126 <xsl:template match="function" mode="output">
1127 <xsl:variable name="decl-open" select="concat(@name, ' (')" />
1128 <xsl:variable name="type-lengths">
1129 <xsl:call-template name="type-lengths">
1130 <xsl:with-param name="items" select="field/@type" />
1131 </xsl:call-template>
1133 <xsl:value-of select="@type" />
1136 <xsl:value-of select="$decl-open" />
1137 <xsl:call-template name="list">
1138 <xsl:with-param name="separator">
1141 <xsl:call-template name="repeat">
1142 <xsl:with-param name="count" select="string-length($decl-open)" />
1143 </xsl:call-template>
1145 <xsl:with-param name="items">
1146 <xsl:for-each select="field">
1148 <xsl:apply-templates select=".">
1149 <xsl:with-param name="type-lengths" select="$type-lengths" />
1150 </xsl:apply-templates>
1154 </xsl:call-template>
1155 <xsl:text>)</xsl:text>
1157 <xsl:if test="$h"><xsl:text>;
1159 </xsl:text></xsl:if>
1165 <xsl:apply-templates select="l|indent" mode="function-body">
1166 <xsl:with-param name="indent" select="$indent-string" />
1167 </xsl:apply-templates>
1174 <xsl:template match="l" mode="function-body">
1175 <xsl:param name="indent" />
1176 <xsl:value-of select="concat($indent, .)" /><xsl:text>
1180 <xsl:template match="indent" mode="function-body">
1181 <xsl:param name="indent" />
1182 <xsl:apply-templates select="l|indent" mode="function-body">
1183 <xsl:with-param name="indent" select="concat($indent, $indent-string)" />
1184 </xsl:apply-templates>
1187 <xsl:template match="value" mode="output-expression">
1188 <xsl:value-of select="." />
1191 <xsl:template match="fieldref" mode="output-expression">
1192 <xsl:param name="field-prefix" />
1193 <xsl:value-of select="concat($field-prefix, .)" />
1196 <xsl:template match="op" mode="output-expression">
1197 <xsl:param name="field-prefix" />
1198 <xsl:text>(</xsl:text>
1199 <xsl:apply-templates select="node()[1]" mode="output-expression">
1200 <xsl:with-param name="field-prefix" select="$field-prefix" />
1201 </xsl:apply-templates>
1202 <xsl:text> </xsl:text>
1203 <xsl:value-of select="@op" />
1204 <xsl:text> </xsl:text>
1205 <xsl:apply-templates select="node()[2]" mode="output-expression">
1206 <xsl:with-param name="field-prefix" select="$field-prefix" />
1207 </xsl:apply-templates>
1208 <xsl:text>)</xsl:text>
1211 <xsl:template match="bit" mode="output-expression">
1212 <xsl:text>(1 << </xsl:text>
1213 <xsl:value-of select="." />
1214 <xsl:text>)</xsl:text>
1217 <xsl:template match="function-call" mode="output-expression">
1218 <xsl:param name="field-prefix" />
1219 <xsl:value-of select="@name" />
1220 <xsl:text>(</xsl:text>
1221 <xsl:call-template name="list">
1222 <xsl:with-param name="separator" select="', '" />
1223 <xsl:with-param name="items">
1224 <xsl:for-each select="param">
1225 <item><xsl:apply-templates mode="output-expression">
1226 <xsl:with-param name="field-prefix" select="$field-prefix" />
1227 </xsl:apply-templates></item>
1230 </xsl:call-template>
1231 <xsl:text>)</xsl:text>
1234 <!-- Catch invalid elements in expressions. -->
1235 <xsl:template match="*" mode="output-expression">
1236 <xsl:message terminate="yes">
1237 <xsl:text>Invalid element in expression: </xsl:text>
1238 <xsl:value-of select="name()" />
1242 <xsl:template match="field|exprfield">
1243 <xsl:param name="type-lengths" select="0" />
1244 <xsl:call-template name="type-and-name">
1245 <xsl:with-param name="type-lengths" select="$type-lengths" />
1246 </xsl:call-template>
1249 <xsl:template match="list[@fixed]">
1250 <xsl:param name="type-lengths" select="0" />
1251 <xsl:call-template name="type-and-name">
1252 <xsl:with-param name="type-lengths" select="$type-lengths" />
1253 </xsl:call-template>
1254 <xsl:text>[</xsl:text>
1255 <xsl:apply-templates mode="output-expression" />
1256 <xsl:text>]</xsl:text>
1259 <xsl:template match="pad">
1260 <xsl:param name="type-lengths" select="0" />
1262 <xsl:variable name="padnum"><xsl:number /></xsl:variable>
1264 <xsl:call-template name="type-and-name">
1265 <xsl:with-param name="type" select="'uint8_t'" />
1266 <xsl:with-param name="name">
1267 <xsl:text>pad</xsl:text>
1268 <xsl:value-of select="$padnum - 1" />
1270 <xsl:with-param name="type-lengths" select="$type-lengths" />
1271 </xsl:call-template>
1272 <xsl:if test="@bytes > 1">
1273 <xsl:text>[</xsl:text>
1274 <xsl:value-of select="@bytes" />
1275 <xsl:text>]</xsl:text>
1279 <!-- Output the given type and name (defaulting to the corresponding
1280 attributes of the context node), with the appropriate spacing. The
1281 type must consist of a base type (which may contain spaces), then
1282 optionally a single space and a suffix of one or more '*' characters.
1283 If the type-lengths parameter is provided, use it to line up the base
1284 types and suffixs of the type declarations. -->
1285 <xsl:template name="type-and-name">
1286 <xsl:param name="type" select="@type" />
1287 <xsl:param name="name" select="@name" />
1288 <xsl:param name="type-lengths">
1289 <max-type-length>0</max-type-length>
1290 <max-suffix-length>0</max-suffix-length>
1293 <xsl:variable name="type-lengths-ns" select="e:node-set($type-lengths)" />
1294 <xsl:variable name="min-type-length"
1295 select="$type-lengths-ns/max-type-length" />
1296 <xsl:variable name="min-suffix-length"
1297 select="$type-lengths-ns/max-suffix-length" />
1299 <xsl:variable name="base-type">
1301 <xsl:when test="contains($type, ' *')">
1302 <xsl:value-of select="substring-before($type, ' *')" />
1305 <xsl:value-of select="$type" />
1309 <xsl:variable name="suffix">
1310 <xsl:if test="contains($type, ' *')">
1311 <xsl:text>*</xsl:text>
1312 <xsl:value-of select="substring-after($type, ' *')" />
1316 <xsl:value-of select="$base-type" />
1317 <xsl:if test="string-length($base-type) < $min-type-length">
1318 <xsl:call-template name="repeat">
1319 <xsl:with-param name="count" select="$min-type-length
1320 - string-length($base-type)" />
1321 </xsl:call-template>
1323 <xsl:text> </xsl:text>
1324 <xsl:if test="string-length($suffix) < $min-suffix-length">
1325 <xsl:call-template name="repeat">
1326 <xsl:with-param name="count" select="$min-suffix-length
1327 - string-length($suffix)" />
1328 </xsl:call-template>
1330 <xsl:value-of select="$suffix" />
1331 <xsl:value-of select="$name" />
1334 <!-- Output a list with a given separator. Empty items are skipped. -->
1335 <xsl:template name="list">
1336 <xsl:param name="separator" />
1337 <xsl:param name="items" />
1339 <xsl:for-each select="e:node-set($items)/*">
1340 <xsl:value-of select="." />
1341 <xsl:if test="not(position() = last())">
1342 <xsl:value-of select="$separator" />
1347 <!-- Repeat a string (space by default) a given number of times. -->
1348 <xsl:template name="repeat">
1349 <xsl:param name="str" select="' '" />
1350 <xsl:param name="count" />
1352 <xsl:if test="$count > 0">
1353 <xsl:value-of select="$str" />
1354 <xsl:call-template name="repeat">
1355 <xsl:with-param name="str" select="$str" />
1356 <xsl:with-param name="count" select="$count - 1" />
1357 </xsl:call-template>
1361 <!-- Record the maximum type lengths of a set of types for use as the
1362 max-type-lengths parameter of type-and-name. -->
1363 <xsl:template name="type-lengths">
1364 <xsl:param name="items" />
1365 <xsl:variable name="type-lengths-rtf">
1366 <xsl:for-each select="$items">
1369 <xsl:when test="contains(., ' *')">
1370 <xsl:value-of select="string-length(
1371 substring-before(., ' *'))" />
1374 <xsl:value-of select="string-length(.)" />
1380 <xsl:variable name="suffix-lengths-rtf">
1381 <xsl:for-each select="$items">
1384 <xsl:when test="contains(., ' *')">
1385 <xsl:value-of select="string-length(substring-after(., ' *'))
1389 <xsl:text>0</xsl:text>
1396 <xsl:call-template name="max">
1397 <xsl:with-param name="items"
1398 select="e:node-set($type-lengths-rtf)/*" />
1399 </xsl:call-template>
1402 <xsl:call-template name="max">
1403 <xsl:with-param name="items"
1404 select="e:node-set($suffix-lengths-rtf)/*" />
1405 </xsl:call-template>
1406 </max-suffix-length>
1409 <!-- Return the maximum number in a set of numbers. -->
1410 <xsl:template name="max">
1411 <xsl:param name="items" />
1413 <xsl:when test="count($items) = 0">
1414 <xsl:text>0</xsl:text>
1417 <xsl:variable name="head" select="number($items[1])" />
1418 <xsl:variable name="tail-max">
1419 <xsl:call-template name="max">
1420 <xsl:with-param name="items" select="$items[position() > 1]" />
1421 </xsl:call-template>
1424 <xsl:when test="$head > number($tail-max)">
1425 <xsl:value-of select="$head" />
1428 <xsl:value-of select="$tail-max" />