4 # Dan Scott / <dan.scott (at) acm.org>
5 # Ferg / <gferg (at) sgi.com>
7 # Used to prepare single-file HTML variant for PDF/Postscript creation
11 # 16Oct2000 - 0.1 - initial entry <gferg (at) sgi.com>
12 # 03Apr2001 - 0.2 - fix for <preface>
13 # 05Jul2001 - 0.3 - fix for <tt> and -f
14 # 12Oct2001 - 0.4 - fix for sections; loop thru both files (body/title)
15 # 27Nov2001 - 0.5 - fixed bug in determining where doc-index lies
16 # 18Jan2002 - 0.5.1 - entity fix (822*)
17 # 02Apr2002 - 0.6 - misc fixes (bibliography/appendix, etc).
18 # 04Apr2002 - 0.7 - fix for newer DSSSL
23 my($in,$out,$ttl) = @_;
25 open(IN_FILE, "< $in") || do {
26 print "fix_print_html: cannot open $in: $!\n";
30 my($buf, $ttl_buf) = '';
37 # ignore everything until we see the chapter or sect
39 if( $_ =~ /CLASS="CHAP/i || $_ =~ /CLASS="PREF/i
41 $_ =~ /CLASS="SECT/i ) {
50 } elsif( $indx == 0 ) {
52 # write out the title page file
54 if( $_ =~ /CLASS="TOC"/ ) {
56 $ttl_buf .= "></DIV>\n</BODY>\n</HTML>\n";
57 $ttl_buf =~ s/<\/H1\n/<\/H1\n><P><BR><BR\n/ms;
58 $ttl_buf =~ s/<HR><\/DIV\n><HR>/<HR><\/DIV\n>/ms;
59 &fix_html(\$ttl_buf, 1);
61 open(TOC_FILE, "> $ttl") || do {
62 print "fix_print_html: cannot open $ttl: $!\n";
66 print TOC_FILE $ttl_buf;
75 } elsif( $indx < 0 ) {
77 if( $_ =~ /CLASS="BOOK"/i ) {
81 # up to this point, both buffers get the line
83 if( $_ =~ /CLASS="TITLEPAGE"/ ) {
85 $ttl_buf .= $_ . ">\n<P>\n<BR><BR><BR><BR>\n<\/P\n";
103 open(OUT_FILE, "> $out") || do {
104 print "fix_print_html: cannot open $out: $!\n";
108 &fix_html(\$buf, $is_article);
120 my($buf, $is_article) = @_;
124 # make corrections and write out the file
127 $$buf =~ s/(\n><LI\n)><P\n(.*?)<\/P\n>/$1$2\n/gms;
128 $$buf =~ s/(\n><LI\n><DIV\nCLASS="FORMALPARA"\n)><P\n(.*?)<\/P\n>/$1$2\n/gms;
129 $$buf =~ s/(\n><LI\nSTYLE="[^\"]+"\n)><P\n(.*?)<\/P\n>/$1$2\n/gms;
130 if( $is_article == 0 ) {
132 s/(\nCLASS="SECT[TION\d]+"\n>)<H1\n(.*?)<\/H1/$1<H0\n$2<\/H0/gims;
134 s/(\nCLASS="SECT[TION\d]+"\n><HR>)<H1\n(.*?)<\/H1/$1<H0\n$2<\/H0/gims;
136 $$buf =~ s/<H1(\nCLASS="INDEXDIV"\n)(.*?)<\/H1/<H2$1$2<\/H2/gims;
137 if( ($indx = rindex($$buf, "<H1\n><A\nNAME=\"DOC-INDEX\"")) > -1 ) {
138 $$buf = substr($$buf, 0, $indx);
139 $$buf .= "\n<\/BODY>\n<\/HTML>\n\n";
140 } elsif( ($indx = rindex($$buf, "<H1\n><A\nNAME=\"doc-index\"")) > -1 ) {
141 $$buf = substr($$buf, 0, $indx);
142 $$buf .= "\n<\/BODY>\n<\/HTML>\n\n";
145 $$buf =~ s/\&\#13;//g;
146 $$buf =~ s/\&\#60;/\</g;
147 $$buf =~ s/\&\#62;/\>/g;
148 $$buf =~ s/\&\#8211;/\-/g;
149 $$buf =~ s/\&\#8220;/\"/g;
150 $$buf =~ s/\&\#8221;/\"/g;
151 $$buf =~ s/WIDTH=\"\d\"//g;
152 $$buf =~ s/><[\/]*TBODY//g;
153 $$buf =~ s/><[\/]*THEAD//g;
154 $$buf =~ s/TYPE=\"1\"\n//gim;
156 $$buf =~ s/<P\nCLASS="LITERALLAYOUT"(.*?)<\/P/<P CLASS="LITERALLAYOUT"><FONT FACE=\"courier\"$1<\/FONT><\/P/gms;
160 if( $$buf !~ /<H1/ ) {
162 # for newer docbook styles, set h2 to h1, etc.
164 for($cnt=2; $cnt < 7; $cnt++ ) {
166 $$buf =~ s/<H${cnt}/<H${j}/g;
167 $$buf =~ s/<\/H${cnt}/<\/H${j}/g;
170 } elsif( $is_article == 0 ) {
172 # decrement the headers by 1 and then re-set the
173 # chapter level only to H1...
175 for($cnt=5; $cnt >= 0; $cnt--) {
180 $$buf =~ s/<H${cnt}/<H${j}/g;
181 $$buf =~ s/<\/H${cnt}/<\/H${j}/g;
184 my(@l) = split(/\n/, $$buf);
185 for( $cnt=0; $cnt < (@l + 0); $cnt++ ) {
188 if( $l[$cnt] =~ /<DIV/ ) {
192 $l[$cnt] =~ s/<H2/<H1/g;
193 $l[$cnt] =~ s/<\/H2/<\/H1/g;
196 if( $l[$cnt] =~ /^CLASS=\"CHAP/i
198 $l[$cnt] =~ /^NAME=\"BIBL/i
200 $l[$cnt] =~ /^CLASS=\"APPENDIX/i
202 $l[$cnt] =~ /^CLASS=\"GLOSSARY/i
204 $l[$cnt] =~ /^CLASS=\"PREF/i ) {
209 $$buf = join("\n", @l);
212 $$buf =~ s/><DIV\nCLASS="\w+"\n//gms;
213 $$buf =~ s/><\/DIV\n//gms;
215 $buf =~ s/<SPAN\n[^>]*?>//gms;
216 $buf =~ s/<\/SPAN\n>//gms;
218 $$buf =~ s/(><LI\n)><P\n(.*?)<\/P\n>(<\/LI\n)/$1$2$3/gms;
224 # Return true from package include