* contrib/vmlog/vmlog_cacao.h: Removed #include of a header that does
[cacao.git] / contrib / svn2cl.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4
5    svn2cl.xsl - xslt stylesheet for converting svn log to a normal
6                 changelog
7
8    Usage (replace ++ with two minus signs which aren't allowed
9    inside xml comments):
10      svn ++verbose ++xml log | \
11        xsltproc ++stringparam strip-prefix `basename $(pwd)` \
12                 ++stringparam linelen 75 \
13                 ++stringparam groupbyday yes \
14                 ++stringparam include-rev yes \
15                 ++stringparam breakbeforemsg yes \
16                 ++stringparam authorsfile FILE \
17                 svn2cl.xsl - > ChangeLog
18
19    This file is based on several implementations of this conversion
20    that I was not completely happy with and some other common
21    xslt constructs found on the web.
22
23    Copyright (C) 2004, 2005, 2006 Arthur de Jong.
24
25    Redistribution and use in source and binary forms, with or without
26    modification, are permitted provided that the following conditions
27    are met:
28    1. Redistributions of source code must retain the above copyright
29       notice, this list of conditions and the following disclaimer.
30    2. Redistributions in binary form must reproduce the above copyright
31       notice, this list of conditions and the following disclaimer in
32       the documentation and/or other materials provided with the
33       distribution.
34    3. The name of the author may not be used to endorse or promote
35       products derived from this software without specific prior
36       written permission.
37
38    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41    ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
42    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44    GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
46    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
48    IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50 -->
51
52 <!DOCTYPE stylesheet [
53  <!ENTITY tab "&#9;">
54  <!ENTITY newl "&#10;">
55  <!ENTITY space "&#32;">
56 ]>
57
58 <xsl:stylesheet
59   version="1.0"
60   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
61
62  <xsl:output
63    method="text"
64    encoding="utf-8"
65    media-type="text/plain"
66    omit-xml-declaration="yes"
67    standalone="yes"
68    indent="no" />
69
70  <xsl:strip-space elements="*" />
71
72  <!-- the prefix of pathnames to strip -->
73  <xsl:param name="strip-prefix" select="'/'" />
74
75  <!-- the length of a line to wrap messages at -->
76  <xsl:param name="linelen" select="80" />
77  
78  <!-- whether entries should be grouped by day -->
79  <xsl:param name="groupbyday" select="'no'" />
80
81  <!-- whether a revision number should be included -->
82  <xsl:param name="include-rev" select="'no'" />
83
84  <!-- whether the log message should start on a new line -->
85  <xsl:param name="breakbeforemsg" select="'no'" />
86
87  <!-- location of authors file if any -->
88  <xsl:param name="authorsfile" select="''" />
89
90  <!-- add newlines at the end of the changelog -->
91  <xsl:template match="log">
92   <xsl:apply-templates/>
93   <xsl:text>&newl;</xsl:text>
94  </xsl:template>
95
96  <!-- format one entry from the log -->
97  <xsl:template match="logentry">
98   <!-- save log entry number -->
99   <xsl:variable name="pos" select="position()" />
100   <!-- fetch previous entry's date -->
101   <xsl:variable name="prevdate">
102    <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/date" />
103   </xsl:variable>
104   <!-- fetch previous entry's author -->
105   <xsl:variable name="prevauthor">
106    <xsl:apply-templates select="../logentry[position()=(($pos)-1)]/author" />
107   </xsl:variable>
108   <!-- fetch this entry's date -->
109   <xsl:variable name="date">
110    <xsl:apply-templates select="date" />
111   </xsl:variable>
112   <!-- fetch this entry's author -->
113   <xsl:variable name="author">
114    <xsl:apply-templates select="author" />
115   </xsl:variable>
116   <!-- check if header is changed -->
117   <xsl:if test="($prevdate!=$date) or ($prevauthor!=$author)">
118    <!-- add newline -->
119    <xsl:if test="not(position()=1)">
120      <xsl:text>&newl;</xsl:text>
121    </xsl:if>
122    <!-- date -->
123    <xsl:apply-templates select="date" />
124    <!-- two spaces -->
125    <xsl:text>&space;&space;</xsl:text>
126    <!-- author's name -->
127    <xsl:apply-templates select="author" />
128    <!-- two newlines -->
129    <xsl:text>&newl;&newl;</xsl:text>
130   </xsl:if>
131   <!-- get paths string -->
132   <xsl:variable name="paths">
133    <xsl:apply-templates select="paths" />
134    <xsl:text>:&space;</xsl:text>
135   </xsl:variable>
136   <!-- get revision number -->
137   <xsl:variable name="rev">
138    <xsl:if test="$include-rev='yes'">
139     <xsl:text>[r</xsl:text>
140     <xsl:value-of select="@revision" />
141     <xsl:text>]&space;</xsl:text>
142    </xsl:if>
143   </xsl:variable>
144   <!-- trim trailing newlines -->
145   <xsl:variable name="msg">
146    <!-- add a line break before the log message -->
147    <xsl:if test="$breakbeforemsg='yes'">
148     <xsl:text>&newl;</xsl:text>
149    </xsl:if>
150    <xsl:call-template name="trim-newln">
151     <xsl:with-param name="txt" select="msg" />
152    </xsl:call-template>
153   </xsl:variable>
154   <!-- first line is indented (other indents are done in wrap template) -->
155   <xsl:text>&tab;</xsl:text>
156   <!-- print the paths and message nicely wrapped -->
157   <xsl:call-template name="wrap">
158    <xsl:with-param name="txt" select="concat($rev,$msg)" />
159   </xsl:call-template>
160  </xsl:template>
161
162  <!-- format date -->
163  <xsl:template match="date">
164   <xsl:variable name="date" select="normalize-space(.)" />
165   <!-- output date part -->
166   <xsl:value-of select="substring($date,1,10)" />
167   <!-- output time part -->
168   <xsl:if test="$groupbyday!='yes'">
169    <xsl:text>&space;</xsl:text>
170    <xsl:value-of select="substring($date,12,5)" />
171   </xsl:if>
172  </xsl:template>
173
174  <!-- format author -->
175  <xsl:template match="author">
176   <xsl:variable name="author" select="normalize-space(.)" />
177   <xsl:choose>
178    <!-- try to look up the author in the authorsfile -->
179    <xsl:when test="$authorsfile!='' and document($authorsfile)//author[@uid=$author]">
180     <xsl:value-of select="normalize-space(document($authorsfile)//author[@uid=$author])" />
181    </xsl:when>
182    <!-- just use the author name as given by svn -->
183    <xsl:otherwise>
184     <xsl:value-of select="$author" />
185    </xsl:otherwise>
186   </xsl:choose>
187  </xsl:template>
188
189  <!-- present a list of paths names -->
190  <xsl:template match="paths">
191   <xsl:for-each select="path">
192    <xsl:sort select="normalize-space(.)" data-type="text" />
193    <!-- unless we are the first entry, add a comma -->
194    <xsl:if test="not(position()=1)">
195     <xsl:text>,&space;</xsl:text>
196    </xsl:if>
197    <!-- print the path name -->
198    <xsl:apply-templates select="." />
199   </xsl:for-each>
200  </xsl:template>
201
202  <!-- transform path to something printable -->
203  <xsl:template match="path">
204   <!-- fetch the pathname -->
205   <xsl:variable name="p1" select="normalize-space(.)" />
206   <!-- strip leading slash -->
207   <xsl:variable name="p2">
208    <xsl:choose>
209     <xsl:when test="starts-with($p1,'/')">
210      <xsl:value-of select="substring($p1,2)" />
211     </xsl:when>
212     <xsl:otherwise>
213      <xsl:value-of select="$p1" />
214     </xsl:otherwise>
215    </xsl:choose>
216   </xsl:variable>
217   <!-- strip trailing slash from strip-prefix -->
218   <xsl:variable name="sp">
219    <xsl:choose>
220     <xsl:when test="substring($strip-prefix,string-length($strip-prefix),1)='/'">
221      <xsl:value-of select="substring($strip-prefix,1,string-length($strip-prefix)-1)" />
222     </xsl:when>
223     <xsl:otherwise>
224      <xsl:value-of select="$strip-prefix" />
225     </xsl:otherwise>
226    </xsl:choose>
227   </xsl:variable>
228   <!-- strip strip-prefix -->
229   <xsl:variable name="p3">
230    <xsl:choose>
231     <xsl:when test="starts-with($p2,$sp)">
232      <xsl:value-of select="substring($p2,1+string-length($sp))" />
233     </xsl:when>
234     <xsl:otherwise>
235      <!-- TODO: do not print strings that do not begin with strip-prefix -->
236      <xsl:value-of select="$p2" />
237     </xsl:otherwise>
238    </xsl:choose>
239   </xsl:variable>
240   <!-- strip another slash -->
241   <xsl:variable name="p4">
242    <xsl:choose>
243     <xsl:when test="starts-with($p3,'/')">
244      <xsl:value-of select="substring($p3,2)" />
245     </xsl:when>
246     <xsl:otherwise>
247      <xsl:value-of select="$p3" />
248     </xsl:otherwise>
249    </xsl:choose>
250   </xsl:variable>
251   <!-- translate empty string to dot -->
252   <xsl:choose>
253    <xsl:when test="$p4 = ''">
254     <xsl:text>.</xsl:text>
255    </xsl:when>
256    <xsl:otherwise>
257     <xsl:value-of select="$p4" />
258    </xsl:otherwise>
259   </xsl:choose>
260  </xsl:template>
261
262  <!-- string-wrapping template -->
263  <xsl:template name="wrap">
264   <xsl:param name="txt" />
265   <xsl:choose>
266    <xsl:when test="contains($txt,'&newl;')">
267      <!-- text contains newlines, do the first line -->
268      <xsl:call-template name="wrap">
269       <xsl:with-param name="txt" select="substring-before($txt,'&newl;')" />
270      </xsl:call-template>
271      <!-- print tab -->
272      <xsl:text>&tab;</xsl:text>
273      <!-- wrap the rest of the text -->
274      <xsl:call-template name="wrap">
275       <xsl:with-param name="txt" select="substring-after($txt,'&newl;')" />
276      </xsl:call-template>
277    </xsl:when>
278    <xsl:when test="(string-length($txt) &lt; (($linelen)-9)) or not(contains($txt,' '))">
279     <!-- this is easy, nothing to do -->
280     <xsl:value-of select="normalize-space($txt)" />
281     <!-- add newline -->
282     <xsl:text>&newl;</xsl:text>
283    </xsl:when>
284    <xsl:otherwise>
285     <!-- find the first line -->
286     <xsl:variable name="tmp" select="substring($txt,1,(($linelen)-10))" />
287     <xsl:variable name="line">
288      <xsl:choose>
289       <xsl:when test="contains($tmp,' ')">
290        <xsl:call-template name="find-line">
291         <xsl:with-param name="txt" select="$tmp" />
292        </xsl:call-template>
293       </xsl:when>
294       <xsl:otherwise>
295        <xsl:value-of select="normalize-space(substring-before($txt,' '))" />
296       </xsl:otherwise>
297      </xsl:choose>
298     </xsl:variable>
299     <!-- print newline and tab -->
300     <xsl:value-of select="normalize-space($line)" />
301     <xsl:text>&newl;&tab;</xsl:text>
302     <!-- wrap the rest of the text -->
303     <xsl:call-template name="wrap">
304      <xsl:with-param name="txt" select="substring($txt,string-length($line)+1)" />
305     </xsl:call-template>
306    </xsl:otherwise>
307   </xsl:choose>
308  </xsl:template>
309
310  <!-- template to trim line to contain space as last char -->
311  <xsl:template name="find-line">
312   <xsl:param name="txt" />
313   <xsl:choose>
314    <xsl:when test="substring($txt,string-length($txt),1) = ' '">
315     <xsl:value-of select="$txt" />
316    </xsl:when>
317    <xsl:otherwise>
318     <xsl:call-template name="find-line">
319      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
320     </xsl:call-template>
321    </xsl:otherwise>
322   </xsl:choose>
323  </xsl:template>
324
325  <!-- template to trim trailing and starting newlines -->
326  <xsl:template name="trim-newln">
327   <xsl:param name="txt" />
328   <xsl:choose>
329    <!-- find starting newlines -->
330    <xsl:when test="substring($txt,1,1) = '&newl;'">
331     <xsl:call-template name="trim-newln">
332      <xsl:with-param name="txt" select="substring($txt,2)" />
333     </xsl:call-template>
334    </xsl:when>
335    <!-- find trailing newlines -->
336    <xsl:when test="substring($txt,string-length($txt),1) = '&newl;'">
337     <xsl:call-template name="trim-newln">
338      <xsl:with-param name="txt" select="substring($txt,1,string-length($txt)-1)" />
339     </xsl:call-template>
340    </xsl:when>
341    <!-- no newlines found, we're done -->
342    <xsl:otherwise>
343     <xsl:value-of select="$txt" />
344    </xsl:otherwise>
345   </xsl:choose>
346  </xsl:template>
347
348 </xsl:stylesheet>