2013-05-20 03:16:19 -04:00
|
|
|
#include "termio.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* TERMIO.C
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* modified by Petri Kutvonen
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef POSIX
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "estruct.h"
|
|
|
|
#include "edef.h"
|
|
|
|
|
2013-04-30 22:06:08 -04:00
|
|
|
/* rfi */
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VMS
|
|
|
|
#include <stsdef.h>
|
|
|
|
#include <ssdef.h>
|
|
|
|
#include <descrip.h>
|
|
|
|
#include <iodef.h>
|
|
|
|
#include <ttdef.h>
|
|
|
|
#include <tt2def.h>
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#define NIBUF 128 /* Input buffer size */
|
|
|
|
#define NOBUF 1024 /* MM says bug buffers win! */
|
|
|
|
#define EFN 0 /* Event flag */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
char obuf[NOBUF]; /* Output buffer */
|
|
|
|
int nobuf; /* # of bytes in above */
|
|
|
|
char ibuf[NIBUF]; /* Input buffer */
|
|
|
|
int nibuf; /* # of bytes in above */
|
|
|
|
int ibufi; /* Read index */
|
|
|
|
int oldmode[3]; /* Old TTY mode bits */
|
|
|
|
int newmode[3]; /* New TTY mode bits */
|
|
|
|
short iochan; /* TTY I/O channel */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & (MSC | TURBO)
|
2005-09-30 18:26:09 -04:00
|
|
|
union REGS rg; /* cpu register for use of DOS calls */
|
|
|
|
int nxtchar = -1; /* character held from type ahead */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USG /* System V */
|
|
|
|
#include <signal.h>
|
|
|
|
#include <termio.h>
|
|
|
|
#include <fcntl.h>
|
2005-09-30 18:26:09 -04:00
|
|
|
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 */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if XONXOFF
|
|
|
|
#define XXMASK 0016000
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | BSD
|
|
|
|
#include <sgtty.h> /* for stty/gtty functions */
|
|
|
|
#include <signal.h>
|
2005-09-30 18:26:09 -04:00
|
|
|
struct sgttyb ostate; /* saved tty state */
|
|
|
|
struct sgttyb nstate; /* values for editor mode */
|
|
|
|
struct tchars otchars; /* Saved terminal special character set */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if XONXOFF
|
2005-09-30 18:26:09 -04:00
|
|
|
struct tchars ntchars = { 0xff, 0xff, 0x11, 0x13, 0xff, 0xff };
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* A lot of nothing and XON/XOFF */
|
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
struct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* A lot of nothing */
|
|
|
|
#endif
|
|
|
|
#if BSD & PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
struct ltchars oltchars; /* Saved terminal local special character set */
|
|
|
|
struct ltchars nltchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* A lot of nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BSD
|
|
|
|
#include <sys/ioctl.h> /* to get at the typeahead */
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int rtfrmshell(); /* return from suspended shell */
|
2005-05-31 11:50:56 -04:00
|
|
|
#define TBUFSIZ 128
|
|
|
|
char tobuf[TBUFSIZ]; /* terminal output buffer */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __hpux | SVR4
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int rtfrmshell(); /* return from suspended shell */
|
2005-05-31 11:50:56 -04:00
|
|
|
#define TBUFSIZ 128
|
2005-09-30 18:26:09 -04:00
|
|
|
char tobuf[TBUFSIZ]; /* terminal output buffer */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-01-29 19:17:02 -05:00
|
|
|
void ttopen(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
struct dsc$descriptor idsc;
|
|
|
|
struct dsc$descriptor odsc;
|
|
|
|
char oname[40];
|
|
|
|
int iosb[2];
|
|
|
|
int status;
|
|
|
|
|
|
|
|
odsc.dsc$a_pointer = "TT";
|
|
|
|
odsc.dsc$w_length = strlen(odsc.dsc$a_pointer);
|
|
|
|
odsc.dsc$b_dtype = DSC$K_DTYPE_T;
|
|
|
|
odsc.dsc$b_class = DSC$K_CLASS_S;
|
|
|
|
idsc.dsc$b_dtype = DSC$K_DTYPE_T;
|
|
|
|
idsc.dsc$b_class = DSC$K_CLASS_S;
|
|
|
|
do {
|
|
|
|
idsc.dsc$a_pointer = odsc.dsc$a_pointer;
|
|
|
|
idsc.dsc$w_length = odsc.dsc$w_length;
|
|
|
|
odsc.dsc$a_pointer = &oname[0];
|
|
|
|
odsc.dsc$w_length = sizeof(oname);
|
|
|
|
status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
|
|
|
|
if (status != SS$_NORMAL && status != SS$_NOTRAN)
|
|
|
|
exit(status);
|
|
|
|
if (oname[0] == 0x1B) {
|
|
|
|
odsc.dsc$a_pointer += 4;
|
|
|
|
odsc.dsc$w_length -= 4;
|
|
|
|
}
|
|
|
|
} while (status == SS$_NORMAL);
|
|
|
|
status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
|
|
|
|
if (status != SS$_NORMAL)
|
|
|
|
exit(status);
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
|
|
|
|
oldmode, sizeof(oldmode), 0, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
|
|
|
|
exit(status);
|
|
|
|
newmode[0] = oldmode[0];
|
|
|
|
newmode[1] = oldmode[1] | TT$M_NOECHO;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if XONXOFF
|
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
newmode[1] &= ~(TT$M_TTSYNC | TT$M_HOSTSYNC);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
newmode[2] = oldmode[2] | TT2$M_PASTHRU;
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
|
|
newmode, sizeof(newmode), 0, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
|
|
|
|
exit(status);
|
|
|
|
term.t_nrow = (newmode[1] >> 24) - 1;
|
|
|
|
term.t_ncol = newmode[0] >> 16;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & (TURBO | (PKCODE & MSC))
|
|
|
|
/* kill the CONTROL-break interupt */
|
|
|
|
rg.h.ah = 0x33; /* control-break check dos call */
|
|
|
|
rg.h.al = 1; /* set the current state */
|
|
|
|
rg.h.dl = 0; /* set it OFF */
|
|
|
|
intdos(&rg, &rg); /* go for it! */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USG
|
|
|
|
ioctl(0, TCGETA, &otermio); /* save old settings */
|
2005-09-30 18:26:09 -04:00
|
|
|
ntermio.c_iflag = 0; /* setup new settings */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if XONXOFF
|
|
|
|
ntermio.c_iflag = otermio.c_iflag & XXMASK; /* save XON/XOFF P.K. */
|
|
|
|
#endif
|
|
|
|
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;
|
2010-01-29 19:17:02 -05:00
|
|
|
#if PKCODE
|
2005-05-31 11:50:56 -04:00
|
|
|
ioctl(0, TCSETAW, &ntermio); /* and activate them */
|
|
|
|
#else
|
|
|
|
ioctl(0, TCSETA, &ntermio); /* and activate them */
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
kbdflgs = fcntl(0, F_GETFL, 0);
|
2005-05-31 11:50:56 -04:00
|
|
|
kbdpoll = FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
gtty(0, &ostate); /* save old state */
|
|
|
|
gtty(0, &nstate); /* get base of new state */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if XONXOFF
|
2005-09-30 18:26:09 -04:00
|
|
|
nstate.sg_flags |= (CBREAK | TANDEM);
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
nstate.sg_flags |= RAW;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
nstate.sg_flags &= ~(ECHO | CRMOD); /* no echo for now... */
|
|
|
|
stty(0, &nstate); /* set mode */
|
|
|
|
ioctl(0, TIOCGETC, &otchars); /* Save old characters */
|
|
|
|
ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if BSD & PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
ioctl(0, TIOCGLTC, &oltchars); /* Save old local characters */
|
|
|
|
ioctl(0, TIOCSLTC, &nltchars); /* New local characters */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if BSD
|
|
|
|
/* provide a smaller terminal output buffer so that
|
|
|
|
the type ahead detection works better (more often) */
|
|
|
|
setbuffer(stdout, &tobuf[0], TBUFSIZ);
|
2005-09-30 18:26:09 -04:00
|
|
|
signal(SIGTSTP, SIG_DFL); /* set signals so that we can */
|
|
|
|
signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __hpux | SVR4
|
2005-09-30 18:26:09 -04:00
|
|
|
/* provide a smaller terminal output buffer so that
|
|
|
|
the type ahead detection works better (more often) */
|
|
|
|
setvbuf(stdout, &tobuf[0], _IOFBF, TBUFSIZ);
|
|
|
|
signal(SIGTSTP, SIG_DFL); /* set signals so that we can */
|
|
|
|
signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */
|
|
|
|
TTflush();
|
|
|
|
#endif /* __hpux */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* on all screens we are not sure of the initial position
|
2005-09-30 18:26:09 -04:00
|
|
|
of the cursor */
|
2005-05-31 11:50:56 -04:00
|
|
|
ttrow = 999;
|
|
|
|
ttcol = 999;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-01-29 19:17:02 -05:00
|
|
|
void ttclose(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
int status;
|
|
|
|
int iosb[1];
|
|
|
|
|
|
|
|
ttflush();
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
|
|
oldmode, sizeof(oldmode), 0, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
|
|
|
|
exit(status);
|
|
|
|
status = SYS$DASSGN(iochan);
|
|
|
|
if (status != SS$_NORMAL)
|
|
|
|
exit(status);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if MSDOS & (TURBO | (PKCODE & MSC))
|
|
|
|
/* restore the CONTROL-break interupt */
|
|
|
|
rg.h.ah = 0x33; /* control-break check dos call */
|
|
|
|
rg.h.al = 1; /* set the current state */
|
|
|
|
rg.h.dl = 1; /* set it ON */
|
|
|
|
intdos(&rg, &rg); /* go for it! */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USG
|
|
|
|
#if PKCODE
|
|
|
|
ioctl(0, TCSETAW, &otermio); /* restore terminal settings */
|
|
|
|
#else
|
|
|
|
ioctl(0, TCSETA, &otermio); /* restore terminal settings */
|
|
|
|
#endif
|
|
|
|
fcntl(0, F_SETFL, kbdflgs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
stty(0, &ostate);
|
2005-05-31 11:50:56 -04:00
|
|
|
ioctl(0, TIOCSETC, &otchars); /* Place old character into K */
|
|
|
|
#if BSD & PKCODE
|
|
|
|
ioctl(0, TIOCSLTC, &oltchars); /* Place old local character into K */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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).
|
|
|
|
*/
|
2013-05-20 03:16:19 -04:00
|
|
|
int ttputc( int c) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
if (nobuf >= NOBUF)
|
|
|
|
ttflush();
|
|
|
|
obuf[nobuf++] = c;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & ~IBMPC
|
|
|
|
bdos(6, c, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
2013-06-06 04:14:15 -04:00
|
|
|
char utf8[6];
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
bytes = unicode_to_utf8(c, utf8);
|
|
|
|
fwrite(utf8, 1, bytes, stdout);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-05-20 03:16:19 -04:00
|
|
|
return 0 ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-04-30 22:06:08 -04:00
|
|
|
void ttflush( void) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
int status;
|
|
|
|
int iosb[2];
|
|
|
|
|
|
|
|
status = SS$_NORMAL;
|
|
|
|
if (nobuf != 0) {
|
|
|
|
status =
|
|
|
|
SYS$QIOW(EFN, iochan, IO$_WRITELBLK | IO$M_NOFORMAT,
|
|
|
|
iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0);
|
|
|
|
if (status == SS$_NORMAL)
|
|
|
|
status = iosb[0] & 0xFFFF;
|
|
|
|
nobuf = 0;
|
|
|
|
}
|
2010-01-29 19:17:02 -05:00
|
|
|
return status;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
|
|
|
/*
|
|
|
|
* Add some terminal output success checking, sometimes an orphaned
|
|
|
|
* process may be left looping on SunOS 4.1.
|
|
|
|
*
|
|
|
|
* How to recover here, or is it best just to exit and lose
|
|
|
|
* everything?
|
|
|
|
*
|
|
|
|
* jph, 8-Oct-1993
|
|
|
|
*/
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#include <errno.h>
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
int status;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
status = fflush(stdout);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (status != 0 && errno != EAGAIN) {
|
|
|
|
exit(errno);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-04-30 22:06:08 -04:00
|
|
|
int ttgetc( void) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
int status;
|
|
|
|
int iosb[2];
|
|
|
|
int term[2];
|
|
|
|
|
|
|
|
while (ibufi >= nibuf) {
|
|
|
|
ibufi = 0;
|
|
|
|
term[0] = 0;
|
|
|
|
term[1] = 0;
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_READLBLK | IO$M_TIMED,
|
|
|
|
iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0);
|
|
|
|
if (status != SS$_NORMAL)
|
|
|
|
exit(status);
|
|
|
|
status = iosb[0] & 0xFFFF;
|
|
|
|
if (status != SS$_NORMAL && status != SS$_TIMEOUT &&
|
|
|
|
status != SS$_DATAOVERUN)
|
|
|
|
exit(status);
|
|
|
|
nibuf = (iosb[0] >> 16) + (iosb[1] >> 16);
|
|
|
|
if (nibuf == 0) {
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_READLBLK,
|
|
|
|
iosb, 0, 0, ibuf, 1, 0, term, 0,
|
|
|
|
0);
|
|
|
|
if (status != SS$_NORMAL
|
|
|
|
|| (status = (iosb[0] & 0xFFFF)) != SS$_NORMAL)
|
2005-05-31 11:50:56 -04:00
|
|
|
if (status != SS$_DATAOVERUN)
|
|
|
|
exit(status);
|
2005-09-30 18:26:09 -04:00
|
|
|
nibuf = (iosb[0] >> 16) + (iosb[1] >> 16);
|
|
|
|
}
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return ibuf[ibufi++] & 0xFF; /* Allow multinational */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & (MSC | TURBO)
|
2005-09-30 18:26:09 -04:00
|
|
|
int c; /* character read */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if a char already is ready, return it */
|
|
|
|
if (nxtchar >= 0) {
|
|
|
|
c = nxtchar;
|
|
|
|
nxtchar = -1;
|
2010-08-29 06:03:55 -04:00
|
|
|
return c;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call the dos to get a char */
|
|
|
|
rg.h.ah = 7; /* dos Direct Console Input call */
|
|
|
|
intdos(&rg, &rg);
|
|
|
|
c = rg.h.al; /* grab the char */
|
2010-08-29 06:03:55 -04:00
|
|
|
return c & 255;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | BSD
|
2010-08-29 06:03:55 -04:00
|
|
|
return 255 & fgetc(stdin); /* 8BIT P.K. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USG
|
2005-09-30 18:26:09 -04:00
|
|
|
if (kbdqp)
|
2005-05-31 11:50:56 -04:00
|
|
|
kbdqp = FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
else {
|
|
|
|
if (kbdpoll && fcntl(0, F_SETFL, kbdflgs) < 0)
|
2005-05-31 11:50:56 -04:00
|
|
|
return FALSE;
|
|
|
|
kbdpoll = FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
while (read(0, &kbdq, 1) != 1);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return kbdq & 255;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if TYPEAH
|
|
|
|
/* typahead: Check to see if any characters are already in the
|
|
|
|
keyboard buffer
|
|
|
|
*/
|
|
|
|
|
2013-04-30 22:06:08 -04:00
|
|
|
int typahead( void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if MSDOS & (MSC | TURBO)
|
|
|
|
if (kbhit() != 0)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
else
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
int x; /* holds # of pending chars */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-08-29 06:03:55 -04:00
|
|
|
return (ioctl(0, FIONREAD, &x) < 0) ? 0 : x;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PKCODE & VMS
|
2010-08-29 06:03:55 -04:00
|
|
|
return ibufi < nibuf;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USG
|
2005-09-30 18:26:09 -04:00
|
|
|
if (!kbdqp) {
|
|
|
|
if (!kbdpoll && fcntl(0, F_SETFL, kbdflgs | O_NDELAY) < 0)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
|
|
|
kbdpoll = 1;
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
kbdqp = (1 == read(0, &kbdq, 1));
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return kbdqp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !UNIX & !VMS & !MSDOS
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#endif /* not POSIX */
|