Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site unc.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!mcnc!unc!sherouse
From: sherouse@unc.UUCP (George W. Sherouse)
Newsgroups: net.sources
Subject: user count for mon - couldn't leave well enough alone
Message-ID: <220@unc.UUCP>
Date: Mon, 17-Dec-84 16:38:57 EST
Article-I.D.: unc.220
Posted: Mon Dec 17 16:38:57 1984
Date-Received: Thu, 20-Dec-84 01:17:28 EST
Organization: CS Dept., U. of N. Carolina at Chapel Hill
Lines: 146

If mon is the greatest thing since sliced bread, and I for
one think it is, then just think how good it will be after you
apply this hack to get it to *also* tell you how many users
are logged in.  There were these 10 empty characters up near
the top of the screen, you see, and nature abhors a vacuum...

George W. Sherouse
Associate Physicist
Division of Radiation Therapy
North Carolina Memorial Hospital
Chapel Hill, NC   27514

(919) 966-1101


===========================================

# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# diff1 diff2 user_count.c

echo x - diff1
cat > "diff1" << '//E*O*F diff1//'
*** old/Makefile	Mon Dec 17 10:07:28 1984
--- Makefile	Mon Dec 17 10:15:25 1984
***************
*** 3,9
  #
  #  Beware dependencies on mon.h are not properly stated.
  #
! OBJS = mon.o io.o vm.o netif.o display.o readnames.o
  
  all: mon
  

--- 3,9 -----
  #
  #  Beware dependencies on mon.h are not properly stated.
  #
! OBJS = mon.o io.o vm.o netif.o display.o readnames.o user_count.o
  
  all: mon
  
***************
*** 14,17
  	rm -f core *.o mon a.out
  
  print:
! 	qpr mon.h mon.c io.c vm.c netif.c readnames.c display.c

--- 14,17 -----
  	rm -f core *.o mon a.out
  
  print:
! 	qpr mon.h mon.c io.c vm.c netif.c readnames.c display.c user_count.c
//E*O*F diff1//

echo x - diff2
cat > "diff2" << '//E*O*F diff2//'
*** old/mon.c	Mon Dec 17 10:07:30 1984
--- mon.c	Mon Dec 17 10:20:54 1984
***************
*** 94,99
          long clock;
  	struct timeval tintv;
  	int i, tin;
  
  	/* set up signals */
  	signal(SIGINT, done);

--- 94,100 -----
          long clock;
  	struct timeval tintv;
  	int i, tin;
+ 	int users, user_count();
  
  	/* set up signals */
  	signal(SIGINT, done);
***************
*** 116,121
          	mvprintw(0,13,"%4.2f %4.2f %4.2f %4.2f", loadavg[3], loadavg[0], loadavg[1], loadavg[2]);
                  time(&clock);
                  mvprintw(0,40,ctime(&clock));
          	dispupdate();
          	mvprintw(LINES-1, 0, "CMD> ");
                  refresh();

--- 117,129 -----
          	mvprintw(0,13,"%4.2f %4.2f %4.2f %4.2f", loadavg[3], loadavg[0], loadavg[1], loadavg[2]);
                  time(&clock);
                  mvprintw(0,40,ctime(&clock));
+ 
+ 		users = user_count();
+ 		if (users == 1)
+ 		    mvprintw(0, 70, "1 user");
+ 		else
+ 		    mvprintw(0, 70, "%d users", users);
+ 
          	dispupdate();
          	mvprintw(LINES-1, 0, "CMD> ");
                  refresh();
//E*O*F diff2//

echo x - user_count.c
cat > "user_count.c" << '//E*O*F user_count.c//'
#include 
#include 

int user_count()
{
	static int first = 1;
	static FILE *strm;
	struct utmp utmp;
	int count = 0;

	if (first)
	{
	    strm = fopen("/etc/utmp", "r");
	    first = 0;
	}

	rewind(strm);
	while(fread(&utmp, sizeof(utmp), 1, strm))
	{
	    if (utmp.ut_name[0] != '\0')
		count++;
	}

	return(count);
}
//E*O*F user_count.c//

echo Possible errors detected by \'wc\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp <<\!!!
      32     104     664 diff1
      42     116    1115 diff2
      25      47     337 user_count.c
      99     267    2116 total
!!!
wc  diff1 diff2 user_count.c | sed 's=[^ ]*/==' | diff -b $temp -
exit 0