Use a shell script, rather than perl script, to make flags.xsl
[ghc-hetmet.git] / docs / man / gen_flags.xsl.sh
1 #!/bin/sh
2
3 if [ "$#" -ne 2 ]
4 then
5     echo "Usage: $0 <ghc commands> <libdir>"
6     exit 1
7 fi
8
9 GHC_COMMANDS="$1"
10 LIBDIR="$2"
11
12 cat <<'EOF'
13 <?xml version="1.0" encoding="iso-8859-1"?>
14 <!DOCTYPE xsl:stylesheet [
15 ]>
16
17 <xsl:stylesheet version="1.0"
18  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
19  xmlns="http://www.w3.org/TR/xhtml1/strict">
20
21 <xsl:output method="text" omit-xml-declaration="yes" />
22
23 <xsl:template match="/">.\"
24 .\" This is a generated file.  Changes might get clobbered.  Edit at own's risk.
25 .\"
26 .TH GHC 1 "2002-10-25" "Glasgow FP Suite" "Glasgow Haskell Compiler"
27 .SH NAME
28 GHC \- the Glasgow Haskell Compiler
29
30
31 .SH SYNOPSIS
32 EOF
33
34 STARTED=0
35
36 for GHC_COMMAND in $GHC_COMMANDS
37 do
38     if [ "$STARTED" -ne 0 ]
39     then
40         echo ".br"
41     fi
42     STARTED=1
43     cat <<EOF
44 .B $GHC_COMMAND
45 .RI [ option | filename ]...
46 EOF
47 done
48
49 cat <<'EOF'
50
51 .SH DESCRIPTION
52 This manual page documents briefly the
53 .B ghc
54 and
55 .B ghci
56 commands.
57 Note that
58 .B ghci
59 is not yet available on all architectures.
60 Extensive documentation is available in various other formats
61 including DVI, PostScript and HTML; see below.
62
63 .PP
64 Each of GHC's command line options is classified as either
65 .IR static " or " dynamic .
66 A static flag may only be specified on the command line, whereas a
67 dynamic flag may also be given in an \f(CROPTIONS\fP pragma in a
68 source file or set from the GHCi command-line with \f(CR:set\fP.
69
70 As a rule of thumb, all the language options are dynamic, as are the
71 warning options and the debugging options.
72
73 The rest are static, with the notable exceptions of
74 .BR \-v ", " \-cpp ", " \-fasm ", " \-fvia\-C ", and " \-#include .
75 The OPTIONS sections lists the status of each flag.
76
77 .PP
78 Common suffixes of file names for Haskell are:
79 .TP
80 .B .hs
81 Haskell source code; preprocess, compile
82 .TP
83 .B .lhs
84 literate Haskell source; unlit, preprocess, compile
85 .TP
86 .B .hi
87 Interface file; contains information about exported
88 symbols
89 .TP
90 .B .hc
91 intermediate C files
92 .TP
93 .BI . x _o
94 way
95 .I x
96 object files; common ways are:
97 .BR p ", " u ", " s
98 .TP
99 .BI . x _hi
100 way
101 .I x
102 interface files
103
104
105 .SH OPTIONS
106
107 <xsl:apply-templates select="sect1/sect2" mode="overview"/>
108
109 <xsl:apply-templates select="sect1/sect2"/>
110
111
112 .SH FILES
113 EOF
114
115 echo ".I $LIBDIR"
116 cat <<'EOF'
117
118 .SH COPYRIGHT
119
120 Copyright 2002, The University Court of the University of Glasgow.
121 .br
122 All rights reserved.
123
124
125 .SH AUTHOR
126
127 This manual page was generated from the XML documentation of GHC with blood,
128 sweat, tears and a breaks-if-you-look-at-it-the-wrong-way XSL
129 stylesheet originally written by Michael Weber &lt;michaelw@debian.org&gt;
130 for the Debian GNU/Linux system (but may be used by others).
131
132 .\" End
133 </xsl:template>
134
135
136 <xsl:template match="sect1/sect2" mode="overview">
137 <xsl:choose>
138 <xsl:when test="contains(title/.,' (')">
139 .SS <xsl:value-of select="substring-before(title/.,' (')"/>
140 </xsl:when>
141 <xsl:otherwise>
142 .SS <xsl:value-of select="title/."/>
143 </xsl:otherwise>
144 </xsl:choose>
145 .nh
146 <xsl:apply-templates select="informaltable/tgroup/tbody/row" mode="overview"/>
147 .hy
148 </xsl:template>
149
150
151 <xsl:template match="sect1/sect2">
152 <xsl:choose>
153 <xsl:when test="contains(title/.,' (')">
154
155 .SH <xsl:value-of select='translate(substring-before(title/.," ("),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")'/>
156
157 </xsl:when>
158 <xsl:otherwise>
159
160 .SH <xsl:value-of select='translate(title/.,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")'/>
161
162 </xsl:otherwise>
163 </xsl:choose><xsl:text>
164 </xsl:text>
165 <xsl:apply-templates select="informaltable/tgroup/tbody/row"/>
166 </xsl:template>
167
168
169 <xsl:template match="informaltable/tgroup/tbody/row" mode="overview">
170   <xsl:apply-templates select="entry[1]|entry[4]" mode="overview"/>
171   <xsl:text> </xsl:text>
172 </xsl:template>
173
174 <xsl:template match="informaltable/tgroup/tbody/row">
175 .TP
176 <xsl:apply-templates select="entry[1]"/><xsl:text>
177 </xsl:text>
178 <xsl:variable name="x">
179 <xsl:apply-templates select="entry[2]"/>
180 </xsl:variable>
181 <xsl:value-of select="normalize-space($x)"/>
182 .rj
183 [<xsl:apply-templates select="entry[3]"/>]
184 <!-- IGNORE NEGATIVE OPTIONS
185 <xsl:if test="not(entry[4]='-')">
186   <xsl:text>.TP
187 </xsl:text>
188   <xsl:apply-templates select="entry[4]/option"/>
189 </xsl:if>
190  -->
191 </xsl:template>
192
193
194 <xsl:template match="option" mode="escape-dash">
195   <xsl:variable name="x">
196     <xsl:value-of select="."/>
197   </xsl:variable>
198   <xsl:variable name="y">
199     <xsl:call-template name="replace-string">
200       <xsl:with-param name="text" select="$x"/>
201       <xsl:with-param name="from" select="'-'"/>
202       <xsl:with-param name="to" select="'\-'"/>
203     </xsl:call-template>
204   </xsl:variable>
205   <xsl:value-of select="$y"/>
206 </xsl:template>
207
208 <xsl:template match="option" mode="overview">
209   <xsl:apply-templates select="." mode="escape-dash"/>
210 </xsl:template>
211
212 <xsl:template match="option">
213   <xsl:text>\fB</xsl:text>
214   <xsl:apply-templates select="." mode="escape-dash"/>
215   <xsl:text>\fP</xsl:text>
216 </xsl:template>
217
218
219 <xsl:template match="entry[1]" mode="overview">
220   <xsl:apply-templates mode="overview"/>
221   <xsl:text> </xsl:text>
222 </xsl:template>
223
224 <xsl:template match="entry[1]">
225   <xsl:apply-templates/><xsl:text> </xsl:text>
226 </xsl:template>
227
228 <xsl:template match="entry[4]" mode="overview">
229   <xsl:if test="not(.='-')">
230     <xsl:apply-templates select="option" mode="overview"/>
231     <xsl:text> </xsl:text>
232   </xsl:if>
233 </xsl:template>
234
235 <xsl:template match="entry[4]">
236   <xsl:if test="not(.='-')">
237     <xsl:value-of select="."/><xsl:text> </xsl:text>
238   </xsl:if>
239 </xsl:template>
240
241
242 <xsl:template match="replaceable" mode="overview">
243   <xsl:apply-templates select="."/>
244 </xsl:template>
245
246 <xsl:template match="replaceable">
247   <xsl:text>\fI</xsl:text>
248   <xsl:value-of select='.'/>
249   <xsl:text>\fP</xsl:text>
250 </xsl:template>
251
252
253 <xsl:template match="literal">
254   <xsl:text>\f(CR</xsl:text>
255   <xsl:value-of select="."/>
256   <xsl:text>\fP</xsl:text>
257 </xsl:template>
258
259
260
261 <!-- reusable replace-string function -->
262   <xsl:template name="replace-string">
263      <xsl:param name="text"/>
264      <xsl:param name="from"/>
265      <xsl:param name="to"/>
266
267      <xsl:choose>
268        <xsl:when test="contains($text, $from)">
269
270          <xsl:variable name="before" select="substring-before($text, $from)"/>
271          <xsl:variable name="after" select="substring-after($text, $from)"/>
272          <xsl:variable name="prefix" select="concat($before, $to)"/>
273
274          <xsl:value-of select="$before"/>
275          <xsl:value-of select="$to"/>
276          <xsl:call-template name="replace-string">
277            <xsl:with-param name="text" select="$after"/>
278            <xsl:with-param name="from" select="$from"/>
279            <xsl:with-param name="to" select="$to"/>
280          </xsl:call-template>
281        </xsl:when>
282        <xsl:otherwise>
283          <xsl:value-of select="$text"/>
284        </xsl:otherwise>
285      </xsl:choose>
286   </xsl:template>
287 </xsl:stylesheet>
288 EOF
289