1 <!-- Stylesheet to extract C enumerations from the Telepathy spec.
2 The master copy of this stylesheet is in telepathy-glib - please make any
5 Copyright (C) 2006, 2007 Collabora Limited
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23 xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
24 exclude-result-prefixes="tp">
26 <xsl:output method="text" indent="no" encoding="ascii"/>
28 <xsl:param name="mixed-case-prefix" select="''"/>
30 <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
31 <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
33 <xsl:variable name="upper-case-prefix" select="concat(translate($mixed-case-prefix, $lower, $upper), '_')"/>
34 <xsl:variable name="lower-case-prefix" select="concat(translate($mixed-case-prefix, $upper, $lower), '_')"/>
37 <xsl:template match="tp:flags">
38 <xsl:variable name="name">
40 <xsl:when test="@plural">
41 <xsl:value-of select="@plural"/>
44 <xsl:value-of select="@name"/>
48 <xsl:variable name="value-prefix">
50 <xsl:when test="@singular">
51 <xsl:value-of select="@singular"/>
53 <xsl:when test="@value-prefix">
54 <xsl:value-of select="@value-prefix"/>
57 <xsl:value-of select="@name"/>
61 <xsl:text>/** </xsl:text>
62 <xsl:text> * </xsl:text>
63 <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
64 <xsl:text>: </xsl:text>
65 <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
66 <xsl:with-param name="value-prefix" select="$value-prefix"/>
67 </xsl:apply-templates>
68 <xsl:text> * </xsl:text>
69 <xsl:if test="tp:docstring">
70 <xsl:text> * <![CDATA[</xsl:text>
71 <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>
72 <xsl:text>]]> </xsl:text>
73 <xsl:text> * </xsl:text>
75 <xsl:text> * Bitfield/set of flags generated from the Telepathy specification. </xsl:text>
76 <xsl:text> */ </xsl:text>
77 <xsl:text>typedef enum { </xsl:text>
79 <xsl:with-param name="value-prefix" select="$value-prefix"/>
80 </xsl:apply-templates>
81 <xsl:text>} </xsl:text>
82 <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
83 <xsl:text>; </xsl:text>
84 <xsl:text> </xsl:text>
87 <xsl:template match="text()" mode="flag-or-enumvalue-gtkdoc"/>
89 <xsl:template match="tp:enumvalue" mode="flag-or-enumvalue-gtkdoc">
90 <xsl:param name="value-prefix"/>
91 <xsl:text> * @</xsl:text>
92 <xsl:value-of select="translate(concat($upper-case-prefix, $value-prefix, '_', @suffix), $lower, $upper)"/>
93 <xsl:text>: <![CDATA[</xsl:text>
94 <xsl:value-of select="translate(string(tp:docstring), ' ', ' ')"/>
95 <xsl:text>]]> </xsl:text>
98 <xsl:template match="tp:flag" mode="flag-or-enumvalue-gtkdoc">
99 <xsl:param name="value-prefix"/>
100 <xsl:text> * @</xsl:text>
101 <xsl:value-of select="translate(concat($upper-case-prefix, $value-prefix, '_', @suffix), $lower, $upper)"/>
102 <xsl:text>: <![CDATA[</xsl:text>
103 <xsl:value-of select="translate(string(tp:docstring), ' ', ' ')"/>
104 <xsl:text>]]> </xsl:text>
107 <xsl:template match="tp:enum">
108 <xsl:variable name="name">
110 <xsl:when test="@singular">
111 <xsl:value-of select="@singular"/>
114 <xsl:value-of select="@name"/>
118 <xsl:variable name="value-prefix">
120 <xsl:when test="@singular">
121 <xsl:value-of select="@singular"/>
123 <xsl:when test="@value-prefix">
124 <xsl:value-of select="@value-prefix"/>
127 <xsl:value-of select="@name"/>
131 <xsl:variable name="name-plural">
133 <xsl:when test="@plural">
134 <xsl:value-of select="@plural"/>
137 <xsl:value-of select="@name"/><xsl:text>s</xsl:text>
141 <xsl:text>/** </xsl:text>
142 <xsl:text> * </xsl:text>
143 <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
144 <xsl:text>: </xsl:text>
145 <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc">
146 <xsl:with-param name="value-prefix" select="$value-prefix"/>
147 </xsl:apply-templates>
148 <xsl:text> * </xsl:text>
149 <xsl:if test="tp:docstring">
150 <xsl:text> * <![CDATA[</xsl:text>
151 <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>
152 <xsl:text>]]> </xsl:text>
153 <xsl:text> * </xsl:text>
155 <xsl:text> * Bitfield/set of flags generated from the Telepathy specification. </xsl:text>
156 <xsl:text> */ </xsl:text>
157 <xsl:text>typedef enum { </xsl:text>
158 <xsl:apply-templates>
159 <xsl:with-param name="value-prefix" select="$value-prefix"/>
160 </xsl:apply-templates>
161 <xsl:text>} </xsl:text>
162 <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
163 <xsl:text>; </xsl:text>
164 <xsl:text> </xsl:text>
165 <xsl:text>/** </xsl:text>
166 <xsl:text> * NUM_</xsl:text>
167 <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/>
168 <xsl:text>: </xsl:text>
169 <xsl:text> * </xsl:text>
170 <xsl:text> * 1 higher than the highest valid value of #</xsl:text>
171 <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>
172 <xsl:text>. </xsl:text>
173 <xsl:text> */ </xsl:text>
174 <xsl:text>#define NUM_</xsl:text>
175 <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/>
176 <xsl:text> (</xsl:text>
177 <xsl:value-of select="tp:enumvalue[position() = last()]/@value"/>
178 <xsl:text>+1) </xsl:text>
179 <xsl:text> </xsl:text>
182 <xsl:template match="tp:flags/tp:flag">
183 <xsl:param name="value-prefix"/>
184 <xsl:variable name="suffix">
186 <xsl:when test="@suffix">
187 <xsl:value-of select="@suffix"/>
190 <xsl:value-of select="@name"/>
194 <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/>
196 <xsl:if test="@name and @suffix and @name != @suffix">
197 <xsl:message terminate="yes">
198 <xsl:text>Flag name </xsl:text>
199 <xsl:value-of select="@name"/>
200 <xsl:text> != suffix </xsl:text>
201 <xsl:value-of select="@suffix"/>
202 <xsl:text> </xsl:text>
205 <xsl:text> </xsl:text>
206 <xsl:value-of select="$name"/>
207 <xsl:text> = </xsl:text>
208 <xsl:value-of select="@value"/>
209 <xsl:text>, </xsl:text>
212 <xsl:template match="tp:enum/tp:enumvalue">
213 <xsl:param name="value-prefix"/>
214 <xsl:variable name="suffix">
216 <xsl:when test="@suffix">
217 <xsl:value-of select="@suffix"/>
220 <xsl:value-of select="@name"/>
224 <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/>
226 <xsl:if test="@name and @suffix and @name != @suffix">
227 <xsl:message terminate="yes">
228 <xsl:text>Enumvalue name </xsl:text>
229 <xsl:value-of select="@name"/>
230 <xsl:text> != suffix </xsl:text>
231 <xsl:value-of select="@suffix"/>
232 <xsl:text> </xsl:text>
236 <xsl:if test="preceding-sibling::tp:enumvalue and number(preceding-sibling::tp:enumvalue[1]/@value) > number(@value)">
237 <xsl:message terminate="yes">
238 <xsl:text>Enum values must be in ascending numeric order, but </xsl:text>
239 <xsl:value-of select="$name"/>
240 <xsl:text> is less than the previous value</xsl:text>
244 <xsl:text> </xsl:text>
245 <xsl:value-of select="$name"/>
246 <xsl:text> = </xsl:text>
247 <xsl:value-of select="@value"/>
248 <xsl:text>, </xsl:text>
251 <xsl:template match="tp:flag">
252 <xsl:message terminate="yes">tp:flag found outside tp:flags </xsl:message>
255 <xsl:template match="tp:enumvalue">
256 <xsl:message terminate="yes">tp:enumvalue found outside tp:enum </xsl:message>
259 <xsl:template match="text()"/>
261 <xsl:template match="/tp:spec">
262 <xsl:if test="$mixed-case-prefix = ''">
263 <xsl:message terminate="yes">
264 <xsl:text>mixed-case-prefix param must be set </xsl:text>
268 <xsl:text>/* Generated from </xsl:text>
269 <xsl:value-of select="tp:title"/>
270 <xsl:if test="tp:version">
271 <xsl:text>, version </xsl:text>
272 <xsl:value-of select="tp:version"/>
274 <xsl:text> </xsl:text>
275 <xsl:text> </xsl:text>
276 <xsl:for-each select="tp:copyright">
277 <xsl:value-of select="."/>
278 <xsl:text> </xsl:text>
280 <xsl:value-of select="tp:license"/>
281 <xsl:text> </xsl:text>
282 <xsl:value-of select="tp:docstring"/>
283 <xsl:text> </xsl:text>
284 <xsl:text> */ </xsl:text>
285 <xsl:text> </xsl:text>
286 <xsl:text>#ifdef __cplusplus </xsl:text>
287 <xsl:text>extern "C" { </xsl:text>
288 <xsl:text>#endif </xsl:text>
289 <xsl:text> </xsl:text>
290 <xsl:apply-templates/>
291 <xsl:text> </xsl:text>
292 <xsl:text>#ifdef __cplusplus </xsl:text>
293 <xsl:text>} </xsl:text>
294 <xsl:text>#endif </xsl:text>
299 <!-- vim:set sw=2 sts=2 et noai noci: -->