head	1.1;
branch	1.1.1;
access;
symbols
	RELENG_9_1_0_RELEASE:1.1.1.4
	RELENG_9_1:1.1.1.4.0.40
	RELENG_9_1_BP:1.1.1.4
	RELENG_8_3_0_RELEASE:1.1.1.4
	RELENG_8_3:1.1.1.4.0.38
	RELENG_8_3_BP:1.1.1.4
	RELENG_9_0_0_RELEASE:1.1.1.4
	RELENG_9_0:1.1.1.4.0.36
	RELENG_9_0_BP:1.1.1.4
	RELENG_9:1.1.1.4.0.34
	RELENG_9_BP:1.1.1.4
	RELENG_7_4_0_RELEASE:1.1.1.4
	RELENG_8_2_0_RELEASE:1.1.1.4
	RELENG_7_4:1.1.1.4.0.32
	RELENG_7_4_BP:1.1.1.4
	RELENG_8_2:1.1.1.4.0.30
	RELENG_8_2_BP:1.1.1.4
	RELENG_8_1_0_RELEASE:1.1.1.4
	RELENG_8_1:1.1.1.4.0.28
	RELENG_8_1_BP:1.1.1.4
	RELENG_7_3_0_RELEASE:1.1.1.4
	RELENG_7_3:1.1.1.4.0.26
	RELENG_7_3_BP:1.1.1.4
	RELENG_8_0_0_RELEASE:1.1.1.4
	RELENG_8_0:1.1.1.4.0.24
	RELENG_8_0_BP:1.1.1.4
	RELENG_8:1.1.1.4.0.22
	RELENG_8_BP:1.1.1.4
	RELENG_7_2_0_RELEASE:1.1.1.4
	RELENG_7_2:1.1.1.4.0.20
	RELENG_7_2_BP:1.1.1.4
	RELENG_7_1_0_RELEASE:1.1.1.4
	RELENG_6_4_0_RELEASE:1.1.1.4
	RELENG_7_1:1.1.1.4.0.18
	RELENG_7_1_BP:1.1.1.4
	RELENG_6_4:1.1.1.4.0.16
	RELENG_6_4_BP:1.1.1.4
	RELENG_7_0_0_RELEASE:1.1.1.4
	RELENG_6_3_0_RELEASE:1.1.1.4
	RELENG_7_0:1.1.1.4.0.14
	RELENG_7_0_BP:1.1.1.4
	RELENG_6_3:1.1.1.4.0.12
	RELENG_6_3_BP:1.1.1.4
	RELENG_7:1.1.1.4.0.10
	RELENG_7_BP:1.1.1.4
	RELENG_6_2_0_RELEASE:1.1.1.4
	RELENG_6_2:1.1.1.4.0.8
	RELENG_6_2_BP:1.1.1.4
	RELENG_5_5_0_RELEASE:1.1.1.3
	RELENG_5_5:1.1.1.3.0.12
	RELENG_5_5_BP:1.1.1.3
	RELENG_6_1_0_RELEASE:1.1.1.4
	RELENG_6_1:1.1.1.4.0.6
	RELENG_6_1_BP:1.1.1.4
	RELENG_6_0_0_RELEASE:1.1.1.4
	RELENG_6_0:1.1.1.4.0.4
	RELENG_6_0_BP:1.1.1.4
	RELENG_6:1.1.1.4.0.2
	RELENG_6_BP:1.1.1.4
	RELENG_5_4_0_RELEASE:1.1.1.3
	RELENG_5_4:1.1.1.3.0.10
	RELENG_5_4_BP:1.1.1.3
	RELENG_4_11_0_RELEASE:1.1.1.1.2.2
	RELENG_4_11:1.1.1.1.2.2.0.6
	RELENG_4_11_BP:1.1.1.1.2.2
	RELENG_5_3_0_RELEASE:1.1.1.3
	RELENG_5_3:1.1.1.3.0.8
	RELENG_5_3_BP:1.1.1.3
	RELENG_5:1.1.1.3.0.6
	RELENG_5_BP:1.1.1.3
	RELENG_4_10_0_RELEASE:1.1.1.1.2.2
	RELENG_4_10:1.1.1.1.2.2.0.4
	RELENG_4_10_BP:1.1.1.1.2.2
	RELENG_5_2_1_RELEASE:1.1.1.3
	RELENG_5_2_0_RELEASE:1.1.1.3
	RELENG_5_2:1.1.1.3.0.4
	RELENG_5_2_BP:1.1.1.3
	RELENG_4_9_0_RELEASE:1.1.1.1.2.2
	RELENG_4_9:1.1.1.1.2.2.0.2
	RELENG_4_9_BP:1.1.1.1.2.2
	v4_6:1.1.1.3
	RELENG_5_1_0_RELEASE:1.1.1.3
	RELENG_5_1:1.1.1.3.0.2
	RELENG_5_1_BP:1.1.1.3
	v4_5:1.1.1.3
	RELENG_4_8_0_RELEASE:1.1.1.1.2.1
	RELENG_4_8:1.1.1.1.2.1.0.6
	RELENG_4_8_BP:1.1.1.1.2.1
	RELENG_5_0_0_RELEASE:1.1.1.2
	RELENG_5_0:1.1.1.2.0.2
	RELENG_5_0_BP:1.1.1.2
	RELENG_4_7_0_RELEASE:1.1.1.1.2.1
	RELENG_4_7:1.1.1.1.2.1.0.4
	RELENG_4_7_BP:1.1.1.1.2.1
	RELENG_4_6_2_RELEASE:1.1.1.1.2.1
	v4_2:1.1.1.2
	RELENG_4_6_1_RELEASE:1.1.1.1.2.1
	RELENG_4_6_0_RELEASE:1.1.1.1.2.1
	RELENG_4_6:1.1.1.1.2.1.0.2
	RELENG_4_6_BP:1.1.1.1.2.1
	v4_1:1.1.1.2
	RELENG_4_5_0_RELEASE:1.1.1.1
	RELENG_4_5:1.1.1.1.0.10
	RELENG_4_5_BP:1.1.1.1
	RELENG_4_4_0_RELEASE:1.1.1.1
	RELENG_4_4:1.1.1.1.0.8
	RELENG_4_4_BP:1.1.1.1
	RELENG_4_3_0_RELEASE:1.1.1.1
	RELENG_4_3:1.1.1.1.0.6
	RELENG_4_3_BP:1.1.1.1
	RELENG_4_2_0_RELEASE:1.1.1.1
	RELENG_4_1_1_RELEASE:1.1.1.1
	PRE_SMPNG:1.1.1.1
	RELENG_4_1_0_RELEASE:1.1.1.1
	RELENG_3_5_0_RELEASE:1.1.1.1.4.1
	RELENG_3:1.1.1.1.0.4
	RELENG_4_0_0_RELEASE:1.1.1.1
	RELENG_4:1.1.1.1.0.2
	RELENG_4_BP:1.1.1.1
	v4_0:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2000.01.17.10.39.58;	author ru;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.01.17.10.39.58;	author ru;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	1.1.1.2;

