From: dan Date: Fri, 23 Feb 2001 02:09:36 +0000 (-0800) Subject: [svn] * configure.in: Look for perl and pod2man and make substitutions. X-Git-Tag: v1.13~2265 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=776d65e829e72ba5af69bcba44251fc0f81a18d4 [svn] * configure.in: Look for perl and pod2man and make substitutions. * 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). --- diff --git a/ChangeLog b/ChangeLog index 21c6f259..d8be523f 100644 --- 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 * windows/Makefile.src: Removed references to ftpparse sources. diff --git a/Makefile.in b/Makefile.in index 17c95212..248a72ab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 2f313916..73d460da 100644 --- 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. diff --git a/configure.in b/configure.in index a715746e..71c0029f 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/doc/ChangeLog b/doc/ChangeLog index 156fac8e..869dbab1 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,21 @@ +2001-02-22 Dan Harkless + + * 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.texi (Download Options): Further improvement to --continue diff --git a/doc/Makefile.in b/doc/Makefile.in index e170e936..a410d97e 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -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 index fcf910d2..00000000 --- a/doc/texi2pod.pl +++ /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() -{ - # 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/&/&/g; - s/\@\{/{/g; - s/\@\}/}/g; - s/\@\@/&at;/g; - # POD doesn't interpret E<> inside a verbatim block. - if ($shift eq "") { - s//>/g; - } else { - s//>/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\<$1\>\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)\{([^\},]*)\}/<C<$1>>/g; - s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g; - s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g; - - # Turn B blah> into B I B to - # match Texinfo semantics of @emph inside @samp. - s/<//g; - 1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B]*)B<([^>]+)>/I<$1>B<$2>I//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/</E/g; - s/>/E/g; - s/{/\{/g; - s/}/\}/g; - s/&at;/\@/g; - s/&/&/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 index 00000000..4f42ad8a --- /dev/null +++ b/doc/texi2pod.pl.in @@ -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() +{ + # 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/&/&/g; + s/\@\{/{/g; + s/\@\}/}/g; + s/\@\@/&at;/g; + # POD doesn't interpret E<> inside a verbatim block. + if ($shift eq "") { + s//>/g; + } else { + s//>/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\<$1\>\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)\{([^\},]*)\}/<C<$1>>/g; + s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g; + s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g; + + # Turn B blah> into B I B to + # match Texinfo semantics of @emph inside @samp. + s/<//g; + 1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B]*)B<([^>]+)>/I<$1>B<$2>I//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/</E/g; + s/>/E/g; + s/{/\{/g; + s/}/\}/g; + s/&at;/\@/g; + s/&/&/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"; +} + +