narnaud
3 years ago
9 changed files with 198 additions and 65 deletions
@ -1,2 +1,13 @@ |
|||
# Minishell |
|||
|
|||
|
|||
## TODO : |
|||
|
|||
|
|||
|
|||
## Notes : |
|||
|
|||
|
|||
|
|||
## Issues : |
|||
|
|||
|
@ -0,0 +1,108 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* utils.c :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/05/03 09:00:40 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "minishell.h" |
|||
|
|||
void push_heredoc(char *str, int fd) |
|||
{ |
|||
char *line; |
|||
|
|||
while(1) |
|||
{ |
|||
line = readline(">"); |
|||
if (!ft_strncmp(line, str, ft_strlen(str) + 1)) |
|||
break; |
|||
ft_putstr_fd(line, fd); |
|||
write(fd, "\n", 1); |
|||
} |
|||
} |
|||
|
|||
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); |
|||
} |
Loading…
Reference in new issue