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