You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.7 KiB
68 lines
1.7 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* 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);
|
|
}
|
|
|