mon.c
the news user
news at cybvax0.UUCP
Sat Dec 29 12:06:47 AEST 1984
#!/bin/sh
#
# Mon is a very nice program to use, and I recently installed the fixes
# in <220 at unc.UUCP> by George W. Sherouse. To make it a bit more efficient
# we had it fstat /etc/utmp, and only reread the file when it changed. Files
# diff1 and user_count.c are a diff for mon.c and a replacement for user_count.c
# respectivly.
#
# Also I installed the changes in <1552 at ittvax.UUCP> by H. Morrow Long. To
# give the user some feedback, it shows the dump taking place, in addition
# to not saving blank spaces at the end of the file. The third file is
# a replacement for dumpit.c
#
# Please use sh to unpack.
#
# -----Cut Here-----Cut Here-----Cut Here-----Cut Here-----
#
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# diff1
# user_count.c
# dumpit.c
echo shar: extracting diff1
sed 's/^X//' << 'SHAR_EOF' > diff1
X*** mon.c.old Fri Dec 28 20:51:42 1984
X--- mon.c Fri Dec 28 20:48:30 1984
X***************
X*** 152,161
X mvprintw(0,40,ctime(&clock));
X
X users = user_count();
X! if (users == 1)
X! mvprintw(0, 70, "1 user");
X! else
X! mvprintw(0, 70, "%d users", users);
X
X dispupdate();
X mvprintw(LINES-1, 0, CMD);
X
X--- 175,189 -----
X mvprintw(0,40,ctime(&clock));
X
X users = user_count();
X! move (0, 70);
X! if (users != -1)
X! {
X! if (users == 1)
X! addstr("1 user");
X! else
X! printw("%d users", users);
X! }
X! clrtoeol();
X
X dispupdate();
X mvprintw(LINES-1, 0, CMD);
SHAR_EOF
echo 'Orignal Sum -> 50730 1'
echo -n 'Current Sum -> '
sum diff1
echo shar: extracting user_count.c
sed 's/^X//' << 'SHAR_EOF' > user_count.c
X#ifndef lint
Xstatic char *CybSccsId = "%W% (Cyb) %G%";
X#endif lint
X
X/*
X * int user_count()
X * Return a count of the number of users on. Returns -1 on
X * error
X *
X * int first;
X * -1 on error; 1 on first time; 0 otherwise
X *
X * time_t mtime;
X * last time file was modified
X *
X * FILE *strm;
X * stream for /etc/utmp (And file descriptor for fstat)
X *
X * int count;
X * last calculated count of number of users on. Only
X * recalculated when /etc/utmp is modified
X */
X
X#include <stdio.h>
X#include <utmp.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
Xint user_count ()
X{
X static int first = 1;
X static time_t mtime;
X static FILE *strm;
X static int count;
X struct utmp utmp;
X struct stat statbuf;
X
X/*
X * If we already had an error once, don't even bother
X */
X if (first == -1)
X return 1;
X
X/*
X * The first time through the loop, open the file. If there is an
X * error; give up
X */
X if (first)
X {
X strm = fopen ("/etc/utmp", "r");
X if (strm == NULL)
X {
X first = -1;
X return - 1;
X }
X }
X
X/*
X * Find last modifed time of file
X */
X if (fstat (strm -> _file, &statbuf))
X {
X first = -1;
X return - 1;
X }
X
X/*
X * If this is the first time, or the file has been modified, calculate
X * the number of users on (also clear the first time flag)
X */
X if (first || mtime != statbuf.st_mtime)
X {
X first = 0;
X mtime = statbuf.st_mtime;
X
X rewind (strm);
X count = 0;
X while (fread (&utmp, sizeof (utmp), 1, strm))
X {
X if (utmp.ut_name[0] != '\0')
X count++;
X }
X }
X
X return (count);
X}
SHAR_EOF
echo 'Orignal Sum -> 32420 2'
echo -n 'Current Sum -> '
sum user_count.c
echo shar: extracting dumpit.c
sed 's/^X//' << 'SHAR_EOF' > dumpit.c
X#ifndef lint
Xstatic char *CybSccsId = "%W% (Cyb) %G%";
X#endif lint
X
X/*
X * dumpit (Outfile)
X * FILE *Outfile;
X *
X * dump curscr (except for last line) to Outfile.
X */
X
X#include <stdio.h>
X#include <curses.h>
X
Xint dumpit (Outfile)
XFILE * Outfile;
X{
X int i, x, y, z;
X char buffer[BUFSIZ];
X
X/*
X * For all lines but the last one ...
X */
X for (i = 0; i < LINES - 1; i++)
X {
X mvprintw (LINES - 1, 0, "Dumping Screen Line %d", i + 1);
X clrtoeol ();
X refresh ();
X
X/*
X * Search backwards on each line for a non-space. Z is the count of
X * significant characters.
X */
X for (z = COLS - 1; z > 0; z--)
X {
X if (curscr -> _y[i][z] != ' ')
X {
X/*
X * Non-space found, increment Z and exit loop
X */
X z++;
X break;
X }
X }
X/*
X * Copy Z characters and append a \n and \0 to the string, then output it
X */
X strncpy (buffer, curscr -> _y[i], z);
X buffer[z] = '\n';
X buffer[z + 1] = '\0';
X fputs (buffer, Outfile);
X }
X
X/*
X * Clear the status line, the prompt will appear the next time around
X */
X move (LINES - 1, 0);
X clrtoeol ();
X}
SHAR_EOF
echo 'Orignal Sum -> 17549 2'
echo -n 'Current Sum -> '
sum dumpit.c
exit
More information about the Comp.sources.bugs
mailing list