home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume3
/
lib_term
/
GetBool.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-30
|
1KB
|
102 lines
#include <stdio.h>
#include <ctype.h>
int GetBool(Default)
int Default;
/*
---------------------------------------------------------------------------
Last revision -
16 November 1984 - GWS
Ignore XON, XOFF
11 April 1984 - GWS
NAME
GetBool - "crash-proof" routine for terminal input of boolean
SYNOPSIS
int GetHospNum(Default)
int Default;
DESCRIPTION
This routine prompts and nudges the user through entry of a
boolean value.
SEE ALSO
DIAGNOSTICS
none
BUGS
none known
AUTHOR
George W. Sherouse
11 April 1984
---------------------------------------------------------------------------
*/
{
int c;
char erase;
int val;
int cookie;
void underline();
int tgetnum();
char TermSetUp();
void TermRewind();
if ((cookie = tgetnum("ug")) < 0)
cookie = 0;
underline(1);
printf(" ");
if (cookie)
{
underline(0);
TermRewind(cookie);
}
erase = TermSetUp(); /* set no echo, single char input */
/* get erase character */
val = Default;
while (1)
{
if (val)
printf("\b\b\byes");
else
printf("\b\b\bno ");
switch (c = (getchar() & 0177))
{
case '\015':
underline(0);
TermSetUp();
return(val);
case ' ':
val = !val;
break;
case 'y':
case 'Y':
val = 1;
break;
case 'n':
case 'N':
val = 0;
break;
case '\021':
case '\023':
break;
default:
printf("%c", '\007');
}
}
}