#include #include #include #ifndef USE_OLD_TTY #include #endif static struct termios org_tbuf; static struct termios set_tbuf; #ifdef USE_OLD_TTY static struct sgttyb org_tbuf; static struct sgttyb set_tbuf; #endif static int call_flag; int init_getch(void) { if(call_flag != 0){ return 0; } else{ call_flag = 1; } if(ioctl(0, TIOCGETA, &org_tbuf) == -1){ fprintf(stderr, "ioctl error!\n"); exit(0); } if(ioctl(0, TIOCGETA, &set_tbuf) == -1){ fprintf(stderr, "ioctl error!\n"); exit(0); } set_tbuf.c_lflag = (set_tbuf.c_lflag & ~ICANON); if(ioctl(0, TIOCSETA, &set_tbuf) == -1){ fprintf(stderr, "ioctl error!\n"); exit(0); } return 1; } int getch(void) { /* char buf; if(read(0, &buf, 1) == -1){ return -1; } else{ return (int)buf; } */ return getc(stdin); } int close_getch(void) { if(call_flag == 0){ return 0; } else{ call_flag = 0; } if(ioctl(0, TIOCSETA, &org_tbuf) == -1){ fprintf(stderr, "ioctl error!\n"); exit(0); } return 1; }