[Lunar-commits] CVS: moonbase/archive/tar mktarman.pl,NONE,1.1

Jerry Lundström prox at lunar-linux.org
Wed May 12 12:22:03 GMT 2004


Update of /var/cvs/lunar/moonbase/archive/tar
In directory dbguin.lunar-linux.org:/tmp/cvs-serv7919

Added Files:
	mktarman.pl 
Log Message:
mktarman.pl is a perl script for generating a man page from the info page in. It will grab options and operations from the file and make a nice uptodate man page. 'cat doc/tar.info | mktarman.pl > tar.1'. NOTE: no automaking of the manual file is made when lining, this should only be done when bumping.

--- NEW FILE: mktarman.pl ---
#!/usr/bin/perl

use strict;
use POSIX;

my $OPER_TAG = 'Operations';
my $OPT_TAG = '`tar\' Options';
my $END_TAG = 'Short Options Cross Reference';

# --

my $inside = 0;
my %opt = ();
my %oper = ();
my $cnt = 0;
my $inside2 = 0;

while(<>)
{
    chomp();

    if(!$inside && /^$OPER_TAG$/o)
    {
        <>;
        chomp();
        $inside = 1 if(length($OPER_TAG) == length($_));
        next;
    }
    elsif($inside && /^$OPT_TAG$/o)
    {
        <>;
        chomp();
        $inside = 2 if(length($OPT_TAG) == length($_));
        next;
    }
    elsif($inside && /^$END_TAG$/o)
    {
        <>;
        chomp();
        $inside = 0 if(length($END_TAG) == length($_));
        next;
    }

    next if(/^File: /o || /^/o);
    next if(!$inside);

    my $href;
    if($inside == 1)
    {
        $href = \%oper;
    }   
    else
    {
        $href = \%opt;
    }

    if(/^\`([^\']+)\'/o) #look for `--options'
    {
        my $opt = $1;

        $cnt++ if($inside2 == 2);
        $inside2 = 1;

        if($opt =~ /^--/o && !exists($href->{$cnt}{sort}))
        {
            $href->{$cnt}{sort} = $opt;
        }

        push(@{$href->{$cnt}{options}}, $opt);
    }
    elsif($inside2 > 0)
    {
        $inside2 = 2;

        s/^[ \t]+//; #trim beingin, we will align later
#        s/\*note [^\.]+\.//i;
        push(@{$href->{$cnt}{desc}}, $_);
    }
}

foreach my $key (keys %oper)
{
    @{$oper{$key}{options}} = sort {
        if($a =~ /^--/o && $b !~ /^--/o)
        {
            1;
        }
        elsif($a !~ /^--/o && $b =~ /^--/o)
        {
            -1;
        }
        else
        {
            $a cmp $b;
        }
    } (@{$oper{$key}{options}}) if(exists($oper{$key}{options}));

    my @old = @{$oper{$key}{desc}};
    @{$oper{$key}{desc}} = ();

    my $text = 0;
    while(defined($_ = pop(@old)))
    {
        next if(!$text && (/^[ \t]+$/o || /^$/o));
        $text = 1;
        unshift(@{$oper{$key}{desc}}, $_);
    }
}

foreach my $key (keys %opt)
{
    @{$opt{$key}{options}} = sort {
        if($a =~ /^--/o && $b !~ /^--/o)
        {
            1;
        }
        elsif($a !~ /^--/o && $b =~ /^--/o)
        {
            -1;
        }
        else
        {
            $a cmp $b;
        }
    } (@{$opt{$key}{options}}) if(exists($opt{$key}{options}));

    my @old = @{$opt{$key}{desc}};
    @{$opt{$key}{desc}} = ();

    my $text = 0;
    while(defined($_ = pop(@old)))
    {
        next if(!$text && (/^[ \t]+$/o || /^$/o));
        $text = 1;
        unshift(@{$opt{$key}{desc}}, $_);
    }
}


print(".\\\" @(#)tar.1 1.14 ".strftime("%Y/%m/%d",gmtime())." lunar-linux.org;
.TH TAR 1 \"".strftime("%d %B %Y",gmtime())."\"
.SH NAME
tar \- The GNU version of the tar archiving utility
.SH SYNOPSIS
.B tar
[
.B OPTION
]...
[
.B FILE
]...
.SH NOTE
This is a autogenerated man page from the info page. To read more
about tar please do `info tar' or `tar --help'.
.SH OPERATIONS
");

foreach my $key (sort {
    if(exists($oper{$a}{sort}) && exists($oper{$b}{sort}))
    {
        $oper{$a}{sort} cmp $oper{$b}{sort};
    }
    else
    {
        0;
    }
} (keys %oper))
{
    next if(!exists($oper{$key}{options}) || !exists($oper{$key}{desc}));

    print(".TP\n.B ",join(', ',@{$oper{$key}{options}}),"\n");
    print(join("\n",@{$oper{$key}{desc}}),"\n");
}

print(".SH OPTIONS\n");

foreach my $key (sort {
    if(exists($opt{$a}{sort}) && exists($opt{$b}{sort}))
    {
        $opt{$a}{sort} cmp $opt{$b}{sort};
    }
    else
    {
        0;
    }
} (keys %opt))
{
    next if(!exists($opt{$key}{options}) || !exists($opt{$key}{desc}));

    print(".TP\n.B ",join(', ',@{$opt{$key}{options}}),"\n");
    print(join("\n",@{$opt{$key}{desc}}),"\n");
}



More information about the Lunar-commits mailing list