# -- perl --

#configuration constants
#extended_opt are the options that change the output format of ps
#unless extended info of a pid is to be shown they are removed
$extended_opt = "lujsvm";
#permanantly removed options:
$removed_opt ="wnh";

$i=0;
@opt;
@users;
$flag = 0;

while($ARGV[$i])
{
   #check if it is a number
   if ($ARGV[$i] =~ /^[0-9]/)
   {
      $flag=1;
	push(@users,$ARGV[$i]);
   }
   else
   {
    	&CheckOptions(@ARGV[$i]);
    	push(@opt,$ARGV[$i]);
    }

   $i=$i+1;
}
#run command
if ($flag == 1)
{
   print `ps @opt @users | <BINDIR>/ps_filter.pl $flag`;
}
else
{
   #remove options that are for extended info only
   @opt = &RemoveOptions(@opt);
   print `ps @opt | <BINDIR>/ps_filter.pl`;

}
#*************************************************
#****************** PROCEDURES *******************
#*************************************************
sub CheckOptions {
    my($Option)=@_;
    foreach $char (split(//,$Option))
    {
         if ($char=~ /[$removed_opt]/)
         { 
   	   	&Help;
	   	   exit;            
         }
    }
}

sub RemoveOptions {
    my(@Options)=@_;
    
    foreach my $option (@Options)
    {
	$option =~ s/[$extended_opt]//g;        
    }
    return @Options;
}
sub Help {
	print "options [$removed_opt] are unavailable in glinaccess version of ps\n";
}

sub ExtendedHelp {
    print("route - Show i.p. routing table\n"); 
    print("Options\n");
    print("id   : Give me info on i.p.\n"); 
    print("       with that id\n");
    print("-n   : print i.p. in numeric format\n");
}

