Article 163 of unix-pc.sources: Path: tut.cis.ohio-state.edu!rutgers!noao!arizona!naucse!rrr From: rrr@naucse.UUCP (Bob Rose ) Newsgroups: unix-pc.sources Subject: source to pbutton Message-ID: <842@naucse.UUCP> Date: 15 Aug 88 17:02:40 GMT Organization: Northern Arizona University, Flagstaff, AZ Lines: 226 [Doesn't anyone post anything here any more??] Here is the source for pbutton, one of the greating little programs for the ever written for the unixpc (to bad I didn't write it.) The orignal version had some bugs which I cleaned up so here it is again. To make just do cc -O -o pbutton pbutton.c And in your .profile put in (after you do stty if you have it in .profile) pbutton See the comments in the code for what pbutton does enjoy -bob ----------------------CUT HERE FOR pbutton.c----------------------------- /* * By Clifford C. Skolnick (lazlo!ccs) Feb 7, 1988 * * One of the most annoying things I find with running a unix system with * only one terminal is the dreaded terminal lockup! This can be easily * overcome on the Unix-PC with multiple gettys, but that is not without * problems of its own. I've also seen people start multiple shells, but * that is a pain. * * My solution is "The Panic Button", or whatever you wish to call it. * What is does it open a small window right next to the "W" icon and * wait. As soon as that window is selected, it expands and runs a * shell. When you exit the shell, it returns to its sleeping status. * * Upon logging out, the window is closed up never to be seen again. It's * only there when you need it. */ /* * Modification History: * * Robert R. Rose (arizona!rrr) Aug 10, 1988 * Went through and rearranged just about everything. Added better * check of system calls, setting process groups so signals get to the * correct location and setting the tty control characters to something * useful. It also passes lint now. */ #include #include #include #include #include #include #include /* * Use this to define what kind of icon you want in the corner. None * of them are very good because there is not enough room to play with. * ARRAYs were done with FATBIT. */ #ifdef BOX_WITH_P_IN_IT static unsigned short ARRAY[12] = { 0x03fe, 0x0202, 0x027b, 0x02db, 0x02db, 0x027b, 0x021b, 0x021b, 0x021b, 0x0203, 0x03ff, 0x00ff }; #else #ifdef PLAN_P static unsigned short ARRAY[12] = { 0x0000, 0x00fc, 0x018c, 0x018c, 0x018c, 0x018c, 0x00fc, 0x000c, 0x000c, 0x000c, 0x000c, 0x0000 }; #else /* BOX_WITH_DOT_IN_IT */ static unsigned short ARRAY[12] = { 0x83fe, 0x8202, 0x8203, 0x8273, 0x8273, 0x8273, 0x8273, 0x8273, 0x8203, 0x8203, 0x03ff, 0x00ff }; #endif #endif /* * Some global varibles and declarations. */ #define MESSAGE "Panic button pressed!\n\n" void perror(), exit(); int shutoff(), awake(); void resetwin(); static int (*sig_int)(), (*sig_quit)(), (*sig_hup)(), (*sig_term)(); static int oldwd; /*ARGSUSED*/ main(argc,argv) int argc; char *argv[]; { struct utdata utd; int wd; /* * Run in the background. */ switch (fork()) { case -1: perror("pbutton: fork"); exit(1); case 0: break; default: exit(0); } sig_int = signal(SIGINT, SIG_IGN); sig_quit = signal(SIGQUIT, SIG_IGN); sig_hup = signal(SIGHUP, shutoff); sig_term = signal(SIGTERM, shutoff); /* * Close all standard fd's and make them the new window. */ if ((wd = open("/dev/window", O_RDWR)) == -1) { perror("pbutton: opening /dev/window"); exit(1); } oldwd = dup(0); (void) close(0); (void) close(1); (void) close(2); (void) dup(wd); (void) dup(wd); (void) dup(wd); (void) close(wd); utd.ut_num = WTXTLABEL; (void) strcpy(utd.ut_text, "Panic Button"); (void) ioctl(1, WIOCSETTEXT, &utd); resetwin(); (void) signal(SIGWIND, awake); /* All set to wake up */ (void) ioctl(oldwd, WIOCSELECT); /* Select old window */ for (;;) (void) pause(); /* wait for an interupt */ } void resetwin() { struct uwdata utw; struct urdata urw; /* * Write the ARRAY in the upper right corner of the screen. */ (void) ioctl(1, WIOCGETD, &utw); utw.uw_x = 710; utw.uw_y = 0; utw.uw_width = 10; utw.uw_height = 12; utw.uw_uflags = NBORDER; (void) ioctl(1, WIOCSETD, &utw); urw.ur_srcbase = ARRAY; urw.ur_srcwidth = 2; urw.ur_dstbase = 0; urw.ur_dstwidth = 0; urw.ur_srcx = 0; urw.ur_srcy = 0; urw.ur_dstx = 0; urw.ur_dsty = 0; urw.ur_width = 10; urw.ur_height = 12; urw.ur_srcop = SRCSRC; urw.ur_dstop = DSTSRC; (void) ioctl(1, WIOCRASTOP, &urw); } awake() { struct termio old, new; struct uwdata utw; if (!ioctl(1, WIOCGETD, &utw) && (utw.uw_uflags & KBDWIN)) { switch (fork()) { case -1: perror("pbutton: fork"); break; case 0: if (!ioctl(oldwd, TCGETA, &old) && !ioctl(1, TCGETA, &new)) { /* * Set the tty chars if possible to what the user had. */ new.c_cc[0] = old.c_cc[0]; new.c_cc[1] = old.c_cc[1]; new.c_cc[2] = old.c_cc[2]; new.c_cc[3] = old.c_cc[3]; (void) ioctl(1, TCSETA, &new); /* who cares now */ } (void) signal(SIGINT, sig_int); (void) signal(SIGQUIT, sig_quit); (void) signal(SIGHUP, sig_hup); (void) signal(SIGTERM, sig_term); (void) setpgrp(); (void) ioctl(0, WIOCPGRP); (void) write(1, "\n\n", (unsigned) 2); utw.uw_x = 10 * utw.uw_hs; utw.uw_y = 6 * utw.uw_vs; utw.uw_width = 60 * utw.uw_hs; utw.uw_height = 12 * utw.uw_vs; utw.uw_uflags = 0; (void) ioctl(1, WIOCSETD, &utw); (void) write(1, MESSAGE, sizeof(MESSAGE) - 1); (void) execl("/bin/ksh", "ksh", (char *)0); perror("pbutton: execl ksh"); break; default: (void) wait((int *)0); (void) resetwin(); (void) ioctl(oldwd, WIOCSELECT); break; } } (void) signal(SIGWIND, awake); } shutoff() { (void) close(0); (void) close(1); (void) close(2); (void) close(oldwd); exit(0); } ----------------------CUT HERE-------------------------------------------