3 # Copyright (C) 2010 Red Hat Inc.
6 # This program 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 program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # Wrapper script around POD utilities which can include files in the
21 # POD and controls HTML generation.
28 PACKAGE_NAME="@PACKAGE_NAME@"
29 PACKAGE_VERSION="@PACKAGE_VERSION@"
34 # This script could be run with any current directory, so if a source
35 # or build path is required it must be relative to the following
37 abs_top_srcdir="@abs_top_srcdir@"
38 abs_top_builddir="@abs_top_builddir@"
40 if [ -z "$abs_top_srcdir" ]; then
41 echo "*** podwrapper.sh: error: abs_top_srcdir not defined"
42 echo "probably this is a very old version of autoconf and you need to"
43 echo "upgrade to a recent version"
47 if [ -z "$abs_top_builddir" ]; then
48 echo "*** podwrapper.sh: error: abs_top_builddir not defined"
49 echo "probably this is a very old version of autoconf and you need to"
50 echo "upgrade to a recent version"
61 --long section:,name:,man:,text:,html:,insert:,verbatim: \
62 -n podwrapper.sh -- "$@"`
64 echo "podwrapper.sh: problem parsing the command line arguments"
78 [ -z "$man_output" ] || {
79 echo "podwrapper.sh: --text option specified more than once"
85 [ -z "$text_output" ] || {
86 echo "podwrapper.sh: --text option specified more than once"
92 [ -z "$html_output" ] || {
93 echo "podwrapper.sh: --html option specified more than once"
99 inserts[$nr_inserts]=`echo "$2" | awk -F: '{print $1}'`
100 pattern[$nr_inserts]=`echo "$2" | awk -F: '{print $2}'`
101 indent[$nr_inserts]=no
105 inserts[$nr_inserts]=`echo "$2" | awk -F: '{print $1}'`
106 pattern[$nr_inserts]=`echo "$2" | awk -F: '{print $2}'`
107 indent[$nr_inserts]=yes
113 echo "podwrapper.sh: internal error in option parsing"
118 # The remaining argument is the input POD file.
119 if [ $# -ne 1 ]; then
120 echo "podwrapper.sh [--options] input.pod"
126 #echo "man_output=$man_output"
127 #echo "text_output=$text_output"
128 #echo "html_output=$html_output"
129 #for i in `seq 0 $(($nr_inserts-1))`; do
130 # echo "insert $i: ${inserts[$i]} (pattern: ${pattern[$i]} indent: ${indent[$i]})"
133 # Should be at least one sort of output.
134 [ -z "$man_output" -a -z "$text_output" -a -z "$html_output" ] && {
135 echo "podwrapper.sh: no output specified"
139 # If name and section are not set, make some sensible defaults.
140 [ -z "$section" ] && section=1
141 [ -z "$name" ] && name=$(basename "$input" .pod)
143 # Perform the insertions to produce a temporary POD file.
144 tmpdir="$(mktemp -d)"
145 trap "rm -rf $tmpdir; exit $?" EXIT
147 if [ $nr_inserts -gt 0 ]; then
150 for i in `seq 0 $(($nr_inserts-1))`; do
151 if [ "${indent[$i]}" = "yes" ]; then
152 sed 's/^/ /' < "${inserts[$i]}" > $tmpdir/$i
154 cp "${inserts[$i]}" $tmpdir/$i
157 cmd="$cmd -e /${pattern[$i]}/r$tmpdir/$i -e s/${pattern[$i]}//"
160 $cmd < "$input" > $tmpdir/full.pod
162 cp "$input" $tmpdir/full.pod
165 # Now generate the final output format(s).
166 if [ -n "$man_output" ]; then
167 "$POD2MAN" --stderr -u \
168 --section "$section" -c "Virtualization Support" --name "$name" \
169 --release "$PACKAGE_NAME-$PACKAGE_VERSION" \
170 < $tmpdir/full.pod > "$man_output".tmp
171 mv "$man_output".tmp "$man_output"
174 if [ -n "$text_output" ]; then
175 "$POD2TEXT" --stderr -u \
176 < $tmpdir/full.pod > "$text_output".tmp
177 mv "$text_output".tmp "$text_output"
180 if [ -n "$html_output" ]; then
182 --css "pod.css" --htmldir "$abs_top_builddir/html" \
183 < $tmpdir/full.pod > "$html_output".tmp
184 mv "$html_output".tmp "$html_output"
186 # Fix up some of the mess in the HTML output, mainly to make links
187 # between man pages work properly.
189 # Rewrite <em>manpage(n)</em> to <a href=...>manpage(n)</a> if
190 # there is a linkable manual page.
192 for f in $(cd "$abs_top_builddir/html" && ls -1 *.html); do
193 b=$(basename $f .html)
194 m=$(echo $b | sed 's/\(.*\)\.\([1-9]\)$/\1(\2)/')
195 sed_cmd="$sed_cmd -e 's,<em>$m</em>,<a href=$f>$m</a>,g'"
198 eval $sed_cmd < "$html_output" > "$html_output".tmp
199 mv "$html_output".tmp "$html_output"
201 # Fix links like L<guestfs-foo(3)>
202 sed 's,<a href="#\([a-z]\+\)">guestfs-\1(\([1-9]\)),<a href="guestfs-\1.\2.html">guestfs-\1(\2),g' < "$html_output" > "$html_output".tmp
203 mv "$html_output".tmp "$html_output"