diff --git a/headers/minishell_prototypes.h b/headers/minishell_prototypes.h index fb0f4ab..a3996de 100644 --- a/headers/minishell_prototypes.h +++ b/headers/minishell_prototypes.h @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */ -/* Updated: 2021/12/20 14:58:00 by hulamy ### ########.fr */ +/* Updated: 2021/12/20 15:07:39 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/exec/find_access.c b/srcs/exec/find_access.c index 13e1b2b..3172460 100644 --- a/srcs/exec/find_access.c +++ b/srcs/exec/find_access.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ -/* Updated: 2021/12/16 05:57:42 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:23:40 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,15 @@ static t_builtin_f search_builtin(char *cmd_name); static int handle_access_error(char *file_name); /* - 2.8.2 Exit Status for Commands -https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html -#tag_18_08_02 -*/ + * 2.8.2 Exit Status for Commands + * https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html + * #tag_18_08_02 + */ -// TODO : faire des test sur la valeur de errno selon les cas (if directory, if pathname invalid, ...) +/* + * TODO : faire des test sur la valeur de errno selon les cas (if directory, if + * pathname invalid, ...) + */ int cmd_find_access(t_cmd *cmd, char *path[]) { diff --git a/srcs/main.c b/srcs/main.c index 9819607..ea21cb4 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */ -/* Updated: 2021/12/20 14:57:48 by hulamy ### ########.fr */ +/* Updated: 2021/12/20 15:07:31 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/parsing/expansions/expand_token.c b/srcs/parsing/expansions/expand_token.c index 1559d26..f0f242e 100644 --- a/srcs/parsing/expansions/expand_token.c +++ b/srcs/parsing/expansions/expand_token.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */ -/* Updated: 2021/12/16 03:03:27 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:47:04 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ t_list *expand_token(char *content) expand->next = content_copy(content, &i, "es_state); expand = expand->next; if (!expand) - {//todo wrap + { perror("expand_token() error"); return (ft_lstclear(&head.next, free)); } @@ -88,7 +88,7 @@ static char *env_var_expansion(char *content, int *i) { char *expansion; - (*i)++; // skip '$' + (*i)++; if (content[*i] == '?') { (*i)++; @@ -112,7 +112,7 @@ static char *retrieve_var(char *content, int *i) char *tmp; int i_exp; - expansion = ft_calloc(ft_strlen(&content[*i - 1]) + 1, 1); // *i - 1 for '$' skip + expansion = ft_calloc(ft_strlen(&content[*i - 1]) + 1, 1); if (!expansion) return (NULL); i_exp = 0; diff --git a/srcs/parsing/expansions/new_token_for_each_field.c b/srcs/parsing/expansions/new_token_for_each_field.c index 91d72f1..951b02b 100644 --- a/srcs/parsing/expansions/new_token_for_each_field.c +++ b/srcs/parsing/expansions/new_token_for_each_field.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */ -/* Updated: 2021/12/10 19:11:52 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:56:05 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ int new_token_for_each_field(char **fields, t_token *t) insert_lst->next = ft_lstnew_generic(sizeof(t_token), 0); insert_lst = insert_lst->next; if (!insert_lst) - {//todo wrap + { perror("insert_token_for_each_field() error"); ft_free_2d_arr(fields); return ((int)ft_lstclear((t_list **)&head.next, NULL)); @@ -51,11 +51,8 @@ static void insert_tokens(t_token *t, t_token *insert_lst) ft_free_null(&t->content); if (!insert_lst) return ; - tmp = t->next; t->next = insert_lst; insert_lst_last = (t_token *)ft_lstlast((t_list *)insert_lst); insert_lst_last->next = tmp; - - //return (insert_lst_last); // return inutile pour reusinage } diff --git a/srcs/parsing/expansions/rejoin_after_expand.c b/srcs/parsing/expansions/rejoin_after_expand.c index 917b921..5b69c65 100644 --- a/srcs/parsing/expansions/rejoin_after_expand.c +++ b/srcs/parsing/expansions/rejoin_after_expand.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */ -/* Updated: 2021/11/07 04:03:02 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:55:03 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,9 +23,9 @@ char *rejoin_after_expand(t_list *expand_lst) { result = ft_strjoinfree_s1(result, expand_lst->content); if (!result) - {//todo wrap + { perror("rejoin_after_expand() error"); - return (ft_lstclear(&head, free)); + return (ft_lstclear(&head, free)); } expand_lst = expand_lst->next; } diff --git a/srcs/parsing/redirections/here_doc.c b/srcs/parsing/redirections/here_doc.c index c5d9693..0561d05 100644 --- a/srcs/parsing/redirections/here_doc.c +++ b/srcs/parsing/redirections/here_doc.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ -/* Updated: 2021/12/18 15:24:25 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:24:51 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,7 +85,7 @@ static int here_doc_write_interactive(char *delimiter, int doc_fd) return (set_last_exit_status(EXIT_SIGNAL + SIGINT)); if (!line) return (shell_error(WARNING_EOF, delimiter, "')", 0)); - if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois. + if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) break ; if (write(doc_fd, line, ft_strlen(line)) == -1) return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC)); @@ -109,7 +109,7 @@ static int here_doc_write_script(char *delimiter, int doc_fd) ret = gnl(STDIN_FILENO, &line, 0); if (ret == -1) return (ft_reti_perror_free(-1, line, free, "gnl() STDIN")); - if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois. + if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) break ; if (write(doc_fd, line, ft_strlen(line)) == -1) return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC)); diff --git a/srcs/parsing/redirections/redirections.c b/srcs/parsing/redirections/redirections.c index a1f354d..987d2b0 100644 --- a/srcs/parsing/redirections/redirections.c +++ b/srcs/parsing/redirections/redirections.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ -/* Updated: 2021/12/11 21:32:31 by lperrey ### ########.fr */ +/* Updated: 2021/12/20 14:53:12 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int here_doc(char *delimiter); -static int redirect_cmd_input(t_token *t, t_cmd *cmd); +static int redirect_cmd_less(t_token *t, t_cmd *cmd); +static int redirect_cmd_dless(t_token *t, t_cmd *cmd); static int redirect_cmd_output(t_token *t, t_cmd *cmd); static int expand_redirection(t_token *t); @@ -29,11 +30,10 @@ int redirections(t_token *t, t_cmd **pipeline) i++; if (!pipeline[i]->error) { - if (t->id == '<' || t->id == T_DLESS) - { - if (!redirect_cmd_input(t, pipeline[i])) - return (0); - } + if (t->id == '<' && !redirect_cmd_less(t, pipeline[i])) + return (0); + else if (t->id == T_DLESS && !redirect_cmd_dless(t, pipeline[i])) + return (0); else if (t->id == '>' || t->id == T_DGREAT) { if (!redirect_cmd_output(t, pipeline[i])) @@ -45,7 +45,7 @@ int redirections(t_token *t, t_cmd **pipeline) return (1); } -static int redirect_cmd_input(t_token *t, t_cmd *cmd) +static int redirect_cmd_less(t_token *t, t_cmd *cmd) { if (cmd->fd_in != STDIN_FILENO) if (close(cmd->fd_in) == -1) @@ -54,7 +54,7 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd) { if (!expand_redirection(t)) { - cmd->error = EXIT_REDIRECTION; + cmd->error = EXIT_REDIRECTION; return (1); } cmd->fd_in = open(t->next->content, O_RDONLY); @@ -64,6 +64,14 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd) cmd->error = EXIT_REDIRECTION; } } + return (1); +} + +static int redirect_cmd_dless(t_token *t, t_cmd *cmd) +{ + if (cmd->fd_in != STDIN_FILENO) + if (close(cmd->fd_in) == -1) + perror("close()"); else if (t->id == T_DLESS) { cmd->fd_in = here_doc(t->next->content); @@ -90,7 +98,7 @@ static int redirect_cmd_output(t_token *t, t_cmd *cmd) perror("close()"); if (!expand_redirection(t)) { - cmd->error = EXIT_REDIRECTION; + cmd->error = EXIT_REDIRECTION; return (1); } flags = O_WRONLY | O_CREAT; @@ -110,7 +118,7 @@ static int redirect_cmd_output(t_token *t, t_cmd *cmd) static int expand_redirection(t_token *t) { t_token *head; - t_token *next_token; + t_token *next_token; int ret; ret = 1; @@ -126,7 +134,7 @@ static int expand_redirection(t_token *t) head->next = t->next; free(t); if (head->next) - head->next->id = T_REDIRECTION_WORD; // Eventuellement a integrer dans token_expansions() + head->next->id = T_REDIRECTION_WORD; if (ft_lstsize((t_list *)head->next) != 1) { ret = 0;