Screen saver (source included)
Michael Galassi
nerd at percy.rain.com
Wed Jan 9 02:27:01 AEST 1991
In article <2184 at ixgch.uucp> chris at ixgch.imp.com (Christoph Eckert) writes:
>hi unix-folk!
>
>i'm looking for a xenix-tool that turns the console
>to black after a specified time no key has been pressed.
>
>is there any program around which does that?
>
>please MAIL any answers to chris at ixgch.imp.com (i cannot
>receive this group!) or at least let me know WHEN and WHERE
>the sources will be posted.
>
>greetings
> chris
Compile this with cc -O -o scrn_save scrn_save.c, then add a line
to /etc/rc.d/8/userdef which starts it up. You MUST run this as
root so check the code carefully or you won't be able to sleep.
I have a few defines at the top of the file which you may want
to change. Enjoy.
-michael
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 01/08/1991 15:21 UTC by nerd at percy
# Source directory /u/nerd
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1617 -rw-rw-rw- scrn_save.c
#
# ============= scrn_save.c ==============
if test -f 'scrn_save.c' -a X"$1" != X"-c"; then
echo 'x - skipping scrn_save.c (File already exists)'
else
echo 'x - extracting scrn_save.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'scrn_save.c' &&
/*
** by Michael Galassi, nerd at percy.rain.com, 02/12/90, completely public
** domain, do anything you like.
*/
/* # of virtual consoles */
#ifndef NUM_TTYS
# define NUM_TTYS 6
#endif
X
/* # of a tty which you don't use (must be <= NUM_TTYS) */
#ifndef IDLE_TTY
# define IDLE_TTY NUM_TTYS
#endif
X
/* after how long should we blank */
#ifndef IDLE_TIME
# define IDLE_TIME (5 * 60)
#endif
X
/* check every how often? */
#ifndef CHECK_INTERVAL
# define CHECK_INTERVAL 60
#endif
X
#undef TRUE
#define TRUE 1
X
#undef FALSE
#define FALSE 0
X
#include <sys/types.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
X
int check(int num_ttys, int idle_tty, long idle_time);
X
main()
{
X char idle_ttyname[16];
X char set_ttystr[16];
X int idle_fd;
X int fd;
X
X if (fork() != 0)
X exit(0);
X
X for (fd = 0; fd < 10; ++fd)
X (void) close(fd);
X
X sprintf(idle_ttyname, "/dev/tty%02d", IDLE_TTY);
X
X if ((idle_fd = open(idle_ttyname, O_RDWR)) < 0)
X exit(-1);
X
X sprintf(set_ttystr, "\033[%02dz", IDLE_TTY - 1);
X
X while (TRUE) {
X sleep(CHECK_INTERVAL);
X if (check(NUM_TTYS, IDLE_TTY, IDLE_TIME) == TRUE) {
X write(idle_fd, set_ttystr, 6);
X write(idle_fd, "\033[=10;9C\f", 9);
X }
X }
}
X
/*
** check returns true if it's time to blank
*/
X
int check(int num_ttys, int idle_tty, long idle_time)
{
X struct stat st;
X char ttyname[16];
X long int ok_time;
X int i;
X
X ok_time = time((long *)0) - idle_time;
X
X for (i = 0; i < num_ttys; ++i) {
X if (i + 1 == idle_tty) /* don't check this one */
X continue;
X sprintf(ttyname, "/dev/tty%02d", i + 1);
X stat(ttyname, &st);
X if (st.st_mtime > ok_time)
X return(FALSE);
X }
X
X return(TRUE);
}
X
X
SHAR_EOF
chmod 0666 scrn_save.c ||
echo 'restore of scrn_save.c failed'
Wc_c="`wc -c < 'scrn_save.c'`"
test 1617 -eq "$Wc_c" ||
echo 'scrn_save.c: original size 1617, current size' "$Wc_c"
fi
exit 0
--
Michael Galassi | nerd at percy.rain.com
MS-DOS: The ultimate PC virus. | ...!tektronix!percy!nerd
More information about the Comp.unix.xenix.misc
mailing list