summaryrefslogtreecommitdiffstats
path: root/scripts/db2html.in
blob: ba35afbc17136385583baf5b92021fdfd38e72c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
# db2html.in - Docbook to HTML rendering (wk 2000-02-15)
#
#	Copyright (C) 2000 Free Software Foundation
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

nosplit=no
copyfiles=no
stylesheet=@DSL_FOR_HTML@
JADE=@JADE@

usage () {
    echo 'usage: db2html [--nosplit] [--copyfiles] filename' >&2
    exit 1
}


while test "`echo $1 | head -c1`" = "-"; do
    case $1 in
      --version)
	cat <<EOF
db2html 0.5
Copyright (C) 2000 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

stylesteet: $stylesheet
EOF
	exit 0
	;;
      --help|-h|-help)
	usage
	;;
      --nosplit)
	nosplit=yes
	;;
      --copyfiles)
	copyfiles=yes
	;;
      --)
	shift
	break
	;;
      *)
	echo "invalid option $1" >&2
	exit 1
	;;
    esac
    shift
done

if test $# = 1; then
   input="$1"
else
   usage
fi

# grep the document type
doctype=`grep -i '\<doctype' $input|awk 'NR==1 {print $2}'| tr '[A-Z]' '[a-z]'`
if test -z $doctype; then
    doctype=book
    echo "no DOCTYPE found - assuming '$doctype'" >&2
else
    echo "DOCTYPE is '$doctype'" >&2
fi

output="`basename $input| sed 's/\.sgml$//'`.html"


if test $nosplit = yes; then
    echo "running jade on '$input' ..." >&2
    $JADE -d $stylesheet -t sgml -i html -V nochunks $input > $output
    echo "$output created"
    exit 0
fi

if test -d html ; then
    :
else
    if mkdir html; then
	echo "'html' directory created" >&2
    else
	echo "failed to create 'html' directory" >&2
	exit 1
    fi
fi

outputdir="html/`basename $input| sed 's/\.sgml$//'`"

if test -d $outputdir ; then
    :
else
    if mkdir $outputdir; then
	echo "'$outputdir' created" >&2
    else
	echo "failed to create '$outputdir'" >&2
	exit 1
    fi
fi
echo "creating html pages in '$outputdir' ..." >&2
if test "$input" = "`basename $input`"; then
    inp="../../$input"
else
    inp="$input"
fi
echo "running jade on '$inp' ..." >&2
(cd $outputdir && $JADE -t sgml -i html -d $stylesheet $inp )
echo "html version in '$outputdir' created" >&2

# break out all filerefs and copy them to the outputdirectory
# fixme: handling of path components is wrong
if test $copyfiles = yes; then
    echo "looking for filerefs ..." >&2
    for file in `nsgmls -i html $input \
		    | awk '/^AFILEREF[ \t]+CDATA/ {print $3}'`; do
	d=$outputdir/`basename $file`
	if cat $file > $outputdir/`basename $file` ; then
	    echo "  $file -> $d" >&2
	fi
    done
fi

mainfile=`ls $outputdir/${doctype}* | head -1`

cat > $output <<EOF
<html><title>$output</title>
<body>

<a href="$mainfile">$mainfile</a>

</body>
</html>
EOF

echo "$output created with link to '$mainfile'" >&2

exit 0