home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume3
/
lib_term
/
GetString.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-30
|
2KB
|
132 lines
#include <stdio.h>
#include <ctype.h>
void GetString(string, size, nullOK)
char *string;
int size;
int nullOK;
/*
---------------------------------------------------------------------------
Last revision -
16 November 1984 - GWS
Ignore XON, XOFF
11 April 1984 - GWS
NAME
GetString - "crash-proof" routine for terminal input of string
SYNOPSIS
void GetString(string, size, nullOK)
char *string;
int size;
int nullOK;
DESCRIPTION
This routine prompts and nudges the user through entry of a
character string. 'Size' is the number of characters in'string'.
'String' should therefore be dimensioned to size + 1.
'NullOK' is a boolean that tells us whether a null string is
acceptable.
SEE ALSO
DIAGNOSTICS
none
BUGS
none known
AUTHOR
George W. Sherouse
11 April 1984
---------------------------------------------------------------------------
*/
{
int c;
char erase;
int loop;
int cookie;
int count;
void underline();
int tgetnum();
char TermSetUp();
void TermRewind();
if ((cookie = tgetnum("ug")) < 0)
cookie = 0;
underline(1);
for (loop = 0; loop < size; loop++)
{
printf(" ");
string[loop] = (char) 0;
}
string[size] = (char) 0;
if (cookie)
{
underline(0);
TermRewind(cookie);
}
TermRewind(size);
erase = TermSetUp(); /* set no echo, single char input */
/* get erase character */
count = 0;
while (1)
{
switch (c = (getchar() & 0177))
{
case '\015':
if (count || nullOK)
{
for (loop = count; loop < size; loop++)
printf(" ");
underline(0);
(void) TermSetUp();
return;
}
else
{
printf("%c", '\007');
break;
}
case '\030':
while (count)
{
string[--count] = (char) 0;
printf("\b \b");
}
break;
case '\021':
case '\023':
break;
default:
if (count && c == erase)
{
printf("\b \b");
string[--count] = (char) 0;
break;
}
if (isprint(c) && count < size)
{
printf("%c", c);
string[count++] = c;
break;
}
printf("%c", '\007');
}
}
}