#!/usr/bin/perl


sub Option {
    local($Option) = @_;
    &ArgvMatch($Option,@ARGV);
}

sub ArgvMatch {
    local($Option,@argv) = @_;
    local($r)=0;
    local($i);
    local($b) = "-" . $Option;
    for ($i=0; $i <= $#argv ; $i++) {
        if ($argv[$i] eq $b) {
            $r = 1 ;
        }
    }                            
    $ENV{"PERL_DEBUG"} && printf(STDERR "[T/F Option    ] -%s = %d\n",$Option,$r);
    return $r;
}                               


sub  StringAfterOption {
    local($Option, $TheDefault) = @_;
    local($r) = &ReturnArgvMatch($Option, @ARGV);
    if ($r ne "ReturnArgvMatch-finds-nothing") {
	printf(STDERR "[New String    ] -%s = %s\n",$Option,$r);
	return $r;
    } else {
	printf(STDERR "[Default String] -%s = %s\n",$Option,$TheDefault);
	return $TheDefault;
    }
}

sub ReturnArgvMatch {
    local($Option,@argv) = @_ ;
    local($r) = 0;
    local($i);
    local($b) = "-" . $Option ;
    for ($i=0; $i <= ($#argv - 1) ; $i++) {
	if ($argv[$i] eq $b) {
	    $r = $i + 1;
	}
    }
    return ($r ? $argv[$r] : "ReturnArgvMatch-finds-nothing" );
}

sub rootname {
    local(@a) = split (/\//,$0);
    local($_) = $a[$#a];
    s/\.pl// ;
    return ($_);
}


sub hello {
    local($host) = `hostname` ;
    chop $host ;
    local($date) = `date` ;
    chop $date ;
    local(@a) = split (/\//,$0);
    local($r) = $a[$#a];
    &msg1("Hello:  Script $r being interpreted by $") ;
    &msg1("Hello:  at $date with pid $$ on $host.");
}



sub bp {
    package simple_io ;
    local($s) = @_ ;
    if (!($bp_name_global)) {
	local(@a) = split (/\//,$0);
	$bp_name_global = $a[$#a];
    }
    if ($ENV{"PERL_DEBUG"}) {
	if ($s ne "") {
	    print STDERR "[ $bp_name_global ] $s\n" ;
	} else {
	    print STDERR "[ $bp_name_global ] $_" ;
	}
    }
}

sub msg {
    package simple_io ;
    local($s) = @_ ;
    if (!($bp_name_global)) {
	local(@a) = split (/\//,$0);
	$bp_name_global = $a[$#a];
    }
    if ($s ne "") {
	print STDERR "[ $bp_name_global ] $s\n" ;
    } else {
	print STDERR "[ $bp_name_global ] $_" ;
    }

}

sub msg1 {
    if ($ENV{"PERL_DEBUG"} >= 1) { &msg(@_); } 
}
sub msg2 {
    if ($ENV{"PERL_DEBUG"} >= 2) { &msg(@_); } 
}
sub msg3 {
    if ($ENV{"PERL_DEBUG"} >= 3) { &msg(@_); } 
}

sub msg4 {
    if ($ENV{"PERL_DEBUG"} >= 4) { &msg(@_); } 
}

sub msg5 {
    if ($ENV{"PERL_DEBUG"} >= 5) { &msg(@_); } 
}

sub msg6 {
    if ($ENV{"PERL_DEBUG"} >= 6) { &msg(@_); } 
}

sub vp {
    local($s) = @_ ;
    if (!($bp_name_global)) {
	local(@a) = split (/\//,$0);
	$bp_name_global = $a[$#a];
    }
    local($v) = eval ("\$" . $s) ;
    
    if ($ENV{"PERL_DEBUG"} >= 1) {
	print STDERR "[ $bp_name_global ] $s = $v\n" ;
    }
}


sub EnvSetOrDefault {
    local($envname,$default) = @_;
    local($print) = 0;
    if ($ENV{"$envname"} ne "") {
	if ($ENV{"PERL_DEBUG"} > 1) {
	    print STDERR 
		"ENV{$envname} SET-TO $ENV{$envname}\n";
	} elsif ($print) {
	    print STDERR "$envname SET-TO $ENV{$envname}\n" ; 
	}
    } else {
	$ENV{$envname} = $default ;
	if ($ENV{"PERL_DEBUG"} > 1) {
	    print STDERR 
		"ENV{$envname} DEFAULTS-TO $ENV{$envname}\n";
	}
    }
    local($tmp) = "\$$envname = \$ENV{'$envname'};" ;
    eval $tmp;
}				


1 ;





