cannam@167: ## HTML output cannam@167: # Copyright (C) 1993-1995 Ian Jackson. cannam@167: cannam@167: # This file is free software; you can redistribute it and/or modify cannam@167: # it under the terms of the GNU General Public License as published by cannam@167: # the Free Software Foundation; either version 2, or (at your option) cannam@167: # any later version. cannam@167: cannam@167: # It is distributed in the hope that it will be useful, cannam@167: # but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@167: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@167: # GNU General Public License for more details. cannam@167: cannam@167: # You should have received a copy of the GNU General Public License cannam@167: # along with GNU Emacs; see the file COPYING. If not, write to cannam@167: # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, cannam@167: # Boston, MA 02111-1307, USA. cannam@167: cannam@167: # (Note: I do not consider works produced using these BFNN processing cannam@167: # tools to be derivative works of the tools, so they are NOT covered cannam@167: # by the GPL. However, I would appreciate it if you credited me if cannam@167: # appropriate in any documents you format using BFNN.) cannam@167: cannam@167: %saniarray= ('<','lt', '>','gt', '&','amp', '"','quot'); cannam@167: cannam@167: sub html_init { cannam@167: $html_prefix = './'.$prefix; cannam@167: $html_prefix =~ s:^\.//:/:; cannam@167: system('rm','-r',"$html_prefix.html"); cannam@167: system('mkdir',"$html_prefix.html"); cannam@167: open(HTML,">$html_prefix.html/index.html"); cannam@167: print HTML "\n"; cannam@167: print HTML "\n"; cannam@167: $html_needpara= -1; cannam@167: $html_end=''; cannam@167: chop($html_date=`date '+%d %B %Y'`); cannam@167: chop($html_year=`date '+%Y'`); cannam@167: } cannam@167: cannam@167: sub html_startup { cannam@167: print HTML < cannam@167: $user_title cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167:

cannam@167: $user_title cannam@167:

