1N/A# Generate a short man page from --help and --version output. 1N/A# Copyright � 1997, 1998, 1999, 2000 Free Software Foundation, Inc. 1N/A# This program is free software; you can redistribute it and/or modify 1N/A# it under the terms of the GNU General Public License as published by 1N/A# the Free Software Foundation; either version 2, or (at your option) 1N/A# This program is distributed in the hope that it will be useful, 1N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A# GNU General Public License for more details. 1N/A# You should have received a copy of the GNU General Public License 1N/A# along with this program; if not, write to the Free Software Foundation, 1N/A# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 1N/A# Written by Brendan O'Dea <bod@compusol.com.au> 1N/AGNU $this_program $this_version 1N/ACopyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. 1N/AThis is free software; see the source for copying conditions. There is NO 1N/Awarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1N/AWritten by Brendan O'Dea <bod\@compusol.com.au> 1N/A`$this_program' generates a man page out of `--help' and `--version' output. 1N/AUsage: $this_program [OPTION]... EXECUTABLE 1N/A -n, --name=STRING use `STRING' as the description for the NAME paragraph 1N/A -s, --section=SECTION use `SECTION' as the section for the man page 1N/A -i, --include=FILE include material from `FILE' 1N/A -I, --opt-include=FILE include material from `FILE' if it exists 1N/A -o, --output=FILE send output to `FILE' 1N/A -N, --no-info suppress pointer to Texinfo manual 1N/A --help print this help, then exit 1N/A --version print version number, then exit 1N/AEXECUTABLE should accept `--help' and `--version' options. 1N/AReport bugs to <bug-help2man\@gnu.org>. 1N/Amy @include = (); # retain order given in include file 1N/A# Provide replacement `quote-regex' operator for pre-5.005. 1N/ABEGIN { eval q(sub qr { '' =~ $_[0]; $_[0] }) if $] < 5.005 } 1N/A# Process include file (if given). Format is: 1N/A unless open INC, $inc; 1N/A my $hash = \%include; 1N/A push @include, $key unless $include{$key}; 1N/A if (m!^/(.*)/([ims]*)!) 1N/A my $pat = $2 ? "(?$2)$1" : $1; 1N/A eval { $key = qr($pat) }; 1N/A $@ =~ s/ at .*? line \d.*//; 1N/A # Silently ignore anything before the first 1N/A # section--allows for comments and revision info. 1N/A $hash->{$key} ||= ''; 1N/A $hash->{$key} .= $_; 1N/A die "$this_program: no valid information found in `$inc'\n" 1N/A# Compress trailing blank lines. 1N/A# Turn off localisation of executable's ouput. 1N/A@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; 1N/A# Turn off localisation of date (for strftime). 1N/Asetlocale LC_TIME, 'C'; 1N/A# Grab help and version info from executable. 1N/A open STDOUT, ">$opt_output" 1N/A# The first line of the --version information is assumed to be in one 1N/A# of the following formats: 1N/A# <program> <version> 1N/A# {GNU,Free} <program> <version> 1N/A# <program> ({GNU,Free} <package>) <version> 1N/A# <program> - {GNU,Free} <package> <version> 1N/Aif (/^(\S+) +\(((?:GNU|Free) +[^)]+)\) +(.*)/ or 1N/A /^(\S+) +- *((?:GNU|Free) +\S+) +(.*)/) 1N/Aelsif (/^((?:GNU|Free) +)?(\S+) +(.*)/) 1N/A$opt_no_info = 1 if $program eq 'info'; 1N/A# --name overrides --include contents. 1N/A$include{NAME} = "$program \\- $opt_name\n" if $opt_name; 1N/A# Default (useless) NAME paragraph. 1N/A$include{NAME} ||= "$program \\- manual page for $program $version\n"; 1N/A# Man pages traditionally have the page title in caps. 1N/Amy $PROGRAM = uc $program; 1N/A# Extract usage clause(s) [if any] for SYNOPSIS. 1N/Aif ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m) 1N/A for (split /\n/) { s/^ *(or: +)?//; push @syn, $_ } 1N/A $synopsis .= ".br\n" if $synopsis; 1N/A $synopsis .= ".B $1\n"; 1N/A s/(([][]|\.\.+)+)/\\fR$1\\fI/g; 1N/A s/^/\\fI/ unless s/^\\fR//; 1N/A s/(\\fI)( *)/$2$1/g; 1N/A $synopsis .= "$_\n"; 1N/A $include{SYNOPSIS} ||= $synopsis; 1N/A# Process text, initial section is DESCRIPTION. 1N/A$_ = "$help_text\n\n$version_text"; 1N/A# Normalise paragraph breaks. 1N/A# Temporarily exchange leading dots, apostrophes and backslashes for 1N/A# Start a new paragraph (if required) for these. 1N/A # Convert some standard paragraph names. 1N/A # Convert iso9959-1 copyright symbol or (c) to nroff 1N/A # Insert line breaks before additional copyright messages 1N/A # and the disclaimer. 1N/A # Join hyphenated lines. 1N/A # Catch bug report text. 1N/A # Examples, indicated by an indented leading $, % or > are 1N/A # rendered in a constant width font. 1N/A if (/^( +)([\$\%>] )\S/) 1N/A # Sub-sections have a trailing colon and the second line indented. 1N/A if (s/^(\S.*:) *\n / /) 1N/A # Option with description. 1N/A if (s/^( {1,10}([+-]\S.*?))(?:( +)|\n( {20,}))(\S.*)\n//) 1N/A # Indent may be different on second line. 1N/A # Option without description. 1N/A elsif (s/^ {1,10}([+-]\S.*)\n//) 1N/A # Indented paragraph with tag. 1N/A elsif (s/^( +(\S.*?) +)(\S.*)\n//) 1N/A # Indented paragraph. 1N/A elsif (s/^( +)(\S.*)\n//) 1N/A # Left justified paragraph. 1N/A # Append continuations. 1N/A # Move to next paragraph. 1N/A # Leading dot and apostrophe protection. 1N/A s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge; 1N/A # Check if matched paragraph contains /pat/. 1N/A for my $pat (keys %append) 1N/A if ($matched =~ $pat) 1N/A $content .= ".PP\n" unless $append{$pat} =~ /^\./; 1N/A $content .= $append{$pat}; 1N/A $include{$sect} .= $content; 1N/A# Refer to the real documentation. 1N/Aunless ($opt_no_info) 1N/A $include{$sect} ||= ''; 1N/A $include{$sect} .= ".PP\n" if $include{$sect}; 1N/A $include{$sect} .= <<EOT; 1N/AThe full documentation for 1N/Ais maintained as a Texinfo manual. If the 1N/Aprograms are properly installed at your site, the command 1N/Ashould give you access to the complete manual. 1N/A.\\" DO NOT MODIFY THIS FILE! It was generated by $this_program $this_version. 1N/A.TH $PROGRAM "$section" "$date" "$package $version" FSF 1N/Amy @pre = qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES); 1N/Amy $filter = join '|', @pre, @post; 1N/Afor (@pre, (grep ! /^($filter)$/o, @include), @post) 1N/A my $quote = /\W/ ? '"' : ''; 1N/A # Replace leading dot, apostrophe and backslash tokens. 1N/A# Convert option dashes to \- to stop nroff from hyphenating 'em, and 1N/A# embolden. Option arguments get italicised. 1N/A local $_ = '\fB' . shift; 1N/A unless (s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/) 1N/A s/=(.)/\\fR=\\fI$1/;