/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */ /* Updated: 2022/05/05 09:18:28 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int is_empty(char *line) { while (*line) { if (*line <= 9 || (*line >= 13 && *line != 32)) return (0); line++; } return (1); } void nothing(int sig_num) { (void)sig_num; } void termios(int ctl) { struct termios termios_p; int tty; tty = ttyslot(); if (tcgetattr(tty, &termios_p) < 0) exit ((perror("stdin"), EXIT_FAILURE)); if (ctl) { termios_p.c_lflag |= ECHOCTL; signal(SIGINT, nothing); signal(SIGQUIT, nothing); } else { termios_p.c_lflag &= ~(ECHOCTL); signal(SIGINT, sigs_handler); signal(SIGQUIT, sigs_handler); } termios_p.c_cc[VQUIT] = ctl * 28; tcsetattr(tty, TCSANOW, &termios_p); } void sigs_handler(int sig_num) { if (sig_num == SIGINT) printf("\n"); rl_on_new_line(); rl_replace_line("", 0); rl_redisplay(); return ; } void halt(int ret_code) { printf("exit\n"); exit(ret_code); }