1.1.1.2
date	2002.03.25.13.08.32;	author ru;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2003.05.02.00.48.41;	author ru;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2005.05.23.10.47.03;	author ru;	state dead;
branches;
next	;

1.1.1.1.2.1
date	2002.03.30.17.09.15;	author ru;	state Exp;
branches;
next	1.1.1.1.2.2;

1.1.1.1.2.2
date	2003.06.26.09.05.48;	author ru;	state Exp;
branches;
next	;

1.1.1.1.4.1
date	2000.05.06.18.53.18;	author ru;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#!/usr/local/bin/perl -w

# Generate a short man page from --help and --version output.
# Copyright  1997, 98, 99 Free Software Foundation, Inc.

# 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>

use 5.004;
use strict;
use Getopt::Long;
use Text::Tabs qw(expand);
use POSIX qw(strftime setlocale LC_TIME);

my $this_program = 'help2man';
my $this_version = '1.013';
my $version_info = <<EOT;
$this_program $this_version

Copyright (C) 1997, 98, 99 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Brendan O'Dea <bod\@@compusol.com.au>
EOT

my $help_info = <<EOT;
`$this_program' generates a man page out of `--help' and `--version' output.

Usage: $this_program [OPTION]... EXECUTABLE

 -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
     --version           print $this_program program version number, then exit

EXECUTABLE should accept `--help' and `--version' options.
EOT

my $section = 1;
my ($include, $opt_name, $opt_include, $opt_output, $opt_no_info);

# Parse options.
Getopt::Long::config('bundling');
GetOptions (
    'n|name=s'		=> \$opt_name,
    's|section=s'	=> \$section,
    'i|include=s'	=> \$include,
    'I|opt-include=s'	=> \$opt_include,
    'o|output=s'	=> \$opt_output,
    'N|no-info'		=> \$opt_no_info,
    help		=> sub { print $help_info; exit },
    version		=> sub { print $version_info; exit },
) or die $help_info;

die $help_info unless @@ARGV == 1;

my %include = ();
my @@include = (); # to retain order

# Process include file (if given).  Format is:
#
# [section name]
# verbatim text

if ($include or $opt_include)
{
    if (open INC, $include || $opt_include)
    {
	my $sect;

	while (<INC>)
	{
	    if (/^\[([^]]+)\]/)
	    {
		$sect = uc $1;
		$sect =~ s/^\s+//;
		$sect =~ s/\s+$//;
		next;
	    }

	    # Silently ignore anything before the first
	    # section--allows for comments and revision info.
	    next unless $sect;

	    push @@include, $sect unless $include{$sect};
	    $include{$sect} ||= '';
	    $include{$sect} .= $_;
	}

	close INC;

	die "$this_program: no valid information found in `$include'\n"
	    unless %include;

	# Compress trailing blank lines.
	for (keys %include)
	{
	    $include{$_} =~ s/\n+$//;
	    $include{$_} .= "\n" unless /^NAME$/;
	}
    }
    else
    {
	die "$this_program: can't open `$include' ($!)\n" if $include;
    }
}

# Turn off localisation of executable's ouput.
@@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;

# Turn off localisation of date (for strftime)
setlocale LC_TIME, 'C';

# Expand tabs, strip trailing spaces and break into paragraphs
sub paragraphs { split /\n\n+/, join '', expand @@_ }

