]> sjero.net Git - wget/commitdiff
[svn] * configure.in: Look for perl and pod2man and make substitutions.
authordan <devnull@localhost>
Fri, 23 Feb 2001 02:09:36 +0000 (18:09 -0800)
committerdan <devnull@localhost>
Fri, 23 Feb 2001 02:09:36 +0000 (18:09 -0800)
* Makefile.in (install): Do install.man if we have pod2man.

* Makefile.in: Make wget man page and install it if we have pod2man.  Added some
  missing '$(srcdir)/'s.  Added missing dependencies on install targets
  (allowing you to just do `make install' rather than forcing you to do `make &&
  make install').  Also, Makefile rules should always use output file parameters
  if available rather than redirecting stdout with '>', or you falsely satisfy
  dependencies if the tool you're running is missing or fails -- fixed call of
  texi2pod.pl that did this wrong.

* texi2pod.pl: Removed from CVS.  Now automatically generated.

* texi2pod.pl.in: This new file is processed into texi2pod.pl, getting the
  appropriate path to the Perl 5+ executable on this system and becoming
  executable (CVS files, by contrast, don't arrive executable).

ChangeLog
Makefile.in
TODO
configure.in
doc/ChangeLog
doc/Makefile.in
doc/texi2pod.pl [deleted file]
doc/texi2pod.pl.in [new file with mode: 0644]

index 21c6f2597dc554ef016231a7f157ca059d54bcde..d8be523f62eaecf40b5b1a20d815b0e458c8d0e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
        * TODO: Remove empty directories created due to --accept/--reject.
 
+       * configure.in: Look for perl and pod2man and make substitutions.
+       
+       * Makefile.in (install): Do install.man if we have pod2man.
+
 2001-02-13  Jan Prikryl  <prikryl@cg.tuwien.ac.at>
 
        * windows/Makefile.src: Removed references to ftpparse sources.
index 17c95212c490834ac650758bf15d3413d9c1747a..248a72aba89265b1f74b6efd608091e6a48df08a 100644 (file)
@@ -80,7 +80,8 @@ $(SUBDIRS): FORCE
        cd $@ && $(MAKE) $(MAKEDEFS)
 
 # install everything
-install: install.bin install.info install.wgetrc install.mo # install.man
+install: install.bin install.info install.wgetrc \
+        install.mo @COMMENT_IF_NO_POD2MAN@install.man
 
 # install/uninstall the binary
 install.bin uninstall.bin:
diff --git a/TODO b/TODO
index 2f31391620f6b6d5ca78ce58b8cf7c6d85b763df..73d460daa3c559eab808e13ee9926e08b0ee5a6d 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,12 +7,6 @@ items are not listed in any particular order (except that recently-added items
 may tend towards the top).  Not all of these represent user-visible
 changes.
 
-* It would be nice to have a simple man page for wget that refers you to the 
-  .info files for more information.  It could be as simple as the output of wget
-  --help plus some boilerplate.  This should stop wget re-packagers like RedHat
-  who include the out-of-date 1.4.5 man page in order to have one.  Perhaps we
-  can automatically generate a man page from the .texi file like gcc does?
-
 * Try to devise a scheme so that, when password is unknown, Wget asks
   the user for one.
 
index a715746e83ed73711467507cf3c4739fc5158721..71c0029fa39a732b5837fac9828fd41bd34facf8 100644 (file)
@@ -224,6 +224,20 @@ case "${MAKEINFO}" in
    *) MAKEINFO="makeinfo \$(srcdir)/wget.texi"            ;;
 esac
 
+dnl
+dnl Find perl and pod2man
+dnl
+
+AC_PATH_PROGS(PERL, perl5 perl, no)
+AC_PATH_PROG(POD2MAN, pod2man, no)
+
+if test "x${POD2MAN}" = xno; then
+  COMMENT_IF_NO_POD2MAN="# "
+else
+  COMMENT_IF_NO_POD2MAN=
+fi
+AC_SUBST(COMMENT_IF_NO_POD2MAN)
+
 dnl
 dnl Create output
 dnl
index 156fac8e67f348a83bb19b2e88e5a07e62a879d9..869dbab18a1148a1a4e48de6e2208a884f3584b9 100644 (file)
@@ -1,3 +1,21 @@
+2001-02-22  Dan Harkless  <wget@harkless.org>
+
+       * Makefile.in: Make wget man page and install it if we have
+       pod2man.  Added some missing '$(srcdir)/'s.  Added missing
+       dependencies on install targets (allowing you to just do `make
+       install' rather than forcing you to do `make && make install').
+       Also, Makefile rules should always use output file parameters if
+       available rather than redirecting stdout with '>', or you falsely
+       satisfy dependencies if the tool you're running is missing or
+       fails -- fixed call of texi2pod.pl that did this wrong.
+
+       * texi2pod.pl: Removed from CVS.  Now automatically generated.
+               
+       * texi2pod.pl.in: This new file is processed into texi2pod.pl,
+       getting the appropriate path to the Perl 5+ executable on this
+       system and becoming executable (CVS files, by contrast, don't
+       arrive executable).
+       
 2001-02-19  Dan Harkless  <wget@harkless.org>
 
        * wget.texi (Download Options): Further improvement to --continue
index e170e9362294575513ee3c9b5faa7ded7c83714a..a410d97ece678cb70f04b988ab788682a3bfaf38 100644 (file)
@@ -45,7 +45,7 @@ INSTALL_DATA = @INSTALL_DATA@
 RM = rm -f
 
 TEXI2POD     = ./texi2pod.pl
-POD2MAN      = pod2man
+POD2MAN      = @POD2MAN@
 MAN          = wget.$(manext)
 WGETRC       = $(sysconfdir)/wgetrc
 SAMPLERCTEXI = sample.wgetrc.munged_for_texi_inclusion
@@ -54,30 +54,32 @@ SAMPLERCTEXI = sample.wgetrc.munged_for_texi_inclusion
 # Dependencies for building
 #
 
-all: wget.info
+all: wget.info @COMMENT_IF_NO_POD2MAN@$(MAN)
 
 everything: all wget_us.ps wget_a4.ps wget_toc.html
 
 $(SAMPLERCTEXI): $(srcdir)/sample.wgetrc
        sed s/@/@@/g $< > $@
 
-wget.info: $(SAMPLERCTEXI) wget.texi
+wget.info: $(SAMPLERCTEXI) $(srcdir)/wget.texi
        -$(MAKEINFO)
 
-wget.pod: wget.texi
-       $(TEXI2POD) $< > $@
+$(TEXI2POD): $(srcdir)/$(TEXI2POD).in
+       sed s^/usr/bin/perl^@PERL@^ $< > $@
+       chmod u+x $@
+
+wget.pod: $(srcdir)/wget.texi texi2pod.pl
+       $(TEXI2POD) $< $@
 
 $(MAN): wget.pod
        $(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" $< > $@
 
-man: $(MAN)
-
 #wget.cat: $(MAN)
 #      nroff -man $< > $@
 
 dvi: wget.dvi
 
-wget.dvi: wget.texi
+wget.dvi: $(srcdir)/wget.texi
        $(TEXI2DVI) $(srcdir)/wget.texi
 
 wget_us.ps: wget.dvi
@@ -86,7 +88,7 @@ wget_us.ps: wget.dvi
 wget_a4.ps: wget.dvi
        $(DVIPS) -t a4 -o $@ wget.dvi
 
-wget_toc.html: wget.texi
+wget_toc.html: $(srcdir)/wget.texi
        $(TEXI2HTML) $(srcdir)/wget.texi
 
 #
@@ -94,10 +96,10 @@ wget_toc.html: wget.texi
 #
 
 # install all the documentation
-install: install.info install.wgetrc install.man
+install: install.info install.wgetrc @COMMENT_IF_NO_POD2MAN@install.man
 
 # uninstall all the documentation
-uninstall: uninstall.info uninstall.man
+uninstall: uninstall.info @COMMENT_IF_NO_POD2MAN@uninstall.man
 
 # install info pages, creating install directory if necessary
 install.info: wget.info
@@ -107,12 +109,12 @@ install.info: wget.info
        done
 
 # install man page, creating install directory if necessary
-install.man:
+install.man: $(MAN)
        $(top_srcdir)/mkinstalldirs $(mandir)/man$(manext)
        $(INSTALL_DATA) $(srcdir)/$(MAN) $(mandir)/man$(manext)/$(MAN)
 
 # install sample.wgetrc
-install.wgetrc:
+install.wgetrc: $(srcdir)/sample.wgetrc
        $(top_srcdir)/mkinstalldirs $(sysconfdir)
        @if test -f $(WGETRC); then \
          if cmp -s $(srcdir)/sample.wgetrc $(WGETRC); then echo ""; \
@@ -151,7 +153,7 @@ clean:
 
 distclean: clean
        $(RM) Makefile
-       $(RM) $(MAN)
+       $(RM) $(MAN) $(TEXI2POD)
 
 realclean: distclean
        $(RM) wget.info*
diff --git a/doc/texi2pod.pl b/doc/texi2pod.pl
deleted file mode 100644 (file)
index fcf910d..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-#! /usr/bin/perl -w
-
-# This does trivial (and I mean _trivial_) conversion of Texinfo
-# markup to Perl POD format.  It's intended to be used to extract
-# something suitable for a manpage from a Texinfo document.
-
-$output = 0;
-$skipping = 0;
-%sects = ();
-$section = "";
-@icstack = ();
-@endwstack = ();
-@skstack = ();
-$shift = "";
-%defs = ();
-$fnno = 1;
-
-while ($_ = shift) {
-    if (/^-D(.*)$/) {
-       if ($1 ne "") {
-           $flag = $1;
-       } else {
-           $flag = shift;
-       }
-       die "no flag specified for -D\n"
-           unless $flag ne "";
-       die "flags may only contain letters, digits, hyphens, and underscores\n"
-           unless $flag =~ /^[a-zA-Z0-9_-]+$/;
-       $defs{$flag} = "";
-    } elsif (/^-/) {
-       usage();
-    } else {
-       $in = $_, next unless defined $in;
-       $out = $_, next unless defined $out;
-       usage();
-    }
-}
-
-if (defined $in) {
-    open(STDIN, $in) or die "opening \"$in\": $!\n";
-}
-if (defined $out) {
-    open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
-}
-
-while(<STDIN>)
-{
-    # Certain commands are discarded without further processing.
-    /^\@(?:
-        [a-z]+index            # @*index: useful only in complete manual
-        |need                  # @need: useful only in printed manual
-        |(?:end\s+)?group      # @group .. @end group: ditto
-        |page                  # @page: ditto
-        |node                  # @node: useful only in .info file
-       )\b/x and next;
-    
-    chomp;
-
-    # Look for filename and title markers.
-    /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
-    /^\@settitle\s+([^.]+)/ and $tl = $1, next;
-
-    # Look for blocks surrounded by @c man begin SECTION ... @c man end.
-    # This really oughta be @ifman ... @end ifman and the like, but such
-    # would require rev'ing all other Texinfo translators.
-    /^\@c man begin ([A-Z]+)/ and $sect = $1, $output = 1, next;
-    /^\@c man end/ and do {
-       $sects{$sect} = "" unless exists $sects{$sect};
-       $sects{$sect} .= postprocess($section);
-       $section = "";
-       $output = 0;
-       next;
-    };
-    next unless $output;
-
-    # Discard comments.  (Can't do it above, because then we'd never see
-    # @c man lines.)
-    /^\@c\b/ and next;
-
-    # End-block handler goes up here because it needs to operate even
-    # if we are skipping.
-    /^\@end\s+([a-z]+)/ and do {
-       # Ignore @end foo, where foo is not an operation which may
-       # cause us to skip, if we are presently skipping.
-       my $ended = $1;
-       next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu)$/;
-
-       die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
-       die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
-
-       $endw = pop @endwstack;
-
-       if ($ended =~ /^(?:ifset|ifclear|ignore|menu)$/) {
-           $skipping = pop @skstack;
-           next;
-       } elsif ($ended =~ /^(?:example|smallexample)$/) {
-           $shift = "";
-           $_ = "";    # need a paragraph break
-       } elsif ($ended =~ /^(?:itemize|enumerate|table)$/) {
-           $_ = "\n=back\n";
-           $ic = pop @icstack;
-       } else {
-           die "unknown command \@end $ended at line $.\n";
-       }
-    };
-
-    # We must handle commands which can cause skipping even while we
-    # are skipping, otherwise we will not process nested conditionals
-    # correctly.
-    /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
-       push @endwstack, $endw;
-       push @skstack, $skipping;
-       $endw = "ifset";
-       $skipping = 1 unless exists $defs{$1};
-       next;
-    };
-
-    /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
-       push @endwstack, $endw;
-       push @skstack, $skipping;
-       $endw = "ifclear";
-       $skipping = 1 if exists $defs{$1};
-       next;
-    };
-
-    /^\@(ignore|menu)\b/ and do {
-       push @endwstack, $endw;
-       push @skstack, $skipping;
-       $endw = $1;
-       $skipping = 1;
-       next;
-    };
-
-    next if $skipping;
-
-    # Character entities.  First the ones that can be replaced by raw text
-    # or discarded outright:
-    s/\@copyright\{\}/(c)/g;
-    s/\@dots\{\}/.../g;
-    s/\@enddots\{\}/..../g;
-    s/\@([.!? ])/$1/g;
-    s/\@[:-]//g;
-    s/\@bullet(?:\{\})?/*/g;
-    s/\@TeX\{\}/TeX/g;
-    s/\@pounds\{\}/\#/g;
-    s/\@minus(?:\{\})?/-/g;
-
-    # Now the ones that have to be replaced by special escapes
-    # (which will be turned back into text by unmunge())
-    s/&/&amp;/g;
-    s/\@\{/&lbrace;/g;
-    s/\@\}/&rbrace;/g;
-    s/\@\@/&at;/g;
-    # POD doesn't interpret E<> inside a verbatim block.
-    if ($shift eq "") {
-       s/</&lt;/g;
-       s/>/&gt;/g;
-    } else {
-       s/</&LT;/g;
-       s/>/&GT;/g;
-    }
-
-    # Single line command handlers.
-    /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and $defs{$1} = $2, next;
-    /^\@clear\s+([a-zA-Z0-9_-]+)/ and delete $defs{$1}, next;
-
-    /^\@section\s+(.+)$/ and $_ = "\n=head2 $1\n";
-    /^\@subsection\s+(.+)$/ and $_ = "\n=head3 $1\n";
-
-    # Block command handlers:
-    /^\@itemize\s+(\@[a-z]+|\*|-)/ and do {
-       push @endwstack, $endw;
-       push @icstack, $ic;
-       $ic = $1;
-       $_ = "\n=over 4\n";
-       $endw = "itemize";
-    };
-
-    /^\@enumerate(?:\s+([A-Z0-9]+))?/ and do {
-       push @endwstack, $endw;
-       push @icstack, $ic;
-       if (defined $1) {
-           $ic = $1 . ".";
-       } else {
-           $ic = "1.";
-       }
-       $_ = "\n=over 4\n";
-       $endw = "enumerate";
-    };
-
-    /^\@table\s+(\@[a-z]+)/ and do {
-       push @endwstack, $endw;
-       push @icstack, $ic;
-       $ic = $1;
-       $ic =~ s/\@(?:samp|strong|key)/B/;
-       $ic =~ s/\@(?:code|kbd)/C/;
-       $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
-       $ic =~ s/\@(?:file)/F/;
-       $_ = "\n=over 4\n";
-       $endw = "table";
-    };
-
-    /^\@((?:small)?example)/ and do {
-       push @endwstack, $endw;
-       $endw = $1;
-       $shift = "\t";
-       $_ = "";        # need a paragraph break
-    };
-
-    /^\@itemx?\s*(.+)?$/ and do {
-       if (defined $1) {
-           # Entity escapes prevent munging by the <> processing below.
-           $_ = "\n=item $ic\&LT;$1\&GT;\n";
-       } else {
-           $_ = "\n=item $ic\n";
-           $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
-       }
-    };
-
-    $section .= $shift.$_."\n";
-}
-
-die "No filename or title\n" unless defined $fn && defined $tl;
-
-$sects{NAME} = "$fn \- $tl\n";
-$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
-
-for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
-             BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
-    if(exists $sects{$sect}) {
-       $head = $sect;
-       $head =~ s/SEEALSO/SEE ALSO/;
-       print "=head1 $head\n\n";
-       print scalar unmunge ($sects{$sect});
-       print "\n";
-    }
-}
-
-sub usage
-{
-    die "usage: $0 [-D toggle...] [infile [outfile]]\n";
-}
-
-sub postprocess
-{
-    local $_ = $_[0];
-
-    # @value{foo} is replaced by whatever 'foo' is defined as.
-    s/\@value\{([a-zA-Z0-9_-]+)\}/$defs{$1}/g;
-
-    # Formatting commands.
-    s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
-    s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
-    s/\@(?:samp|strong|key|option|env|b)\{([^\}]*)\}/B<$1>/g;
-    s/\@sc\{([^\}]*)\}/\U$1/g;
-    s/\@file\{([^\}]*)\}/F<$1>/g;
-    s/\@w\{([^\}]*)\}/S<$1>/g;
-    s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
-
-    # Cross references are thrown away, as are @noindent and @refill.
-    # (@noindent is impossible in .pod, and @refill is unnecessary.)
-    # @* is also impossible in .pod; we discard it and any newline that
-    # follows it.
-
-    s/\@xref\{(?:[^\}]*)\}[^.]*.//g;
-
-    # Originally "s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;", would not
-    # process cross-references like '(@pxref{some section} for more
-    # details)"
-    s/\s+\(\@pxref\{(?:[^\}]*)\}[^\)]*\)//g;
-
-    s/;\s+\@pxref\{(?:[^\}]*)\}//g;
-    s/\@noindent\s*//g;
-    s/\@refill//g;
-    s/\@\*\s*\n?//g;
-
-    # @uref can take one, two, or three arguments, with different
-    # semantics each time.  @url and @email are just like @uref with
-    # one argument, for our purposes.
-    s/\@(?:uref|url|email)\{([^\},]*)\}/&lt;C<$1>&gt;/g;
-    s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
-    s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
-
-    # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
-    # match Texinfo semantics of @emph inside @samp.
-    s/&LT;/</g;
-    s/&GT;/>/g;
-    1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
-    1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
-    s/[BI]<>//g;
-    s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
-    s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
-
-    # Extract footnotes.  This has to be done after all other
-    # processing because otherwise the regexp will choke on formatting
-    # inside @footnote.
-    while (/\@footnote/g) {
-       s/\@footnote\{([^\}]+)\}/[$fnno]/;
-       add_footnote($1, $fnno);
-       $fnno++;
-    }
-
-    return $_;
-}
-
-sub unmunge
-{
-    # Replace escaped symbols with their equivalents.
-    local $_ = $_[0];
-
-    s/&lt;/E<lt>/g;
-    s/&gt;/E<gt>/g;
-    s/&lbrace;/\{/g;
-    s/&rbrace;/\}/g;
-    s/&at;/\@/g;
-    s/&amp;/&/g;
-    return $_;
-}
-
-sub add_footnote
-{
-    unless (exists $sects{FOOTNOTES}) {
-       $sects{FOOTNOTES} = "\n=over 4\n\n";
-    }
-
-    $sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++;
-    $sects{FOOTNOTES} .= $_[0];
-    $sects{FOOTNOTES} .= "\n\n";
-}
-    
-
diff --git a/doc/texi2pod.pl.in b/doc/texi2pod.pl.in
new file mode 100644 (file)
index 0000000..4f42ad8
--- /dev/null
@@ -0,0 +1,331 @@
+#!/usr/bin/perl -w
+
+# This does trivial (and I mean _trivial_) conversion of Texinfo
+# markup to Perl POD format.  It's intended to be used to extract
+# something suitable for a manpage from a Texinfo document.
+
+$output = 0;
+$skipping = 0;
+%sects = ();
+$section = "";
+@icstack = ();
+@endwstack = ();
+@skstack = ();
+$shift = "";
+%defs = ();
+$fnno = 1;
+
+while ($_ = shift) {
+    if (/^-D(.*)$/) {
+       if ($1 ne "") {
+           $flag = $1;
+       } else {
+           $flag = shift;
+       }
+       die "no flag specified for -D\n"
+           unless $flag ne "";
+       die "flags may only contain letters, digits, hyphens, and underscores\n"
+           unless $flag =~ /^[a-zA-Z0-9_-]+$/;
+       $defs{$flag} = "";
+    } elsif (/^-/) {
+       usage();
+    } else {
+       $in = $_, next unless defined $in;
+       $out = $_, next unless defined $out;
+       usage();
+    }
+}
+
+if (defined $in) {
+    open(STDIN, $in) or die "opening \"$in\": $!\n";
+}
+if (defined $out) {
+    open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
+}
+
+while(<STDIN>)
+{
+    # Certain commands are discarded without further processing.
+    /^\@(?:
+        [a-z]+index            # @*index: useful only in complete manual
+        |need                  # @need: useful only in printed manual
+        |(?:end\s+)?group      # @group .. @end group: ditto
+        |page                  # @page: ditto
+        |node                  # @node: useful only in .info file
+       )\b/x and next;
+    
+    chomp;
+
+    # Look for filename and title markers.
+    /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
+    /^\@settitle\s+([^.]+)/ and $tl = $1, next;
+
+    # Look for blocks surrounded by @c man begin SECTION ... @c man end.
+    # This really oughta be @ifman ... @end ifman and the like, but such
+    # would require rev'ing all other Texinfo translators.
+    /^\@c man begin ([A-Z]+)/ and $sect = $1, $output = 1, next;
+    /^\@c man end/ and do {
+       $sects{$sect} = "" unless exists $sects{$sect};
+       $sects{$sect} .= postprocess($section);
+       $section = "";
+       $output = 0;
+       next;
+    };
+    next unless $output;
+
+    # Discard comments.  (Can't do it above, because then we'd never see
+    # @c man lines.)
+    /^\@c\b/ and next;
+
+    # End-block handler goes up here because it needs to operate even
+    # if we are skipping.
+    /^\@end\s+([a-z]+)/ and do {
+       # Ignore @end foo, where foo is not an operation which may
+       # cause us to skip, if we are presently skipping.
+       my $ended = $1;
+       next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu)$/;
+
+       die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
+       die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
+
+       $endw = pop @endwstack;
+
+       if ($ended =~ /^(?:ifset|ifclear|ignore|menu)$/) {
+           $skipping = pop @skstack;
+           next;
+       } elsif ($ended =~ /^(?:example|smallexample)$/) {
+           $shift = "";
+           $_ = "";    # need a paragraph break
+       } elsif ($ended =~ /^(?:itemize|enumerate|table)$/) {
+           $_ = "\n=back\n";
+           $ic = pop @icstack;
+       } else {
+           die "unknown command \@end $ended at line $.\n";
+       }
+    };
+
+    # We must handle commands which can cause skipping even while we
+    # are skipping, otherwise we will not process nested conditionals
+    # correctly.
+    /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
+       push @endwstack, $endw;
+       push @skstack, $skipping;
+       $endw = "ifset";
+       $skipping = 1 unless exists $defs{$1};
+       next;
+    };
+
+    /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
+       push @endwstack, $endw;
+       push @skstack, $skipping;
+       $endw = "ifclear";
+       $skipping = 1 if exists $defs{$1};
+       next;
+    };
+
+    /^\@(ignore|menu)\b/ and do {
+       push @endwstack, $endw;
+       push @skstack, $skipping;
+       $endw = $1;
+       $skipping = 1;
+       next;
+    };
+
+    next if $skipping;
+
+    # Character entities.  First the ones that can be replaced by raw text
+    # or discarded outright:
+    s/\@copyright\{\}/(c)/g;
+    s/\@dots\{\}/.../g;
+    s/\@enddots\{\}/..../g;
+    s/\@([.!? ])/$1/g;
+    s/\@[:-]//g;
+    s/\@bullet(?:\{\})?/*/g;
+    s/\@TeX\{\}/TeX/g;
+    s/\@pounds\{\}/\#/g;
+    s/\@minus(?:\{\})?/-/g;
+
+    # Now the ones that have to be replaced by special escapes
+    # (which will be turned back into text by unmunge())
+    s/&/&amp;/g;
+    s/\@\{/&lbrace;/g;
+    s/\@\}/&rbrace;/g;
+    s/\@\@/&at;/g;
+    # POD doesn't interpret E<> inside a verbatim block.
+    if ($shift eq "") {
+       s/</&lt;/g;
+       s/>/&gt;/g;
+    } else {
+       s/</&LT;/g;
+       s/>/&GT;/g;
+    }
+
+    # Single line command handlers.
+    /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and $defs{$1} = $2, next;
+    /^\@clear\s+([a-zA-Z0-9_-]+)/ and delete $defs{$1}, next;
+
+    /^\@section\s+(.+)$/ and $_ = "\n=head2 $1\n";
+    /^\@subsection\s+(.+)$/ and $_ = "\n=head3 $1\n";
+
+    # Block command handlers:
+    /^\@itemize\s+(\@[a-z]+|\*|-)/ and do {
+       push @endwstack, $endw;
+       push @icstack, $ic;
+       $ic = $1;
+       $_ = "\n=over 4\n";
+       $endw = "itemize";
+    };
+
+    /^\@enumerate(?:\s+([A-Z0-9]+))?/ and do {
+       push @endwstack, $endw;
+       push @icstack, $ic;
+       if (defined $1) {
+           $ic = $1 . ".";
+       } else {
+           $ic = "1.";
+       }
+       $_ = "\n=over 4\n";
+       $endw = "enumerate";
+    };
+
+    /^\@table\s+(\@[a-z]+)/ and do {
+       push @endwstack, $endw;
+       push @icstack, $ic;
+       $ic = $1;
+       $ic =~ s/\@(?:samp|strong|key)/B/;
+       $ic =~ s/\@(?:code|kbd)/C/;
+       $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
+       $ic =~ s/\@(?:file)/F/;
+       $_ = "\n=over 4\n";
+       $endw = "table";
+    };
+
+    /^\@((?:small)?example)/ and do {
+       push @endwstack, $endw;
+       $endw = $1;
+       $shift = "\t";
+       $_ = "";        # need a paragraph break
+    };
+
+    /^\@itemx?\s*(.+)?$/ and do {
+       if (defined $1) {
+           # Entity escapes prevent munging by the <> processing below.
+           $_ = "\n=item $ic\&LT;$1\&GT;\n";
+       } else {
+           $_ = "\n=item $ic\n";
+           $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
+       }
+    };
+
+    $section .= $shift.$_."\n";
+}
+
+die "No filename or title\n" unless defined $fn && defined $tl;
+
+$sects{NAME} = "$fn \- $tl\n";
+$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
+
+for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
+             BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
+    if(exists $sects{$sect}) {
+       $head = $sect;
+       $head =~ s/SEEALSO/SEE ALSO/;
+       print "=head1 $head\n\n";
+       print scalar unmunge ($sects{$sect});
+       print "\n";
+    }
+}
+
+sub usage
+{
+    die "usage: $0 [-D toggle...] [infile [outfile]]\n";
+}
+
+sub postprocess
+{
+    local $_ = $_[0];
+
+    # @value{foo} is replaced by whatever 'foo' is defined as.
+    s/\@value\{([a-zA-Z0-9_-]+)\}/$defs{$1}/g;
+
+    # Formatting commands.
+    s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
+    s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
+    s/\@(?:samp|strong|key|option|env|b)\{([^\}]*)\}/B<$1>/g;
+    s/\@sc\{([^\}]*)\}/\U$1/g;
+    s/\@file\{([^\}]*)\}/F<$1>/g;
+    s/\@w\{([^\}]*)\}/S<$1>/g;
+    s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
+
+    # Cross references are thrown away, as are @noindent and @refill.
+    # (@noindent is impossible in .pod, and @refill is unnecessary.)
+    # @* is also impossible in .pod; we discard it and any newline that
+    # follows it.
+
+    s/\@xref\{(?:[^\}]*)\}[^.]*.//g;
+
+    # Originally "s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;", would not
+    # process cross-references like '(@pxref{some section} for more
+    # details)"
+    s/\s+\(\@pxref\{(?:[^\}]*)\}[^\)]*\)//g;
+
+    s/;\s+\@pxref\{(?:[^\}]*)\}//g;
+    s/\@noindent\s*//g;
+    s/\@refill//g;
+    s/\@\*\s*\n?//g;
+
+    # @uref can take one, two, or three arguments, with different
+    # semantics each time.  @url and @email are just like @uref with
+    # one argument, for our purposes.
+    s/\@(?:uref|url|email)\{([^\},]*)\}/&lt;C<$1>&gt;/g;
+    s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
+    s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
+
+    # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
+    # match Texinfo semantics of @emph inside @samp.
+    s/&LT;/</g;
+    s/&GT;/>/g;
+    1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
+    1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
+    s/[BI]<>//g;
+    s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
+    s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
+
+    # Extract footnotes.  This has to be done after all other
+    # processing because otherwise the regexp will choke on formatting
+    # inside @footnote.
+    while (/\@footnote/g) {
+       s/\@footnote\{([^\}]+)\}/[$fnno]/;
+       add_footnote($1, $fnno);
+       $fnno++;
+    }
+
+    return $_;
+}
+
+sub unmunge
+{
+    # Replace escaped symbols with their equivalents.
+    local $_ = $_[0];
+
+    s/&lt;/E<lt>/g;
+    s/&gt;/E<gt>/g;
+    s/&lbrace;/\{/g;
+    s/&rbrace;/\}/g;
+    s/&at;/\@/g;
+    s/&amp;/&/g;
+    return $_;
+}
+
+sub add_footnote
+{
+    unless (exists $sects{FOOTNOTES}) {
+       $sects{FOOTNOTES} = "\n=over 4\n\n";
+    }
+
+    $sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++;
+    $sects{FOOTNOTES} .= $_[0];
+    $sects{FOOTNOTES} .= "\n\n";
+}
+    
+