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

$user_title

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

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

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

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

\n"; $html_needpara=-1; } } sub html_endmajorheading { print HTML "\n

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

\n"; } sub html_endminorheading { print HTML "\n

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

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

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

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