espo@bpa.UUCP (11/30/83)
Here's a mod to swc.c to allow disabling the display, executing a command, and re-displaying the clock. Bob Esposito....bpa!espo /* ** ** program = swc.c ** ** author = R.J. Esposito ** ** Swc is an interface to vtclock - it switches the display on/off ** depending on it's previous state. ** ** Modified to allow user to turn display off, execute a command, ** and turn the display back on after the command completes. ** If the cursor is at row 24, we must move the screen up one line ** so we don't lose the last line returned from the passed command. ** */ #include <stdio.h> #include <termio.h> #define REQCR "\33[6n" /* request cursor position */ #define CTOE "\33[23;0f\33[J" /* reposition cursor and clear to end of screen */ FILE *fp; char pid_file[100]; char *strcpy(), *strcat(); char *getenv(); struct termio *t; main(argc, argv) char **argv; { char *pid; int f_pid; (void )strcpy(pid_file, getenv("HOME")); (void )strcat(pid_file, "/.clock_pid"); if((fp=fopen(pid_file, "r")) == NULL) exit(1);; pid = fgets(pid_file, 100, fp); (void )kill (atoi(pid), 16); /* send SIGUSR1 to vtclock */ (void )fclose(fp); if (argc >= 2) { /* check for command line */ (void )*argv++; /* to shut-up lint */ if ((f_pid=fork()) == 0) { (void )execvp(*argv, argv); /* do the command */ }while((wait((int *)0)) != f_pid); /* wait here for command to complete */ (void )ioctl(0, TCGETA, t); t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 0; t->c_lflag &= ~(ICANON|ECHO); (void )ioctl(0, TCSETAW, t); (void )fputs(REQCR, stdout); (void )getchar(); /* skip ESC */ (void )getchar(); /* skip [ */ if ((getchar()) == '2' && (getchar()) == '4') (void )fputc('\n', stdout); /* move screen up one line */ (void )fputs(CTOE, stdout); t->c_lflag |= (ICANON|ECHO); (void )ioctl(0, TCSETAW, t); (void )ioctl(0, TCFLSH, 2); /* flush stdin/stdout */ (void )kill (atoi(pid), 16); /* turn display back on */ } }