home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sgtty.h>
- #include <sys/ioctl.h>
-
- char TermSetUp()
-
- /*
- ---------------------------------------------------------------------------
-
- Last revision -
- 11 April 1984 - GWS
-
-
- NAME
- TermSetUp - set/clear terminal no echo, raw mode
-
- SYNOPSIS
- char TermSetUp()
-
- DESCRIPTION
- This routine is a toggle function which places the terminal
- into RAW and !ECHO modes on odd calls and back to the original
- state on even-number calls. The return character is the terminal's
- erase character.
-
- SEE ALSO
-
-
- DIAGNOSTICS
- Will exit(1) on any error.
-
- BUGS
- none known
-
- AUTHOR
- George W. Sherouse
- 9 April 1984
-
- ---------------------------------------------------------------------------
- */
-
- {
- struct sgttyb params;
- int ret;
- static int count=0;
- static struct sgttyb old_params;
- int ioctl();
-
- if (!count)
- {
- ret = ioctl(0, TIOCGETP, &old_params);
- if (ret == -1)
- {
- fprintf(stderr, "ioctl fail\n");
- perror("TermSetUp");
- exit(1);
- }
- ret = ioctl(0, TIOCGETP, ¶ms);
- if (ret == -1)
- {
- fprintf(stderr, "ioctl fail\n");
- perror("TermSetUp");
- exit(1);
- }
-
- /* single-character activation, disable all character processing */
- params.sg_flags |= RAW;
- if (params.sg_flags & ECHO)
- params.sg_flags ^= ECHO;
- ret = ioctl(0, TIOCSETP, ¶ms);
- if (ret == -1)
- {
- fprintf(stderr, "ioctl fail\n");
- perror("TermSetUp");
- exit(1);
- }
- count++;
- }
- else
- {
- /* put it back the way you found it */
- ret = ioctl(0, TIOCSETP, &old_params);
- if (ret == -1)
- {
- fprintf(stderr, "ioctl fail\n");
- perror("TermSetUp");
- exit(1);
- }
- count = 0;
- }
-
- return(params.sg_erase);
- }
-