|
|
@ -6,12 +6,28 @@ |
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/05 11:10:24 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/05 11:49:53 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
# include "minishell.h" |
|
|
|
|
|
|
|
void handle_status(t_datas *datas, int status) |
|
|
|
{ |
|
|
|
if (WIFSIGNALED(status)) |
|
|
|
{ |
|
|
|
datas->exit_code = WTERMSIG(status); |
|
|
|
if (datas->exit_code == 3) |
|
|
|
printf("Quit: 3\n"); |
|
|
|
if (datas->exit_code == 9) |
|
|
|
printf("Kill: 15\n"); |
|
|
|
if (datas->exit_code == 15) |
|
|
|
printf("Terminated: 15\n"); |
|
|
|
} |
|
|
|
else |
|
|
|
datas->exit_code = WEXITSTATUS(status); |
|
|
|
} |
|
|
|
|
|
|
|
int caller(t_datas *datas, t_command *cmd) |
|
|
|
{ |
|
|
|
pid_t pid; |
|
|
@ -40,18 +56,9 @@ int caller(t_datas *datas, t_command *cmd) |
|
|
|
if (cmd->fd[1]) |
|
|
|
close(cmd->fd[1]); |
|
|
|
if (cmd->next) |
|
|
|
return (caller(datas, cmd->next)); |
|
|
|
caller(datas, cmd->next); |
|
|
|
waitpid(pid, &status, 0); |
|
|
|
if (WIFSIGNALED(status)) |
|
|
|
{ |
|
|
|
datas->exit_code = WTERMSIG(status); |
|
|
|
if (datas->exit_code == 3) |
|
|
|
printf("Quit: 3\n"); |
|
|
|
if (datas->exit_code == 9) |
|
|
|
printf("Kill: 15\n"); |
|
|
|
if (datas->exit_code == 15) |
|
|
|
printf("Terminated: 15\n"); |
|
|
|
} |
|
|
|
handle_status(datas, status); |
|
|
|
if (cmd->fd[0]) |
|
|
|
close(cmd->fd[0]); |
|
|
|
return (1); |
|
|
@ -86,7 +93,7 @@ t_command *parser(t_token *tok, t_command *prev) |
|
|
|
return(cmd); |
|
|
|
} |
|
|
|
|
|
|
|
t_token *lexer(char *line) |
|
|
|
t_token *lexer(t_datas *datas, char *line) |
|
|
|
{ |
|
|
|
t_lexer *lex; |
|
|
|
char *tmp; |
|
|
@ -101,7 +108,7 @@ t_token *lexer(char *line) |
|
|
|
if (check_state(lex, &line)) |
|
|
|
continue; |
|
|
|
if (lex->state != S_QUOTE_ST && *line == '$') |
|
|
|
tmp_i = replace_var(&line, tmp, tmp_i); |
|
|
|
tmp_i = replace_var(datas, &line, tmp, tmp_i); |
|
|
|
if (check_register(lex, &line, tmp)) |
|
|
|
{ |
|
|
|
tmp_i = 0; |
|
|
@ -134,7 +141,7 @@ int main(int argc, char **argv, char **envp) |
|
|
|
halt(EXIT_FAILURE); |
|
|
|
if (is_empty(line)) |
|
|
|
continue ; |
|
|
|
caller(&datas, parser(lexer(line), NULL)); |
|
|
|
caller(&datas, parser(lexer(&datas, line), NULL)); |
|
|
|
add_history(line); |
|
|
|
} |
|
|
|
clear_history(); |
|
|
|