/* Configuration du terminal */ /* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "tty.h" #include #include #define DEFAULT_TTY_INTR '\003' /* ^C */ #define DEFAULT_TTY_QUIT '\034' /* ^\ */ #define DEFAULT_TTY_SUSP '\032' /* ^Z */ static int tty; static int tty_setup; static struct termios saved_termios; int tty_echo; int tty_isig; char tty_intr; char tty_quit; char tty_susp; void setup_tty() { struct termios termios; tty = fileno(rl_instream); tty_setup = 0; if (tcgetattr(tty, &saved_termios) == -1) { tty_echo = 0; tty_isig = 0; return; } tty_echo = saved_termios.c_lflag & ECHO; if ((tty_isig = saved_termios.c_lflag & ISIG)) { tty_intr = saved_termios.c_cc[VINTR]; tty_quit = saved_termios.c_cc[VQUIT]; tty_susp = saved_termios.c_cc[VSUSP]; } else { /* valeurs par defaut */ tty_isig = 1; /* simulation des signaux du clavier */ tty_intr = DEFAULT_TTY_INTR; tty_quit = DEFAULT_TTY_QUIT; tty_susp = DEFAULT_TTY_SUSP; } termios = saved_termios; termios.c_iflag &= ~(ICRNL | INLCR); termios.c_lflag &= ~(ICANON | ECHO | ISIG); termios.c_cc[VMIN] = 1; termios.c_cc[VTIME] = 0; if (tcsetattr(tty, TCSADRAIN, &termios) == -1) return; tty_setup = 1; } void restore_tty() { if (tty_setup) tcsetattr(tty, TCSADRAIN, &saved_termios); }