#!/bin/bash
# gnome-doc-html - Convert documentation to HTML
# gnome-doc-html. Generated from gnome-doc-html.in by configure.
# Copyright (C) 2006 Shaun McCance
#
# This program 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 program 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.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
progname=`echo "$0" | sed 's%^.*/%%'`
PROGRAM=gnome-doc-html
PACKAGE=gnome-doc-utils
VERSION=0.20.10
prefix=/usr
datarootdir=${prefix}/share
datadir=/usr/share
pkgdatadir=/usr/share/gnome-doc-utils
xsltdir=/usr/share/xml/gnome/xslt
# This is important to make sure string manipulation is handled
# byte-by-byte.
export LANG=C
XSL_ICONS='
admon-caution
admon-important
admon-bug
admon-note
admon-tip
admon-warning
admon-important
admon-bug
admon-important
admon-tip
admon-warning
admon-note
watermark-code-cpp
watermark-code-python
'
XSL_CACHE_LS='
'
XSL_DOCBOOK_MEDIA='
'
XSL_MALLARD_CSS='
'
XSL_MALLARD_MEDIA='
'
error() {
echo "$progname: $1" 1>&2;
exit 1;
}
print_help() {
cat < [OPTIONS] FILES...
Process a documentation file.
COMMAND is one of:
list-icons list automatic icons and watermarks
list-media list all referenced media files
html convert the documents to HTML
xhtml convert the documents to XHTML
css create a CSS file for a Mallard document
help display this help and exit
EOF
}
print_help_css() {
cat <'
while [ "$#" != "0" ]; do
doc_input="$1"
shift
if [ -d "$doc_input" ]; then
doc_input_full=$(cd "$doc_input" && pwd)
for doc_input_file in "$doc_input_full/"*.page; do
echo "$doc_input_file"
done
unset doc_input_full
else
echo "$(pwd)/$doc_input"
fi
done | while read doc_input; do
doc_input_esc=$(urlencode "$doc_input" | sed -e 's/\&/\&/g' -e 's/\</g' -e "s/'/\'/g")
echo ""
done
echo ''
) > "$doc_cache_in"
xsltproc -o "$doc_cache" "$xsltdir/mallard/cache/mal-cache.xsl" "$doc_cache_in"
rm "$doc_cache_in"
echo "$XSL_CACHE_LS" | xsltproc - "$doc_cache" | while read doc_input; do
doc_input=$(urldecode $(echo "$doc_input" | sed -e 's/^file:\/\///'))
doc_indir=$( (cd $(dirname "$doc_input") && pwd) )
doc_infile=$(basename "$doc_input")
doc_inbase=$(basename "$doc_infile" ".page")
if [ "x$doc_outfile_q" != "x1" ]; then
doc_outfile="${doc_inbase}${doc_extension}"
fi
params='--param mal.chunk.chunk_top 0'
params="$params --stringparam mal.cache.file \"$doc_cache\""
if [ "x$doc_css_file" != "x" ]; then
params="$params --stringparam mal2html.css.file \"$doc_css_file\""
fi
if [ "x$doc_copy_icons" = "x1" ]; then
doc_icons=$(list_icons "$doc_indir/$doc_infile")
doc_icons_to_copy="$doc_icons $doc_icons_to_copy"
for doc_icon in $(echo $doc_icons | tr ' ' '\n' | grep '^admon-' | sort | uniq); do
param="theme.icon."$(echo $doc_icon | sed -e 's/-/./');
params="$params --stringparam $param \"$doc_icon\""
done
fi
if [ "x$doc_copy_icons" != "x1" -a "x$doc_icons_path" != "x" ]; then
params="$params --stringparam theme.icon.admon.path \"$doc_icons_admon_path\""
fi
if [ "x$doc_admon_graphics_size" != "x" ]; then
params="$params --stringparam theme.icon.admon.size \"$doc_icons_admon_size\""
fi
if [ "x$doc_custom_xslt" != "x" ]; then
cmd="echo '\
\
' |\
xsltproc --nonet --xinclude $params -o \"$doc_outdir/$doc_outfile\"\
- \"$doc_indir/$doc_infile\""
else
cmd="xsltproc --nonet --xinclude $params -o \"$doc_outdir/$doc_outfile\"\
\"$xsltdir/mallard/html/mal2$doc_format.xsl\" \"$doc_indir/$doc_infile\""
fi
echo_verbose "$cmd"
eval "$cmd"
if [ "x$doc_no_figures" != "x1" -a "$doc_indir" != "$doc_outdir" ]; then
echo "$XSL_MALLARD_MEDIA" \
| xsltproc --nonet --xinclude - "$doc_indir/$doc_infile" \
| while read doc_media; do
mkdir_p "$doc_outdir/"`dirname "$doc_media"`
cmd="cp \"$doc_indir/$doc_media\" \"$doc_outdir/$doc_media\""
echo_verbose "$cmd"
eval "$cmd"
done
fi
done
copy_icons
}
create_css() {
longopts='
-loutput:
-lverbose
-lversion
-lhelp
';
options=`getopt -qn$progname $longopts -- o:vVh "$@"`
if [ "$?" != "0" ]; then print_help_css 1>&2; exit 1; fi
eval set -- "$options";
while [ "$1" != "--" ]; do
case "$1" in
-o | --output)
doc_output="$2";;
-v | --verbose)
doc_verbose=1;;
-V | --version)
echo "$PROGRAM ($PACKAGE) $VERSION"
exit 0;;
-h | --help)
print_help_css
exit 0;;
--)
print_help_css 1>&2
exit 1;;
esac
shift
done
shift
doc_input_page="$1"
if [ "x$doc_input_page" = "x" ]; then
doc_input_page="index.page"
fi
if [ "x$doc_output" = "x" ]; then
doc_output="index.css"
fi
echo_verbose "Creating $doc_output using $doc_input_page"
echo "$XSL_MALLARD_CSS" | xsltproc -o "$doc_output" - "$doc_input_page";
}
convert_2html() {
doc_format="$1"
shift
longopts='
-lcss-file:
-lchunk-depth:
-lextension:
-lno-figures
-loutput:
-lcustom-xslt:
-lcopy-graphics
-ladmon-graphics-path:
-ladmon-graphics-size:
-lclasssynopsis-language:
-lfuncsynopsis-style:
-lverbose
-lversion
-lhelp
';
options=`getopt -qn$progname $longopts -- c:d:e:o:x:nvVh "$@"`
if [ "$?" != "0" ]; then print_help_html $doc_format 1>&2; exit 1; fi
eval set -- "$options";
while [ "$1" != "--" ]; do
case "$1" in
-c | --css-file)
doc_css_file="$2";;
-d | --chunk-depth)
doc_chunk_depth="$2";;
-e | --extension)
doc_extension="$2";;
-n | --no-figures)
doc_no_figures="1";;
-o | --output)
doc_output="$2";;
-x | --custom-xslt)
doc_custom_xslt="$2";;
--copy-graphics)
doc_copy_icons="1";;
--admon-graphics-path)
doc_icons_admon_path="$2";;
--admon-graphics-size)
doc_icons_admon_size="$2";;
--classsynopsis-language)
doc_classsynopsis_language="$2";;
--funcsynopsis-style)
doc_funcsynopsis_style="$2";;
-v | --verbose)
doc_verbose=1;;
-V | --version)
echo "$PROGRAM ($PACKAGE) $VERSION"
exit 0;;
-h | --help)
print_help_html $doc_format
exit 0;;
--)
print_help_html $doc_format 1>&2
exit 1;;
esac
shift
done
shift
if [ "$#" = "0" ]; then print_help_html $doc_format 1>&2; exit 1; fi
if [ "x$(echo "$1" | sed -e 's/.*\.//')" = "xpage" -o -d "$1" ]; then
convert_mallard2html $@;
else
convert_docbook2html $@;
fi
exit 0
}
command="$1";
if [ "x$command" = "x" ]; then
print_help 1>&2;
exit 1;
fi;
shift;
if [ "$command" = "html" -o "$command" = "xhtml" ]; then
convert_2html "$command" $@;
elif [ "$command" = "css" ]; then
create_css $@;
elif [ "$command" = "list-icons" ]; then
list_icons $@;
elif [ "$command" = "list-media" ]; then
list_media $@;
elif [ "$command" = "-V" -o "$command" = "--version" ]; then
echo "$PROGRAM ($PACKAGE) $VERSION";
exit 0;
elif [ "$command" = "help" ]; then
print_help;
exit 0;
else
print_help 1>&2;
exit 1;
fi;