1 <!-- Stylesheet to extract C enumerations from the AT-SPI spec.
3 Copyright (C) 2006, 2007 Collabora Limited
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
22 xmlns:str="http://exslt.org/strings"
23 exclude-result-prefixes="str tp">
25 <xsl:output method="text" indent="no" encoding="ascii"/>
27 <xsl:param name="mixed-case-prefix" select="''"/>
29 <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
30 <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
32 <xsl:variable name="lower-case-prefix" select="translate($mixed-case-prefix, $upper, $lower)"/>
35 <xsl:template match="tp:flags">
36 <xsl:variable name="name">
38 <xsl:when test="@plural">
39 <xsl:value-of select="@plural"/>
42 <xsl:value-of select="@name"/>
46 <xsl:variable name="value-prefix">
48 <xsl:when test="@singular">
49 <xsl:value-of select="@singular"/>
51 <xsl:when test="@value-prefix">
52 <xsl:value-of select="@value-prefix"/>
55 <xsl:value-of select="@name"/>
59 <xsl:text>/** </xsl:text>
60 <xsl:text> * </xsl:text>
61 <xsl:value-of select="concat($mixed-case-prefix, $name)"/>
62 <xsl:text>: </xsl:text>
63 <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
64 <xsl:with-param name="value-prefix" select="$value-prefix"/>
65 </xsl:apply-templates>
66 <xsl:text> * </xsl:text>
67 <xsl:if test="tp:docstring">
68 <xsl:text> * <![CDATA[</xsl:text>
69 <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>
70 <xsl:text>]]> </xsl:text>
71 <xsl:text> * </xsl:text>
73 <xsl:text> * Bitfield/set of flags generated from the AT-SPI specification. </xsl:text>
74 <xsl:text> */ </xsl:text>
75 <xsl:text>typedef enum { </xsl:text>
77 <xsl:with-param name="value-prefix" select="$value-prefix"/>
78 </xsl:apply-templates>
79 <xsl:text>} </xsl:text>
80 <xsl:value-of select="concat($mixed-case-prefix, $name)"/>
81 <xsl:text>; </xsl:text>
82 <xsl:text> </xsl:text>
85 <xsl:template match="text()" mode="flag-or-enumvalue-gtkdoc"/>
87 <xsl:template match="tp:enumvalue" mode="flag-or-enumvalue-gtkdoc">
88 <xsl:param name="value-prefix"/>
89 <xsl:variable name="suffix">
91 <xsl:when test="ancestor::interface">
92 <xsl:value-of select="concat(str:replace(ancestor::interface/@name, 'org.freedesktop.atspi.', ''), '_', @suffix)"/>
95 <xsl:value-of select="@suffix"/>
99 <xsl:text> * @</xsl:text>
100 <xsl:value-of select="concat($mixed-case-prefix, $suffix)"/>
101 <xsl:text>: <![CDATA[</xsl:text>
102 <xsl:value-of select="translate(string(tp:docstring), ' ', ' ')"/>
103 <xsl:text>]]> </xsl:text>
106 <xsl:template match="tp:flag" mode="flag-or-enumvalue-gtkdoc">
107 <xsl:param name="value-prefix"/>
108 <xsl:text> * @</xsl:text>
109 <xsl:value-of select="translate(concat($mixed-case-prefix, $value-prefix, '_', @suffix), $lower, $upper)"/>
110 <xsl:text>: <![CDATA[</xsl:text>
111 <xsl:value-of select="translate(string(tp:docstring), ' ', ' ')"/>
112 <xsl:text>]]> </xsl:text>
115 <xsl:template match="tp:enum">
116 <xsl:variable name="name">
118 <xsl:when test="ancestor::interface">
119 <xsl:value-of select="concat(str:replace(ancestor::interface/@name, 'org.freedesktop.atspi.', ''), '_', @name)"/>
122 <xsl:value-of select="@name"/>
126 <xsl:variable name="value-prefix">
128 <xsl:when test="@singular">
129 <xsl:value-of select="@singular"/>
131 <xsl:when test="@value-prefix">
132 <xsl:value-of select="@value-prefix"/>
135 <xsl:value-of select="@name"/>
139 <xsl:variable name="name-plural">
141 <xsl:when test="@plural">
142 <xsl:value-of select="@plural"/>
145 <xsl:value-of select="@name"/><xsl:text>s</xsl:text>
149 <xsl:text>/** </xsl:text>
150 <xsl:text> * </xsl:text>
151 <xsl:value-of select="concat($mixed-case-prefix, $name)"/>
152 <xsl:text>: </xsl:text>
153 <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
154 <xsl:with-param name="value-prefix" select="$value-prefix"/>
155 </xsl:apply-templates>
156 <xsl:text> * </xsl:text>
157 <xsl:if test="tp:docstring">
158 <xsl:text> * <![CDATA[</xsl:text>
159 <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>
160 <xsl:text>]]> </xsl:text>
161 <xsl:text> * </xsl:text>
163 <xsl:text> * Bitfield/set of flags generated from the AT-SPI specification. </xsl:text>
164 <xsl:text> */ </xsl:text>
165 <xsl:text>typedef enum { </xsl:text>
166 <xsl:apply-templates>
167 <xsl:with-param name="value-prefix" select="$value-prefix"/>
168 </xsl:apply-templates>
169 <xsl:text>} </xsl:text>
170 <xsl:value-of select="concat($mixed-case-prefix, $name)"/>
171 <xsl:text>; </xsl:text>
172 <xsl:text> </xsl:text>
173 <xsl:text>/** </xsl:text>
174 <xsl:text> * NUM_</xsl:text>
175 <xsl:value-of select="translate(concat($mixed-case-prefix, $name-plural), $lower, $upper)"/>
176 <xsl:text>: </xsl:text>
177 <xsl:text> * </xsl:text>
178 <xsl:text> * 1 higher than the highest valid value of #</xsl:text>
179 <xsl:value-of select="concat($mixed-case-prefix, $name)"/>
180 <xsl:text>. </xsl:text>
181 <xsl:text> */ </xsl:text>
182 <xsl:text>#define NUM_</xsl:text>
183 <xsl:value-of select="translate(concat($mixed-case-prefix, $name-plural), $lower, $upper)"/>
184 <xsl:text> (</xsl:text>
185 <xsl:value-of select="tp:enumvalue[position() = last()]/@value"/>
186 <xsl:text>+1) </xsl:text>
187 <xsl:text> </xsl:text>
190 <xsl:template match="tp:flags/tp:flag">
191 <xsl:param name="value-prefix"/>
192 <xsl:variable name="suffix">
194 <xsl:when test="@suffix">
195 <xsl:value-of select="@suffix"/>
198 <xsl:value-of select="@name"/>
202 <xsl:variable name="name" select="translate(concat($mixed-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/>
204 <xsl:if test="@name and @suffix and @name != @suffix">
205 <xsl:message terminate="yes">
206 <xsl:text>Flag name </xsl:text>
207 <xsl:value-of select="@name"/>
208 <xsl:text> != suffix </xsl:text>
209 <xsl:value-of select="@suffix"/>
210 <xsl:text> </xsl:text>
213 <xsl:text> </xsl:text>
214 <xsl:value-of select="$name"/>
215 <xsl:text> = </xsl:text>
216 <xsl:value-of select="@value"/>
217 <xsl:text>, </xsl:text>
220 <xsl:template match="tp:enum/tp:enumvalue">
221 <xsl:param name="value-prefix"/>
222 <xsl:variable name="suffix">
224 <xsl:when test="ancestor::interface">
225 <xsl:value-of select="concat(str:replace(ancestor::interface/@name, 'org.freedesktop.atspi.', ''), '_', @suffix)"/>
228 <xsl:value-of select="@suffix"/>
232 <xsl:variable name="name" select="concat($mixed-case-prefix, $suffix)"/>
234 <xsl:if test="@name and @suffix and @name != @suffix">
235 <xsl:message terminate="yes">
236 <xsl:text>Enumvalue name </xsl:text>
237 <xsl:value-of select="@name"/>
238 <xsl:text> != suffix </xsl:text>
239 <xsl:value-of select="@suffix"/>
240 <xsl:text> </xsl:text>
244 <xsl:if test="preceding-sibling::tp:enumvalue and number(preceding-sibling::tp:enumvalue[1]/@value) > number(@value)">
245 <xsl:message terminate="yes">
246 <xsl:text>Enum values must be in ascending numeric order, but </xsl:text>
247 <xsl:value-of select="$name"/>
248 <xsl:text> is less than the previous value</xsl:text>
252 <xsl:text> </xsl:text>
253 <xsl:value-of select="$name"/>
254 <xsl:text>, </xsl:text>
257 <xsl:template match="tp:flag">
258 <xsl:message terminate="yes">tp:flag found outside tp:flags </xsl:message>
261 <xsl:template match="tp:enumvalue">
262 <xsl:message terminate="yes">tp:enumvalue found outside tp:enum </xsl:message>
265 <xsl:template match="text()"/>
267 <xsl:template match="/tp:spec">
268 <xsl:if test="$mixed-case-prefix = ''">
269 <xsl:message terminate="yes">
270 <xsl:text>mixed-case-prefix param must be set </xsl:text>
274 <xsl:text>/* Generated from </xsl:text>
275 <xsl:value-of select="tp:title"/>
276 <xsl:if test="tp:version">
277 <xsl:text>, version </xsl:text>
278 <xsl:value-of select="tp:version"/>
280 <xsl:text> </xsl:text>
281 <xsl:text> </xsl:text>
282 <xsl:for-each select="tp:copyright">
283 <xsl:value-of select="."/>
284 <xsl:text> </xsl:text>
286 <xsl:value-of select="tp:license"/>
287 <xsl:text> </xsl:text>
288 <xsl:value-of select="tp:docstring"/>
289 <xsl:text> </xsl:text>
290 <xsl:text> */ </xsl:text>
291 <xsl:text> </xsl:text>
292 <xsl:text>#ifndef _ACCESSIBILITY_H_ </xsl:text>
293 <xsl:text>#define _ACCESSIBILITY_H_ </xsl:text>
294 <xsl:text>#ifdef __cplusplus </xsl:text>
295 <xsl:text>extern "C" { </xsl:text>
296 <xsl:text>#endif </xsl:text>
297 <xsl:text> </xsl:text>
298 <xsl:apply-templates/>
299 <xsl:text> </xsl:text>
300 <xsl:text>#ifdef __cplusplus </xsl:text>
301 <xsl:text>} </xsl:text>
302 <xsl:text>#endif </xsl:text>
303 <xsl:text>#endif </xsl:text>
308 <!-- vim:set sw=2 sts=2 et noai noci: -->