sloane@noscvax.UUCP (Gary K. Sloane) (08/09/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # part2 # This archive created: Fri Aug 8 17:13:57 1986 # By: Gary K. Sloane (Computer Sciences Corporation, San Diego) export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'part2' then echo shar: "will not over-write existing file 'part2'" else cat << \SHAR_EOF > 'part2' /*******************************************/ /* clear a field and reposition the cursor */ /*******************************************/ clrfield(fld_length) int fld_length; { int i; /* write out as many blanks as required */ for (i = 0; i < fld_length; ++i) (void)fputc(' ', stdout); /* move cursor back to start of field */ gotoxy(termctrl.curcol, termctrl.curline); } /********************************************************************/ /* routine to clear display, except system title and message border */ /********************************************************************/ clscr() { gotoxy(0,3); cleod(); gotoxy(0,21); printf("--------------------------------------------------------------------------------"); gotoxy(0,3); return; } /******************************************/ /* routine to move cursor to position x,y */ /******************************************/ gotoxy(col,lin) int col, lin; { char *cmstr; cmstr = tgoto(termctrl.CM, col, lin); /* if special mode for CM, start it */ if(termctrl.TI != 0) putpad(termctrl.TI); /* do the CM */ putpad(cmstr); /* if special mode for CM, end it */ if(termctrl.TE != 0) putpad(termctrl.TE); /* set current line and column */ termctrl.curline = lin; termctrl.curcol = col; return; } /*********************************/ /* routine to move cursor home */ /* uses curxy so HO is not req'd */ /*********************************/ home() { gotoxy(0,0); return; } /**********************************************/ /* Routine to display blank screen with title */ /**********************************************/ initscrn(title, sysname) char *sysname, *title; { int i, j; char *bptr; char blank[40]; /* compute padding for centering */ j = (80-(strlen(sysname))) / 2; for(bptr=blank, i=1; i<=j; bptr++, i++) *bptr = ' '; *bptr = '\0'; /* display system name and version */ home(); clear(); inverse(); printf("%s%s%s", blank, sysname, blank); if((strlen(sysname)) % 2) printf(" "); normal(); /* print the title on the screen */ gotoxy(((80 - strlen(title))/2)-2,1); printf("%s",title); gotoxy(0,2); printf("--------------------------------------------------------------------------------"); /* print the help box line */ gotoxy(0,21); printf("--------------------------------------------------------------------------------"); return; } /***********************/ /* Enter Standout Mode */ /***********************/ inverse() { if((termctrl.SE != 0) && (termctrl.SO != 0)) putpad(termctrl.SO); return; } /**************************************************************************/ /* Display a Message in the Message area and Sleep for the Specified Time */ /* If the time is 0, leave the message, else erase it when the time is up */ /**************************************************************************/ /*VARARGS2*/ msg(msg, beep, time, a1, a2, a3, a4, a5, a6, a7, a8) int beep; unsigned time; char *msg; { if(beep == BEEP) { bell(); (void)fflush(stdout); } tmsg(1); printf(msg, a1, a2, a3, a4, a5, a6, a7, a8); (void)fflush(stdout); if(time != 0) { sleep(time); clmsg(); } tmsg(0); return; } /**********************/ /* Exit Standout Mode */ /**********************/ normal() { if((termctrl.SE != 0) && (termctrl.SO != 0)) putpad(termctrl.SE); return; } /**************************************************************************/ /* routines to send control sequences to terminal with appropriate padding */ /**************************************************************************/ static outch(c) register char c; { putchar(c); return; } putpad(str) register char *str; { if(str) tputs(str, 0, outch); return; } /************************************************************************/ /* Get terminal out of CBREAK mode and restore ECHO and restore signals */ /************************************************************************/ termreset() { /* Unblock Signals */ (void)signal(SIGINT, SIG_DFL); (void)signal(SIGQUIT, SIG_DFL); (void)signal(SIGTERM, SIG_DFL); (void)signal(SIGTSTP, SIG_DFL); (void)signal(SIGALRM, SIG_DFL); (void)signal(SIGTTIN, SIG_DFL); (void)signal(SIGTTOU, SIG_DFL); /* turn on cooked mode with echo and case sensitivity */ ttyset("cooked"); ttyset("echo"); } /***************************************************************/ /* Put Terminal into CBREAK mode with NOECHO and block SIGNALS */ /***************************************************************/ termset(prog) char *prog; { int tpgrp; /* Don't let this program run in background */ if( (ioctl(1,(int)TIOCGPGRP,(char *)&tpgrp) != 0) || (tpgrp != getpgrp(0)) ) { printf("%s cannot be run in background.\n", prog); exit(0); } /* Block Signals */ (void)signal(SIGINT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGTERM, SIG_IGN); (void)signal(SIGTSTP, SIG_IGN); (void)signal(SIGALRM, SIG_IGN); (void)signal(SIGTTIN, SIG_IGN); (void)signal(SIGTTOU, SIG_IGN); /* go into cbreak mode with no echo */ ttyset("cbreak"); ttyset("-echo"); return; } /***********************/ /* Toggle Message Mode */ /***********************/ tmsg(flag) int flag; { static int col,lin; /* branch on start or end */ switch(flag) { /* restore cursor to wher it was prior to tmsg([12]) */ case 0: termctrl.curline = lin; termctrl.curcol = col; gotoxy(termctrl.curcol,termctrl.curline); break; /* go to 1st line of help box */ case 1: lin = termctrl.curline; col = termctrl.curcol; gotoxy(0,22); cleod(); break; /* go to 2nd line of help box (must tmsg(1) FIRST) */ case 2: gotoxy(0,23); cleod(); break; /* should read: ERROR: bad programmer */ default: printf("***ERROR: Bad argument to tmsg: %d...",flag); exit(1); } return; } /**************************************/ /* Get todays date in mm/dd/yy format */ /**************************************/ today(date) char *date; { struct tm *localtime(), *dt; struct timeval tp; /* get time in seconds since January 1, 1970 */ (void)gettimeofday(&tp,(struct timezone *)0); /* get date and time and place in structure 'dt' */ dt = localtime((long *)&tp.tv_sec); /* build the date in an ascii string */ dt->tm_mon += 1; /* months go 0-11 */ date[0] = dt->tm_mon / 10 + '0'; date[1] = dt->tm_mon % 10 + '0'; date[2] = '/'; date[3] = dt->tm_mday / 10 + '0'; date[4] = dt->tm_mday % 10 + '0'; date[5] = '/'; date[6] = dt->tm_year / 10 + '0'; date[7] = dt->tm_year % 10 + '0'; date[8] = '\0'; } /*********************************************************/ /* set tty modes ala stty(1) - arguments are: */ /* raw - turn on raw mode */ /* cbreak - turn on cbreak mode */ /* cooked - turn off raw and cbreak mode */ /* echo - cause echo (full duplex) */ /* -echo - turn off echo (half duplex) */ /* lcase - map upper case into lower case */ /* -lcase - don't map upper case to lower case */ /*********************************************************/ ttyset(cmd) char *cmd; { struct sgttyb ttystate; /* read the current status from the driver */ if(ioctl(1, (int)TIOCGETP, (char *)&ttystate) != 0) { printf("***ERROR: ioctl TIOCGETP failure in function ttyset()...\n"); exit(0); } /* set raw mode */ if(strcmp(cmd, "raw") == 0) { ttystate.sg_flags &= ~CBREAK; ttystate.sg_flags |= RAW; } /* set cbreak mode */ else if(strcmp(cmd, "cbreak") == 0) { ttystate.sg_flags &= ~RAW; ttystate.sg_flags |= CBREAK; } /* set cooked mode */ else if(strcmp(cmd, "cooked") == 0) ttystate.sg_flags &= ~(RAW+CBREAK); /* set echo on */ else if(strcmp(cmd, "echo") == 0) ttystate.sg_flags |= ECHO; /* set echo off */ else if(strcmp(cmd, "-echo") == 0) ttystate.sg_flags &= ~ECHO; /* map upper to lower case on input */ else if(strcmp(cmd, "lcase") == 0) ttystate.sg_flags |= LCASE; /* differentiate between upper and lower case */ else if(strcmp(cmd, "-lcase") == 0) ttystate.sg_flags &= ~LCASE; /* bad argument given */ else { printf("***ERROR: bad argument to ttyset()...\n"); exit(0); } /* write out the changes to the driver */ if(ioctl(1, (int)TIOCSETP, (char *)&ttystate) != 0) { printf("***ERROR: ioctl TIOCSETP failure in function ttyset()...\n"); exit(0); } return; } SHAR_EOF fi exit 0 # End of shell archive