home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume3 / libc_term / get_bool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.6 KB  |  108 lines

  1. #include <curses.h>
  2. #include <ctype.h>
  3. #include "c_term.h"
  4.  
  5. int get_bool(Default)
  6. int Default;
  7.  
  8. /*
  9.  ---------------------------------------------------------------------------
  10.  
  11.    Last revision - 
  12.     6 January 1985 - GWS
  13.     Change to use curses
  14.  
  15.     16 November 1984 - GWS
  16.     Ignore XON, XOFF
  17.  
  18.      11 April 1984 - GWS
  19.  
  20.  
  21.    NAME
  22.      get_bool - "crash-proof" routine for terminal input of boolean
  23.  
  24.    SYNOPSIS
  25.     int get_bool(Default)
  26.     int Default;
  27.  
  28.    DESCRIPTION
  29.     This routine prompts and nudges the user through entry of a
  30.     boolean value.
  31.  
  32.    SEE ALSO
  33.  
  34.  
  35.    DIAGNOSTICS
  36.     none 
  37.  
  38.    BUGS
  39.     none known
  40.  
  41.    AUTHOR
  42.      George W. Sherouse
  43.      11 April 1984
  44.  
  45.  ---------------------------------------------------------------------------
  46. */
  47.  
  48. {
  49.     int c;
  50.     int    val,
  51.     where_y,
  52.     where_x;
  53.  
  54.     getyx(stdscr, where_y, where_x);
  55.     standout();
  56.  
  57.     val = Default;
  58.     while (1)
  59.     {
  60.     if (val)
  61.         mvprintw(where_y, where_x, "yes");
  62.     else
  63.         mvprintw(where_y, where_x, "no ");
  64.     refresh();
  65.  
  66.     switch (c = (getch() & 0177))
  67.     {
  68. #ifdef ABORT_CHAR
  69.     case ABORT_CHAR:
  70.         clear();
  71.         standend();
  72.         mvprintw(0, 0, "Program aborted at your request...");
  73.         move(LINES - 1, 0);
  74.         refresh();
  75.         endwin();
  76.         exit(0);
  77.         break;
  78. #endif ABORT_CHAR
  79.  
  80.     case '\015':
  81.         standend();
  82.         if (val)
  83.         mvprintw(where_y, where_x, "yes");
  84.         else
  85.         mvprintw(where_y, where_x, "no ");
  86.         refresh();
  87.         return(val);
  88.         break;
  89.     case ' ':
  90.         val = !val;
  91.         break;
  92.     case 'y':
  93.     case 'Y':
  94.         val = 1;
  95.         break;
  96.     case 'n':
  97.     case 'N':
  98.         val = 0;
  99.         break;
  100.     case '\021':
  101.     case '\023':
  102.         break;
  103.     default:
  104.         fprintf(stderr, "%c", '\007');
  105.     }
  106.     }
  107. }
  108.