00001 #ifndef __J2K_NTO__CONIO_H__
00002 #define __J2K_NTO__CONIO_H__
00003
00004 #include <stdio.h>
00005 #include <unistd.h>
00006 #include <termios.h>
00007 #include <time.h>
00008
00009 inline char getch()
00010 {
00011 fflush( stdin );
00012 fflush( stdout );
00013 register char ch = 0;
00014 struct timespec rqtp;
00015
00016 struct termios raw_tios =
00017 {
00018 0,
00019 0,
00020 #ifdef __QNXNTO__
00021 (CREAD|HUPCL),
00022 #else
00023 (CREAD),
00024 #endif
00025 #ifdef __QNXNTO__
00026 0,
00027 #else
00028 (IEXTEN),
00029 #endif
00030 };
00031 struct termios tios;
00032
00033 rqtp.tv_sec = 0;
00034 rqtp.tv_nsec = 5000000;
00035 tcgetattr(0, &tios);
00036 while (tcischars(0) == 0) {nanosleep(&rqtp, NULL);}
00037 tcsetattr(0, TCSANOW, &raw_tios);
00038
00039 read (0, &ch, 1);
00040
00041 tcsetattr(0, TCSANOW, &tios);
00042 return ch;
00043 }
00044
00045 inline char getche()
00046 {
00047 register char ch = getch();
00048 putc( ch, stdout );
00049 fflush( stdout );
00050 return ch;
00051 }
00052
00053 inline int kbhit()
00054 {
00055 return ( (tcischars(1) > 0) ? 1 : 0 );
00056 }
00057
00058 #endif