dave@timeinc.UUCP (David Mutterer) (01/04/85)
Well.... here it is in all it's fame and glory... clk .. I wrote this a couple of years ago when I had to access the computer thru a data switch.. I was also busy running around... and when I came back I usually found that the switch had timed out and logged me off.. well, here is something that will keep you terminal active, and keep other people from using your id while your not there... It also provides the functionality of checking for mail.. so you can tell at a glance.. Let me know what you think of it... This program was origanally written and upgraded on AT&T Unix.. Sys 3 -> S5V2..... I make no claims that it will run on berkley without some changes.. if it does.. well, all the better.. -----Cut Here-----Cut Here-----Cut Here-----Cut Here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # clk.1 # clk.c echo shar: extracting clk.1 sed 's/^X//' << 'SHAR_EOF' > clk.1 X.deTH X.PD X.nrIN \\n()Mu X.ift .ds ]H \\$1\^(\^\\$2\^) X.ifn .ds ]H \\$1(\\$2) X.if\\n()s .ds ]D X.if\\n()t .ds ]D UNIX System V X.ifn .ds ]D UNIX System V X.ds]L X.if!\\$3 .ds ]L (\^\\$3\^) X.if!\\$4 .ds ]D \\$4 X.wh0 }H X.wh-\\n(:mu }F X.em}M X.if\\n(nl .bp X.nr)I \\n()Mu X.nr)R 0 X.}E X.DT X.ifn \{.na X.nh\} X.ift \{.bd S 3 3 X.hy14 \} X.. X.TH CLK 1 X.SH NAME Xclk \- display the time and check for mail (continuously). X.SH SYNOPSIS X.B clk X[ X.B \-p X] X.SH DESCRIPTION X.I Clk\^ Xdisplays the current time of day randomly Xon the screen every five seconds, while monitoring Xfor new mail every thirty seconds. It uses terminfo(4) Xto add a degree of terminal independence. You exit Xby sending a DEL, QUIT, or TERMINATE signal. When Xterminating, it looks for a file in the $HOME directory Xcall ".pswd". If this file exsists and contains an Xencrypted password (set by the -p option) it will prompt Xyou for it before terminating. If the passwords do not Xmatch then clk resumes displaying the time. X.PP XThe X.B \-p Xwill prompt you to enter in a password. X.SH FILES X$HOME/.pswd X.br X$MAIL X.\" @(#)clk.1 6.2 of 9/19/84 SHAR_EOF echo shar: extracting clk.c sed 's/^X//' << 'SHAR_EOF' > clk.c X/* X X clk.c - compile with "cc -O -s -o clk -DMINICURSES clk.c -lcurses" X X Written by David Mutterer... X 1.1 - Sometime in '82 for termcap. X 1.2 - Sometime in '84 for curses. X 1.3 - Changed to use MINICURSES. X 1.4 - added built-in password control. X X*/ X X#include <curses.h> X#include <time.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <sys/signal.h> X Xchar *sccs = "@(#)clk.c 1.4"; Xchar *mptr, *getenv(); Xchar mfile[20]="/usr/mail/", pswdf[60], pbuff[20], buf[10]; XFILE *fp; Xlong ttime, mtime=0; Xint nol, noc, row, col, cnt, bye(), (*oldsig)(), (*signal())(); Xbool mflg = FALSE; Xstruct tm *tp, *localtime(); Xstruct stat mstat; Xchar *strcat(), *cuserid(); X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X if(!(mptr = getenv("MAIL"))) mptr = strcat(mfile, cuserid((char *)0)); X if(stat(mptr, &mstat) != -1) mtime = mstat.st_mtime; X if(!getenv("HOME")) strcat(pswdf, "."); X else strcat(pswdf, getenv("HOME")); X strcat(pswdf, "/.pswd"); X if (argc > 2) usage(argv[0]); X if (argc == 2) { X if ((argv[1][0] == '-') && (argv[1][1] == 'p')) { X strcpy(pbuff, crypt(getpass("Password: "), cuserid((char *)0))); X if (strcmp(pbuff, crypt(getpass("Again: "), cuserid((char *)0)))) { X printf("%s: passwords do not match.!\n", argv[0]); X exit(1); X } X if (!(fp = fopen(pswdf, "w"))) { X printf("%s: could not open %s for writing.!\n", argv[0], pswdf); X exit(1); X } X fprintf(fp, "%s", pbuff); X fclose(fp); X exit(0); X } else usage(argv[0]); X } X initscr(); X nol = LINES-1; X noc = COLS-8; X srand((int)time((long *)0)); X clear(); X signal(SIGINT, bye); X signal(SIGQUIT, bye); X for(;;) { X for(cnt=0; cnt<6; cnt++) { X ttime = time((long *)0); X tp = localtime(&ttime); X row = rand() % nol; X col = rand() % noc; X move(row, col); X sprintf(buf, "%02d:%02d:%02d", tp->tm_hour, tp->tm_min, tp->tm_sec); X addstr(buf); X refresh(); X sleep(5); X move(row, col); X addstr(" "); X refresh(); X } X display(mailck()); X } X} X Xdisplay(sw) Xint sw; X{ X switch(sw) { X case 0: X break; X case 1: X move(nol, 0); X addstr("You have mail."); X break; X case 2: X move(nol, 0); X addstr(" "); X break; X } X} X Xmailck() X{ X if(stat(mptr, &mstat) != -1) X if(mtime < mstat.st_mtime) { X mtime = mstat.st_mtime; X mflg = TRUE; X return(1); X } X else return(0); X else if(!mflg) return(0); X else { X mflg = FALSE; X return(2); X } X} X Xbye() X{ X oldsig = signal(SIGALRM, SIG_IGN); X signal(SIGINT, SIG_IGN); X signal(SIGQUIT, SIG_IGN); X if((fp = fopen(pswdf, "r")) != NULL) { X fgets(pbuff, 20, fp); X fclose(fp); X if(strlen(pbuff) == 13) { X clear(); move(0,0); refresh(); X if(strcmp(pbuff, crypt(getpass("Password:"), cuserid((char *)0))) != 0) { X clear(); refresh(); X if(mflg) display(1); X signal(SIGINT, bye); X signal(SIGQUIT, bye); X signal(SIGALRM, oldsig); X return; X } X } X } X clear(); refresh(); X endwin(); X exit(0); X} X Xusage(prog) Xchar *prog; X{ X printf("Usage: %s [-p]\n", prog); X exit(1); X} SHAR_EOF exit -- David Mutterer [vax135|ihnp4]!timeinc!dave "Any opinions expressed herein are those of the writer and do not necessarily reflect the opinion of Time Incorporated."