"Fossies" - the Fresh Open Source Software Archive 
Member "rman-3.2/contrib/rman_html_split" (26 Jul 2003, 7531 Bytes) of package /linux/www/old/rman-3.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/bin/sh
2 #
3 # Script to break up rman html output into separate sections in a directory.
4 #
5 # Author: Robert Moniot <moniot@fordham.edu>
6 # Date: 4 Aug 1998
7 #
8
9 version="rman_html_split V1.0 (c) 1998 Robert K. Moniot"
10
11 # Usage function prints synopsis and exits
12 Usage(){
13 myname=`echo $0 | sed -e 's,.*/,,'`
14 cat <<EOF
15
16 Usage: $myname [ options ] [ file ]
17
18 Breaks up rman HTML output in file (or standard input) into separate
19 section files, placing them into a directory.
20
21 Options:
22 -d | --html-dir dir Place output into directory dir (default = html).
23 -m | --merge # Merge sections 0 thru # (default 1) into one file.
24 -t | --toc-first Link index.html to table of contents instead
25 of to sect0.html.
26 -T | --title "title" Use "title" as title on top of each page
27 instead of rman's title. "title" may be empty.
28 -h | --help Print synopsis and exit.
29 -V | --version Print version information and exit.
30 EOF
31 exit 0
32 }
33
34 # Version function prints version number and exits
35 Version(){
36 echo "$version"
37 exit 0
38 }
39
40 # This function puts out header needed by all but 1st page.
41 do_header(){
42 cat <<EOF
43 <HTML>
44 <HEAD>
45 <TITLE>$*</TITLE>
46 </HEAD>
47 <BODY>
48 EOF
49 do_title
50 }
51
52 # This function puts out the title with name of manpage
53 do_title(){
54 if [ -n "$title" ]
55 then
56 echo "<H2>$title</H2>"
57 fi
58 }
59
60 # This function puts out ref to table of contents that
61 # follows header for all but 1st and toc page.
62 do_href_toc(){
63 cat <<EOF
64 <A HREF="toc.html">Table of Contents</A><P>
65 EOF
66 }
67
68 # This function puts out ref to previous section
69 do_href_prev(){
70 echo "<P>Previous: <A HREF=\"$1.html\">$2</A><HR><P>"
71 }
72
73 # This function puts out footer needed by all but last page.
74 do_footer(){
75 cat <<EOF
76 </BODY></HTML>
77 EOF
78 }
79
80 # This function changes the trailing NAME anchor
81 # of a section into an href to the next section.
82 # The first edit is for sections. The second edit
83 # handles the toc anchor, which has no href and so
84 # is missed by the first edit.
85 do_href_next(){
86 sed -e '$s,^.*<A NAME="\([^"]*\)" HREF=[^>]*>\([^<]*\).*$,<P><HR><P>Next: <A HREF="\1.html">\2</A>,' \
87 -e '$s,<A NAME="\(toc[^"]*\)",Next: <A HREF="\1.html",'
88 }
89
90 # This function adapts internal refs from one-big-file
91 # form into multi-file format.
92 # First edit changes "#tocn" into "toc.html#tocn"
93 # Second edit changes "#sectn" into "sectn.html#sectn"
94 # Third edit changes "#toc" into "toc.html"
95 change_hrefs(){
96 sed -e 's,HREF="#toc\([0-9][0-9]*\)",HREF="toc.html#toc\1",g' \
97 -e 's,HREF="#sect\([0-9][0-9]*\)",HREF="sect\1.html#sect\1",g' \
98 -e 's,HREF="#\(toc\)",HREF="\1.html",g'
99 }
100
101
102 # Execution begins here.
103
104 # Process the command-line options.
105 htmldir="html"
106 mergesect="1"
107
108 while [ $# != 0 ]
109 do
110 case $1 in
111
112 -d | --html-dir)
113 shift
114 if [ $# != 0 ]
115 then
116 htmldir="$1"
117 shift
118 fi
119 ;;
120
121 -m | --merge)
122 shift
123 if [ $# != 0 ]
124 then
125 mergesect="$1"
126 shift
127 fi
128 case $mergesect in
129 [0-9])
130 ;;
131 *)
132 echo "ERROR: merge section must be a digit from 0 to 9."
133 Usage
134 ;;
135 esac
136 ;;
137
138 -t | --toc-first)
139 shift
140 tocfirst="t"
141 ;;
142
143 -T | --title)
144 shift
145 if [ $# != 0 ]
146 then
147 title="$1"
148 shift
149 fi
150 if [ -z "$title" ] # If title is the null string, set notitle
151 then
152 notitle="t"
153 fi
154 ;;
155
156 -h | --help)
157 Usage
158 ;;
159
160 -V | --version)
161 Version
162 ;;
163
164 # Unrecognized flag.
165 -*)
166 echo "Unrecognized option: $1"
167 Usage
168 ;;
169
170 # Non-flag: go to process file.
171 *)
172 break
173 ;;
174 esac
175 done
176
177 # At this point we should have at most one
178 # argument, the file name. Check it.
179 if [ $# -gt 1 ]
180 then
181 Usage
182 fi
183
184 if [ $# = 1 ]
185 then
186 if [ ! -r "$1" ]
187 then
188 echo "ERROR: Cannot open file $1."
189 exit 1
190 fi
191 fi
192
193 # Filter the input (file arg or stdin) thru a sed script
194 # that fixes cases where an anchor for a section has
195 # had its section title split across two or more lines.
196 # Put the result in a tmp file so it can be re-read.
197
198 filename="/tmp/rman_html_split_$$.html"
199 trap "rm -f $filename" 0
200 sed -e ':top' \
201 -e '/^<H[1-9]><A NAME="sect.*[^>]$/N' \
202 -e '/^<LI><A NAME="toc.*[^>]$/N' \
203 -e 's/\n/ /' \
204 -e 't top' $1 > $filename
205
206 # If user did not supply title, get title for top of
207 # each page from rman-generated <TITLE> line. If user
208 # gave a blank title then leave it blank.
209 if [ -z "$title" -a -z "$notitle" ]
210 then
211 title=`sed -e '/^<TITLE>/q' $filename |
212 sed -n -e 's,^<TITLE>\([^<]*\).*$,\1,p'`
213 fi
214
215 # Get a list of all the sections. Separate it into a
216 # list of merged sections and a list of all other sections.
217 # Merged sects are combined and get special treatment besides.
218 allsects=`sed -n 's,^.*<A NAME="\(sect[0-9][0-9]*\)".*$,\1,p' $filename`
219
220 mergesects=`echo $allsects | \
221 awk '{for(i=1; i<=NF && i<'"$mergesect"+2'; i++) print \$i;}'`
222
223 sectlist=`echo $allsects |
224 awk '{for(i='"$mergesect"'+2; i<=NF; i++) print \$i;}'`
225
226
227 # This little bit, copied from GNU configure, sets ac_n and ac_c such
228 # that echo $ac_n "stuff $ac_c" yields "stuff " w/o following newline.
229 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
230 # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
231 if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
232 ac_n= ac_c='
233 ' ac_t=' '
234 else
235 ac_n=-n ac_c= ac_t=
236 fi
237 else
238 ac_n= ac_c='\c' ac_t=
239 fi
240
241 # Create html directory if it does not exist.
242 if [ -d $htmldir ]
243 then
244 echo "Re-using directory $htmldir."
245 else
246 echo "Creating directory $htmldir..."
247 if mkdir $htmldir
248 then
249 true
250 else
251 echo "Failed!"
252 exit 1
253 fi
254 fi
255
256 echo "Creating section pages..."
257
258 # Produce index page. It is special, since it combines
259 # merged sections and uses the rman-generated header.
260 nextsect=`echo $sectlist | awk '{print $1;}'`
261 echo $ac_n $mergesects "$ac_c"
262 (do_title ;
263 sed -n -e "1,/^<H[23]><A NAME=\"$nextsect\"/p" $filename | \
264 do_href_next | \
265 change_hrefs ;
266 do_footer) > $htmldir/sect0.html
267
268 # Produce pages for all other sections except toc.
269 prevsect="sect$mergesect"
270 prevtext=`sed -n 's,^<H[23]><A NAME="'$prevsect'" HREF="#toc[0-9][0-9]*">\([^<]*\).*$,\1,p' $filename | sed -e 's/ *$//'`
271 for sect in $sectlist;
272 do
273 echo $ac_n "$sect $ac_c"
274 headtext=`sed -n 's,^<H[23]><A NAME="'$sect'" HREF="#toc[0-9][0-9]*">\([^<]*\).*$,\1,p' $filename | sed -e 's/ *$//'`
275 (do_header $headtext ;
276 do_href_toc ;
277 do_href_prev "$prevsect" "$prevtext" ;
278 sed -n -e '/<A NAME="'$sect'"/,/<A NAME=/p' $filename |
279 do_href_next |
280 change_hrefs ;
281 do_footer) > $htmldir/$sect.html
282 prevsect="$sect"
283 prevtext="$headtext"
284 done
285
286
287 # Produce table of contents
288 echo "toc"
289 (do_header Table of Contents ;
290 sed -n -e '/<A NAME="toc">/,$p' $filename | \
291 change_hrefs ;
292 ) > $htmldir/toc.html
293
294
295 # Finally, make sure the symlinks index.html and
296 # sect1.html -> sect0.html are in place, and if not,
297 # create them. If --tocfirst is not specified, then
298 # link index.html to section 0, otherwise link it to
299 # index.html
300
301 echo "Doing symlinks..."
302 cd $htmldir
303
304 rm -f index.html
305 if [ -z "$tocfirst" ]
306 then
307 echo "Linking index.html -> sect0.html"
308 ln -s sect0.html index.html
309 else
310 echo "Linking index.html -> toc.html"
311 ln -s toc.html index.html
312 fi
313
314 for sect in $mergesects
315 do
316 if [ "$sect" != "sect0" ]
317 then
318 echo "Linking $sect.html -> sect0.html"
319 rm -f $sect.html
320 ln -fs sect0.html $sect.html
321 fi
322 done
323
324 echo "Done."