diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 20:33:19 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 20:33:19 +0200 |
commit | f1cb52db53e6b25de301e7d95edaa359a1d2c99f (patch) | |
tree | 9ae920aa49f220c43420938c75c712695b0a12cb /src | |
parent | Renormed p_lblock (diff) | |
download | 42-minishell-f1cb52db53e6b25de301e7d95edaa359a1d2c99f.tar.gz 42-minishell-f1cb52db53e6b25de301e7d95edaa359a1d2c99f.tar.bz2 42-minishell-f1cb52db53e6b25de301e7d95edaa359a1d2c99f.tar.xz 42-minishell-f1cb52db53e6b25de301e7d95edaa359a1d2c99f.tar.zst 42-minishell-f1cb52db53e6b25de301e7d95edaa359a1d2c99f.zip |
Commit
Diffstat (limited to 'src')
-rw-r--r-- | src/p_lblock_next.c | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index b319229..49bedd6 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -25,10 +25,7 @@ #include "u_vars.h" #include "u_vars_next.h" -/* TODO: norme */ - -static char - *p_double_them_bs(char varval[]) +static char *p_double_them_bs(char varval[]) { char *ptr; @@ -45,8 +42,7 @@ static char return (varval); } -static void - p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) +static void p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) { char tmp[ARG_MAX]; char varval[ARG_MAX]; @@ -69,8 +65,7 @@ static void *(p) = word + (i + ft_strlen(varval) - 1); } -void - p_subst_vars(char word[], t_msh *msh) +void p_subst_vars(char word[], t_msh *msh) { char *ptr; t_quote_mode mode; @@ -92,16 +87,14 @@ void } } -static char - *p_skip_whitespace(char *ptr) +static char *p_skip_whitespace(char *ptr) { while (*ptr != C_NUL && ft_iswhitespace(*ptr)) ptr++; return (ptr); } -static t_bool - p_meet_whitespace(char *head, char *ptr, t_quote_mode mode) +static t_bool p_meet_whitespace(char *head, char *ptr, t_quote_mode mode) { if (mode == Q_NONE && u_is_not_escaped(head, ptr) == TRUE) { @@ -110,8 +103,7 @@ static t_bool return (FALSE); } -size_t - p_subst_alias(char word[], t_bool reset, t_msh *msh) +size_t p_subst_alias(char word[], t_bool reset, t_msh *msh) { static size_t used[4096]; static size_t i = 0; @@ -198,8 +190,7 @@ size_t return (0); } -char - **p_subst_home(char *words[], t_msh *msh) +char **p_subst_home(char *words[], t_msh *msh) { char path[PATH_MAX]; char **ptr; @@ -219,8 +210,7 @@ char return (words); } -static void - p_register_word(char word[], t_msh *msh) +static void p_register_word(char word[], t_msh *msh) { char name[255]; char val[ARG_MAX]; @@ -249,8 +239,7 @@ static void u_subst_var_value(name, val, msh); } -static char - **p_add_to_variables_and_delete(char *words[], +static char **p_add_to_variables_and_delete(char *words[], t_bool reg, int64_t i, t_msh *msh) @@ -292,10 +281,7 @@ static char return (rewords); } -static void - p_add_to_env_fork(int64_t i, - char *words[], - t_msh *msh) +static void p_add_to_env_fork(int64_t i, char *words[], t_msh *msh) { int64_t j; @@ -308,40 +294,41 @@ static void msh->env_fork_tmp[j][0] = '\0'; } -char - **p_check_args_equals(char *words[], t_msh *msh) +static char *p_set_ptr(char *words[], int64_t i, t_bool *reg, t_bool *isvar) +{ + char *ptr; + + ptr = words[i]; + while (*ptr != '\0' && *ptr != '=') + ptr++; + *reg = (*ptr == '=') ? (TRUE) : (*reg); + *isvar = (*ptr == '=') ? (TRUE) : (*isvar); + return (ptr); +} + +char **p_check_args_equals(char *words[], t_msh *msh) { char *ptr; + int64_t i; t_bool reg; t_bool isvar; - int64_t i; - i = 0; reg = FALSE; isvar = FALSE; - while (words[i]) + i = -1; + while (words[++i] != NULL) { - ptr = words[i]; - while (*ptr != '\0' && *ptr != '=') - ptr++; - if (*ptr == '=') - { - reg = TRUE; - isvar = TRUE; - } - if (*ptr == '\0' || words[i][0] == '=' || - ft_isdigit(words[i][0]) == TRUE) + ptr = p_set_ptr(words, i, ®, &isvar); + if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0])) { reg = FALSE; - if (i == 0) - isvar = 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'; break ; } - i++; } if (isvar == TRUE) return (p_add_to_variables_and_delete(words, reg, i, msh)); |