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">
31 <xsl:output method="text" />
33 <xsl:strip-space elements="*" />
35 <!-- "header" or "source" -->
36 <xsl:param name="mode" />
38 <!-- Path to the core protocol descriptions. -->
39 <xsl:param name="base-path" />
41 <!-- Path to the extension protocol descriptions. -->
42 <xsl:param name="extension-path" select="$base-path" />
44 <xsl:variable name="h" select="$mode = 'header'" />
45 <xsl:variable name="c" select="$mode = 'source'" />
47 <!-- String used to indent lines of code. -->
48 <xsl:variable name="indent-string" select="' '" />
50 <xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
51 <xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
53 <xsl:variable name="header" select="/xcb/@header" />
54 <xsl:variable name="ucase-header"
55 select="translate($header,$lcase,$ucase)" />
57 <xsl:variable name="ext" select="/xcb/@extension-name" />
59 <!-- Other protocol descriptions to search for types in, after checking the
60 current protocol description. -->
61 <xsl:variable name="search-path-rtf">
62 <xsl:for-each select="/xcb/import">
63 <path><xsl:value-of select="concat($extension-path, ., '.xml')" /></path>
66 <xsl:when test="$header='xproto'">
67 <path><xsl:value-of select="concat($base-path,
68 'xcb_types.xml')" /></path>
70 <xsl:when test="$header='xcb_types'" />
72 <path><xsl:value-of select="concat($base-path,
73 'xproto.xml')" /></path>
74 <path><xsl:value-of select="concat($base-path,
75 'xcb_types.xml')" /></path>
79 <xsl:variable name="search-path" select="e:node-set($search-path-rtf)/path"/>
81 <xsl:variable name="root" select="/" />
83 <!-- First pass: Store everything in a variable. -->
84 <xsl:variable name="pass1-rtf">
85 <xsl:apply-templates select="/" mode="pass1" />
87 <xsl:variable name="pass1" select="e:node-set($pass1-rtf)" />
89 <xsl:template match="xcb" mode="pass1">
91 <xsl:copy-of select="@*" />
93 <constant type="XCBExtension" name="XCB{$ext}Id">
94 <xsl:attribute name="value">{ "<xsl:value-of select="@extension-xname" />" }</xsl:attribute>
96 <function type="const XCBQueryExtensionRep *" name="XCB{$ext}Init">
97 <field type="XCBConnection *" name="c" />
98 <l>return XCBGetExtensionData(c, &XCB<!--
99 --><xsl:value-of select="$ext" />Id);</l>
102 <xsl:apply-templates mode="pass1" />
106 <!-- Modify names that conflict with C++ keywords by prefixing them with an
107 underscore. If the name parameter is not specified, it defaults to the
108 value of the name attribute on the context node. -->
109 <xsl:template name="canonical-var-name">
110 <xsl:param name="name" select="@name" />
111 <xsl:if test="$name='new' or $name='delete'
112 or $name='class' or $name='operator'">
113 <xsl:text>_</xsl:text>
115 <xsl:value-of select="$name" />
118 <!-- List of core types, for use in canonical-type-name. -->
119 <xsl:variable name="core-types-rtf">
122 <type name="CARD8" />
123 <type name="CARD16" />
124 <type name="CARD32" />
126 <type name="INT16" />
127 <type name="INT32" />
131 <type name="float" />
132 <type name="double" />
135 <xsl:variable name="core-types" select="e:node-set($core-types-rtf)" />
138 Output the canonical name for a type. This will be
139 XCB{extension-containing-Type-if-any}Type, wherever the type is found in
140 the search path, or just Type if not found. If the type parameter is not
141 specified, it defaults to the value of the type attribute on the context
144 <xsl:template name="canonical-type-name">
145 <xsl:param name="type" select="string(@type)" />
147 <xsl:variable name="is-unqualified" select="not(contains($type, ':'))"/>
148 <xsl:variable name="namespace" select="substring-before($type, ':')" />
149 <xsl:variable name="unqualified-type">
151 <xsl:when test="$is-unqualified">
152 <xsl:value-of select="$type" />
155 <xsl:value-of select="substring-after($type, ':')" />
161 <xsl:when test="$is-unqualified and $core-types/type[@name=$type]">
162 <xsl:value-of select="$type" />
165 <xsl:variable name="type-definitions"
166 select="(/xcb|document($search-path)/xcb
167 )[$is-unqualified or @header=$namespace]
168 /*[((self::struct or self::union
169 or self::xidtype or self::enum
170 or self::event or self::eventcopy
171 or self::error or self::errorcopy)
172 and @name=$unqualified-type)
174 and @newname=$unqualified-type)]" />
176 <xsl:when test="count($type-definitions) = 1">
177 <xsl:for-each select="$type-definitions">
178 <xsl:text>XCB</xsl:text>
179 <xsl:value-of select="concat(/xcb/@extension-name,
180 $unqualified-type)" />
183 <xsl:when test="count($type-definitions) > 1">
184 <xsl:message terminate="yes">
185 <xsl:text>Multiple definitions of type "</xsl:text>
186 <xsl:value-of select="$type" />
187 <xsl:text>" found.</xsl:text>
188 <xsl:if test="$is-unqualified">
189 <xsl:for-each select="$type-definitions">
192 <xsl:value-of select="concat(/xcb/@header, ':', $type)" />
198 <xsl:message terminate="yes">
199 <xsl:text>No definitions of type "</xsl:text>
200 <xsl:value-of select="$type" />
201 <xsl:text>" found</xsl:text>
202 <xsl:if test="$is-unqualified">
203 <xsl:text>, and it is not a known core type</xsl:text>
205 <xsl:text>.</xsl:text>
213 <!-- Helper template for requests, that outputs the cookie type. The
214 context node must be the request. -->
215 <xsl:template name="cookie-type">
216 <xsl:text>XCB</xsl:text>
218 <xsl:when test="reply">
219 <xsl:value-of select="concat($ext, @name)" />
222 <xsl:text>Void</xsl:text>
225 <xsl:text>Cookie</xsl:text>
228 <xsl:template match="request" mode="pass1">
229 <xsl:if test="reply">
230 <struct name="XCB{$ext}{@name}Cookie">
231 <field type="unsigned int" name="sequence" />
234 <struct name="XCB{$ext}{@name}Req">
235 <field type="CARD8" name="major_opcode" no-assign="true" />
237 <field type="CARD8" name="minor_opcode" no-assign="true" />
239 <xsl:apply-templates select="*[not(self::reply)]" mode="field" />
241 <field type="CARD16" name="length" no-assign="true" />
244 <function name="XCB{$ext}{@name}">
245 <xsl:attribute name="type">
246 <xsl:call-template name="cookie-type" />
248 <field type="XCBConnection *" name="c" />
249 <xsl:apply-templates select="*[not(self::reply)]" mode="param" />
250 <do-request ref="XCB{$ext}{@name}Req" opcode="{@opcode}">
251 <xsl:if test="reply">
252 <xsl:attribute name="has-reply">true</xsl:attribute>
256 <xsl:if test="reply">
257 <struct name="XCB{$ext}{@name}Rep">
258 <field type="BYTE" name="response_type" />
259 <xsl:apply-templates select="reply/*" mode="field" />
261 <field type="CARD16" name="sequence" />
262 <field type="CARD32" name="length" />
265 <iterator-functions ref="XCB{$ext}{@name}" kind="Rep" />
266 <function type="XCB{$ext}{@name}Rep *" name="XCB{$ext}{@name}Reply">
267 <field type="XCBConnection *" name="c" />
268 <field name="cookie">
269 <xsl:attribute name="type">
270 <xsl:call-template name="cookie-type" />
273 <field type="XCBGenericError **" name="e" />
274 <l>return (XCB<xsl:value-of select="concat($ext, @name)" />Rep *)<!--
275 --> XCBWaitForReply(c, cookie.sequence, e);</l>
280 <xsl:template match="xidtype" mode="pass1">
281 <struct name="XCB{$ext}{@name}">
282 <field type="CARD32" name="xid" />
284 <iterator ref="XCB{$ext}{@name}" />
285 <iterator-functions ref="XCB{$ext}{@name}" />
286 <function type="XCB{$ext}{@name}" name="XCB{$ext}{@name}New">
287 <field type="XCBConnection *" name="c" />
288 <l>XCB<xsl:value-of select="concat($ext, @name)" /> ret;</l>
289 <l>ret.xid = XCBGenerateID(c);</l>
294 <xsl:template match="struct|union" mode="pass1">
295 <struct name="XCB{$ext}{@name}">
296 <xsl:if test="self::union">
297 <xsl:attribute name="kind">union</xsl:attribute>
299 <xsl:apply-templates select="*" mode="field" />
301 <iterator ref="XCB{$ext}{@name}" />
302 <iterator-functions ref="XCB{$ext}{@name}" />
305 <xsl:template match="event|eventcopy|error|errorcopy" mode="pass1">
306 <xsl:variable name="suffix">
308 <xsl:when test="self::event|self::eventcopy">
309 <xsl:text>Event</xsl:text>
311 <xsl:when test="self::error|self::errorcopy">
312 <xsl:text>Error</xsl:text>
316 <constant type="number" name="XCB{$ext}{@name}" value="{@number}" />
318 <xsl:when test="self::event|self::error">
319 <struct name="XCB{$ext}{@name}{$suffix}">
320 <field type="BYTE" name="response_type" />
321 <xsl:if test="self::error">
322 <field type="BYTE" name="error_code" />
324 <xsl:apply-templates select="*" mode="field" />
325 <xsl:if test="not(self::event and boolean(@no-sequence-number))">
327 <field type="CARD16" name="sequence" />
332 <xsl:when test="self::eventcopy|self::errorcopy">
333 <typedef newname="XCB{$ext}{@name}{$suffix}">
334 <xsl:attribute name="oldname">
335 <xsl:call-template name="canonical-type-name">
336 <xsl:with-param name="type" select="@ref" />
338 <xsl:value-of select="$suffix" />
345 <xsl:template match="typedef" mode="pass1">
347 <xsl:attribute name="oldname">
348 <xsl:call-template name="canonical-type-name">
349 <xsl:with-param name="type" select="@oldname" />
352 <xsl:attribute name="newname">
353 <xsl:call-template name="canonical-type-name">
354 <xsl:with-param name="type" select="@newname" />
358 <iterator ref="XCB{$ext}{@newname}" />
359 <iterator-functions ref="XCB{$ext}{@newname}" />
362 <xsl:template match="enum" mode="pass1">
363 <enum name="XCB{$ext}{@name}">
364 <xsl:for-each select="item">
365 <item name="XCB{$ext}{../@name}{@name}">
366 <xsl:copy-of select="*" />
373 Templates for processing fields.
376 <xsl:template match="pad" mode="field">
377 <xsl:copy-of select="." />
380 <xsl:template match="field|exprfield" mode="field">
382 <xsl:attribute name="type">
383 <xsl:call-template name="canonical-type-name" />
385 <xsl:attribute name="name">
386 <xsl:call-template name="canonical-var-name" />
388 <xsl:copy-of select="*" />
392 <xsl:template match="list" mode="field">
393 <xsl:variable name="type"><!--
394 --><xsl:call-template name="canonical-type-name" /><!--
396 <list type="{$type}">
397 <xsl:attribute name="name">
398 <xsl:call-template name="canonical-var-name" />
400 <xsl:if test="not(parent::request) and node()
401 and not(.//*[not(self::value or self::op)])">
402 <xsl:attribute name="fixed">true</xsl:attribute>
404 <!-- Handle lists with no length expressions. -->
405 <xsl:if test="not(node())">
407 <!-- In a request, refer to an implicit localparam for length. -->
408 <xsl:when test="parent::request">
410 <xsl:value-of select="concat(@name, '_len')" />
413 <!-- In a reply, use the length of the reply to determine the length
415 <xsl:when test="parent::reply">
418 <fieldref>length</fieldref>
421 <function-call name="sizeof">
422 <param><xsl:value-of select="$type" /></param>
426 <!-- Other cases generate an error. -->
428 <xsl:message terminate="yes"><!--
429 -->Encountered a list with no length expresssion outside a<!--
430 --> request or reply.<!--
435 <xsl:copy-of select="*" />
439 <xsl:template match="valueparam" mode="field">
441 <xsl:attribute name="type">
442 <xsl:call-template name="canonical-type-name">
443 <xsl:with-param name="type" select="@value-mask-type" />
446 <xsl:attribute name="name">
447 <xsl:call-template name="canonical-var-name">
448 <xsl:with-param name="name" select="@value-mask-name" />
453 <xsl:attribute name="name">
454 <xsl:call-template name="canonical-var-name">
455 <xsl:with-param name="name" select="@value-list-name" />
458 <function-call name="XCBPopcount">
461 <xsl:call-template name="canonical-var-name">
462 <xsl:with-param name="name" select="@value-mask-name" />
470 <xsl:template match="field|localfield" mode="param">
472 <xsl:attribute name="type">
473 <xsl:call-template name="canonical-type-name" />
475 <xsl:attribute name="name">
476 <xsl:call-template name="canonical-var-name" />
481 <xsl:template match="list" mode="param">
482 <!-- If no length expression is provided, use a CARD32 localfield. -->
483 <xsl:if test="not(node())">
484 <field type="CARD32" name="{@name}_len" />
487 <xsl:attribute name="type">
488 <xsl:text>const </xsl:text>
489 <xsl:call-template name="canonical-type-name" />
490 <xsl:text> *</xsl:text>
492 <xsl:attribute name="name">
493 <xsl:call-template name="canonical-var-name" />
498 <xsl:template match="valueparam" mode="param">
500 <xsl:attribute name="type">
501 <xsl:call-template name="canonical-type-name">
502 <xsl:with-param name="type" select="@value-mask-type" />
505 <xsl:attribute name="name">
506 <xsl:call-template name="canonical-var-name">
507 <xsl:with-param name="name" select="@value-mask-name" />
511 <field type="const CARD32 *">
512 <xsl:attribute name="name">
513 <xsl:call-template name="canonical-var-name">
514 <xsl:with-param name="name" select="@value-list-name" />
520 <!-- Second pass: Process the variable. -->
521 <xsl:variable name="result-rtf">
522 <xsl:apply-templates select="$pass1/*" mode="pass2" />
524 <xsl:variable name="result" select="e:node-set($result-rtf)" />
526 <xsl:template match="xcb" mode="pass2">
528 <xsl:copy-of select="@*" />
529 <xsl:apply-templates mode="pass2"
530 select="constant|enum|struct|typedef|iterator" />
531 <xsl:apply-templates mode="pass2"
532 select="function|iterator-functions" />
536 <!-- Generic rules for nodes that don't need further processing: copy node
537 with attributes, and recursively process the child nodes. -->
538 <xsl:template match="*" mode="pass2">
540 <xsl:copy-of select="@*" />
541 <xsl:apply-templates mode="pass2" />
545 <xsl:template match="struct" mode="pass2">
546 <xsl:if test="@kind='union' and list[not(@fixed)]">
547 <xsl:message terminate="yes">Unions must be fixed length.</xsl:message>
549 <struct name="{@name}">
550 <xsl:if test="@kind">
551 <xsl:attribute name="kind">
552 <xsl:value-of select="@kind" />
555 <!-- FIXME: This should go by size, not number of fields. -->
556 <xsl:copy-of select="node()[not(self::middle)
557 and position() < 3]" />
558 <xsl:if test="middle and (count(*[not(self::middle)]) < 2)">
559 <pad bytes="{2 - count(*[not(self::middle)])}" />
561 <xsl:copy-of select="middle/*" />
562 <xsl:copy-of select="node()[not(self::middle) and (position() > 2)]" />
566 <xsl:template match="do-request" mode="pass2">
567 <xsl:variable name="struct"
568 select="$pass1/xcb/struct[@name=current()/@ref]" />
570 <xsl:variable name="num-parts" select="(1+count($struct/list))*2" />
572 <l>static const XCBProtocolRequest xcb_req = {</l>
574 <l>/* count */ <xsl:value-of select="$num-parts" />,</l>
575 <l>/* ext */ <xsl:choose>
576 <xsl:when test="$ext">
577 <xsl:text>&XCB</xsl:text>
578 <xsl:value-of select="$ext" />
579 <xsl:text>Id</xsl:text>
581 <xsl:otherwise>0</xsl:otherwise>
583 <l>/* opcode */ <xsl:value-of select="@opcode" />,</l>
584 <l>/* isvoid */ <xsl:value-of select="1-boolean(@has-reply)" /></l>
589 <l>struct iovec xcb_parts[<xsl:value-of select="$num-parts+2" />];</l>
590 <l><xsl:value-of select="../@type" /> xcb_ret;</l>
591 <l><xsl:value-of select="@ref" /> xcb_out;</l>
594 <xsl:apply-templates select="$struct//*[(self::field or self::exprfield)
595 and not(boolean(@no-assign))]"
599 <l>xcb_parts[2].iov_base = (char *) &xcb_out;</l>
600 <l>xcb_parts[2].iov_len = sizeof(xcb_out);</l>
601 <l>xcb_parts[3].iov_base = 0;</l>
602 <l>xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;</l>
604 <xsl:for-each select="$struct/list">
605 <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_base = (char *) <!--
606 --><xsl:value-of select="@name" />;</l>
607 <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len = <!--
608 --><xsl:apply-templates mode="output-expression" /><!--
609 --><xsl:if test="not(@type = 'void')">
610 <xsl:text> * sizeof(</xsl:text>
611 <xsl:value-of select="@type" />
612 <xsl:text>)</xsl:text>
614 <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_base = 0;</l>
615 <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>
618 <l>xcb_ret.sequence = XCBSendRequest(c, <!--
620 <xsl:when test="@has-reply">XCB_REQUEST_CHECKED</xsl:when>
621 <xsl:otherwise>0</xsl:otherwise>
622 </xsl:choose>, xcb_parts + 2, &xcb_req);</l>
623 <l>return xcb_ret;</l>
626 <xsl:template match="field" mode="assign">
628 <xsl:text>xcb_out.</xsl:text>
629 <xsl:value-of select="@name" />
630 <xsl:text> = </xsl:text>
631 <xsl:value-of select="@name" />
632 <xsl:text>;</xsl:text>
636 <xsl:template match="exprfield" mode="assign">
638 <xsl:text>xcb_out.</xsl:text>
639 <xsl:value-of select="@name" />
640 <xsl:text> = </xsl:text>
641 <xsl:apply-templates mode="output-expression" />
642 <xsl:text>;</xsl:text>
646 <xsl:template match="iterator" mode="pass2">
647 <struct name="{@ref}Iter">
648 <field type="{@ref} *" name="data" />
649 <field type="int" name="rem" />
650 <field type="int" name="index" />
654 <!-- Change a_name_like_this to ANameLikeThis. If the parameter name is not
655 given, it defaults to the name attribute of the context node. -->
656 <xsl:template name="capitalize">
657 <xsl:param name="name" select="string(@name)" />
658 <xsl:if test="$name">
659 <xsl:value-of select="translate(substring($name,1,1), $lcase, $ucase)" />
661 <xsl:when test="contains($name, '_')">
662 <xsl:value-of select="substring(substring-before($name, '_'), 2)" />
663 <xsl:call-template name="capitalize">
664 <xsl:with-param name="name" select="substring-after($name, '_')" />
668 <xsl:value-of select="substring($name, 2)" />
674 <xsl:template match="iterator-functions" mode="pass2">
675 <xsl:variable name="ref" select="@ref" />
676 <xsl:variable name="kind" select="@kind" />
677 <xsl:variable name="struct"
678 select="$pass1/xcb/struct[@name=concat($ref,$kind)]" />
679 <xsl:variable name="nextfields-rtf">
680 <nextfield>R + 1</nextfield>
681 <xsl:for-each select="$struct/list[not(@fixed)]">
683 <xsl:when test="substring(@type, 1, 3) = 'XCB'">
684 <nextfield><xsl:value-of select="@type" />End(<!--
685 --><xsl:value-of select="$ref" /><!--
686 --><xsl:call-template name="capitalize" />Iter(R))</nextfield>
689 <nextfield><xsl:value-of select="$ref" /><!--
690 --><xsl:call-template name="capitalize" />End(R)</nextfield>
695 <xsl:variable name="nextfields" select="e:node-set($nextfields-rtf)" />
696 <xsl:for-each select="$struct/list[not(@fixed)]">
697 <xsl:variable name="number"
698 select="1+count(preceding-sibling::list[not(@fixed)])" />
699 <xsl:variable name="nextfield" select="$nextfields/nextfield[$number]" />
700 <xsl:variable name="is-first"
701 select="not(preceding-sibling::list[not(@fixed)])" />
702 <xsl:variable name="field-name"><!--
703 --><xsl:call-template name="capitalize" /><!--
705 <xsl:variable name="is-variable"
706 select="$pass1/xcb/struct[@name=current()/@type]/list
707 or document($search-path)/xcb
708 /struct[concat('XCB',
709 ancestor::xcb/@extension-name,
710 @name) = current()/@type]
711 /*[self::valueparam or self::list]" />
712 <xsl:if test="not($is-variable)">
713 <function type="{@type} *" name="{$ref}{$field-name}">
714 <field type="{$ref}{$kind} *" name="R" />
716 <xsl:when test="$is-first">
717 <l>return (<xsl:value-of select="@type" /> *) <!--
718 -->(<xsl:value-of select="$nextfield" />);</l>
721 <l>XCBGenericIter prev = <!--
722 --><xsl:value-of select="$nextfield" />;</l>
723 <l>return (<xsl:value-of select="@type" /> *) <!--
724 -->((char *) prev.data + XCB_TYPE_PAD(<!--
725 --><xsl:value-of select="@type" />, prev.index));</l>
730 <function type="int" name="{$ref}{$field-name}Length">
731 <field type="{$ref}{$kind} *" name="R" />
732 <l>return <xsl:apply-templates mode="output-expression">
733 <xsl:with-param name="field-prefix" select="'R->'" />
734 </xsl:apply-templates>;</l>
737 <xsl:when test="substring(@type, 1, 3) = 'XCB'">
738 <function type="{@type}Iter" name="{$ref}{$field-name}Iter">
739 <field type="{$ref}{$kind} *" name="R" />
740 <l><xsl:value-of select="@type" />Iter i;</l>
742 <xsl:when test="$is-first">
743 <l>i.data = (<xsl:value-of select="@type" /> *) <!--
744 -->(<xsl:value-of select="$nextfield" />);</l>
747 <l>XCBGenericIter prev = <!--
748 --><xsl:value-of select="$nextfield" />;</l>
749 <l>i.data = (<xsl:value-of select="@type" /> *) <!--
750 -->((char *) prev.data + XCB_TYPE_PAD(<!--
751 --><xsl:value-of select="@type" />, prev.index));</l>
754 <l>i.rem = <xsl:apply-templates mode="output-expression">
755 <xsl:with-param name="field-prefix" select="'R->'" />
756 </xsl:apply-templates>;</l>
757 <l>i.index = (char *) i.data - (char *) R;</l>
762 <xsl:variable name="cast">
764 <xsl:when test="@type='void'">char</xsl:when>
765 <xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
768 <function type="XCBGenericIter" name="{$ref}{$field-name}End">
769 <field type="{$ref}{$kind} *" name="R" />
770 <l>XCBGenericIter i;</l>
772 <xsl:when test="$is-first">
773 <l>i.data = ((<xsl:value-of select="$cast" /> *) <!--
774 -->(<xsl:value-of select="$nextfield" />)) + (<!--
775 --><xsl:apply-templates mode="output-expression">
776 <xsl:with-param name="field-prefix" select="'R->'" />
777 </xsl:apply-templates>);</l>
780 <l>XCBGenericIter child = <!--
781 --><xsl:value-of select="$nextfield" />;</l>
782 <l>i.data = ((<xsl:value-of select="$cast" /> *) <!--
783 -->child.data) + (<!--
784 --><xsl:apply-templates mode="output-expression">
785 <xsl:with-param name="field-prefix" select="'R->'" />
786 </xsl:apply-templates>);</l>
790 <l>i.index = (char *) i.data - (char *) R;</l>
796 <xsl:if test="not($kind)">
797 <function type="void" name="{$ref}Next">
798 <field type="{$ref}Iter *" name="i" />
800 <xsl:when test="$struct/list[not(@fixed)]">
801 <l><xsl:value-of select="$ref" /> *R = i->data;</l>
802 <l>XCBGenericIter child = <!--
803 --><xsl:value-of select="$nextfields/nextfield[last()]" />;</l>
805 <l>i->data = (<xsl:value-of select="$ref" /> *) child.data;</l>
806 <l>i->index = child.index;</l>
811 <l>i->index += sizeof(<xsl:value-of select="$ref" />);</l>
815 <function type="XCBGenericIter" name="{$ref}End">
816 <field type="{$ref}Iter" name="i" />
817 <l>XCBGenericIter ret;</l>
819 <xsl:when test="$struct/list[not(@fixed)]">
820 <l>while(i.rem > 0)</l>
822 <l><xsl:value-of select="$ref" />Next(&i);</l>
824 <l>ret.data = i.data;</l>
825 <l>ret.rem = i.rem;</l>
826 <l>ret.index = i.index;</l>
829 <l>ret.data = i.data + i.rem;</l>
830 <l>ret.index = i.index + ((char *) ret.data - (char *) i.data);</l>
839 <!-- Output the results. -->
840 <xsl:template match="/">
841 <xsl:if test="not(function-available('e:node-set'))">
842 <xsl:message terminate="yes"><!--
843 -->Error: This stylesheet requires the EXSL node-set extension.<!--
847 <xsl:if test="not($h) and not($c)">
848 <xsl:message terminate="yes"><!--
849 -->Error: Parameter "mode" must be "header" or "source".<!--
853 <xsl:apply-templates select="$result/*" mode="output" />
856 <xsl:template match="xcb" mode="output">
857 <xsl:variable name="guard"><!--
858 -->__<xsl:value-of select="$ucase-header" />_H<!--
862 * This file generated automatically from </xsl:text>
863 <xsl:value-of select="$header" /><xsl:text>.xml by c-client.xsl using XSLT.
864 * Edit at your peril.
868 <xsl:if test="$h"><xsl:text>
869 #ifndef </xsl:text><xsl:value-of select="$guard" /><xsl:text>
870 #define </xsl:text><xsl:value-of select="$guard" /><xsl:text>
873 <xsl:for-each select="$root/xcb/import">
874 <xsl:text>#include "</xsl:text><xsl:value-of select="." /><xsl:text>.h"
881 <xsl:if test="$c"><xsl:text>
882 #include <assert.h>
884 #include "</xsl:text><xsl:value-of select="$header" /><xsl:text>.h"
888 <xsl:apply-templates mode="output" />
897 <xsl:template match="constant" mode="output">
899 <xsl:when test="@type = 'number'">
901 <xsl:text>#define </xsl:text>
902 <xsl:value-of select="@name" />
903 <xsl:text> </xsl:text>
904 <xsl:value-of select="@value" />
910 <xsl:when test="@type = 'string'">
912 <xsl:text>extern </xsl:text>
914 <xsl:text>const char </xsl:text>
915 <xsl:value-of select="@name" />
916 <xsl:text>[]</xsl:text>
918 <xsl:text> = "</xsl:text>
919 <xsl:value-of select="@value" />
920 <xsl:text>"</xsl:text>
928 <xsl:text>extern </xsl:text>
930 <xsl:call-template name="type-and-name" />
932 <xsl:text> = </xsl:text>
933 <xsl:value-of select="@value" />
942 <xsl:template match="typedef" mode="output">
944 <xsl:text>typedef </xsl:text>
945 <xsl:value-of select="@oldname" />
946 <xsl:text> </xsl:text>
947 <xsl:value-of select="@newname" />
954 <xsl:template match="struct" mode="output">
956 <xsl:variable name="type-lengths">
957 <xsl:call-template name="type-lengths">
958 <xsl:with-param name="items" select="field/@type" />
961 <xsl:text>typedef </xsl:text>
962 <xsl:if test="not(@kind)">struct</xsl:if><xsl:value-of select="@kind" />
965 <xsl:for-each select="exprfield|field|list[@fixed]|pad">
966 <xsl:text> </xsl:text>
967 <xsl:apply-templates select=".">
968 <xsl:with-param name="type-lengths" select="$type-lengths" />
969 </xsl:apply-templates>
973 <xsl:text>} </xsl:text>
974 <xsl:value-of select="@name" />
981 <xsl:template match="enum" mode="output">
983 <xsl:text>typedef enum {
985 <xsl:call-template name="list">
986 <xsl:with-param name="separator"><xsl:text>,
987 </xsl:text></xsl:with-param>
988 <xsl:with-param name="items">
989 <xsl:for-each select="item">
991 <xsl:value-of select="@name" />
992 <xsl:if test="node()"> <!-- If there is an expression -->
993 <xsl:text> = </xsl:text>
994 <xsl:apply-templates mode="output-expression" />
1001 } </xsl:text><xsl:value-of select="@name" /><xsl:text>;
1007 <xsl:template match="function" mode="output">
1008 <xsl:variable name="decl-open" select="concat(@name, ' (')" />
1009 <xsl:variable name="type-lengths">
1010 <xsl:call-template name="type-lengths">
1011 <xsl:with-param name="items" select="field/@type" />
1012 </xsl:call-template>
1014 <xsl:value-of select="@type" />
1017 <xsl:value-of select="$decl-open" />
1018 <xsl:call-template name="list">
1019 <xsl:with-param name="separator">
1022 <xsl:call-template name="repeat">
1023 <xsl:with-param name="count" select="string-length($decl-open)" />
1024 </xsl:call-template>
1026 <xsl:with-param name="items">
1027 <xsl:for-each select="field">
1029 <xsl:apply-templates select=".">
1030 <xsl:with-param name="type-lengths" select="$type-lengths" />
1031 </xsl:apply-templates>
1035 </xsl:call-template>
1036 <xsl:text>)</xsl:text>
1038 <xsl:if test="$h"><xsl:text>;
1040 </xsl:text></xsl:if>
1046 <xsl:apply-templates select="l|indent" mode="function-body">
1047 <xsl:with-param name="indent" select="$indent-string" />
1048 </xsl:apply-templates>
1055 <xsl:template match="l" mode="function-body">
1056 <xsl:param name="indent" />
1057 <xsl:value-of select="concat($indent, .)" /><xsl:text>
1061 <xsl:template match="indent" mode="function-body">
1062 <xsl:param name="indent" />
1063 <xsl:apply-templates select="l|indent" mode="function-body">
1064 <xsl:with-param name="indent" select="concat($indent, $indent-string)" />
1065 </xsl:apply-templates>
1068 <xsl:template match="value" mode="output-expression">
1069 <xsl:value-of select="." />
1072 <xsl:template match="fieldref" mode="output-expression">
1073 <xsl:param name="field-prefix" />
1074 <xsl:value-of select="concat($field-prefix, .)" />
1077 <xsl:template match="op" mode="output-expression">
1078 <xsl:param name="field-prefix" />
1079 <xsl:text>(</xsl:text>
1080 <xsl:apply-templates select="node()[1]" mode="output-expression">
1081 <xsl:with-param name="field-prefix" select="$field-prefix" />
1082 </xsl:apply-templates>
1083 <xsl:text> </xsl:text>
1084 <xsl:value-of select="@op" />
1085 <xsl:text> </xsl:text>
1086 <xsl:apply-templates select="node()[2]" mode="output-expression">
1087 <xsl:with-param name="field-prefix" select="$field-prefix" />
1088 </xsl:apply-templates>
1089 <xsl:text>)</xsl:text>
1092 <xsl:template match="bit" mode="output-expression">
1093 <xsl:text>(1 << </xsl:text>
1094 <xsl:value-of select="@bit" />
1095 <xsl:text>)</xsl:text>
1098 <xsl:template match="function-call" mode="output-expression">
1099 <xsl:param name="field-prefix" />
1100 <xsl:value-of select="@name" />
1101 <xsl:text>(</xsl:text>
1102 <xsl:call-template name="list">
1103 <xsl:with-param name="separator" select="', '" />
1104 <xsl:with-param name="items">
1105 <xsl:for-each select="param">
1106 <item><xsl:apply-templates mode="output-expression">
1107 <xsl:with-param name="field-prefix" select="$field-prefix" />
1108 </xsl:apply-templates></item>
1111 </xsl:call-template>
1112 <xsl:text>)</xsl:text>
1115 <!-- Catch invalid elements in expressions. -->
1116 <xsl:template match="*" mode="output-expression">
1117 <xsl:message terminate="yes">
1118 <xsl:text>Invalid element in expression: </xsl:text>
1119 <xsl:value-of select="name()" />
1123 <xsl:template match="field|exprfield">
1124 <xsl:param name="type-lengths" select="0" />
1125 <xsl:call-template name="type-and-name">
1126 <xsl:with-param name="type-lengths" select="$type-lengths" />
1127 </xsl:call-template>
1130 <xsl:template match="list[@fixed]">
1131 <xsl:param name="type-lengths" select="0" />
1132 <xsl:call-template name="type-and-name">
1133 <xsl:with-param name="type-lengths" select="$type-lengths" />
1134 </xsl:call-template>
1135 <xsl:text>[</xsl:text>
1136 <xsl:apply-templates mode="output-expression" />
1137 <xsl:text>]</xsl:text>
1140 <xsl:template match="pad">
1141 <xsl:param name="type-lengths" select="0" />
1143 <xsl:variable name="padnum"><xsl:number /></xsl:variable>
1145 <xsl:call-template name="type-and-name">
1146 <xsl:with-param name="type" select="'CARD8'" />
1147 <xsl:with-param name="name">
1148 <xsl:text>pad</xsl:text>
1149 <xsl:value-of select="$padnum - 1" />
1151 <xsl:with-param name="type-lengths" select="$type-lengths" />
1152 </xsl:call-template>
1153 <xsl:if test="@bytes > 1">
1154 <xsl:text>[</xsl:text>
1155 <xsl:value-of select="@bytes" />
1156 <xsl:text>]</xsl:text>
1160 <!-- Output the given type and name (defaulting to the corresponding
1161 attributes of the context node), with the appropriate spacing. The
1162 type must consist of a base type (which may contain spaces), then
1163 optionally a single space and a suffix of one or more '*' characters.
1164 If the type-lengths parameter is provided, use it to line up the base
1165 types and suffixs of the type declarations. -->
1166 <xsl:template name="type-and-name">
1167 <xsl:param name="type" select="@type" />
1168 <xsl:param name="name" select="@name" />
1169 <xsl:param name="type-lengths">
1170 <max-type-length>0</max-type-length>
1171 <max-suffix-length>0</max-suffix-length>
1174 <xsl:variable name="type-lengths-ns" select="e:node-set($type-lengths)" />
1175 <xsl:variable name="min-type-length"
1176 select="$type-lengths-ns/max-type-length" />
1177 <xsl:variable name="min-suffix-length"
1178 select="$type-lengths-ns/max-suffix-length" />
1180 <xsl:variable name="base-type">
1182 <xsl:when test="contains($type, ' *')">
1183 <xsl:value-of select="substring-before($type, ' *')" />
1186 <xsl:value-of select="$type" />
1190 <xsl:variable name="suffix">
1191 <xsl:if test="contains($type, ' *')">
1192 <xsl:text>*</xsl:text>
1193 <xsl:value-of select="substring-after($type, ' *')" />
1197 <xsl:value-of select="$base-type" />
1198 <xsl:if test="string-length($base-type) < $min-type-length">
1199 <xsl:call-template name="repeat">
1200 <xsl:with-param name="count" select="$min-type-length
1201 - string-length($base-type)" />
1202 </xsl:call-template>
1204 <xsl:text> </xsl:text>
1205 <xsl:if test="string-length($suffix) < $min-suffix-length">
1206 <xsl:call-template name="repeat">
1207 <xsl:with-param name="count" select="$min-suffix-length
1208 - string-length($suffix)" />
1209 </xsl:call-template>
1211 <xsl:value-of select="$suffix" />
1212 <xsl:value-of select="$name" />
1215 <!-- Output a list with a given separator. Empty items are skipped. -->
1216 <xsl:template name="list">
1217 <xsl:param name="separator" />
1218 <xsl:param name="items" />
1220 <xsl:for-each select="e:node-set($items)/*">
1221 <xsl:value-of select="." />
1222 <xsl:if test="not(position() = last())">
1223 <xsl:value-of select="$separator" />
1228 <!-- Repeat a string (space by default) a given number of times. -->
1229 <xsl:template name="repeat">
1230 <xsl:param name="str" select="' '" />
1231 <xsl:param name="count" />
1233 <xsl:if test="$count > 0">
1234 <xsl:value-of select="$str" />
1235 <xsl:call-template name="repeat">
1236 <xsl:with-param name="str" select="$str" />
1237 <xsl:with-param name="count" select="$count - 1" />
1238 </xsl:call-template>
1242 <!-- Record the maximum type lengths of a set of types for use as the
1243 max-type-lengths parameter of type-and-name. -->
1244 <xsl:template name="type-lengths">
1245 <xsl:param name="items" />
1246 <xsl:variable name="type-lengths-rtf">
1247 <xsl:for-each select="$items">
1250 <xsl:when test="contains(., ' *')">
1251 <xsl:value-of select="string-length(
1252 substring-before(., ' *'))" />
1255 <xsl:value-of select="string-length(.)" />
1261 <xsl:variable name="suffix-lengths-rtf">
1262 <xsl:for-each select="$items">
1265 <xsl:when test="contains(., ' *')">
1266 <xsl:value-of select="string-length(substring-after(., ' *'))
1270 <xsl:text>0</xsl:text>
1277 <xsl:call-template name="max">
1278 <xsl:with-param name="items"
1279 select="e:node-set($type-lengths-rtf)/*" />
1280 </xsl:call-template>
1283 <xsl:call-template name="max">
1284 <xsl:with-param name="items"
1285 select="e:node-set($suffix-lengths-rtf)/*" />
1286 </xsl:call-template>
1287 </max-suffix-length>
1290 <!-- Return the maximum number in a set of numbers. -->
1291 <xsl:template name="max">
1292 <xsl:param name="items" />
1294 <xsl:when test="count($items) = 0">
1295 <xsl:text>0</xsl:text>
1298 <xsl:variable name="head" select="number($items[1])" />
1299 <xsl:variable name="tail-max">
1300 <xsl:call-template name="max">
1301 <xsl:with-param name="items" select="$items[position() > 1]" />
1302 </xsl:call-template>
1305 <xsl:when test="$head > number($tail-max)">
1306 <xsl:value-of select="$head" />
1309 <xsl:value-of select="$tail-max" />