home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
-
- void GetHospNum(HospNum)
- char *HospNum;
-
- /*
- ---------------------------------------------------------------------------
-
- Last revision -
- 16 November 1984 - GWS
- Ignore XON, XOFF
-
- 11 April 1984 - GWS
-
-
- NAME
- GetHospNum - "crash-proof" routine for terminal input of ##-##-##
-
- SYNOPSIS
- void GetHospNum(HospNum)
- char *HospNum;
-
- DESCRIPTION
- This routine prompts and nudges the user through entry of a
- hospital number in the proper format.
-
- SEE ALSO
-
-
- DIAGNOSTICS
- none
-
- BUGS
- Doesn't do any validity checking on the number, only the format.
-
- AUTHOR
- George W. Sherouse
- 9 April 1984
-
- ---------------------------------------------------------------------------
- */
-
- {
- int c;
- char erase;
- int count;
- 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);
- }
- TermRewind(8);
-
- erase = TermSetUp(); /* set no echo, single char input */
- /* get erase character */
- count = 0;
- while (1)
- {
- switch (count)
- {
- case 2:
- case 5:
- printf("-");
- HospNum[count++] = '-';
- break;
- default:
- switch (c = (getchar() & 0177))
- {
- case '\015':
- if (count == 8)
- {
- HospNum[8] = (char) 0;
- underline(0);
- TermSetUp();
- return;
- }
- else
- {
- printf("%c", '\007');
- break;
- }
- case 030:
- TermRewind(count);
- printf(" - - ");
- count = 0;
- TermRewind(8);
- break;
- case '\021':
- case '\023':
- break;
- default:
- if (c == erase && count)
- {
- switch (count)
- {
- case 3:
- case 6:
- printf("\b");
- count--;
- case 1:
- case 2:
- case 4:
- case 5:
- case 7:
- case 8:
- printf("\b \b");
- HospNum[--count] = 0;
- break;
- }
- break;
- }
-
- if (isdigit(c) && count < 8)
- {
- printf("%c", c);
- HospNum[count++] = (char) c;
- }
- else
- printf("%c", '\007');
- }
- }
- }
- }
-