home *** CD-ROM | disk | FTP | other *** search
- /*
- * The functions in this file negotiate with the operating system for
- * characters, and write characters in a barely buffered fashion on the display.
- * All operating systems.
- */
-
- #include "def.h"
-
- #if UNIX /* System V */
-
- #include <stdio.h>
- #include <signal.h>
- #include <termio.h>
- #include <errno.h>
- #include <fcntl.h>
- int kbdflgs; /* saved keyboard fd flags */
- int kbdpoll; /* in O_NDELAY mode */
- int kbdqp; /* there is a char in kbdq */
- char kbdq; /* char we've already read */
- struct termio otermio; /* original terminal characteristics */
- struct termio ntermio; /* charactoristics to use inside */
-
- int nrow; /* Terminal size, rows. */
- int ncol; /* Terminal size, columns. */
-
- /*
- * This function is called once to set up the terminal device streams.
- * On VMS, it translates TT until it finds the terminal, then assigns
- * a channel to it and sets it raw. On CPM it is a no-op.
- */
- ttopen()
- {
- ioctl(0, TCGETA, &otermio); /* save old settings */
- ntermio.c_iflag = 0; /* setup new settings */
- ntermio.c_oflag = 0;
- ntermio.c_cflag = otermio.c_cflag;
- ntermio.c_lflag = 0;
- ntermio.c_line = otermio.c_line;
- ntermio.c_cc[VMIN] = 1;
- ntermio.c_cc[VTIME] = 0;
- ioctl(0, TCSETAW, &ntermio); /* and activate them */
- kbdflgs = fcntl( 0, F_GETFL, 0 );
- kbdpoll = FALSE;
- /* on all screens we are not sure of the initial position
- of the cursor */
- ttrow = 999;
- ttcol = 999;
- nrow = NROW;
- ncol = NCOL;
- }
-
- /*
- * This function gets called just before we go back home to the command
- * interpreter. On VMS it puts the terminal back in a reasonable state.
- * Another no-operation on CPM.
- */
- ttclose()
- {
- if (ioctl(0, TCSETAW, &otermio) == -1) /* restore terminal settings */
- printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
- if (fcntl(0, F_SETFL, kbdflgs) == -1)
- printf ("closing fcntl on dev 0 failure, error = %d\n", errno);
- }
-
- /*
- * Write a character to the display. On VMS, terminal output is buffered, and
- * we just put the characters in the big array, after checking for overflow.
- * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
- * MS-DOS (use the very very raw console output routine).
- */
- ttputc(c)
- {
- fputc(c, stdout);
- }
-
- /*
- * Flush terminal buffer. Does real work where the terminal output is buffered
- * up. A no-operation on systems where byte at a time terminal I/O is done.
- */
- ttflush()
- {
- fflush(stdout);
- }
-
- /*
- * Read a character from the terminal, performing no editing and doing no echo
- * at all. More complex in VMS that almost anyplace else, which figures. Very
- * simple on CPM, because the system can do exactly what you want.
- */
- ttgetc()
- {
- if( kbdqp )
- kbdqp = FALSE;
- else
- {
- if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
- return FALSE;
- kbdpoll = FALSE;
- while (read(0, &kbdq, 1) != 1)
- ;
- }
- return ( kbdq & 127 );
- }
-
- /* typahead(): Check to see if any characters are already in the
- keyboard buffer
- */
- ttkeyready ()
- {
- if( !kbdqp )
- {
- if( !kbdpoll && fcntl( 0, F_SETFL, kbdflgs | O_NDELAY ) < 0 )
- return(FALSE);
- kbdqp = (1 == read( 0, &kbdq, 1 ));
- }
- return ( kbdqp );
- }
- #endif
-
-