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.
 
 

94 lines
2.1 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/07 11:54:34 by narnaud #+# #+# */
/* Updated: 2022/03/22 15:38:08 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char **get_commands(char *line)
{
char **split;
split = ft_split(line, '|');
return (split);
}
int is_empty(char *line)
{
while (*line)
{
if (*line <= 9 || (*line >= 13 && *line != 32))
return (0);
line++;
}
return (1);
}
int msg_n_ret(char *msg, int ret)
{
printf("%s", msg);
return (ret);
}
int init_file(char *filename, int mode)
{
return (open(filename, mode | O_CREAT, 0644));
}
int is_space(char ch)
{
if (ch == 32 || (ch > 8 && ch < 14))
return (1);
else
return (0);
}
void termios(int ctl)
{
struct termios termios_p;
int tty;
tty = ttyslot();
if (tcgetattr(tty, &termios_p) < 0)
{
perror("stdin");
exit (EXIT_FAILURE);
}
//termios_p.c_oflag &= CRDLY;
//termios_p.c_lflag &= ICANON;
if (ctl)
{
termios_p.c_lflag |= ECHOCTL;
termios_p.c_cc[VQUIT] = 28;
}
else
{
termios_p.c_lflag &= ~(ECHOCTL);
termios_p.c_cc[VQUIT] = 0;
}
tcsetattr(tty, TCSANOW, &termios_p);
}
void sigs_handler(int sig_num)
{
if (sig_num == SIGQUIT)
printf("QUIT: 3\n");
else if (sig_num == SIGINT)
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
return ;
}
void halt(int ret_code)
{
printf("exit");
exit(ret_code);
}