# Grab help and version paragraphs from executable
my @@help = paragraphs `$ARGV[0] --help 2>/dev/null`
    or die "$this_program: can't get `--help' info from $ARGV[0]\n";

my @@version = paragraphs `$ARGV[0] --version 2>/dev/null`
    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>
#   {GNU,Free} <program> <version>
#   <program> ({GNU,Free} <package>) <version>
#   <program> - {GNU,Free} <package> <version>
#
# and seperated from any copyright/author details by a blank line.

$_ = shift @@version;

if (/^(\S+) +\(((?:GNU|Free) +[^)]+)\) +(.*)/ or
    /^(\S+) +- *((?:GNU|Free) +\S+) +(.*)/)
{
    $program = $1;
    $package = $2;
    $version = $3;
}
elsif (/^((?:GNU|Free) +)?(\S+) +(.*)/)
{
    $program = $2;
    $package = $1 ? "$1$2" : $2;
    $version = $3;
}
else
{
    $version = $_;
}

$program =~ s!.*/!!;

# no info for `info' itself
$opt_no_info = 1 if $program eq 'info';

# --name overrides --include contents
$include{NAME} = "$program \\- $opt_name" if $opt_name;

# Default (useless) NAME paragraph
$include{NAME} ||= "$program \\- manual page for $program $version";

# Man pages traditionally have the page title in caps.
my $PROGRAM = uc $program;

# Header.
print <<EOT;
.\\" DO NOT MODIFY THIS FILE!  It was generated by $this_program $this_version.
.TH $PROGRAM "$section" "$date" "$package $version" FSF
.SH NAME
$include{NAME}
EOT

my $break;
my $accumulate = 1;
my @@description = ();

sub convert_option;

