home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
editor
/
less
/
ttyin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-31
|
2KB
|
122 lines
/*
* Routines dealing with getting input from the keyboard (i.e. from the user).
*/
#include "less.h"
#if __MSDOS__
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#endif
#ifdef OS2
#undef NULL
#undef VOID
#undef CONTROL
#define INCL_DOSPROCESS
#define INCL_SUB
#define INCL_NOPM
#include <os2.h>
#include <stdio.h>
#endif
static int tty;
/*
* Open keyboard for input.
*/
public void
open_getchr()
{
#if __MSDOS__
/*
* Open a new handle to CON: in binary mode
* for unbuffered keyboard read.
*/
tty = open("CON", O_RDONLY|O_BINARY);
#else
/*
* Just use file descriptor 2, which in Unix
* is usually attached to the screen and keyboard.
*/
tty = 2;
#endif
}
/*
* Get a character from the keyboard.
*/
public int
getchr()
{
int c;
int result;
flush();
do
{
#ifdef OS2
static int ext, scan;
KBDKEYINFO ki;
if ( ext )
{
ext = 0;
c = scan;
}
else
{
KbdCharIn(&ki, IO_WAIT, 0);
c = ki.chChar;
if ( c == 0 || c == 0xE0 )
{
c = 0xE0;
ext = 1;
scan = ki.chScan;
}
}
result = 1;
#else
result = iread(tty, &c, sizeof(char));
if (result == READ_INTR)
return (READ_INTR);
#endif
if (result < 0)
{
/*
* Don't call error() here,
* because error calls getchr!
*/
quit(1);
}
#if __MSDOS__
/*
* In raw read, we don't see ^C so look here for it.
*/
if (c == '\003')
raise(SIGINT);
#endif
/*
* Various parts of the program cannot handle
* an input character of '\0'.
* If a '\0' was actually typed, convert it to '\200' here.
*/
if (c == '\0')
c = '\200';
} while (result != 1);
return (c);
}
#ifdef OS2
sleep(x)
int x;
{
DosSleep(1000L * x);
}
#endif