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: }

Defined functions

getans defined in line 19; never used
intrser defined in line 82; used 4 times

Defined variables

ansbuf defined in line 11; used 6 times
interrupted defined in line 13; used 4 times
sigenv defined in line 15; used 3 times
Last modified: 1985-10-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1028
Valid CSS Valid XHTML 1.0 Strict