diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 21:05:23 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 21:05:23 +0200 |
commit | f02b44e3b49743c6217233ec6498f7a5151f81fc (patch) | |
tree | a7435803ac2f089977909307c06b9246c804fb2a | |
parent | Commit (diff) | |
download | 42-minishell-f02b44e3b49743c6217233ec6498f7a5151f81fc.tar.gz 42-minishell-f02b44e3b49743c6217233ec6498f7a5151f81fc.tar.bz2 42-minishell-f02b44e3b49743c6217233ec6498f7a5151f81fc.tar.xz 42-minishell-f02b44e3b49743c6217233ec6498f7a5151f81fc.tar.zst 42-minishell-f02b44e3b49743c6217233ec6498f7a5151f81fc.zip |
Norming p_lblock_next
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/p_lblock_more.c | 45 | ||||
-rw-r--r-- | src/p_lblock_more.h | 20 | ||||
-rw-r--r-- | src/p_lblock_next.c | 58 |
4 files changed, 82 insertions, 42 deletions
@@ -76,6 +76,7 @@ SRCS_NAME += p_args_escape SRCS_NAME += p_line SRCS_NAME += p_lblock SRCS_NAME += p_lblock_next +SRCS_NAME += p_lblock_more SRCS_NAME += p_redirs SRCS_NAME += p_redirs_heredoc SRCS_NAME += p_split diff --git a/src/p_lblock_more.c b/src/p_lblock_more.c new file mode 100644 index 0000000..ac61605 --- /dev/null +++ b/src/p_lblock_more.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_lblock_more.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <stddef.h> + +#include "s_struct.h" +#include "u_vars_next.h" + +void p_register_word(char word[], t_msh *msh) +{ + char val[ARG_MAX]; + char name[255]; + char *ptr; + size_t i; + + name[0] = '$'; + ptr = word; + i = 1; + while (*ptr != '\0' && *ptr != '=') + { + name[i] = *ptr; + i++; + ptr++; + } + name[i] = '\0'; + ptr++; + i = 0; + while (*ptr != '\0') + { + val[i] = *ptr; + i++; + ptr++; + } + val[i] = '\0'; + u_subst_var_value(name, val, msh); +} diff --git a/src/p_lblock_more.h b/src/p_lblock_more.h new file mode 100644 index 0000000..671f49f --- /dev/null +++ b/src/p_lblock_more.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_lblock_more.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_P_LBLOCK_MORE_H +# define FT_P_LBLOCK_MORE_H + +# include "s_struct.h" + +void p_register_word(char word[], t_msh *msh); + +#endif diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 49bedd6..03d7f80 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -18,6 +18,7 @@ #include "d_define.h" #include "s_destroy.h" #include "f_fail.h" +#include "p_lblock_more.h" #include "s_struct.h" #include "u_alias.h" #include "u_parse.h" @@ -210,61 +211,34 @@ char **p_subst_home(char *words[], t_msh *msh) return (words); } -static void p_register_word(char word[], t_msh *msh) +static char **p_alloc_rewords(char *words[], int64_t j, t_msh *msh) { - char name[255]; - char val[ARG_MAX]; - char *ptr; - size_t i; + char **rewords; - name[0] = '$'; - ptr = word; - i = 1; - while (*ptr != '=' && *ptr != '\0') - { - name[i] = *ptr; - i++; - ptr++; - } - name[i] = '\0'; - ptr++; - i = 0; - while (*ptr != '\0') + if ((rewords = (char**)malloc((j + 1) * sizeof(char*))) == NULL) { - val[i] = *ptr; - i++; - ptr++; + ft_delwords(words); + f_alloc_and_destroy_msh(msh); } - val[i] = '\0'; - u_subst_var_value(name, val, msh); + return (rewords); } static char **p_add_to_variables_and_delete(char *words[], - t_bool reg, - int64_t i, - t_msh *msh) + t_bool reg, + int64_t i, + t_msh *msh) { char **rewords; int64_t j; int64_t k; - j = 0; - if (reg == TRUE) - { - while (words[j] && j < i) - { - p_register_word(words[j], msh); - j++; - } - } + j = -1; + while (reg == TRUE && words[++j] != NULL && j < i) + p_register_word(words[j], msh); j = 0; while (words[i + j] != NULL) j++; - if ((rewords = (char**)malloc((j + 1) * sizeof(char*))) == NULL) - { - ft_delwords(words); - f_alloc_and_destroy_msh(msh); - } + rewords = p_alloc_rewords(words, j, msh); k = i; while (i - k < j) { @@ -319,14 +293,14 @@ char **p_check_args_equals(char *words[], t_msh *msh) while (words[++i] != NULL) { ptr = p_set_ptr(words, i, ®, &isvar); - if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0])) + if (*ptr == C_NUL || words[i][0] == '=' || ft_isdigit(words[i][0])) { reg = FALSE; isvar = (i == 0) ? (FALSE) : (isvar); if (isvar == TRUE) p_add_to_env_fork(i, words, msh); else - msh->env_fork_tmp[0][0] = '\0'; + msh->env_fork_tmp[0][0] = C_NUL; break ; } } |