home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume3 / lib_term / GetBool.c < prev    next >
C/C++ Source or Header  |  1986-11-30  |  1KB  |  102 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int GetBool(Default)
  5. int Default;
  6.  
  7. /*
  8.  ---------------------------------------------------------------------------
  9.  
  10.    Last revision - 
  11.     16 November 1984 - GWS
  12.     Ignore XON, XOFF
  13.  
  14.      11 April 1984 - GWS
  15.  
  16.  
  17.    NAME
  18.      GetBool - "crash-proof" routine for terminal input of boolean
  19.  
  20.    SYNOPSIS
  21.     int GetHospNum(Default)
  22.     int Default;
  23.  
  24.    DESCRIPTION
  25.     This routine prompts and nudges the user through entry of a
  26.     boolean value.
  27.  
  28.    SEE ALSO
  29.  
  30.  
  31.    DIAGNOSTICS
  32.     none 
  33.  
  34.    BUGS
  35.     none known
  36.  
  37.    AUTHOR
  38.      George W. Sherouse
  39.      11 April 1984
  40.  
  41.  ---------------------------------------------------------------------------
  42. */
  43.  
  44. {
  45.     int c;
  46.     char erase;
  47.     int val;
  48.     int cookie;
  49.  
  50.     void underline();
  51.     int tgetnum();
  52.     char TermSetUp();
  53.     void TermRewind();
  54.  
  55.     if ((cookie = tgetnum("ug")) < 0)
  56.     cookie = 0;
  57.  
  58.     underline(1);
  59.     printf("   ");
  60.  
  61.     if (cookie)
  62.     {
  63.     underline(0);
  64.     TermRewind(cookie);
  65.     }
  66.  
  67.     erase = TermSetUp();    /* set no echo, single char input */
  68.                     /* get erase character */
  69.     val = Default;
  70.     while (1)
  71.     {
  72.         if (val)
  73.         printf("\b\b\byes");
  74.         else
  75.         printf("\b\b\bno ");
  76.  
  77.     switch (c = (getchar() & 0177))
  78.     {
  79.     case '\015':
  80.         underline(0);
  81.         TermSetUp();
  82.         return(val);
  83.     case ' ':
  84.         val = !val;
  85.         break;
  86.     case 'y':
  87.     case 'Y':
  88.         val = 1;
  89.         break;
  90.     case 'n':
  91.     case 'N':
  92.         val = 0;
  93.         break;
  94.     case '\021':
  95.     case '\023':
  96.         break;
  97.     default:
  98.         printf("%c", '\007');
  99.     }
  100.     }
  101. }
  102.