diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-22 19:58:27 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-22 19:58:27 +0200 |
commit | f498fb6dbbeab4b2993b834a6abd41ba8c2ed316 (patch) | |
tree | 996160c574ef2efb0145fc9cf007404facf3977a | |
parent | Unfinished (diff) | |
download | 42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.gz 42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.bz2 42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.xz 42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.tar.zst 42-minishell-f498fb6dbbeab4b2993b834a6abd41ba8c2ed316.zip |
On the way but norm this shit
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | TODO.org | 1 | ||||
-rw-r--r-- | src/e_line.c | 2 | ||||
-rw-r--r-- | src/e_line.h | 2 | ||||
-rw-r--r-- | src/m_comm.c | 2 | ||||
-rw-r--r-- | src/m_loop.c | 15 | ||||
-rw-r--r-- | src/p_redirs.c | 13 | ||||
-rw-r--r-- | src/s_com.c | 4 | ||||
-rw-r--r-- | src/s_lredir.c | 16 |
9 files changed, 40 insertions, 17 deletions
@@ -1,4 +1,4 @@ -default: msan +default: debug #==============================================================================# #--------------------------------- SHELL --------------------------------------# #==============================================================================# @@ -49,6 +49,7 @@ ** TODO Handle memory ** TODO Fix ~ only first pos of arg ** TODO exit 25 leak is back +** TODO -c option full redo ** TODO Various in-code TODO * Stuff to add diff --git a/src/e_line.c b/src/e_line.c index c0edb60..726c3f3 100644 --- a/src/e_line.c +++ b/src/e_line.c @@ -22,7 +22,7 @@ #include "s_struct.h" #include "u_utils.h" -void e_line(t_msh *msh) +void e_line_block(t_msh *msh) { uint8_t bu_id; diff --git a/src/e_line.h b/src/e_line.h index 9940b55..e3e1e8f 100644 --- a/src/e_line.h +++ b/src/e_line.h @@ -17,6 +17,6 @@ # include "s_struct.h" -void e_line(t_msh *msh); +void e_line_block(t_msh *msh); #endif diff --git a/src/m_comm.c b/src/m_comm.c index 3580403..7dc574d 100644 --- a/src/m_comm.c +++ b/src/m_comm.c @@ -24,7 +24,7 @@ uint8_t m_comm(const char line[], t_msh *msh) if (line[0] != '\0') { p_line((char*)line, msh); - e_line(msh); + e_line_block(msh); s_line_clear(&msh->curr); } else diff --git a/src/m_loop.c b/src/m_loop.c index 0be77a2..a2cf621 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -45,12 +45,15 @@ static void m_parse_and_run_line(char line[], uint8_t previf, t_msh *msh) if ((previf == 0) || (previf == 1 && msh->ret == 0) || (previf == 2 && msh->ret != 0)) { - if (p_find_good_pipe(ptr->lblock) == TRUE - && (s_split_pipes(ptr->lblock, msh)) == NULL) - break ; - else if ((msh->com = s_com_new(ptr->lblock, msh)) == NULL) - break ; - e_line(msh); + if ((p_find_good_pipe(ptr->lblock) == TRUE + && (s_split_pipes(ptr->lblock, msh)) == NULL) + || (msh->com = s_com_new(ptr->lblock, msh)) == NULL) + { + previf = ptr->nextif; + ptr = ptr->next; + continue ; + } + e_line_block(msh); if (msh->com != NULL) s_com_destroy(&msh->com); if (msh->pipes != NULL) diff --git a/src/p_redirs.c b/src/p_redirs.c index 108a2a3..0ecdee7 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -30,7 +30,7 @@ #include "u_parse.h" #include "u_vars.h" -static void p_append_redir(const char path[], +static uint8_t p_append_redir(const char path[], int32_t fd_rdr[], t_com *com, t_msh *msh) @@ -44,8 +44,7 @@ static void p_append_redir(const char path[], new = s_lredir_new(path, fd, redir); if (new == NULL) { - /* TODO: return (1) and abort command right here */ - return ; + return (1); } new->heredoc = NULL; if (redir == -2 || redir == -3) @@ -53,6 +52,7 @@ static void p_append_redir(const char path[], new->heredoc = p_get_heredoc(path, redir, msh); } s_lredir_add_back(&com->rdr, new); + return (0); } static size_t p_get_path(char path[], @@ -108,7 +108,7 @@ static int32_t p_get_fd(const char word[], char *ptr) return (ft_atoi(digit)); } -static void p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh) +static uint8_t p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh) { struct s_rdr_tmp tmp; char path[PATH_MAX]; @@ -131,7 +131,7 @@ static void p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh) pos[1] = p_get_path(path, tmp, msh); (void)ft_memmove(word + pos[0], word + pos[1], (ft_strlen(word + pos[1]) + 1) * sizeof(char)); - p_append_redir(path, fd_rdr, com, msh); + return (p_append_redir(path, fd_rdr, com, msh)); } int8_t p_redirs(char word[], t_com **com, t_msh *msh) @@ -149,7 +149,8 @@ int8_t p_redirs(char word[], t_com **com, t_msh *msh) mode = u_meet_squote(word, ptr, mode); else if (mode == Q_NONE && (*ptr == '<' || *ptr == '>') == 1) { - p_get_redir(word, ptr, *com, msh); + if (p_get_redir(word, ptr, *com, msh) != 0) + return (1); ptr = word; } ptr++; diff --git a/src/s_com.c b/src/s_com.c index 0f69993..7ed20bc 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -99,7 +99,11 @@ static void *s_get_nword(char nword[], char word[], t_com *com, t_msh *msh) nword[0] = C_NUL; ft_strlcpy(nword, word, ARG_MAX); if (p_redirs(nword, &com, msh) != 0) + { + msh->ret = 1; + ft_memdel((void*)&com); return (NULL); + } if (msh->alias != NULL) { ret = p_subst_alias(nword, TRUE, msh); diff --git a/src/s_lredir.c b/src/s_lredir.c index 109f313..b2e94e8 100644 --- a/src/s_lredir.c +++ b/src/s_lredir.c @@ -13,12 +13,14 @@ #include <libft.h> #include <stdint.h> #include <stdlib.h> +#include <unistd.h> #ifdef __linux__ # include <linux/limits.h> #else # include <limits.h> #endif +#include "d_define.h" #include "s_struct.h" static t_lredir *s_lredir_last(struct s_lredir *lredir) @@ -66,8 +68,17 @@ void s_lredir_clear(struct s_lredir **lredir) static int32_t s_get_right_fd(const char path[]) { + char *ptr; int32_t rfd; + ptr = (char*)path; + while (ft_isdigit(*ptr) == TRUE) + ptr++; + if (*ptr != C_NUL) + { + ft_dprintf(STDERR_FILENO, "minishell: %s: ambigous redirect\n", path); + return (-1); + } rfd = 0; return (rfd); } @@ -80,8 +91,11 @@ struct s_lredir *s_lredir_new(const char path[], int32_t fd, int8_t redir) return (NULL); rdr->fd = fd; rdr->right_fd = -1; - if (redir == 3 && rdr->right_fd = s_get_right_fd(path) == -1) + if (redir == 3 && (rdr->right_fd = s_get_right_fd(path)) == -1) + { + ft_memdel((void*)&rdr); return (NULL); + } rdr->redir = redir; rdr->next = NULL; ft_strlcpy(rdr->path, path, PATH_MAX); |