1#!/bin/sh 2# 3# $Id: make_html.sh,v 1.7 2001/05/06 14:16:23 moniot Rel $ 4# 5# Script to break up ftnchek.html into separate sections in html directory. 6# 7# Author: Robert Moniot 8# Date: 31 Jul 1998 9# Originally written for use with PolyglotMan (rman) 10# Modified for use with vh-man2html 22 Apr 2001 11# 12 13 # This function puts out header needed by all but 1st page. 14do_header(){ 15cat <<EOF 16<HTML> 17<HEAD> 18<TITLE>$*</TITLE> 19</HEAD> 20<BODY bgcolor=white> 21EOF 22} 23 24 # This function puts out ref to table of contents that 25 # follows header for all but 1st and toc page. 26do_href_toc(){ 27cat <<EOF 28<A HREF="toc.html">Table of Contents</A><P> 29EOF 30} 31 # This function puts out ref to previous section 32do_href_prev(){ 33 echo "<P>Previous: <A HREF=\"$1.html\">$2</A><HR><P>" 34} 35 36 37 # This function puts out footer needed by all but last page. 38do_footer(){ 39cat <<EOF 40</BODY></HTML> 41EOF 42} 43 44 # This function changes the trailing NAME anchor 45 # of a page into an href to the next page. 46 # The first edit is for links to section pages. The second edit is 47 # for the link to table of contents. The third edit is 48 # for links to option pages. 49href_next(){ 50 sed -e '$s,^.*<A NAME="\([^"]*\)">[^<]*</A> <H2>\([^<]*\)</H2>*$,<P><HR><P>Next: <A HREF="\1.html">\2</A>,' \ 51 -e '$s,^<A NAME="toc">.*$,<P><HR><P>Next: <A HREF="toc.html">Table of contents</A>,' \ 52 -e '$s,^.*<A NAME="\([^"]*\)".*$,<P><HR><P>Next: <A HREF="\1.html">-\1</A>,' 53} 54 55 # This function adapts internal refs from one-big-file 56 # form into multi-file format. 57 # First edit changes "#lbAB" and "#lbAC" (refs to 1st two sections) 58 # into "index.html#lb[BC]" (where they are combined). 59 # Next changes all other "lbXX" hrefs to into "lbXX.html#lbXX". 60 # Third edit changes "#option" into "option.html" 61change_hrefs(){ 62 sed -e 's,HREF="#\(lbA[BC]\)",HREF="index.html#\1",g' \ 63 -e 's,HREF="#\(lb[A-Z][A-Z]\)",HREF="\1.html#\1",g' \ 64 -e 's,HREF="#\([^"]*\)",HREF="\1.html",g' 65} 66 67 68# Execution begins here. 69 # Filter the input (file arg or stdin) thru a sed script 70 # that concatenates section NAME tags with the H2 titles 71 # on following line, to associate section name with title. 72 # It also changes the name "index" to "toc" to avoid 73 # confusion with index.html, which is the first page, not 74 # the table of contents page. 75 # Put the input in a tmp file so it can be re-read. 76 77filename="/tmp/html_split_$$.html" 78trap "rm -f $filename" 0 79sed -e '/^<A NAME="lb[A-Z][A-Z]"/N' \ 80 -e 's/\n/ /' \ 81 -e 's/HREF="#index">Index</HREF="#toc">Table of Contents</' \ 82 -e 's/<A NAME="index"/<A NAME="toc"/' \ 83 -e '/^<A HREF=[^>]*>Return to Main Contents/d' \ 84 $1 > $filename 85 86 # Get a list of all ftnchek main options, excluding the 87 # leading '-'. Sort them for use on Options page. 88options=`ftnchek -help | \ 89 awk '/^ *-/ {split($0,command); 90 sub(/\[no\]/,"",command[1]); 91 sub(/=.*$/,"",command[1]); 92 sub(/^-/,"",command[1]); 93 print command[1]; 94 }' | sort` 95 96 # Get a list of all the sections excluding special ones. 97 # Sections are named "lbAB" "lbAC" ... by vh-man2html. 98 # (As of v1.5.3 it doesn't use lbAA.) 99sectlist=`sed -n -e 's,^.*<A NAME="\(lb[A-Z][A-Z]*\)".*$,\1,p' $filename | 100 grep -v 'lbA[BC]$'` 101 102# This little bit, copied from GNU configure, sets ac_n and ac_c such 103# that echo $ac_n "stuff $ac_c" yields "stuff " w/o following newline. 104if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then 105 # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. 106 if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then 107 ac_n= ac_c=' 108' ac_t=' ' 109 else 110 ac_n=-n ac_c= ac_t= 111 fi 112else 113 ac_n= ac_c='\c' ac_t= 114fi 115 116 # Create html directory if it does not exist. 117if [ -d html ] 118then 119 echo "Re-using directory html." 120else 121 echo "Creating directory html..." 122 if mkdir html 123 then 124 true 125 else 126 echo "Failed!" 127 exit 1 128 fi 129fi 130 131echo "Creating section pages..." 132 133 # Produce index.html page. It is special, since it combines 134 # NAME and SYNOPSIS and uses the man2html-generated header. 135 # Also make sure the background color is same as the rest. 136echo $ac_n "lbAB lbAC $ac_c" 137(sed -n -e 's/<BODY>/<BODY bgcolor=white>/' \ 138 -e '1,/^<A NAME="lbAD"/p' $filename | \ 139 href_next | \ 140 change_hrefs ; 141 do_footer) > html/index.html 142 143 # Produce pages for all other sections except last (toc). 144 # Section for options gets special treatment since 145 # individual options will be split off into separate files, 146 # and links to all options are placed at end of page. 147 148prevsect='index' 149prevtext=`sed -n 's,^<A NAME="lbAC"> </A> <H2>\([^<]*\)</H2>$,\1,p' $filename` 150for sect in $sectlist; 151do 152 echo $ac_n "$sect $ac_c" 153 headtext=`sed -n 's,^<A NAME="'$sect'"> </A> <H2>\([^<]*\)</H2>$,\1,p' $filename` 154 155 # save section name of OPTIONS section for use by first option. 156 if [ "$headtext" = "OPTIONS" ] 157 then 158 optsect="$sect" 159 fi 160 161 (do_header $headtext ; do_href_toc ; 162 do_href_prev "$prevsect" "$prevtext" ; 163 if [ "$headtext" = "OPTIONS" ] 164 then 165 (sed -n -e '/<A NAME="'$sect'"/,/<A NAME="lb/p' $filename | \ 166 href_next | \ 167 sed -n -e '1,/<A NAME=/p' -e '$p' | \ 168 sed -e '/<A NAME="a/d' ; 169 echo "<P><HR><P>" ; 170 echo $options | \ 171 sed -e 's@\([^ ][^ ]*\)@\ 172<B><A HREF="\1.html">-\1,</A></B>@g' \ 173 -e 's@,</A></B> *$@.</A></B>@' 174 ) 175 else 176 sed -n -e '/<A NAME="'$sect'"/,/<A NAME=/p' $filename | \ 177 href_next 178 fi | \ 179 change_hrefs ; 180 do_footer) > html/$sect.html 181 prevsect="$sect" 182 prevtext="$headtext" 183done 184 185 186 # Produce table of contents 187echo "toc" 188(do_header Table of Contents ; 189 sed -n -e '/<A NAME="toc">/,$p' $filename | \ 190 change_hrefs ; 191) > html/toc.html 192 193 # Now produce pages for all the options 194echo "Creating option pages..." 195 196prevsect="$optsect" 197prevtext="OPTIONS" 198for opt in $options 199do 200 echo $ac_n "$opt $ac_c" 201(do_header "Option: $opt" ; do_href_toc ; 202 do_href_prev "$prevsect" "$prevtext" ; 203 echo "<H2>Option: <font color="#FF0080">$opt</font></H2><P>" ; 204 sed -n -e '/<A NAME="'$opt'"/,/<A NAME=/p' $filename | \ 205 href_next | \ 206 change_hrefs ; 207 do_footer) > html/$opt.html 208 prevsect="$opt" 209 prevtext="-$opt" 210done 211echo "" 212 213