# HG changeset patch # User Markus Bröker # Date 1239878952 -7200 # Node ID 6b3d7e3418c11545bc07c42c8843f53999b3f473 # Parent 1fa566e9d13f19076abb3359f7622273dae8b88c getch.c renamed to cross_getch.c committer: Markus Bröker diff --git a/libConsole/Makefile b/libConsole/Makefile --- a/libConsole/Makefile +++ b/libConsole/Makefile @@ -16,7 +16,7 @@ Console.java OBJECTS= \ - getch.o + cross_getch.o .SUFFIXES: .java diff --git a/libConsole/cross_getch.c b/libConsole/cross_getch.c new file mode 100644 --- /dev/null +++ b/libConsole/cross_getch.c @@ -0,0 +1,41 @@ +#include +#include +#include + +#ifdef WIN32 +#include + +int cross_getch () +{ + int ch = -1; + + while (!kbhit ()) { + ch = getch (); + } + + return ch; +} + +#else +#include + +int cross_getch () +{ + int ch = -1, fd = 0; + struct termios neu, alt; + + fd = fileno (stdin); + tcgetattr (fd, &alt); + neu = alt; + neu.c_lflag &= ~(ICANON | ECHO); + tcsetattr (fd, TCSANOW, &neu); + ch = getchar (); + tcsetattr (fd, TCSANOW, &alt); + return ch; +} +#endif + +JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass) +{ + return cross_getch (); +} diff --git a/libConsole/getch.c b/libConsole/getch.c deleted file mode 100644 --- a/libConsole/getch.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include - -#ifdef WIN32 -#include - -int cross_getch () -{ - int ch = -1; - - while (!kbhit ()) { - ch = getch (); - } - - return ch; -} - -#else -#include - -int cross_getch () -{ - int ch = -1, fd = 0; - struct termios neu, alt; - - fd = fileno (stdin); - tcgetattr (fd, &alt); - neu = alt; - neu.c_lflag &= ~(ICANON | ECHO); - tcsetattr (fd, TCSANOW, &neu); - ch = getchar (); - tcsetattr (fd, TCSANOW, &alt); - return ch; -} -#endif - -JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass) -{ - return cross_getch (); -}