|
|
1.1 ! root 1: /* getans.c - get an answer from the user and return a string array */ ! 2: ! 3: #include "../h/mh.h" ! 4: #ifdef BSD42 ! 5: #include <setjmp.h> ! 6: #endif BSD42 ! 7: #include <signal.h> ! 8: #include <stdio.h> ! 9: ! 10: ! 11: static char ansbuf[BUFSIZ]; ! 12: #ifndef BSD42 ! 13: static int interrupted; ! 14: #else BSD42 ! 15: static jmp_buf sigenv; ! 16: #endif BSD42 ! 17: int intrser (); ! 18: ! 19: char **getans (prompt, ansp) ! 20: register char *prompt; ! 21: register struct swit *ansp; ! 22: { ! 23: register int i; ! 24: int (*istat) (); ! 25: register char *cp, ! 26: **cpp; ! 27: ! 28: #ifndef BSD42 ! 29: interrupted = 0; ! 30: istat = signal (SIGINT, intrser); ! 31: #else BSD42 ! 32: switch (setjmp (sigenv)) { ! 33: case OK: ! 34: istat = signal (SIGINT, intrser); ! 35: break; ! 36: ! 37: default: ! 38: (void) signal (SIGINT, istat); ! 39: return NULL; ! 40: } ! 41: #endif BSD42 ! 42: for (;;) { ! 43: printf ("%s", prompt); ! 44: (void) fflush (stdout); ! 45: cp = ansbuf; ! 46: while ((i = getchar ()) != '\n') { ! 47: #ifndef BSD42 ! 48: if (i == EOF || interrupted) { ! 49: interrupted = 0; ! 50: (void) signal (SIGINT, istat); ! 51: return NULL; ! 52: } ! 53: #else BSD42 ! 54: if (i == EOF) ! 55: longjmp (sigenv, DONE); ! 56: #endif BSD42 ! 57: if (cp < &ansbuf[sizeof ansbuf - 1]) ! 58: *cp++ = i; ! 59: } ! 60: *cp = 0; ! 61: if (ansbuf[0] == '?' || cp == ansbuf) { ! 62: printf ("Options are:\n"); ! 63: printsw (ALL, ansp, ""); ! 64: continue; ! 65: } ! 66: cpp = brkstring (ansbuf, " ", NULLCP); ! 67: switch (smatch (*cpp, ansp)) { ! 68: case AMBIGSW: ! 69: ambigsw (*cpp, ansp); ! 70: continue; ! 71: case UNKWNSW: ! 72: printf (" -%s unknown. Hit <CR> for help.\n", *cpp); ! 73: continue; ! 74: default: ! 75: (void) signal (SIGINT, istat); ! 76: return cpp; ! 77: } ! 78: } ! 79: } ! 80: ! 81: ! 82: static int intrser () { ! 83: #ifndef BSD42 ! 84: (void) signal(SIGINT, intrser); ! 85: interrupted = 1; ! 86: #else BSD42 ! 87: longjmp (sigenv, NOTOK); ! 88: #endif BSD42 ! 89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.