cannam@167: END cannam@167: &html_readrefs($_[0]); cannam@167: if (length($user_copyrightref)) { cannam@167: local ($refn) = $qrefn{$user_copyrightref}; cannam@167: if (!length($refn)) { cannam@167: warn "unknown question (copyright) `$user_copyrightref'"; cannam@167: } cannam@167: $refn =~ m/(\d+)\.(\d+)/; cannam@167: local ($s,$n) = ($1,$2); cannam@167: $html_copyrighthref= ($s == $html_sectionn)?'':"section$s.html"; cannam@167: $html_copyrighthref.= "#$qn2ref{$s,$n}"; cannam@167: } cannam@167: } cannam@167: cannam@167: sub html_close { cannam@167: print HTML $html_end,"
\n$user_author\n"; cannam@167: print HTML "- $html_date\n

\n"; cannam@167: print HTML "Extracted from $user_title,\n"; cannam@167: print HTML "" if length($html_copyrighthref); cannam@167: print HTML "Copyright © $html_year $user_copyholder."; cannam@167: print HTML "" if length($html_copyrighthref); cannam@167: print HTML "\n\n"; cannam@167: close(HTML); cannam@167: } cannam@167: cannam@167: sub html_startmajorheading { cannam@167: local ($ref, $this,$next,$back) = @_; cannam@167: local ($nextt,$backt); cannam@167: $this =~ s/^Section /section/; $html_sectionn= $ref; cannam@167: $next =~ s/^Section /section/ && ($nextt= $sn2title{$'}); cannam@167: $back =~ s/^Section /section/ ? ($backt= $sn2title{$'}) : ($back=''); cannam@167: if ($html_sectionn) { cannam@167: &html_close; cannam@167: open(HTML,">$html_prefix.html/$this.html"); cannam@167: print HTML "\n"; cannam@167: print HTML "\n"; cannam@167: $html_end= "
\n"; cannam@167: $html_end.= "Next: $nextt.
\n" cannam@167: if $next; cannam@167: $html_end.= "Back: $backt.
\n" cannam@167: if $back; cannam@167: $html_end.= ""; cannam@167: $html_end.= "Return to contents.

\n"; cannam@167: print HTML < cannam@167: $user_brieftitle - Section $html_sectionn cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: END cannam@167: print HTML "" if $next; cannam@167: print HTML "" if $back; cannam@167: print HTML < cannam@167:

cannam@167: $user_brieftitle - Section $html_sectionn
cannam@167: END cannam@167: $html_needpara= -1; cannam@167: } cannam@167: else { cannam@167: print HTML "\n

\n"; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: } cannam@167: cannam@167: sub html_endmajorheading { cannam@167: print HTML "\n

\n\n"; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: cannam@167: sub html_startminorheading { cannam@167: local ($ref, $this) = @_; cannam@167: $html_needpara=0; cannam@167: $this =~ m/^Question (\d+)\.(\d+)/; cannam@167: local ($s,$n) = ($1,$2); cannam@167: print HTML "\n

\n"; cannam@167: } cannam@167: cannam@167: sub html_endminorheading { cannam@167: print HTML "\n

\n\n"; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: cannam@167: sub html_newsgroup { &arg('newsgroup'); } cannam@167: sub html_endnewsgroup { &endarg('newsgroup'); } cannam@167: sub html_do_newsgroup { cannam@167: print HTML "$_[0]"; cannam@167: } cannam@167: cannam@167: sub html_email { &arg('email'); } cannam@167: sub html_endemail { &endarg('email'); } cannam@167: sub html_do_email { cannam@167: print HTML "$_[0]"; cannam@167: } cannam@167: cannam@167: sub html_courier { print HTML "" ; } cannam@167: sub html_endcourier { print HTML ""; } cannam@167: sub html_italic { print HTML "" ; } cannam@167: sub html_enditalic { print HTML "" ; } cannam@167: cannam@167: sub html_docref { &arg('docref'); } cannam@167: sub html_enddocref { &endarg('docref'); } cannam@167: sub html_do_docref { cannam@167: if (!defined($html_refval{$_[0]})) { cannam@167: warn "undefined HTML reference $_[0]"; cannam@167: $html_refval{$n}='UNDEFINED'; cannam@167: } cannam@167: print HTML ""; cannam@167: &recurse($_[0]); cannam@167: print HTML ""; cannam@167: } cannam@167: cannam@167: sub html_readrefs { cannam@167: local ($p); cannam@167: open(HTMLREFS,"<$_[0]") || (warn("failed to open HTML refs $_[0]: $!"),return); cannam@167: while() { cannam@167: next if m/^\\\s/; cannam@167: s/\s*\n$//; cannam@167: if (s/^\\prefix\s*//) { cannam@167: $p= $'; next; cannam@167: } elsif (s/^\s*(\S.*\S)\s*\\\s*//) { cannam@167: $_=$1; $v=$'; cannam@167: s/\\\\/\\/g; cannam@167: $html_refval{$_}= $p.$v; cannam@167: } else { cannam@167: warn("ununderstood line in HTML refs >$_<"); cannam@167: } cannam@167: } cannam@167: close(HTMLREFS); cannam@167: } cannam@167: cannam@167: sub html_ftpsilent { &arg('ftpsilent'); } cannam@167: sub html_endftpsilent { &endarg('ftpsilent'); } cannam@167: sub html_do_ftpsilent { cannam@167: if ($_[0] =~ m/:/) { cannam@167: $html_ftpsite= $`; cannam@167: $html_ftpdir= $'.'/'; cannam@167: } else { cannam@167: $html_ftpsite= $_[0]; cannam@167: $html_ftpdir= ''; cannam@167: } cannam@167: } cannam@167: cannam@167: sub html_ftpon { &arg('ftpon'); } cannam@167: sub html_endftpon { &endarg('ftpon'); } cannam@167: sub html_do_ftpon { cannam@167: #print STDERR "ftpon($_[0])\n"; cannam@167: $html_ftpsite= $_[0]; $html_ftpdir= ''; cannam@167: print HTML ""; cannam@167: &recurse($_[0]); cannam@167: print HTML ""; cannam@167: } cannam@167: cannam@167: sub html_ftpin { &arg('ftpin'); } cannam@167: sub html_endftpin { &endarg('ftpin'); } cannam@167: sub html_do_ftpin { cannam@167: #print STDERR "ftpin($_[0])\n"; cannam@167: print HTML ""; cannam@167: &recurse($_[0]); cannam@167: print HTML ""; cannam@167: } cannam@167: cannam@167: sub html_text { cannam@167: print HTML "\n

\n" if $html_needpara > 0; cannam@167: $html_needpara=0; cannam@167: $html_stuff= &html_sanitise($_[0]); cannam@167: while ($html_stuff =~ s/^(.{40,70}) //) { cannam@167: print HTML "$1\n"; cannam@167: } cannam@167: print HTML $html_stuff; cannam@167: } cannam@167: cannam@167: sub html_tab { cannam@167: $htmltabignore++ || warn "html tab ignored"; cannam@167: } cannam@167: cannam@167: sub html_newline { print HTML "
\n" ; } cannam@167: sub html_startverbatim { print HTML "

\n"   ;                       }
cannam@167: sub html_verbatim      { print HTML &html_sanitise($_[0]),"\n";         }
cannam@167: sub html_endverbatim   { print HTML "
\n" ; $html_needpara= -1; } cannam@167: cannam@167: sub html_endpara { cannam@167: $html_needpara || $html_needpara++; cannam@167: } cannam@167: cannam@167: sub html_finish { cannam@167: &html_close; cannam@167: } cannam@167: cannam@167: sub html_startindex { cannam@167: print HTML "
\n"; cannam@167: } cannam@167: cannam@167: sub html_startindexitem { cannam@167: local ($ref,$qval) = @_; cannam@167: $qval =~ m/Q(\d+)\.(\d+)/; cannam@167: local ($s,$n) = ($1,$2); cannam@167: print HTML "
  • Q$s.$n. "; cannam@167: $html_indexunhead=''; cannam@167: } cannam@167: cannam@167: sub html_startindexmainitem { cannam@167: local ($ref,$s) = @_; cannam@167: $s =~ m/\d+/; $s= $&; cannam@167: print HTML "

    " if ($s > 1); cannam@167: print HTML "
  • Section $s. "; cannam@167: $html_indexunhead=''; cannam@167: } cannam@167: cannam@167: sub html_endindexitem { cannam@167: print HTML "$html_indexunhead\n"; cannam@167: } cannam@167: cannam@167: sub html_startlist { cannam@167: print HTML "\n"; cannam@167: $html_itemend="
      "; cannam@167: } cannam@167: cannam@167: sub html_endlist { cannam@167: print HTML "$html_itemend\n
    \n"; cannam@167: $html_needpara=-1 cannam@167: } cannam@167: cannam@167: sub html_item { cannam@167: print HTML "$html_itemend\n
  • "; cannam@167: $html_itemend=""; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: cannam@167: sub html_startpackedlist { cannam@167: print HTML "\n"; cannam@167: $html_itemend=""; cannam@167: } cannam@167: cannam@167: sub html_endpackedlist { cannam@167: print HTML "$html_itemend\n\n"; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: cannam@167: sub html_packeditem { cannam@167: print HTML "$html_itemend\n
  • "; cannam@167: $html_itemend=""; cannam@167: $html_needpara=-1; cannam@167: } cannam@167: cannam@167: sub html_startindent { print HTML "
    \n"; } cannam@167: sub html_endindent { print HTML "
    \n"; } cannam@167: cannam@167: sub html_pageref { cannam@167: local ($ref,$sq) = @_; cannam@167: $sq =~ m/(\d+)\.(\d+)/; cannam@167: local ($s,$n) = ($1,$2); cannam@167: print HTML "Q$sq \`"; cannam@167: } cannam@167: cannam@167: sub html_endpageref { cannam@167: print HTML "'"; cannam@167: } cannam@167: cannam@167: sub html_sanitise { cannam@167: local ($in) = @_; cannam@167: local ($out); cannam@167: while ($in =~ m/[<>&"]/) { cannam@167: $out.= $`. '&'. $saniarray{$&}. ';'; cannam@167: $in=$'; cannam@167: } cannam@167: $out.= $in; cannam@167: $out; cannam@167: } cannam@167: cannam@167: 1;