1999-03-24 21:48:22 +08:00
|
|
|
|
#!/sw/tools/bin/perl -w
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
|
|
|
|
# Generate a short man page from --help and --version output.
|
1999-03-24 21:48:22 +08:00
|
|
|
|
# Copyright <20> 1997, 98, 99 Free Software Foundation, Inc.
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
|
|
|
|
# This program 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.
|
|
|
|
|
|
|
|
|
|
# This program 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 this program; if not, write to the Free Software Foundation,
|
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
|
# Written by Brendan O'Dea <bod@compusol.com.au>
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Available from ftp://ftp.gnu.org/gnu/help2man/
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1998-12-11 21:34:23 +08:00
|
|
|
|
use 5.004;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
use strict;
|
|
|
|
|
use Getopt::Long;
|
1999-07-10 15:28:05 +08:00
|
|
|
|
use Text::Tabs qw(expand);
|
1998-12-11 21:34:23 +08:00
|
|
|
|
use POSIX qw(strftime setlocale LC_TIME);
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
|
|
|
|
my $this_program = 'help2man';
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my $this_version = '1.018';
|
1998-09-09 21:47:43 +08:00
|
|
|
|
my $version_info = <<EOT;
|
|
|
|
|
$this_program $this_version
|
|
|
|
|
|
1999-03-24 21:48:22 +08:00
|
|
|
|
Copyright (C) 1997, 98, 99 Free Software Foundation, Inc.
|
1998-09-09 21:47:43 +08:00
|
|
|
|
This is free software; see the source for copying conditions. There is NO
|
|
|
|
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
1998-12-11 21:34:23 +08:00
|
|
|
|
|
|
|
|
|
Written by Brendan O'Dea <bod\@compusol.com.au>
|
1998-09-09 21:47:43 +08:00
|
|
|
|
EOT
|
|
|
|
|
|
|
|
|
|
my $help_info = <<EOT;
|
|
|
|
|
`$this_program' generates a man page out of `--help' and `--version' output.
|
|
|
|
|
|
|
|
|
|
Usage: $this_program [OPTION]... EXECUTABLE
|
|
|
|
|
|
1999-07-10 16:44:49 +08:00
|
|
|
|
-n, --name=STRING use `STRING' as the description for the NAME paragraph
|
|
|
|
|
-s, --section=SECTION use `SECTION' as the section for the man page
|
|
|
|
|
-i, --include=FILE include material from `FILE'
|
|
|
|
|
-I, --opt-include=FILE include material from `FILE' if it exists
|
|
|
|
|
-o, --output=FILE send output to `FILE'
|
|
|
|
|
-N, --no-info suppress pointer to Texinfo manual
|
|
|
|
|
--help print this help, then exit
|
1999-10-23 21:30:28 +08:00
|
|
|
|
--version print version number, then exit
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-08-04 19:37:54 +08:00
|
|
|
|
EXECUTABLE should accept `--help' and `--version' options.
|
1998-09-09 21:47:43 +08:00
|
|
|
|
EOT
|
|
|
|
|
|
1999-07-10 16:44:49 +08:00
|
|
|
|
my $section = 1;
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my ($opt_name, @opt_include, $opt_output, $opt_no_info);
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
|
|
|
|
# Parse options.
|
1999-07-10 16:44:49 +08:00
|
|
|
|
Getopt::Long::config('bundling');
|
1998-09-09 21:47:43 +08:00
|
|
|
|
GetOptions (
|
1999-07-10 16:44:49 +08:00
|
|
|
|
'n|name=s' => \$opt_name,
|
|
|
|
|
's|section=s' => \$section,
|
1999-11-02 21:08:05 +08:00
|
|
|
|
'i|include=s' => sub { push @opt_include, [ pop, 1 ] },
|
|
|
|
|
'I|opt-include=s' => sub { push @opt_include, [ pop, 0 ] },
|
1999-07-10 16:44:49 +08:00
|
|
|
|
'o|output=s' => \$opt_output,
|
|
|
|
|
'N|no-info' => \$opt_no_info,
|
|
|
|
|
help => sub { print $help_info; exit },
|
|
|
|
|
version => sub { print $version_info; exit },
|
1998-09-09 21:47:43 +08:00
|
|
|
|
) or die $help_info;
|
|
|
|
|
|
|
|
|
|
die $help_info unless @ARGV == 1;
|
|
|
|
|
|
|
|
|
|
my %include = ();
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my %append = ();
|
1999-10-23 21:30:28 +08:00
|
|
|
|
my @include = (); # retain order given in include file
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# Provide replacement `quote-regex' operator for pre-5.005.
|
|
|
|
|
BEGIN { eval q(sub qr { '' =~ $_[0]; $_[0] }) if $] < 5.005 }
|
|
|
|
|
|
1998-09-09 21:47:43 +08:00
|
|
|
|
# Process include file (if given). Format is:
|
|
|
|
|
#
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# [section name]
|
|
|
|
|
# verbatim text
|
|
|
|
|
#
|
|
|
|
|
# or
|
|
|
|
|
#
|
|
|
|
|
# /pattern/
|
|
|
|
|
# verbatim text
|
|
|
|
|
#
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
for (@opt_include)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my ($inc, $required) = @$_;
|
|
|
|
|
|
|
|
|
|
next unless -f $inc or $required;
|
|
|
|
|
die "$this_program: can't open `$inc' ($!)\n"
|
|
|
|
|
unless open INC, $inc;
|
|
|
|
|
|
|
|
|
|
my $key;
|
|
|
|
|
my $hash = \%include;
|
|
|
|
|
|
|
|
|
|
while (<INC>)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# [section]
|
|
|
|
|
if (/^\[([^]]+)\]/)
|
|
|
|
|
{
|
|
|
|
|
$key = uc $1;
|
|
|
|
|
$key =~ s/^\s+//;
|
|
|
|
|
$key =~ s/\s+$//;
|
|
|
|
|
$hash = \%include;
|
|
|
|
|
push @include, $key unless $include{$key};
|
|
|
|
|
next;
|
|
|
|
|
}
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# /pattern/
|
|
|
|
|
if (m!^/(.*)/([ims]*)!)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my $pat = $2 ? "(?$2)$1" : $1;
|
|
|
|
|
|
|
|
|
|
# Check pattern.
|
|
|
|
|
eval { $key = qr($pat) };
|
|
|
|
|
if ($@)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$@ =~ s/ at .*? line \d.*//;
|
|
|
|
|
die "$inc:$.:$@";
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$hash = \%append;
|
|
|
|
|
next;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# Silently ignore anything before the first
|
|
|
|
|
# section--allows for comments and revision info.
|
|
|
|
|
next unless $key;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$hash->{$key} ||= '';
|
|
|
|
|
$hash->{$key} .= $_;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
1999-11-02 21:08:05 +08:00
|
|
|
|
|
|
|
|
|
close INC;
|
|
|
|
|
|
|
|
|
|
die "$this_program: no valid information found in `$inc'\n"
|
|
|
|
|
unless $key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Compress trailing blank lines.
|
|
|
|
|
for my $hash (\(%include, %append))
|
|
|
|
|
{
|
|
|
|
|
for (keys %$hash) { $hash->{$_} =~ s/\n+$/\n/ }
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Turn off localisation of executable's ouput.
|
|
|
|
|
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Turn off localisation of date (for strftime).
|
1998-12-11 21:34:23 +08:00
|
|
|
|
setlocale LC_TIME, 'C';
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Grab help and version info from executable.
|
|
|
|
|
my $help_text = join '', map { expand $_ } `$ARGV[0] --help 2>/dev/null`
|
1998-10-06 12:07:25 +08:00
|
|
|
|
or die "$this_program: can't get `--help' info from $ARGV[0]\n";
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
my $version_text = join '', map { expand $_ } `$ARGV[0] --version 2>/dev/null`
|
1998-09-09 21:47:43 +08:00
|
|
|
|
or die "$this_program: can't get `--version' info from $ARGV[0]\n";
|
|
|
|
|
|
|
|
|
|
my $date = strftime "%B %Y", localtime;
|
|
|
|
|
(my $program = $ARGV[0]) =~ s!.*/!!;
|
|
|
|
|
my $package = $program;
|
|
|
|
|
my $version;
|
|
|
|
|
|
|
|
|
|
if ($opt_output)
|
|
|
|
|
{
|
|
|
|
|
unlink $opt_output
|
|
|
|
|
or die "$this_program: can't unlink $opt_output ($!)\n"
|
|
|
|
|
if -e $opt_output;
|
|
|
|
|
|
|
|
|
|
open STDOUT, ">$opt_output"
|
|
|
|
|
or die "$this_program: can't create $opt_output ($!)\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# The first line of the --version information is assumed to be in one
|
|
|
|
|
# of the following formats:
|
|
|
|
|
#
|
|
|
|
|
# <version>
|
|
|
|
|
# <program> <version>
|
1999-01-11 10:40:27 +08:00
|
|
|
|
# {GNU,Free} <program> <version>
|
|
|
|
|
# <program> ({GNU,Free} <package>) <version>
|
|
|
|
|
# <program> - {GNU,Free} <package> <version>
|
1998-09-09 21:47:43 +08:00
|
|
|
|
#
|
|
|
|
|
# and seperated from any copyright/author details by a blank line.
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
($_, $version_text) = split /\n+/, $version_text, 2;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-07-10 15:28:05 +08:00
|
|
|
|
if (/^(\S+) +\(((?:GNU|Free) +[^)]+)\) +(.*)/ or
|
|
|
|
|
/^(\S+) +- *((?:GNU|Free) +\S+) +(.*)/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
|
|
|
|
$program = $1;
|
|
|
|
|
$package = $2;
|
|
|
|
|
$version = $3;
|
|
|
|
|
}
|
1999-07-10 15:28:05 +08:00
|
|
|
|
elsif (/^((?:GNU|Free) +)?(\S+) +(.*)/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
|
|
|
|
$program = $2;
|
|
|
|
|
$package = $1 ? "$1$2" : $2;
|
|
|
|
|
$version = $3;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$version = $_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$program =~ s!.*/!!;
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# No info for `info' itself.
|
1998-12-11 21:34:23 +08:00
|
|
|
|
$opt_no_info = 1 if $program eq 'info';
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# --name overrides --include contents.
|
|
|
|
|
$include{NAME} = "$program \\- $opt_name\n" if $opt_name;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Default (useless) NAME paragraph.
|
|
|
|
|
$include{NAME} ||= "$program \\- manual page for $program $version\n";
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
|
|
|
|
# Man pages traditionally have the page title in caps.
|
|
|
|
|
my $PROGRAM = uc $program;
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Extract usage clause(s) [if any] for SYNOPSIS.
|
1999-11-02 21:08:05 +08:00
|
|
|
|
if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m)
|
1999-10-23 21:30:28 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my @syn = $2 . $3;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
if ($_ = $4)
|
1999-10-23 21:30:28 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
s/^\n//;
|
|
|
|
|
for (split /\n/) { s/^ *(or: +)?//; push @syn, $_ }
|
1999-10-23 21:30:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $synopsis = '';
|
|
|
|
|
for (@syn)
|
|
|
|
|
{
|
|
|
|
|
$synopsis .= ".br\n" if $synopsis;
|
|
|
|
|
s/(\S+) *//;
|
|
|
|
|
$synopsis .= ".B $1\n";
|
|
|
|
|
s/\s+$//;
|
|
|
|
|
s/(([][]|\.\.+)+)/\\fR$1\\fI/g;
|
|
|
|
|
s/^/\\fI/ unless s/^\\fR//;
|
|
|
|
|
$_ .= '\fR';
|
|
|
|
|
s/(\\fI)( *)/$2$1/g;
|
|
|
|
|
s/\\fI\\fR//g;
|
|
|
|
|
s/^\\fR//;
|
|
|
|
|
s/\\fI$//;
|
|
|
|
|
s/^\./\\&./;
|
|
|
|
|
|
|
|
|
|
$synopsis .= "$_\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$include{SYNOPSIS} ||= $synopsis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Process text, initial section is DESCRIPTION.
|
|
|
|
|
my $sect = 'DESCRIPTION';
|
|
|
|
|
$_ = "$help_text\n\n$version_text";
|
|
|
|
|
|
|
|
|
|
# Normalise paragraph breaks.
|
|
|
|
|
s/^\n+//;
|
|
|
|
|
s/\n*$/\n/;
|
|
|
|
|
s/\n\n+/\n\n/g;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Temporarily exchange leading dots and backslashes for tokens.
|
|
|
|
|
s/^\./\x80/mg;
|
|
|
|
|
s/\\/\x81/g;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# Start a new paragraph (if required) for these.
|
|
|
|
|
s/([^\n])\n(Report +bugs|Email +bug +reports +to|Written +by)/$1\n\n$2/g;
|
|
|
|
|
|
1998-09-09 21:47:43 +08:00
|
|
|
|
sub convert_option;
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
while (length)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Convert some standard paragraph names.
|
|
|
|
|
if (s/^(Options|Examples): *\n//)
|
|
|
|
|
{
|
|
|
|
|
$sect = uc $1;
|
|
|
|
|
next;
|
|
|
|
|
}
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Copyright section
|
1999-11-02 21:08:05 +08:00
|
|
|
|
if (/^Copyright +[(\xa9]/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$sect = 'COPYRIGHT';
|
|
|
|
|
$include{$sect} ||= '';
|
|
|
|
|
$include{$sect} .= ".PP\n" if $include{$sect};
|
|
|
|
|
|
|
|
|
|
my $copy;
|
|
|
|
|
($copy, $_) = split /\n\n/, $_, 2;
|
|
|
|
|
|
|
|
|
|
for ($copy)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Add back newline
|
|
|
|
|
s/\n*$/\n/;
|
|
|
|
|
|
|
|
|
|
# Convert iso9959-1 copyright symbol or (c) to nroff
|
|
|
|
|
# character.
|
1999-11-02 21:08:05 +08:00
|
|
|
|
s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
|
|
|
|
|
# Insert line breaks before additional copyright messages
|
|
|
|
|
# and the disclaimer.
|
1999-11-02 21:08:05 +08:00
|
|
|
|
s/(.)\n(Copyright |This +is +free +software)/$1\n.br\n$2/g;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
|
|
|
|
|
# Join hyphenated lines.
|
|
|
|
|
s/([A-Za-z])-\n */$1/g;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$include{$sect} .= $copy;
|
|
|
|
|
$_ ||= '';
|
|
|
|
|
next;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Catch bug report text.
|
1999-11-02 21:08:05 +08:00
|
|
|
|
if (/^(Report +bugs|Email +bug +reports +to) /)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$sect = 'REPORTING BUGS';
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Author section.
|
|
|
|
|
elsif (/^Written +by/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$sect = 'AUTHOR';
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Examples, indicated by an indented leading $, % or > are
|
|
|
|
|
# rendered in a constant width font.
|
|
|
|
|
if (/^( +)([\$\%>] )\S/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
my $indent = $1;
|
|
|
|
|
my $prefix = $2;
|
|
|
|
|
my $break = '.IP';
|
|
|
|
|
$include{$sect} ||= '';
|
|
|
|
|
while (s/^$indent\Q$prefix\E(\S.*)\n*//)
|
|
|
|
|
{
|
|
|
|
|
$include{$sect} .= "$break\n\\f(CW$prefix$1\\fR\n";
|
|
|
|
|
$break = '.br';
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-09 21:47:43 +08:00
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
my $matched = '';
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$include{$sect} ||= '';
|
1999-11-02 21:08:05 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Sub-sections have a trailing colon and the second line indented.
|
|
|
|
|
if (s/^(\S.*:) *\n / /)
|
1999-07-10 16:44:49 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$matched .= $& if %append;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$include{$sect} .= qq(.SS "$1"\n);
|
1999-07-10 16:44:49 +08:00
|
|
|
|
}
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
my $indent = 0;
|
|
|
|
|
my $content = '';
|
1999-07-10 15:28:05 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# Tagged paragraph (option).
|
|
|
|
|
if (s/^( {1,10}(-\S+(?: \S+|(?:, *-\S+)*)))(?: +|\n( {20,}))(\S.*)\n//)
|
|
|
|
|
{
|
|
|
|
|
$matched .= $& if %append;
|
|
|
|
|
$indent = length ($3 || $1);
|
|
|
|
|
my $tag = $2;
|
|
|
|
|
my $desc = $4;
|
|
|
|
|
unless ($3)
|
|
|
|
|
{
|
|
|
|
|
$indent = length $1;
|
|
|
|
|
$indent = length $1 if /^( {20,})[^\s-]/;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = ".TP\n\x82$tag\n\x82$desc\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Tagged paragraph (other).
|
|
|
|
|
elsif (s/^( +(\S.*?) +)(\S.*)\n//)
|
1999-10-23 21:30:28 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$matched .= $& if %append;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$indent = length $1;
|
|
|
|
|
$content = ".TP\n\x82$2\n\x82$3\n";
|
|
|
|
|
}
|
1999-07-10 15:28:05 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Indented paragraph.
|
|
|
|
|
elsif (s/^( +)(\S.*)\n//)
|
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$matched .= $& if %append;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$indent = length $1;
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$content = ".IP\n\x82$2\n";
|
1999-10-23 21:30:28 +08:00
|
|
|
|
}
|
1999-07-10 15:28:05 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Left justified paragraph.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s/(.*)\n//;
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$matched .= $& if %append;
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$content = ".PP\n" if $include{$sect};
|
|
|
|
|
$content .= "$1\n";
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
1999-07-10 15:28:05 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Append continuations.
|
1999-11-02 21:08:05 +08:00
|
|
|
|
while (s/^ {$indent}(\S.*)\n//)
|
|
|
|
|
{
|
|
|
|
|
$matched .= $& if %append;
|
|
|
|
|
$content .= "\x82$1\n"
|
|
|
|
|
}
|
1999-07-10 15:28:05 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Move to next paragraph.
|
|
|
|
|
s/^\n+//;
|
1999-09-02 18:40:44 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
for ($content)
|
|
|
|
|
{
|
|
|
|
|
# Leading dot protection.
|
|
|
|
|
s/\x82\./\x80/g;
|
|
|
|
|
s/\x82//g;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Convert options.
|
|
|
|
|
s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
# Check if matched paragraph contains /pat/.
|
|
|
|
|
if (%append)
|
|
|
|
|
{
|
|
|
|
|
for my $pat (keys %append)
|
|
|
|
|
{
|
|
|
|
|
if ($matched =~ $pat)
|
|
|
|
|
{
|
|
|
|
|
$content .= ".PP\n" unless $append{$pat} =~ /^\./;
|
|
|
|
|
$content .= $append{$pat};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$include{$sect} .= $content;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Refer to the real documentation.
|
1999-10-23 21:30:28 +08:00
|
|
|
|
unless ($opt_no_info)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-10-23 21:30:28 +08:00
|
|
|
|
$sect = 'SEE ALSO';
|
|
|
|
|
$include{$sect} ||= '';
|
|
|
|
|
$include{$sect} .= ".PP\n" if $include{$sect};
|
|
|
|
|
$include{$sect} .= <<EOT;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
The full documentation for
|
|
|
|
|
.B $program
|
|
|
|
|
is maintained as a Texinfo manual. If the
|
|
|
|
|
.B info
|
|
|
|
|
and
|
|
|
|
|
.B $program
|
|
|
|
|
programs are properly installed at your site, the command
|
|
|
|
|
.IP
|
|
|
|
|
.B info $program
|
|
|
|
|
.PP
|
|
|
|
|
should give you access to the complete manual.
|
|
|
|
|
EOT
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Output header.
|
|
|
|
|
print <<EOT;
|
|
|
|
|
.\\" DO NOT MODIFY THIS FILE! It was generated by $this_program $this_version.
|
|
|
|
|
.TH $PROGRAM "$section" "$date" "$package $version" FSF
|
|
|
|
|
EOT
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Section ordering.
|
|
|
|
|
my @pre = qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES);
|
|
|
|
|
my @post = ('AUTHOR', 'REPORTING BUGS', 'COPYRIGHT', 'SEE ALSO');
|
|
|
|
|
my $filter = join '|', @pre, @post;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-10-23 21:30:28 +08:00
|
|
|
|
# Output content.
|
|
|
|
|
for (@pre, (grep ! /^($filter)$/o, @include), @post)
|
|
|
|
|
{
|
|
|
|
|
if ($include{$_})
|
|
|
|
|
{
|
|
|
|
|
my $quote = /\W/ ? '"' : '';
|
|
|
|
|
print ".SH $quote$_$quote\n";
|
|
|
|
|
|
|
|
|
|
for ($include{$_})
|
|
|
|
|
{
|
|
|
|
|
# Replace leading dot an backslash tokens.
|
|
|
|
|
s/\x80/\\&./g;
|
|
|
|
|
s/\x81/\\e/g;
|
|
|
|
|
print;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
# Convert option dashes to \- to stop nroff from hyphenating 'em, and
|
|
|
|
|
# embolden. Option arguments get italicised.
|
|
|
|
|
sub convert_option
|
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
local $_ = '\fB' . shift;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
s/-/\\-/g;
|
|
|
|
|
unless (s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/)
|
1998-09-09 21:47:43 +08:00
|
|
|
|
{
|
1999-11-02 21:08:05 +08:00
|
|
|
|
s/=(.)/\\fR=\\fI$1/;
|
|
|
|
|
s/ (.)/ \\fI$1/;
|
|
|
|
|
$_ .= '\fR';
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 21:08:05 +08:00
|
|
|
|
$_;
|
1998-09-09 21:47:43 +08:00
|
|
|
|
}
|