/* termios テストプログラム */ /* デフォルトの設定 : シグナル(Ctrl-C/Ctrl-Z)を受け付ける */ /* c_iflag &= IGNCR : ENTER の入力を無視する(Ctrl-D:EOF)で入力完了 */ /* c_lflag &= ~ICANON : 非カノニカルモード(キー押下時点で入力を受け付ける) */ /* c_lflag &= ~ECNO : 入力をエコーしない */ /* c_lflag &= ~ISIG : シグナルを無視する */ #include #include #include #include #include int main() { struct termios save_term; struct termios temp_term; int wretc; int inch; /* 現在の入力設定を取得 */ wretc = tcgetattr(fileno(stdin), &save_term); if (wretc == -1) { perror("tcgetattr ERROR"); exit(1); } /* 現在の入力設定をコピー */ temp_term = save_term; printf("VMIN = %d\n", temp_term.c_cc[VMIN]); printf("VTIME = %d\n", temp_term.c_cc[VTIME]); /* 設定を変更 */ temp_term.c_iflag &= IGNCR; /* CR の入力を無視する */ temp_term.c_lflag &= ~ICANON; /* 非カノニカルモードにする */ temp_term.c_lflag &= ~ECHO; /* 入力のエコーを行わないようにする */ temp_term.c_lflag &= ~ISIG; /* シグナルを無視する */ wretc = tcsetattr(fileno(stdin), TCSANOW, &temp_term); if (wretc == -1) { perror("tcsetattr ERROR"); exit(1); } /* 入力を受け付ける */ inch = '\0'; while (inch != 'q') { inch = getchar(); printf("input = 0x%02x", inch); if (iscntrl(inch) == 0) { printf(" (%c)\n", inch); } else { printf("\n"); } } /* 設定を元に戻す */ wretc = tcsetattr(fileno(stdin), TCSANOW, &save_term); if (wretc == -1) { perror("tcsetattr ERROR"); exit(1); } }