-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9db35a0
Showing
21 changed files
with
2,564 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* Extremely inefficient but portable POSIX getch() */ | ||
#ifndef WIN32 | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <termios.h> /* for tcgetattr() and tcsetattr() */ | ||
#include <unistd.h> /* for read() */ | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <sys/time.h> | ||
#include "getch.h" | ||
|
||
#ifndef STDIN_FILENO | ||
# define STDIN_FILENO 0 | ||
#endif | ||
|
||
int | ||
getch (void) | ||
{ | ||
struct termios save_termios; | ||
struct termios ios; | ||
int c = 0; | ||
|
||
if (!isatty (STDIN_FILENO)) | ||
return EOF; | ||
|
||
if (tcgetattr (STDIN_FILENO, &save_termios) < 0) | ||
return EOF; | ||
|
||
ios = save_termios; | ||
ios.c_lflag &= ~(ICANON | ECHO | ISIG); | ||
ios.c_cc[VMIN] = 1; /* read() will return with one char */ | ||
ios.c_cc[VTIME] = 0; /* read() blocks forever */ | ||
|
||
if (tcsetattr (STDIN_FILENO, TCSANOW, &ios) < 0) | ||
return EOF; | ||
|
||
if (read (STDIN_FILENO, &c, 1) != 1) | ||
c = EOF; | ||
|
||
tcsetattr (STDIN_FILENO, TCSANOW, &save_termios); | ||
|
||
return c; | ||
} | ||
|
||
int | ||
kbhit (void) | ||
{ | ||
struct termios save_termios; | ||
struct termios ios; | ||
fd_set inp; | ||
struct timeval timeout = {0, 0}; | ||
int result; | ||
|
||
if (!isatty (STDIN_FILENO)) | ||
return 0; | ||
|
||
if (tcgetattr (STDIN_FILENO, &save_termios) < 0) | ||
return 0; | ||
|
||
ios = save_termios; | ||
ios.c_lflag &= ~(ICANON | ECHO | ISIG); | ||
ios.c_cc[VMIN] = 1; /* read() will return with one char */ | ||
ios.c_cc[VTIME] = 0; /* read() blocks forever */ | ||
|
||
if (tcsetattr (STDIN_FILENO, TCSANOW, &ios) < 0) | ||
return 0; | ||
|
||
/* set up select() args */ | ||
FD_ZERO(&inp); | ||
FD_SET(STDIN_FILENO, &inp); | ||
|
||
result = select (STDIN_FILENO+1, &inp, NULL, NULL, &timeout) == 1; | ||
|
||
tcsetattr (STDIN_FILENO, TCSANOW, &save_termios); | ||
|
||
return result; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* Extremely inefficient but portable POSIX getch(), see getch.c */ | ||
#ifndef GETCH_H | ||
#define GETCH_H | ||
|
||
#if defined __cplusplus | ||
extern "C" { | ||
#endif | ||
int getch(void); | ||
int kbhit(void); | ||
|
||
#if defined __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* GETCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Things needed to compile under linux. | ||
* | ||
* Should be reworked totally to use GNU's 'configure' | ||
*/ | ||
#ifndef SCLINUX_H | ||
#define SCLINUX_H | ||
|
||
/* getchar() is not a 'cool' replacement for MSDOS getch: Linux/unix depends on the features activated or not about the | ||
* controlling terminal's tty. This means that ioctl(2) calls must be performed, for instance to have the controlling | ||
* terminal tty's in 'raw' mode, if we want to be able to fetch a single character. This also means that everything must | ||
* be put back correctly when the function ends. See GETCH.C for an implementation. | ||
* | ||
* For interactive use of SRUN/SDBG if would be much better to use GNU's readline package: the user would be able to | ||
* have a complete emacs/vi like line editing system. | ||
*/ | ||
#include "getch.h" | ||
|
||
#define stricmp(a,b) strcasecmp(a,b) | ||
#define strnicmp(a,b,c) strncasecmp(a,b,c) | ||
|
||
/* | ||
* WinWorld wants '\'. Unices do not. | ||
*/ | ||
#define DIRECTORY_SEP_CHAR '/' | ||
#define DIRECTORY_SEP_STR "/" | ||
|
||
/* | ||
* SC assumes that a computer is Little Endian unless told otherwise. It uses | ||
* (and defines) the macros BYTE_ORDER and BIG_ENDIAN. | ||
* For Linux, we must overrule these settings with those defined in glibc. | ||
*/ | ||
#if !defined __BYTE_ORDER | ||
# include <stdlib.h> | ||
#endif | ||
|
||
#if defined __OpenBSD__ || defined __FreeBSD__ | ||
# define __BYTE_ORDER BYTE_ORDER | ||
# define __LITTLE_ENDIAN LITTLE_ENDIAN | ||
# define __BIG_ENDIAN BIG_ENDIAN | ||
#endif | ||
|
||
#if !defined __BYTE_ORDER | ||
# error "Can't figure computer byte order (__BYTE_ORDER macro not found)" | ||
#endif | ||
|
||
#endif /* SCLINUX_H */ |
Oops, something went wrong.