davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (12/09/90)
Someone sent mail and asked for a copy of the better screen blanker for Xenix. Unfortunately their return address was toasted by some mailer along the way. Here it is, far better than the one I posted last month. #!/bin/sh # shar: Shell Archiver (v1.27) # # Run the following text with /bin/sh to create: # readme # makefile # scrnblank2.c # scrnblank2.L # sb2.man # echo "x - extracting readme (Text)" sed 's/^X//' << 'SHAR_EOF' > readme && X SCRNBLANK2 X X Screen Blanker for SCO Xenix, UNIX, and OpenDeskTop X X Bill Davidsen - Nov 1990 X X X scrnblank2 is a program which will run on a system and blank the Xscreen after inactivity on the virtual screens associated with the Xconsole. It does this by changing to a designates "blank" virtual Xterminal, clearing it to blank, and setting the height of the cursor to Xzero, so that the display is completely blank. X X In addition, after blanking the screen, it checks for new activity on Xany screen, and switches to display of the screen with most recent Xinformation. This works particularly well for a program which may only Xproduce new information every hour or so. X XHOW IT WORKS X X The devices tty01 through tty12 are checked for time last modified, Xand compared to the current time. If the 'age' of the most recently Xmodified screen is greater than the blanking interval requested, a Xswitch is made to the blank screen. When the screen has been blanked the Xprogram begins to monitor all screens and when any screen changes Xviewing is changed to that terminal. If no additional changes take place Xthe screen will again be blanked. X XPORTABILITY X X While the method used to change screens is dependent in SCO extensions Xto the ANSI sequences, any implementation capable of clearing the screen Xand cursor and switching screens could be made to work, usually by Xadding ioctl calls in place of the output statements. X XAUTHOR AND COPYRIGHT X X Written by Bill Davidsen, Nov 1990. Copyright 1990 by Bill Davidsen, Xall rights reserved. This program and documentation may be used and Xdistributed without fee, providing the copyright is intact. SHAR_EOF chmod 0644 readme || echo "restore of readme fails" echo "x - extracting makefile (Text)" sed 's/^X//' << 'SHAR_EOF' > makefile && X# makefile for screen blanker #2 X X# ================> config start X# the vterm to use as a blank screen XBLANKTTY = 7 X# timeout, minutes XTIMEOUT = 10 X# retest time for activeity when blank, sec XRETEST = 90 X# where you want your binaries XBINDIR = /u/local/bin X# where you want your documentation XDOCDIR = /usr/man X# manual section, should be C, L, or LOCAL XLOCAL = LOCAL X# if scrnblank2 is too long a name, change it here X# ** don't change this unless you have nroff to reformat the man page! ** XINSTALLNAME = sb2 X# your favorite shar if not installed as shar XSHAR = shar X# ================> config ends X XBACKLIST = readme makefile s.scrnblank2.c scrnblank2.L sb2.man XSHARLIST = readme makefile scrnblank2.c scrnblank2.L sb2.man XDEFAULTS = -DBLANK_TTY=$(BLANKTTY) -DTIMEOUT=$(TIMEOUT) \ X -DRETEST=$(RETEST) XDESTNAME = $(BINDIR)/$(INSTALLNAME) XDOCDIR2 = $(DOCDIR)/man.$(LOCAL) XDOCNAME2 = $(DOCDIR2)/$(INSTALLNAME).$(LOCAL) XCATDIR2 = $(DOCDIR)/cat.$(LOCAL) XCATNAME2 = $(CATDIR2)/sb2.$(LOCAL) X X.c~.c: X get $< X Xscrnblank2 : scrnblank2.o X $(CC) -o scrnblank2 $(LFLAGS) scrnblank2.o X Xscrnblank2.o : scrnblank2.c X $(CC) -c $(CFLAGS) $(DEFAULTS) scrnblank2.c X X Xdebug: X $(MAKE) CFLAGS="$(CFLAGS) -DDEBUG" X Xclean : scrnblank2 X @if [ -f p.scrnblank2.c ]; then \ X echo "edit in progress";\ X exit 1;\ X fi;\ X rm -f scrnblank2.[co] scrnblnk2.shar X Xbackup : clean zoo X Xzoo : $(BACKLIST) X zoo aunMPP scrnblank2 $(BACKLIST) X rm -f scrnblank2.bak X Xshar : $(SHARLIST) X $(SHAR) $(SHARLIST) > scrnblnk2.shar X X# this must be run as root or other admin login Xinstall : scrnblank2 X @if [ ! -d $(BINDIR) ];\ X then echo "$(BINDIR) - missing dir"; exit 1; fi X @if [ ! -d $(DOCDIR) ];\ X then echo "$(DOCDIR) - missing dir"; exit 1; fi X @if [ ! -d $(DOCDIR2) ];\ X then echo "$(DOCDIR2) - missing dir"; exit 1; fi X @if [ ! -d $(CATDIR2) ];\ X then echo "$(CATDIR2) - missing dir"; exit 1; fi X cp scrnblank2 $(DESTNAME) X strip $(DESTNAME) X chown bin $(DESTNAME) X chmod 755 $(DESTNAME) X @if [ ! -f /usr/bin/nroff ]; then \ X set -x;\ X cp sb2.man $(CATNAME2);\ X chuse bin $(CATNAME2);\ X chmod 644 $(CATNAME2);\ X set +x;\ X else \ X set -x;\ X sed 's/scrnblank2/$(INSTALLNAME)/g' scrnblank2.L | \ X sed 's/LOCAL/$(LOCAL)/g' > $(DOCNAME2);\ X chown bin $(DOCNAME2);\ X chmod 644 $(DOCNAME2);\ X set +x;\ X fi SHAR_EOF chmod 0644 makefile || echo "restore of makefile fails" echo "x - extracting scrnblank2.c (Text)" sed 's/^X//' << 'SHAR_EOF' > scrnblank2.c && X/* blank screen */ X X#include <stdio.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <sys/param.h> X X#include <string.h> X X#ifdef DEBUG X#define Debug(x) if (debug) printf x Xstatic int debug = 0; X#else /* not even the code exists */ X#define Debug(x) X#endif /* optional debug */ X Xstatic int check_ttys(); X X/* number and id of ttys to ignore - ongoing output */ Xstatic int num_ignore = 0; /* pseudo stack pointer */ Xstatic int ignorelist[12]; X Xextern int optind, opterr; Xextern char *optarg; X X#ifndef lint Xstatic char *SCCSid[] = { X "@(#)scrnblank2.c - v1.5, modified 11/14/90", X "Copyright (c) 1990 by Bill Davidsen, may be freely distributed and used" X}; X#endif /* lint */ X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X int blanktty = BLANK_TTY; /* tty to use for blank screen */ X int checktime = RETEST; /* time to check, def 90 sec */ X int timeout = TIMEOUT*60; /* default timeout, 10 min */ X int timeleft; /* time left before oldest tty times out */ X int optchar; /* next option */ X char *wkptr; /* pointer for ignore parse */ X X /* parse the args */ X while ((optchar = getopt(argc, argv, "i:b:t:r:d")) != EOF) { X Debug(("Next option: %c\n", optchar)); X switch (optchar) { X case 'b': /* tty to blank */ X blanktty = atoi(optarg); X Debug((" Set blank tty to %d\n", blanktty)); X break; X case 't': /* timeout in minutes */ X timeout = 60*atoi(optarg); X Debug((" Set blank time %d sec\n", timeout)); X break; X case 'r': /* retest time when blank */ X checktime = atoi(optarg); X break; X case 'i': /* ignore certain terminals */ X for (wkptr=optarg; wkptr; wkptr = strchr(wkptr, ',')) { X if (*wkptr == ',') ++wkptr; X ignorelist[num_ignore++] = atoi(wkptr); X Debug((" Ignore #%d %2d\n", X num_ignore, X ignorelist[num_ignore - 1] X )); X } X break; X#ifdef DEBUG X case 'd': /* debug on */ X debug = 1; X break; X#endif /* only when needed */ X case '?': /* bad option */ X help_and_exit(); X break; X } X } X X for (;;) { X timeleft = check_ttys(blanktty, timeout, checktime); X sleep(timeleft+1); X } X} X Xstatic int Xcheck_ttys(blkttynum, maxage, checktime) Xint blkttynum, maxage, checktime; X{ X static char blkttyname[50]; /* name of the blank tty */ X static FILE *blktty = NULL; /* open the blank screen tty */ X static int blanked = 0; /* flag when screen blanked */ X X int n; X char devname[50]; X time_t newest = 0, now = time((char *)NULL); X int new_tty = 0, age; X struct stat stbuf; X X if (blktty == NULL) { X /* open the file */ X sprintf(blkttyname, "/dev/tty%02d", blkttynum); X blktty = fopen(blkttyname, "a+"); X if (blktty == NULL) { X perror("Can't open blank tty"); X exit(1); X } X } X X do { X for (n=1; n <= 12; ++n) { X /* skip the blank tty, may have things going on */ X if (skipcheck(n, blkttynum)) continue; X X /* form the name and stat it */ X sprintf(devname, "/dev/tty%02d", n); X stat(devname, &stbuf); X X age = now - stbuf.st_mtime; X if (new_tty == 0 || age < newest) { X /* this tty is more recent, log it */ X new_tty = n; X newest = age; X } X } X X /* wait for activity */ X if (blanked) { X if (newest < maxage) { X /* return to this one */ X fprintf(blktty, "\033[%02dz", new_tty-1); X fflush(blktty); X blanked = 0; X } else { X sleep(checktime); X } X } X } while (blanked); X X if (!blanked && newest > maxage) { X /* switch to blank screen and wait input */ X fprintf(blktty, "\033[%02dz", blkttynum-1); X fprintf(blktty, "\033[=10;9C\f"); X fflush(blktty); X blanked = 1; X } X X /* return earliest timeout value */ X return (maxage - newest); X} X X/* X * returns true if this tty is being skipped X */ X Xint Xskipcheck(curtty, blktty) Xint curtty, blktty; X{ X int flag = 0, m; X X if (curtty == blktty) flag = 1; X else { X for (m=0; m < num_ignore; ++m) { X if (curtty == ignorelist[m]) { X flag = 1; X break; X } X } X } X X return flag; X} X X/* X * print usage and quit X */ X Xhelp_and_exit() { X static char *helplines[] = { X "Screenblanker v1.5, modified 11/14/90", X "", X "scrnblank2 [ options ]", X "", X " -bN blank vterm N (default 7)", X " -tN timeout N minutes (default 10)", X " -rN when blank, retest every N sec (default 90)", X " -iL ignore output to list L (comma separated list)", X " Used when a vterm is getting regular monitoring output", X " which is checked when interesting", X "", X (char *)0 X }; X int n; X X for (n=0; helplines[n]; ++n) { X printf("%s\n", helplines[n]); X } X exit(1); X} SHAR_EOF chmod 0444 scrnblank2.c || echo "restore of scrnblank2.c fails" echo "x - extracting scrnblank2.L (Text)" sed 's/^X//' << 'SHAR_EOF' > scrnblank2.L && X'\ run through tbl, too X.TH scrnblank2 LOCAL Local X.SH NAME Xscrnblank2 \- blank console screen when not in use X.SH SYNOPSIS Xscrnblank2 [ options ] X.SH DESCRIPTION X.ds sb \fBscrnblank2\fP X\*(sb is a program which blanks the console screen after inactivity. It Xuses the SCO specific extensions to ANSI escapes, but could be modified Xto use ioctl on other systems. One vterm will be selected and blanked, Xand therefore may not have a getty active on it. X.sp XAfter the screen is blanked, when activity resumes of \fIany\fP vterm X(see the -i option), the most recently active vterm will be selected and Xdisplayed. Then screen blanking will resume as before. X.SS Options X.TS Xtab(@); Xlbw(1i) l. X-t\fIN\fP@timeout after N minutes (default 10) X X-r\fIN\fP@T{ Xwhen blanked check for activity every N sec (default 90) XT} X X-b\fIN\fP@T{ Xblank to vterm N (default 7) XT} X X-i\fIlist\fP@T{ XIgnore activity on vterms in \fIlist\fP, comma separated. This is useful Xwhen one vterm is displaying periodic information, when you wish to Xcheck only when of interest. XT} X.TE X.SS Installation XSelect a vterm and insure that there is no getty on it. The default Xvterm is tty07, although that may be changed. Edit the makefile where Xindicated and make. After testing make install as root. X.SH EXAMPLES X.nf Xscrnblank2 -t15 # 15 minute timeout Xscrnblank2 -b12 # blank screen on tty12 Xscrnblank2 -i5 # ignore tty05 activity X.fi X.SH FILES X/dev/tty01-12 X.SH SEE ALSO Xdisable(C), console(M) X.SH DIAGNOSTICS XError message only. X.SH LIMITATIONS XDoesn't check ttys higher than 12 if you diddle your config. May not Xwork if run from rc.d files rather than from a login session. X.SH AUTHOR XBill Davidsen, davidsen@crdos1.crd.ge.com X.SH Copyright XCopyright (c) 1990 by Bill Davidsen, all rights reserved. This program Xand documentation may be used and distributed without payment, provided Xthat the copyright notices are left intact. SHAR_EOF chmod 0666 scrnblank2.L || echo "restore of scrnblank2.L fails" echo "x - extracting sb2.man (Text)" sed 's/^X//' << 'SHAR_EOF' > sb2.man && X X X X s\010s\010s\010sb\010b\010b\010b2\0102\0102\0102(\010(\010(\010(L\010L\010L\010LO\010O\010O\010OC\010C\010C\010CA\010A\010A\010AL\010L\010L\010L)\010)\010)\010) X\010X\010X\010XE\010E\010E\010EN\010N\010N\010NI\010I\010I\010IX\010X\010X\010X S\010S\010S\010Sy\010y\010y\010ys\010s\010s\010st\010t\010t\010te\010e\010e\010em\010m\010m\010m V\010V\010V\010V (\010(\010(\010(L\010L\010L\010Lo\010o\010o\010oc\010c\010c\010ca\010a\010a\010al\010l\010l\010l)\010)\010)\010) s\010s\010s\010sb\010b\010b\0 10b2\0102\0102\0102(\010(\010(\010(L\010L\010L\010LO\010O\010O\010OC\010C\010C\010CA\010A\010A\010AL\010L\010L\010L)\010)\010)\010) X X X X N\010N\010N\010NA\010A\010A\010AM\010M\010M\010ME\010E\010E\010E X sb2 - blank console screen when not in use X X S\010S\010S\010SY\010Y\010Y\010YN\010N\010N\010NO\010O\010O\010OP\010P\010P\010PS\010S\010S\010SI\010I\010I\010IS\010S\010S\010S X sb2 [ options ] X X D\010D\010D\010DE\010E\010E\010ES\010S\010S\010SC\010C\010C\010CR\010R\010R\010RI\010I\010I\010IP\010P\010P\010PT\010T\010T\010TI\010I\010I\010IO\010O\010O\010ON\010N\010N\010N X s\010s\010s\010sb\010b\010b\010b2\0102\0102\0102 is a program which blanks the console screen after X inactivity. It uses the SCO specific extensions to ANSI X escapes, but could be modified to use ioctl on other X systems. One vterm will be selected and blanked, and X therefore may not have a getty active on it. X X After the screen is blanked, when activity resumes of _\010a_\010n_\010y X vterm (see the -i option), the most recently active vterm X will be selected and displayed. Then screen blanking will X resume as before. X X O\010O\010O\010Op\010p\010p\010pt\010t\010t\010ti\010i\010i\010io\010o\010o\010on\010n\010n\010ns\010s\010s\010s X -\010-\010-\010-t\010t\010t\010t_\010N timeout after N minutes (default 10) X X -\010-\010-\010-r\010r\010r\010r_\010N when blanked check for activity X every N sec (default 90) X X -\010-\010-\010-b\010b\010b\010b_\010N blank to vterm N (default 7) X X -\010-\010-\010-i\010i\010i\010i_\010l_\010i_\010s_\010t Ignore activity on vterms in _\010l_\010i_\010s_\010t, X comma separated. This is useful when X one vterm is displaying periodic X information, when you wish to check X only when of interest. X X I\010I\010I\010In\010n\010n\010ns\010s\010s\010st\010t\010t\010ta\010a\010a\010al\010l\010l\010ll\010l\010l\010la\010a\010a\010at\010t\010t\010ti\010i\010i\010io\010o\010o\010on\010n\010n\010n X Select a vterm and insure that there is no getty on it. The X default vterm is tty07, although that may be changed. Edit X the makefile where indicated and make. After testing make X install as root. X X E\010E\010E\010EX\010X\010X\010XA\010A\010A\010AM\010M\010M\010MP\010P\010P\010PL\010L\010L\010LE\010E\010E\010ES\010S\010S\010S X sb2 -t15 # 15 minute timeout X sb2 -b12 # blank screen on tty12 X sb2 -i5 # ignore tty05 activity X X F\010F\010F\010FI\010I\010I\010IL\010L\010L\010LE\010E\010E\010ES\010S\010S\010S X /dev/tty01-12 X X S\010S\010S\010SE\010E\010E\010EE\010E\010E\010E A\010A\010A\010AL\010L\010L\010LS\010S\010S\010SO\010O\010O\010O X disable(C), console(M) X X D\010D\010D\010DI\010I\010I\010IA\010A\010A\010AG\010G\010G\010GN\010N\010N\010NO\010O\010O\010OS\010S\010S\010ST\010T\010T\010TI\010I\010I\010IC\010C\010C\010CS\010S\010S\010S X Error message only. X X X X X Page 1 (printed 11/14/90) X X X X X X X s\010s\010s\010sb\010b\010b\010b2\0102\0102\0102(\010(\010(\010(L\010L\010L\010LO\010O\010O\010OC\010C\010C\010CA\010A\010A\010AL\010L\010L\010L)\010)\010)\010) X\010X\010X\010XE\010E\010E\010EN\010N\010N\010NI\010I\010I\010IX\010X\010X\010X S\010S\010S\010Sy\010y\010y\010ys\010s\010s\010st\010t\010t\010te\010e\010e\010em\010m\010m\010m V\010V\010V\010V (\010(\010(\010(L\010L\010L\010Lo\010o\010o\010oc\010c\010c\010ca\010a\010a\010al\010l\010l\010l)\010)\010)\010) s\010s\010s\010sb\010b\010b\0 10b2\0102\0102\0102(\010(\010(\010(L\010L\010L\010LO\010O\010O\010OC\010C\010C\010CA\010A\010A\010AL\010L\010L\010L)\010)\010)\010) X X X X L\010L\010L\010LI\010I\010I\010IM\010M\010M\010MI\010I\010I\010IT\010T\010T\010TA\010A\010A\010AT\010T\010T\010TI\010I\010I\010IO\010O\010O\010ON\010N\010N\010NS\010S\010S\010S X Doesn't check ttys higher than 12 if you diddle your config. X May not work if run from rc.d files rather than from a login X session. X X A\010A\010A\010AU\010U\010U\010UT\010T\010T\010TH\010H\010H\010HO\010O\010O\010OR\010R\010R\010R X Bill Davidsen, davidsen@crdos1.crd.ge.com X X C\010C\010C\010Co\010o\010o\010op\010p\010p\010py\010y\010y\010yr\010r\010r\010ri\010i\010i\010ig\010g\010g\010gh\010h\010h\010ht\010t\010t\010t X Copyright (c) 1990 by Bill Davidsen, all rights reserved. X This program and documentation may be used and distributed X without payment, provided that the copyright notices are X left intact. X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Page 2 (printed 11/14/90) X X X SHAR_EOF chmod 0644 sb2.man || echo "restore of sb2.man fails" exit 0 -- bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen) sysop *IX BBS and Public Access UNIX moderator of comp.binaries.ibm.pc and 80386 mailing list "Stupidity, like virtue, is its own reward" -me