#!/usr/pkg/bin/perl
#
#  @(#)rotary.faces 1.4 91/11/19
#
#  Copyright (c) Steve Kinzler - April 1991.
#
#  Permission is given to distribute these sources, as long as the
#  copyright messages are not removed, and no monies are exchanged.
#
#  No responsibility is taken for any errors on inaccuracies inherent
#  either to the comments or the code of this program, but if reported
#  to me, then an attempt will be made to fix them.

# Uncomment this line if you are running a version of faces earlier
# than version 1.5.0:
# $oldformat = 1;

$cols = 7;
$rface = 'rotary';

# rotary.faces - faces script to monitor the dialin rotary users
# Steve Kinzler, kinzler@cs.indiana.edu, 7 Feb 1991

$format = $oldformat ? "%-20s%-20s%-10s%-10s%-10s%-10s\n" :
		       "%s\t%s\t%s\t%s\t%s\t%s\n";

$num = 0;

open(ROTARY, "rotary |");

while (<ROTARY>) {
	$n++;
	s/(\S*):tty(..)/\2:\1/;
	split;
	$user = 'NOTHING';
	($user = $_[2], $num++) if $_[2] ne '-';
	$output .= sprintf($format, $user, '', $_[2], '', $_[1], '');
}

close(ROTARY);

printf "%sCols=%d Rows=%d\n",
    $oldformat ? '' : sprintf($format, $rface, '', 'ROTARY', $num, '', ''),
    ($n > $cols) ? $cols : $n, ($n - 1) / $cols + 1;
print $output;
