2002-04-24 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / scripts / db2html.in
blobba35afbc17136385583baf5b92021fdfd38e72c9
1 #!/bin/sh
2 # db2html.in - Docbook to HTML rendering (wk 2000-02-15)
4 # Copyright (C) 2000 Free Software Foundation
6 # This is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 nosplit=no
21 copyfiles=no
22 stylesheet=@DSL_FOR_HTML@
23 JADE=@JADE@
25 usage () {
26 echo 'usage: db2html [--nosplit] [--copyfiles] filename' >&2
27 exit 1
31 while test "`echo $1 | head -c1`" = "-"; do
32 case $1 in
33 --version)
34 cat <<EOF
35 db2html 0.5
36 Copyright (C) 2000 Free Software Foundation, Inc.
37 This is free software; see the source for copying conditions. There is NO
38 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
40 stylesteet: $stylesheet
41 EOF
42 exit 0
44 --help|-h|-help)
45 usage
47 --nosplit)
48 nosplit=yes
50 --copyfiles)
51 copyfiles=yes
53 --)
54 shift
55 break
58 echo "invalid option $1" >&2
59 exit 1
61 esac
62 shift
63 done
65 if test $# = 1; then
66 input="$1"
67 else
68 usage
71 # grep the document type
72 doctype=`grep -i '\<doctype' $input|awk 'NR==1 {print $2}'| tr '[A-Z]' '[a-z]'`
73 if test -z $doctype; then
74 doctype=book
75 echo "no DOCTYPE found - assuming '$doctype'" >&2
76 else
77 echo "DOCTYPE is '$doctype'" >&2
80 output="`basename $input| sed 's/\.sgml$//'`.html"
83 if test $nosplit = yes; then
84 echo "running jade on '$input' ..." >&2
85 $JADE -d $stylesheet -t sgml -i html -V nochunks $input > $output
86 echo "$output created"
87 exit 0
90 if test -d html ; then
92 else
93 if mkdir html; then
94 echo "'html' directory created" >&2
95 else
96 echo "failed to create 'html' directory" >&2
97 exit 1
101 outputdir="html/`basename $input| sed 's/\.sgml$//'`"
103 if test -d $outputdir ; then
105 else
106 if mkdir $outputdir; then
107 echo "'$outputdir' created" >&2
108 else
109 echo "failed to create '$outputdir'" >&2
110 exit 1
113 echo "creating html pages in '$outputdir' ..." >&2
114 if test "$input" = "`basename $input`"; then
115 inp="../../$input"
116 else
117 inp="$input"
119 echo "running jade on '$inp' ..." >&2
120 (cd $outputdir && $JADE -t sgml -i html -d $stylesheet $inp )
121 echo "html version in '$outputdir' created" >&2
123 # break out all filerefs and copy them to the outputdirectory
124 # fixme: handling of path components is wrong
125 if test $copyfiles = yes; then
126 echo "looking for filerefs ..." >&2
127 for file in `nsgmls -i html $input \
128 | awk '/^AFILEREF[ \t]+CDATA/ {print $3}'`; do
129 d=$outputdir/`basename $file`
130 if cat $file > $outputdir/`basename $file` ; then
131 echo " $file -> $d" >&2
133 done
136 mainfile=`ls $outputdir/${doctype}* | head -1`
138 cat > $output <<EOF
139 <html><title>$output</title>
140 <body>
142 <a href="$mainfile">$mainfile</a>
144 </body>
145 </html>
148 echo "$output created with link to '$mainfile'" >&2
150 exit 0