# -- perl --

&PrintOnScreen($ARGV[0]);

#*************************************************
#****************** PROCEDURES *******************
#*************************************************
sub PrintOnScreen {

   my($who)=@_;
   
   if ($who)
   {

      #get info
      $line=<STDIN>;
      chomp($line);
	   while($line ne "")
	   {
		   push(@linesplit,split(' ',$line));
         #get next line
  	      $line=<STDIN>;
         chomp($line);         
	   }
      #print $linesplit[1],"\n";
      &PrintIfInfo(@linesplit);
   }
   #else #print out iface list
   #{
   #   $line=<STDIN>;
   #   while($line ne "")
   #	   {
   #      chomp($line);
   #      if ($line !~ /^\s/)
   #      {
   #        @linesplit = split(' ',$line);
   #	     push(@ifc,$linesplit[0]);
   #      }
   #      #get next line
   #      $line=<STDIN>;
   #   }
   #   &PrintIfInfo(@ifc);   
   #}
   else #print summary
   {
      #get info
      $line=<STDIN>;
      
      while($line ne "")
      {
         chomp($line);
         if ($line ne "")
         {
            push(@linesplit,split(' ',$line));
         }
         else
         {
            &PrintSummary(@linesplit);
            print "\n";
            @linesplit =();
         }
         #get next line
         $line=<STDIN>;

      }
   }
}

sub PrintSummary {
   my(@info) = @_;
   my ($addr,$bcast,$mask);
   foreach my $field (@info)
   {
      if ( $field =~ s/addr:// )
      {
         $addr = $field;
      }
      if ( $field =~ s/Bcast:// )
      {
         $bcast = $field;
      }
      if ( $field =~ s/Mask:// )
      {
         $mask = $field;
      }

   }
   printf ("%-10s",$info[0]);
   if ($addr)
   {
      print $addr;
   }
   else
   {
      print "N/A";
   }
   print "\n";
   print "          ";

   if ($bcast)
   {
      print $bcast;
   }
   else
   {
      print "N/A";
   }
   print "\n";
   print "          ";
   if ($mask)
   {
      print $mask;
   }
   else
   {
      print "N/A";
   }
#   print "\n";
}

sub PrintIfInfo {
   my(@fields) = @_;
   
   $size = 30;#width of terminal
   $pos = 0; #current pos on line
   
   foreach my $field (@fields)
   {
      $pos = $pos + length($field);
      #print "\n$pos\n";
      if ($pos > $size)
      {
         print "\n";
         $pos = length($field);
      }
      
      print "$field";
      #put a space before putting next field 
      #but if at the end of the screen don't put a space
      if ($pos == $size)
      {
         print "\n";
         $pos = 0;
      }
      else
      {
         print ' ';
         $pos++;
      }

   }
   print "\n";
}

