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

cannam@95: $user_title cannam@95:

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

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

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

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

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

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

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

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

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

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

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