package xm::o;
use strict;
BEGIN {
use Exporter;
use vars qw(@EXPORT_OK @EXPORT %EXPORT_TAGS %o);
use subs qw(argv_stdin argv_filehash xx);
@EXPORT = qw( %o %xm );
@EXPORT_OK = qw( argv_stdin argv_filehash);
%EXPORT_TAGS = ( FIELDS => [ @EXPORT, @EXPORT_OK ] );
}
use vars @EXPORT;
goto &Exporter::import }
return defined $_[0] ? $_[0] : ""
}
my $argv = shift;
my $desc = shift;
if ($#$argv < 0)
{
$main::package = $0 if not defined $main::package;
print STDERR "$$: $main::package @$argv\n";
if (defined $desc)
{
print STDERR "DESCRIPTION\n";
print STDERR $desc;
}
exit;
}
$o{" "} = "";
$o{"="} = [ ];
for (@$argv)
{
if (/^--help$/ or /^-\?/)
{ print $desc if defined $desc; print " <$$>\n"; exit; }
elsif (/^--?([\w-]+)=(.*)/) { $o{$1} = $2; }
elsif (/^--?([\w-]+)/) { $o{$1} = ""; }
elsif (/^-$/) {
push @{$o{"="}}, $_;
$o{" "} .= join ("",<STDIN>);
}
else {
push @{$o{"="}}, $_;
my $F = $_;
if (open F, "<$F") { $o{" "} .= join("",<F>); close F; }
else { die "could not open $F", $1; }
}
}
return $o{" "};
}
return args_stdin \@ARGV, @_;
}
my $desc = shift;
my $f = { }; if ($#ARGV < 0)
{
$main::package = $0 if not defined $main::package;
print STDERR "$$: $main::package @ARGV\n";
if (defined $desc)
{
print STDERR "DESCRIPTION\n";
print STDERR $desc;
}
exit;
}
$o{" "} = "";
$o{"="} = [ ];
for (@ARGV)
{
if (/^--help$/)
{ print $desc if defined $desc; print " <$$>\n"; exit; }
elsif (/^--?([\w-]+)=(.*)/) { $o{$1} = $2; }
elsif (/^--?([\w-]+)/) { $o{$1} = ""; }
elsif (/^-$/) {
push @{$o{"="}}, $_;
$$f{"-"} .= join ("",<STDIN>);
}
else {
push @{$o{"="}}, $_;
my $F = $_;
if (open F, "<$F") { $$f{$F} .= join("",<F>); close F; }
else { die "could not open $F", $1; }
}
}
return $f;
}
my $argv = shift;
my $desc = shift;
if ($#$argv < 0)
{
$main::package = $0 if not defined $main::package;
print STDERR "$$: $main::package @$argv\n";
if (defined $desc)
{
print STDERR "DESCRIPTION\n";
print STDERR $desc;
}
exit;
}
$o{"="} = [ ];
for (@$argv)
{
if (/^--help$/)
{ print $desc if defined $desc; print " <$$>\n"; exit; }
elsif (/^--?([\w-]+)=(.*)/) { $o{$1} = $2; }
elsif (/^--?([\w-]+)/) { $o{$1} = ""; }
elsif (/^-@?$/) { my $f;
while ($f = <STDIN>)
{
if ($f !~ /^\s*/ and $f !~ /^\#\s/)
{
push @{$o{"="}}, $f;
}
}
}
elsif (/^-@=(.*)$/) { my $F = $1;
my $f;
open F, "<$F" or next;
while ($f = <F>)
{
if ($f !~ /^\s*/ and $f !~ /^\#\s/)
{
push @{$o{"="}}, $f;
}
}
close F;
}
else {
push @{$o{"="}}, $_;
}
}
return $o{"="};
}
return args_files \@ARGV, @_;
}
my $argv = shift;
my $desc = shift;
if ($#$argv < 0)
{
$main::package = $0 if not defined $main::package;
print STDERR "$$: $main::package @$argv\n";
if (defined $desc)
{
print STDERR "DESCRIPTION\n";
print STDERR $desc;
}
exit;
}
$o{"="} = [ ];
for (@$argv)
{
if (/^--help$/)
{ print $desc if defined $desc; print " <$$>\n"; exit; }
elsif (/^--?([\w-]+)=(.*)/) { $o{$1} = $2; }
elsif (/^--?([\w-]+)/) { $o{$1} = ""; print STDERR "<?",$1,">"; }
elsif (/^-@=(.*)$/) { my $F = $1;
my $f;
open F,"<$F" or next;
while ($f = <F>)
{
if ($f !~ /^\s*/ and $f !~ /^\#\s/)
{
push @{$o{"="}}, $f;
}
}
close F;
}
else {
push @{$o{"="}}, $_;
}
}
return $o{"="};
}
return args_command \@ARGV, @_;
}
1;