#!/usr/local/bin/perl -P
#
# Copyright (C) 1992 by Gustaf Neumann, Stefan Nusser
#
#      Wirtschaftsuniversitaet Wien,
#      Abteilung fuer Wirtschaftsinformatik
#      Augasse 2-6,
#      A-1090 Vienna, Austria
#      neumann@wu-wien.ac.at, nusser@wu-wien.ac.at
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appears in all copies and that both that
# copyright notice and this permission notice appear in all supporting
# documentation.  This software is provided "as is" without expressed or
# implied warranty.
#
# Date: Mon, Apr 13 1992
# Author: Gustaf Neumann
# Version: 0.91
#
{
$options = 'u:';
$WafeLib = $ENV{'WAFELIB'} || "/usr/lib/X11/wafe";
require "$WafeLib/perl/wafe.pl";

$opt_u = $opt_u ||  3; # each five seconds per default

@charts = ( "input-packets", "input-errors", "output-packets", 
	   "output-errors", "collisions");
%scale  = ( "input-packets", 100, "input-errors", 1, "output-packets", 100, 
	   "output-errors", 1, "collisions", 2);

#if defined(_IBMR2) || defined(hpux)
%pos = ( "input-packets",   6, "input-errors", 7, "output-packets", 8, 
	   "output-errors", 9, "collisions", 10);
#else
%pos = ( "input-packets",   1, "input-errors", 2, "output-packets", 3, 
	   "output-errors", 4, "collisions", 5);
#endif

$ruleColor="highlight $1" if $sbColors =~ /background\s+(\S+)/; 
chop($hostname=`hostname`); $hostname =~ s/\..*$//;

&Xui(<<"__");
  sV topLevel iconName {$appName@$hostname} title {$appName@$hostname}
  mergeResources topLevel *borderWidth 0
  form top topLevel \\
      defaultDistance 2 $backGround translations "<Key>q: exec(quit)"
__
for (@charts) {
    &Xui(<<"__");
    label name_$_ top {
	label {$_: $scale{$_}} right chainLeft $backGround $vert 
    }
    stripChart $_ top {
	jumpScroll 1 update $opt_u width 160 height 50
	fromVert name_$_ $roColors $ruleColor
    }
__
    $stats{$_} = 0;
    $scale{$_} *= $opt_u; 
    $vert = "fromVert $_";
}
&Xui("realize;deleteWindowProtocol quit");

open(STAT,"netstat -i $opt_u|");
while(<STAT>) {
    if (/^ +[a-zA-Z]+/) { 
	$ignore= <STAT>; $ignore= <STAT>; <STAT>;
    } 
    split(/\s+/," $_");

    foreach $c (keys %scale) {	
	&Xui("scSet $c " . ($_[$pos{$c}]/$scale{$c}));
    }
}
}
