#!/bin/sh
# db2any - Docbook to html/ps/info rendering
#
# Copyright (C) 2000, 2001 Free Software Foundation, Inc
#
# 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
#
# Note: This requires a Posix shell
#
# $Id$
pgm="db2any"
version="0.7.3"
usage () {
echo 'usage: db2any [--help] [options] filename' >&2
exit 1
}
show_banner () {
cat <&2
exit 1
fi
mode="$1"
;;
--manvolume)
shift
if [ $# = 0 ]; then
echo "$pgm: missing argument for --manvolume" >&2
exit 1
fi
manvolume="$1"
;;
--usestyle)
shift
if [ $# = 0 ]; then
echo "$pgm: missing argument for --usestyle" >&2
exit 1
fi
usestyle="$1"
;;
--verbose)
verbose=yes
;;
--draft)
draft=yes
;;
--ignore-xref)
ignore_xref=yes
;;
--)
shift
break
;;
*)
echo "$pgm: invalid option $1" >&2
exit 1
;;
esac
shift
done
if [ $# = $expected_args ]; then
if [ $# = 1 ]; then
input="$1"
fi
else
usage
fi
# check the mode
case "$mode" in
html|HTML)
mode=html
;;
tex|TEX|TeX|dvi)
mode=dvi
;;
man|MAN)
mode=man
;;
texi|TEXI|texinfo|TEXINFO)
mode=texinfo
;;
check)
;;
none)
if [ $systemcheck_only != yes ]; then
echo "$pgm: no mode specified; use one of: ${all_modes}" >&2
exit 1
fi
;;
*)
echo "$pgm: invalid mode $mode" >&2
echo "$pgm: valid modes are: ${all_modes}" >&2
exit 1
;;
esac
if [ -n $usestyle ]; then
if [ ! -f $usestyle ]; then
echo "$pgm: cannot access local stylesteet" >&2
exit 1
fi
fi
#######################################
# Options are all parsed here #
#######################################
# check whether the given program is availbale in the path
check_prog () {
tmp="$1"
save_ifs="$IFS"; IFS=":"
for i in $PATH; do
test -z "$i" && i=.
if test -f $i/$tmp; then
IFS="$save_ifs"
return 0
fi
done
IFS="$save_ifs"
return 1
}
# Figure out all what we need to know about the system we are
# running on and where the Docbook tools are installed.
# Tell about it when running in verbose mode.
do_systemcheck () {
# look for Jade
jade_version=`jade -v &1 | \
sed -n 's/.*:I:.*Jade version "\([0-9.]*\)"/\1/p'`
if [ -z "$jade_version" ]; then
echo "$pgm: error: jade not found" >&2
exit 1
fi
[ $verbose = yes ] && echo "$pgm: Jade version $jade_version found" >&2
# look for JadeTeX
if ! jadetex -v 2>/dev/null | grep -q '^TeX' ; then
echo "$pgm: error: jadetex not found" >&2
exit 1
fi
# look for the docbook-to-man script. Fixme: we should check that it
# it is a recent version.
if ! docbook-to-man 2>&1 | grep -q '^usage' ; then
echo "$pgm: error: docbook-to-man not found" >&2
exit 1
fi
[ $verbose = yes ] && echo "$pgm: docbook-to-man found" >&2
# look for the docbook-to-texi scripts.
if ! check_prog docbook2texi ; then
echo "$pgm: error: docbook2texi not found" >&2
exit 1
fi
[ $verbose = yes ] && echo "$pgm: docbook2texi found" >&2
if ! sgml2xml -v /dev/null 2>&1 | grep 'SP version' >/dev/null 2>&1 ; then
echo "$pgm: error: sgml2xml not found" >&2
exit 1
fi
[ $verbose = yes ] && echo "$pgm: sgml2xml found" >&2
# figure out where our stylesheets are
tex_stylesheet=none
for d in ${stylesheet_dirs}; do
file=${d}/print/docbook.dsl
if [ -f $file ]; then
tex_stylesheet=$file
break
fi
done
[ $verbose = yes ] && echo "$pgm: TeX stylesheet: ${tex_stylesheet}" >&2
html_stylesheet=none
for d in ${stylesheet_dirs}; do
file=${d}/html/docbook.dsl
if [ -f $file ]; then
html_stylesheet=$file
break
fi
done
[ $verbose = yes ] && echo "$pgm: HTML stylesheet: ${html_stylesheet}" >&2
if [ $tex_stylesheet = none -o $html_stylesheet = none ]; then
echo "$pgm: error: stylesheets not found" >&2
exit 1
fi
}
# Render the docbook as HTML
render_html () {
output="`basename $input| sed 's/\.sgml$//'`.html"
if [ -n "$usestyle" ]; then
tmpstyle="`pwd`/`basename $usestyle`-html.tmp"
if [ ! -f $tmpstyle -o $usestyle -nt $tmpstyle ]; then
sed "s%@DOCBOOK_DSL@%$html_stylesheet%" $usestyle > $tmpstyle
fi
else
tmpstyle="$tex_stylesheet"
fi
# --nosplts creates just one HTML file
if test $nosplit = yes; then
echo "running jade on '$input' ..." >&2
jade -D . -d $tmpstyle -t sgml -i html -V nochunks $input > $output
echo "$output created"
return 0
fi
# Make sure that we have a html subdir
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
[ $verbose = yes ] && echo "running jade on '$inp' ..." >&2
(cd $outputdir && jade -D . -t sgml -i html -d $tmpstyle $inp )
[ $verbose = yes ] && 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`
# create a html index file for it, so that we can more easy
# find the rendred pages
cat > $output <$output
$mainfile