# Output converted --help information.
for (@@help)
{
    chomp;

    if (s/^Usage: +\S+ +(.*)\n?//)
    {
	# Turn the usage clause into a synopsis.
	my $synopsis = '';

	do {
	    my $syn = $1;
	    $syn =~ s/(([][]|\.\.+)+)/\\fR$1\\fI/g;
	    $syn =~ s/^/\\fI/ unless $syn =~ s/^\\fR//;
	    $syn .= '\fR';
	    $syn =~ s/\\fI( *)\\fR/$1/g;

	    $synopsis .= ".br\n" unless $accumulate;
	    $synopsis .= ".B $program\n";
	    $synopsis .= "$syn\n";
	    $accumulate = 0;
	} while s/^(?:Usage| *or): +\S+ +(.*)\n?//;

	# Include file overrides SYNOPSIS.
	print ".SH SYNOPSIS\n", $include{SYNOPSIS} || $synopsis;

	# Dump any accumulated description text.
	print ".SH DESCRIPTION\n";
	print @@description;

	# Add additional description text from include file.
	if ($include{DESCRIPTION})
	{
	    print ".PP\n" unless $include{DESCRIPTION} =~ /^\..P/;
	    print $include{DESCRIPTION};
	}

	$break = 1;
	next unless $_;
    }

    # Accumulate text if the synopsis has not been produced yet.
    if ($accumulate)
    {
	push @@description, ".PP\n" if @@description;
	push @@description, "$_\n";
	next;
    }

    # Convert some standard paragraph names
    if (s/^(Options|Examples): *\n//)
    {
	print qq(.SH \U$1\n);
	$break = '';
	next unless length;
    }

    # Catch bug report text.
    if (/^Report bugs |^Email bug reports to /)
    {
	print qq(.SH "REPORTING BUGS"\n$_\n);
	$break = '';
	next;
    }

    # Option subsections have second line indented.
    if (s/^(\S.*)\n / /)
    {
	print qq(.SS "$1"\n);
	$break = '';
    }

    my $output = '';
    while (length)
    {
	my $indent = 0;

	# Tagged paragraph
	if (s/^( +(\S.*?)  +)(\S.*)\n?//)
	{
	    $indent = length $1;
	    $output .= ".TP\n$2\n$3\n";
	    $break = 1;
	}

	# Indented paragraph
	elsif (s/^( +)(\S.*)\n?//)
	{
	    $indent = length $1;
	    $output .= ".IP\n$2\n";
	    $break = 1;
	}

	# Left justified paragraph
	else
	{
	    s/(.*)\n?//;
	    $output .= ".PP\n" if $break;
	    $output .= "$1\n";
	    $break = 1;
	}

	# Continuations
	$output .= "$1\n" while s/^ {$indent}(\S.*)\n?//;
    }

    $_ = $output;

    # Escape backslashes.
    s/\\/\\e/g;

    # Convert options.
    s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge;
    print;
}

# Print any include items other than the ones we have already dealt
# with.
for (@@include)
{
    print qq(.SH "$_"\n$include{$_})
	unless /^(NAME|SYNOPSIS|DESCRIPTION|SEE ALSO)$/;
}

# Refer to the real documentation.
if ($include{'SEE ALSO'} or !$opt_no_info)
{
    print qq(.SH "SEE ALSO"\n);
    print $include{'SEE ALSO'}, ".PP\n" if $include{'SEE ALSO'};

    print <<EOT unless $opt_no_info;
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
}

# Output converted --version information.
for (@@version)
{
    chomp;

    # Join hyphenated lines.
    s/([A-Za-z])-\n */$1/g;

    # Convert copyright symbol or (c) to nroff character.
    s/Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/g;

    # Insert appropriate headings for copyright and author.
    if    (/^Copyright \\/) { print ".SH COPYRIGHT\n" }
    elsif (/^Written +by/)  { print ".SH AUTHOR\n" }
    else		    { print ".PP\n"; }

    # Insert line breaks before additional copyright messages and the
    # disclaimer.
    s/(.)\n(Copyright |This is free software)/$1\n.br\n$2/g;

    print "$_\n";
}

exit;

# Convert option dashes to \- to stop nroff from hyphenating 'em, and
# embolden.  Option arguments get italicised.
sub convert_option
{
    my $option = '\fB' . shift;

    $option =~ s/-/\\-/g;
    unless ($option =~ s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/)
    {
	$option =~ s/=(.)/\\fR=\\fI$1/;
	$option =~ s/ (.)/ \\fI$1/;
	$option .= '\fR';
    }

    $option;
}
@


1.1.1.1
log
@Virgin import of GNU texinfo 4.0
@
text
@@


1.1.1.1.2.1
log
@MFC: GNU texinfo 4.1 import.
@
text
@d4 1
a4 1
# Copyright  1997, 1998, 1999, 2000 Free Software Foundation, Inc.
a20 1
# Available from ftp://ftp.gnu.org/gnu/help2man/
d29 1
a29 1
my $this_version = '1.24';
d31 1
a31 1
GNU $this_program $this_version
d33 1
a33 1
Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
d52 1
a52 1
     --version           print version number, then exit
a54 2

Report bugs to <bug-help2man\@@gnu.org>.
d58 5
a62 2
my ($opt_name, @@opt_include, $opt_output, $opt_no_info);
my %opt_def = (
d65 2
a66 2
    'i|include=s'	=> sub { push @@opt_include, [ pop, 1 ] },
    'I|opt-include=s'	=> sub { push @@opt_include, [ pop, 0 ] },
d69 2
a70 7
);

# Parse options.
Getopt::Long::config('bundling');
GetOptions (%opt_def,
    help    => sub { print $help_info; exit },
    version => sub { print $version_info; exit },
d76 1
a76 5
my %append = ();
my @@include = (); # retain order given in include file

# Provide replacement `quote-regex' operator for pre-5.005.
BEGIN { eval q(sub qr { '' =~ $_[0]; $_[0] }) if $] < 5.005 }
d80 2
a81 8
#   [section name]
#   verbatim text
#
# or
#
#   /pattern/
#   verbatim text
#
d83 1
a83 1
while (@@opt_include)
d85 1
a85 10
    my ($inc, $required) = @@{shift @@opt_include};

    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>)
d87 1
a87 10
	# [section]
	if (/^\[([^]]+)\]/)
	{
	    $key = uc $1;
	    $key =~ s/^\s+//;
	    $key =~ s/\s+$//;
	    $hash = \%include;
	    push @@include, $key unless $include{$key};
	    next;
	}
d89 1
a89 2
	# /pattern/
	if (m!^/(.*)/([ims]*)!)
d91 1
a91 5
	    my $pat = $2 ? "(?$2)$1" : $1;

	    # Check pattern.
	    eval { $key = qr($pat) };
	    if ($@@)
d93 4
a96 2
		$@@ =~ s/ at .*? line \d.*//;
		die "$inc:$.:$@@";
d99 7
a105 2
	    $hash = \%append;
	    next;
d108 7
a114 4
	# Check for options before the first section--anything else is
	# silently ignored, allowing the first for comments and
	# revision info.
	unless ($key)
d116 2
a117 8
	    # handle options
	    if (/^-/)
	    {
		local @@ARGV = split;
		GetOptions %opt_def;
	    }

	    next;
a118 3

	$hash->{$key} ||= '';
	$hash->{$key} .= $_;
d120 4
a123 11

    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/ }
d129 1
a129 1
# Turn off localisation of date (for strftime).
d132 9
a140 5
# Grab help and version info from executable.
my ($help_text, $version_text) = map {
    join '', map { s/ +$//; expand $_ } `$ARGV[0] --$_ 2>/dev/null`
	or die "$this_program: can't get `--$_' info from $ARGV[0]\n"
} qw(help version);
d168 1
a168 1
($_, $version_text) = split /\n+/, $version_text, 2;
d190 1
a190 1
# No info for `info' itself.
d193 2
a194 2
# --name overrides --include contents.
$include{NAME} = "$program \\- $opt_name\n" if $opt_name;
d196 2
a197 2
# Default (useless) NAME paragraph.
$include{NAME} ||= "$program \\- manual page for $program $version\n";
d202 7
a208 4
# Extract usage clause(s) [if any] for SYNOPSIS.
if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m)
{
    my @@syn = $2 . $3;
d210 3
a212 46
    if ($_ = $4)
    {
	s/^\n//;
	for (split /\n/) { s/^ *(or: +)?//; push @@syn, $_ }
    }

    my $synopsis = '';
    for (@@syn)
    {
	$synopsis .= ".br\n" if $synopsis;
	s!^\S*/!!;
	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;

# Temporarily exchange leading dots, apostrophes and backslashes for
# tokens.
s/^\./\x80/mg;
s/^'/\x81/mg;
s/\\/\x82/g;

# Start a new paragraph (if required) for these.
s/([^\n])\n(Report +bugs|Email +bug +reports +to|Written +by)/$1\n\n$2/g;
d216 2
a217 1
while (length)
d219 1
a219 6
    # Convert some standard paragraph names.
    if (s/^(Options|Examples): *\n//)
    {
	$sect = uc $1;
	next;
    }
d221 1
a221 2
    # Copyright section
    if (/^Copyright +[(\xa9]/)
d223 22
a244 6
	$sect = 'COPYRIGHT';
	$include{$sect} ||= '';
	$include{$sect} .= ".PP\n" if $include{$sect};

	my $copy;
	($copy, $_) = split /\n\n/, $_, 2;
d246 2
a247 1
	for ($copy)
d249 2
a250 13
	    # Add back newline
	    s/\n*$/\n/;

	    # Convert iso9959-1 copyright symbol or (c) to nroff
	    # character.
	    s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;

	    # Insert line breaks before additional copyright messages
	    # and the disclaimer.
	    s/(.)\n(Copyright |This +is +free +software)/$1\n.br\n$2/g;

	    # Join hyphenated lines.
	    s/([A-Za-z])-\n */$1/g;
d253 2
a254 3
	$include{$sect} .= $copy;
	$_ ||= '';
	next;
d257 2
a258 2
    # Catch bug report text.
    if (/^(Report +bugs|Email +bug +reports +to) /)
d260 3
a262 1
	$sect = 'REPORTING BUGS';
d265 2
a266 2
    # Author section.
    elsif (/^Written +by/)
d268 3
a270 1
	$sect = 'AUTHOR';
d273 2
a274 3
    # Examples, indicated by an indented leading $, % or > are
    # rendered in a constant width font.
    if (/^( +)([\$\%>] )\S/)
d276 2
a277 10
	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';
	}

d281 2
a282 5
    my $matched = '';
    $include{$sect} ||= '';

    # Sub-sections have a trailing colon and the second line indented.
    if (s/^(\S.*:) *\n / /)
d284 2
a285 2
	$matched .= $& if %append;
	$include{$sect} .= qq(.SS "$1"\n);
d288 4
a291 2
    my $indent = 0;
    my $content = '';
d293 2
a294 7
    # Option with description.
    if (s/^( {1,10}([+-]\S.*?))(?:(  +)|\n( {20,}))(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length ($4 || "$1$3");
	$content = ".TP\n\x83$2\n\x83$5\n";
	unless ($4)
d296 3
a298 2
	    # Indent may be different on second line.
	    $indent = length $& if /^ {20,}/;
a299 1
    }
d301 7
a307 7
    # Option without description.
    elsif (s/^ {1,10}([+-]\S.*)\n//)
    {
	$matched .= $& if %append;
	$content = ".HP\n\x83$1\n";
	$indent = 80; # not continued
    }
d309 8
a316 24
    # Indented paragraph with tag.
    elsif (s/^( +(\S.*?)  +)(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length $1;
	$content = ".TP\n\x83$2\n\x83$3\n";
    }

    # Indented paragraph.
    elsif (s/^( +)(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length $1;
	$content = ".IP\n\x83$2\n";
    }

    # Left justified paragraph.
    else
    {
	s/(.*)\n//;
	$matched .= $& if %append;
	$content = ".PP\n" if $include{$sect};
	$content .= "$1\n";
    }
d318 2
a319 5
    # Append continuations.
    while (s/^ {$indent}(\S.*)\n//)
    {
	$matched .= $& if %append;
	$content .= "\x83$1\n"
d322 1
a322 2
    # Move to next paragraph.
    s/^\n+//;
d324 2
a325 6
    for ($content)
    {
	# Leading dot and apostrophe protection.
	s/\x83\./\x80/g;
	s/\x83'/\x81/g;
	s/\x83//g;
d327 4
a330 3
	# Convert options.
	s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge;
    }
d332 6
a337 14
    # 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};
	    }
	}
    }

    $include{$sect} .= $content;
d341 1
a341 1
unless ($opt_no_info)
d343 4
a346 4
    $sect = 'SEE ALSO';
    $include{$sect} ||= '';
    $include{$sect} .= ".PP\n" if $include{$sect};
    $include{$sect} .= <<EOT;
d361 15
a375 5
# 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
d377 3
a379 4
# Section ordering.
my @@pre = qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES);
my @@post = ('AUTHOR', 'REPORTING BUGS', 'COPYRIGHT', 'SEE ALSO');
my $filter = join '|', @@pre, @@post;
d381 1
a381 17
# Output content.
for (@@pre, (grep ! /^($filter)$/o, @@include), @@post)
{
    if ($include{$_})
    {
	my $quote = /\W/ ? '"' : '';
	print ".SH $quote$_$quote\n";
	
	for ($include{$_})
	{
	    # Replace leading dot, apostrophe and backslash tokens.
	    s/\x80/\\&./g;
	    s/\x81/\\&'/g;
	    s/\x82/\\e/g;
	    print;
	}
    }
d390 1
a390 1
    local $_ = '\fB' . shift;
d392 2
a393 2
    s/-/\\-/g;
    unless (s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/)
d395 3
a397 3
	s/=(.)/\\fR=\\fI$1/;
	s/ (.)/ \\fI$1/;
	$_ .= '\fR';
d400 1
a400 1
    $_;
@


1.1.1.1.2.2
log
@MFC: GNU texinfo 4.6.
@
text
@d4 1
a4 2
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software
# Foundation, Inc.
d20 1
a20 1
# Written by Brendan O'Dea <bod@@debian.org>
d23 1
a23 1
use 5.005;
d30 1
a30 1
my $this_version = '1.29';
d34 1
a34 1
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
d38 1
a38 1
Written by Brendan O'Dea <bod\@@debian.org>
d46 2
a47 4
 -n, --name=STRING       description for the NAME paragraph
 -s, --section=SECTION   section number for manual page (1, 6, 8)
 -m, --manual=TEXT       name of manual (User Commands, ...)
 -S, --source=TEXT       source of program (FSF, Debian, ...)
a50 1
 -p, --info-page=TEXT    name of Texinfo manual
d55 1
a55 5
EXECUTABLE should accept `--help' and `--version' options although
alternatives may be specified using:

 -h, --help-option=STRING     help option string
 -v, --version-option=STRING  version option string
d61 1
a61 6
my $manual = '';
my $source = '';
my $help_option = '--help';
my $version_option = '--version';
my ($opt_name, @@opt_include, $opt_output, $opt_info, $opt_no_info);

d63 6
a68 11
    'n|name=s'		 => \$opt_name,
    's|section=s'	 => \$section,
    'm|manual=s'	 => \$manual,
    'S|source=s'	 => \$source,
    'i|include=s'	 => sub { push @@opt_include, [ pop, 1 ] },
    'I|opt-include=s'	 => sub { push @@opt_include, [ pop, 0 ] },
    'o|output=s'	 => \$opt_output,
    'p|info-page=s'	 => \$opt_info,
    'N|no-info'		 => \$opt_no_info,
    'h|help-option=s'	 => \$help_option,
    'v|version-option=s' => \$version_option,
d84 3
d178 3
a180 3
    join '', map { s/ +$//; expand $_ } `$ARGV[0] $_ 2>/dev/null`
	or die "$this_program: can't get `$_' info from $ARGV[0]\n"
} $help_option, $version_option;
a241 12
# Set default page head/footers
$source ||= "$program $version";
unless ($manual)
{
    for ($section)
    {
	if (/^(1[Mm]|8)/) { $manual = 'System Administration Utilities' }
	elsif (/^6/)	  { $manual = 'Games' }
	else		  { $manual = 'User Commands' }
    }
}

d380 1
a380 1
    if (s/^( {1,10}([+-]\S.*?))(?:(  +(?!-))|\n( {20,}))(\S.*)\n//)
a464 2
    my $info_page = $opt_info || $program;

d477 1
a477 1
.B info $info_page
d486 1
a486 1
.TH $PROGRAM "$section" "$date" "$source" "$manual"
@


1.1.1.2
log
@Import of stripped down GNU texinfo 4.1
@
text
@d4 1
a4 1
# Copyright  1997, 1998, 1999, 2000 Free Software Foundation, Inc.
a20 1
# Available from ftp://ftp.gnu.org/gnu/help2man/
d29 1
a29 1
my $this_version = '1.24';
d31 1
a31 1
GNU $this_program $this_version
d33 1
a33 1
Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
d52 1
a52 1
     --version           print version number, then exit
a54 2

Report bugs to <bug-help2man\@@gnu.org>.
d58 5
a62 2
my ($opt_name, @@opt_include, $opt_output, $opt_no_info);
my %opt_def = (
d65 2
a66 2
    'i|include=s'	=> sub { push @@opt_include, [ pop, 1 ] },
    'I|opt-include=s'	=> sub { push @@opt_include, [ pop, 0 ] },
d69 2
a70 7
);

# Parse options.
Getopt::Long::config('bundling');
GetOptions (%opt_def,
    help    => sub { print $help_info; exit },
    version => sub { print $version_info; exit },
d76 1
a76 5
my %append = ();
my @@include = (); # retain order given in include file

# Provide replacement `quote-regex' operator for pre-5.005.
BEGIN { eval q(sub qr { '' =~ $_[0]; $_[0] }) if $] < 5.005 }
d80 2
a81 8
#   [section name]
#   verbatim text
#
# or
#
#   /pattern/
#   verbatim text
#
d83 1
a83 1
while (@@opt_include)
d85 1
a85 10
    my ($inc, $required) = @@{shift @@opt_include};

    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>)
d87 1
a87 10
	# [section]
	if (/^\[([^]]+)\]/)
	{
	    $key = uc $1;
	    $key =~ s/^\s+//;
	    $key =~ s/\s+$//;
	    $hash = \%include;
	    push @@include, $key unless $include{$key};
	    next;
	}
d89 1
a89 2
	# /pattern/
	if (m!^/(.*)/([ims]*)!)
d91 1
a91 5
	    my $pat = $2 ? "(?$2)$1" : $1;

	    # Check pattern.
	    eval { $key = qr($pat) };
	    if ($@@)
d93 4
a96 2
		$@@ =~ s/ at .*? line \d.*//;
		die "$inc:$.:$@@";
d99 7
a105 2
	    $hash = \%append;
	    next;
d108 7
a114 4
	# Check for options before the first section--anything else is
	# silently ignored, allowing the first for comments and
	# revision info.
	unless ($key)
d116 2
a117 8
	    # handle options
	    if (/^-/)
	    {
		local @@ARGV = split;
		GetOptions %opt_def;
	    }

	    next;
a118 3

	$hash->{$key} ||= '';
	$hash->{$key} .= $_;
d120 4
a123 11

    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/ }
d129 1
a129 1
# Turn off localisation of date (for strftime).
d132 9
a140 5
# Grab help and version info from executable.
my ($help_text, $version_text) = map {
    join '', map { s/ +$//; expand $_ } `$ARGV[0] --$_ 2>/dev/null`
	or die "$this_program: can't get `--$_' info from $ARGV[0]\n"
} qw(help version);
d168 1
a168 1
($_, $version_text) = split /\n+/, $version_text, 2;
d190 1
a190 1
# No info for `info' itself.
d193 2
a194 2
# --name overrides --include contents.
$include{NAME} = "$program \\- $opt_name\n" if $opt_name;
d196 2
a197 2
# Default (useless) NAME paragraph.
$include{NAME} ||= "$program \\- manual page for $program $version\n";
d202 7
a208 4
# Extract usage clause(s) [if any] for SYNOPSIS.
if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m)
{
    my @@syn = $2 . $3;
d210 3
a212 46
    if ($_ = $4)
    {
	s/^\n//;
	for (split /\n/) { s/^ *(or: +)?//; push @@syn, $_ }
    }

    my $synopsis = '';
    for (@@syn)
    {
	$synopsis .= ".br\n" if $synopsis;
	s!^\S*/!!;
	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;

# Temporarily exchange leading dots, apostrophes and backslashes for
# tokens.
s/^\./\x80/mg;
s/^'/\x81/mg;
s/\\/\x82/g;

# Start a new paragraph (if required) for these.
s/([^\n])\n(Report +bugs|Email +bug +reports +to|Written +by)/$1\n\n$2/g;
d216 2
a217 1
while (length)
d219 1
a219 6
    # Convert some standard paragraph names.
    if (s/^(Options|Examples): *\n//)
    {
	$sect = uc $1;
	next;
    }
d221 1
a221 2
    # Copyright section
    if (/^Copyright +[(\xa9]/)
d223 22
a244 6
	$sect = 'COPYRIGHT';
	$include{$sect} ||= '';
	$include{$sect} .= ".PP\n" if $include{$sect};

	my $copy;
	($copy, $_) = split /\n\n/, $_, 2;
d246 2
a247 1
	for ($copy)
d249 2
a250 13
	    # Add back newline
	    s/\n*$/\n/;

	    # Convert iso9959-1 copyright symbol or (c) to nroff
	    # character.
	    s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;

	    # Insert line breaks before additional copyright messages
	    # and the disclaimer.
	    s/(.)\n(Copyright |This +is +free +software)/$1\n.br\n$2/g;

	    # Join hyphenated lines.
	    s/([A-Za-z])-\n */$1/g;
d253 2
a254 3
	$include{$sect} .= $copy;
	$_ ||= '';
	next;
d257 2
a258 2
    # Catch bug report text.
    if (/^(Report +bugs|Email +bug +reports +to) /)
d260 3
a262 1
	$sect = 'REPORTING BUGS';
d265 2
a266 2
    # Author section.
    elsif (/^Written +by/)
d268 3
a270 1
	$sect = 'AUTHOR';
d273 2
a274 3
    # Examples, indicated by an indented leading $, % or > are
    # rendered in a constant width font.
    if (/^( +)([\$\%>] )\S/)
d276 2
a277 10
	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';
	}

d281 2
a282 5
    my $matched = '';
    $include{$sect} ||= '';

    # Sub-sections have a trailing colon and the second line indented.
    if (s/^(\S.*:) *\n / /)
d284 2
a285 2
	$matched .= $& if %append;
	$include{$sect} .= qq(.SS "$1"\n);
d288 4
a291 2
    my $indent = 0;
    my $content = '';
d293 2
a294 7
    # Option with description.
    if (s/^( {1,10}([+-]\S.*?))(?:(  +)|\n( {20,}))(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length ($4 || "$1$3");
	$content = ".TP\n\x83$2\n\x83$5\n";
	unless ($4)
d296 3
a298 2
	    # Indent may be different on second line.
	    $indent = length $& if /^ {20,}/;
a299 1
    }
d301 7
a307 7
    # Option without description.
    elsif (s/^ {1,10}([+-]\S.*)\n//)
    {
	$matched .= $& if %append;
	$content = ".HP\n\x83$1\n";
	$indent = 80; # not continued
    }
d309 8
a316 24
    # Indented paragraph with tag.
    elsif (s/^( +(\S.*?)  +)(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length $1;
	$content = ".TP\n\x83$2\n\x83$3\n";
    }

    # Indented paragraph.
    elsif (s/^( +)(\S.*)\n//)
    {
	$matched .= $& if %append;
	$indent = length $1;
	$content = ".IP\n\x83$2\n";
    }

    # Left justified paragraph.
    else
    {
	s/(.*)\n//;
	$matched .= $& if %append;
	$content = ".PP\n" if $include{$sect};
	$content .= "$1\n";
    }
d318 2
a319 5
    # Append continuations.
    while (s/^ {$indent}(\S.*)\n//)
    {
	$matched .= $& if %append;
	$content .= "\x83$1\n"
d322 1
a322 2
    # Move to next paragraph.
    s/^\n+//;
d324 2
a325 6
    for ($content)
    {
	# Leading dot and apostrophe protection.
	s/\x83\./\x80/g;
	s/\x83'/\x81/g;
	s/\x83//g;
d327 4
a330 3
	# Convert options.
	s/(^| )(-[][\w=-]+)/$1 . convert_option $2/mge;
    }
d332 6
a337 14
    # 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};
	    }
	}
    }

    $include{$sect} .= $content;
d341 1
a341 1
unless ($opt_no_info)
d343 4
a346 4
    $sect = 'SEE ALSO';
    $include{$sect} ||= '';
    $include{$sect} .= ".PP\n" if $include{$sect};
    $include{$sect} .= <<EOT;
d361 15
a375 5
# 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
d377 3
a379 4
# Section ordering.
my @@pre = qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES);
my @@post = ('AUTHOR', 'REPORTING BUGS', 'COPYRIGHT', 'SEE ALSO');
my $filter = join '|', @@pre, @@post;
d381 1
a381 17
# Output content.
for (@@pre, (grep ! /^($filter)$/o, @@include), @@post)
{
    if ($include{$_})
    {
	my $quote = /\W/ ? '"' : '';
	print ".SH $quote$_$quote\n";
	
	for ($include{$_})
	{
	    # Replace leading dot, apostrophe and backslash tokens.
	    s/\x80/\\&./g;
	    s/\x81/\\&'/g;
	    s/\x82/\\e/g;
	    print;
	}
    }
d390 1
a390 1
    local $_ = '\fB' . shift;
d392 2
a393 2
    s/-/\\-/g;
    unless (s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/)
d395 3
a397 3
	s/=(.)/\\fR=\\fI$1/;
	s/ (.)/ \\fI$1/;
	$_ .= '\fR';
d400 1
a400 1
    $_;
@


1.1.1.3
log
@Import of stripped down GNU texinfo 4.5
@
text
@d4 1
a4 2
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software
# Foundation, Inc.
d20 1
a20 1
# Written by Brendan O'Dea <bod@@debian.org>
d23 1
a23 1
use 5.005;
d30 1
a30 1
my $this_version = '1.29';
d34 1
a34 1
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
d38 1
a38 1
Written by Brendan O'Dea <bod\@@debian.org>
d46 2
a47 4
 -n, --name=STRING       description for the NAME paragraph
 -s, --section=SECTION   section number for manual page (1, 6, 8)
 -m, --manual=TEXT       name of manual (User Commands, ...)
 -S, --source=TEXT       source of program (FSF, Debian, ...)
a50 1
 -p, --info-page=TEXT    name of Texinfo manual
d55 1
a55 5
EXECUTABLE should accept `--help' and `--version' options although
alternatives may be specified using:

 -h, --help-option=STRING     help option string
 -v, --version-option=STRING  version option string
d61 1
a61 6
my $manual = '';
my $source = '';
my $help_option = '--help';
my $version_option = '--version';
my ($opt_name, @@opt_include, $opt_output, $opt_info, $opt_no_info);

d63 6
a68 11
    'n|name=s'		 => \$opt_name,
    's|section=s'	 => \$section,
    'm|manual=s'	 => \$manual,
    'S|source=s'	 => \$source,
    'i|include=s'	 => sub { push @@opt_include, [ pop, 1 ] },
    'I|opt-include=s'	 => sub { push @@opt_include, [ pop, 0 ] },
    'o|output=s'	 => \$opt_output,
    'p|info-page=s'	 => \$opt_info,
    'N|no-info'		 => \$opt_no_info,
    'h|help-option=s'	 => \$help_option,
    'v|version-option=s' => \$version_option,
d84 3
d178 3
a180 3
    join '', map { s/ +$//; expand $_ } `$ARGV[0] $_ 2>/dev/null`
	or die "$this_program: can't get `$_' info from $ARGV[0]\n"
} $help_option, $version_option;
a241 12
# Set default page head/footers
$source ||= "$program $version";
unless ($manual)
{
    for ($section)
    {
	if (/^(1[Mm]|8)/) { $manual = 'System Administration Utilities' }
	elsif (/^6/)	  { $manual = 'Games' }
	else		  { $manual = 'User Commands' }
    }
}

d380 1
a380 1
    if (s/^( {1,10}([+-]\S.*?))(?:(  +(?!-))|\n( {20,}))(\S.*)\n//)
a464 2
    my $info_page = $opt_info || $program;

d477 1
a477 1
.B info $info_page
d486 1
a486 1
.TH $PROGRAM "$section" "$date" "$source" "$manual"
@


1.1.1.4
log
@Removed files not present in v4.8 import.
@
text
@@


1.1.1.1.4.1
log
@MFC: Upgrade to GNU texinfo 4.0.
@
text
@@

