diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-12 16:33:02 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-12 16:33:02 +0200 |
commit | 949f93b57b6411b07eb12110e0db37cdf393db0c (patch) | |
tree | ce90ac0b84cbdab7c3ea2c47c8397310045db386 | |
parent | Fix (diff) | |
download | 42-minishell-949f93b57b6411b07eb12110e0db37cdf393db0c.tar.gz 42-minishell-949f93b57b6411b07eb12110e0db37cdf393db0c.tar.bz2 42-minishell-949f93b57b6411b07eb12110e0db37cdf393db0c.tar.xz 42-minishell-949f93b57b6411b07eb12110e0db37cdf393db0c.tar.zst 42-minishell-949f93b57b6411b07eb12110e0db37cdf393db0c.zip |
Fuck
-rw-r--r-- | src/b_alias.c | 2 | ||||
-rw-r--r-- | src/p_lblock_next.c | 55 | ||||
-rw-r--r-- | src/p_lblock_next.h | 3 | ||||
-rw-r--r-- | src/s_com.c | 7 | ||||
-rw-r--r-- | src/s_lalias.c | 5 | ||||
-rw-r--r-- | src/s_struct.h | 1 | ||||
-rw-r--r-- | src/u_alias.c | 8 |
7 files changed, 63 insertions, 18 deletions
diff --git a/src/b_alias.c b/src/b_alias.c index 8aff531..08298b3 100644 --- a/src/b_alias.c +++ b/src/b_alias.c @@ -50,7 +50,7 @@ static uint8_t } if (*ptr == C_NUL) { - if (u_get_alias_value(val, arg, ARG_MAX, msh) == 0) + if (u_get_alias_value(val, arg, ARG_MAX, msh) != 0) { ft_printf("alias %s='%s'", arg, val); return (0); diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 3fa0ea5..0c1c1f4 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -110,16 +110,30 @@ static t_bool return (FALSE); } -void - p_subst_alias(char word[], 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; char value[ARG_MAX]; char tmp[255]; size_t locat[2]; + size_t j; + size_t usedcmp; char *ptr; t_bool good; t_quote_mode mode; + if (reset == TRUE) + { + i = 0; + while (i < 4096) + { + used[i] = 0; + i++; + } + i = 0; + } mode = Q_NONE; ptr = word; ptr = p_skip_whitespace(ptr); @@ -157,15 +171,36 @@ void ft_strlcpy(tmp, word + locat[0], ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); - if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0) - return ; - (void)ft_memmove(word + (locat[0] + ft_strlen(value)), - word + locat[1], - ft_strlen(word + locat[1]) + 1 * sizeof(char)); - (void)ft_memmove(word + locat[0], - value, - ft_strlen(value) * sizeof(char)); + if ((usedcmp = u_get_alias_value(value, tmp, ARG_MAX, msh)) != 0) + { + j = 0; + good = TRUE; + while (j < i) + { + if (used[j] == usedcmp) + good = FALSE; + j++; + } + if (good == TRUE) + { + (void)ft_memmove(word + (locat[0] + ft_strlen(value)), + word + locat[1], + ft_strlen(word + locat[1]) + 1 * sizeof(char)); + (void)ft_memmove(word + locat[0], + value, + ft_strlen(value) * sizeof(char)); + used[i] = usedcmp; + i++; + return (usedcmp); + } + } + /* ptr = value; */ + /* save = value; */ + /* while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE) */ + /* ptr++; */ + /* ft_strlcpy(tmp, save, (ptr - save) + 1); */ } + return (0); } char diff --git a/src/p_lblock_next.h b/src/p_lblock_next.h index 030be27..4ffdfcf 100644 --- a/src/p_lblock_next.h +++ b/src/p_lblock_next.h @@ -13,12 +13,13 @@ #ifndef P_LCOM_NEXT_H #define P_LCOM_NEXT_H +#include <libft.h> #include <stdint.h> #include "s_struct.h" void p_subst_vars(char word[], t_msh *msh); -void p_subst_alias(char word[], t_msh *msh); +size_t p_subst_alias(char word[], t_bool reset, t_msh *msh); char **p_subst_args(const char word[], int8_t redir); char **p_subst_home(char *word[], t_msh *msh); char **p_check_args_equals(char *words[], t_msh *msh); diff --git a/src/s_com.c b/src/s_com.c index a5c594a..b899555 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -103,6 +103,7 @@ t_com char nword[ARG_MAX]; t_com *com; char **words; + size_t ret; if ((com = (t_com*)malloc(sizeof(t_com))) == NULL) return (NULL); @@ -117,7 +118,11 @@ t_com if (p_get_redir(nword, &com) != 0) return (NULL); if (msh->alias != NULL) - p_subst_alias(nword, msh); + { + ret = p_subst_alias(nword, TRUE, msh); + while (ret != 0) + ret = p_subst_alias(nword, TRUE, msh); + } p_subst_vars(nword, msh); if ((words = p_split_args(nword, com->redir)) == NULL) return (NULL); diff --git a/src/s_lalias.c b/src/s_lalias.c index eeac08b..56b3985 100644 --- a/src/s_lalias.c +++ b/src/s_lalias.c @@ -72,7 +72,8 @@ void t_lalias *s_lalias_new(const char name[], const char val[]) { - t_lalias *link; + t_lalias *link; + static size_t id = 1; if ((link = (t_lalias*)malloc(sizeof(t_lalias))) == NULL) { @@ -86,6 +87,8 @@ t_lalias { return (NULL); } + link->id = id; link->next = NULL; + id += 1; return (link); } diff --git a/src/s_struct.h b/src/s_struct.h index 310c5f4..ba56e82 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -29,6 +29,7 @@ typedef struct s_lalias { char *name; char *val; + size_t id; struct s_lalias *next; } t_lalias; diff --git a/src/u_alias.c b/src/u_alias.c index 92bd498..14ca75e 100644 --- a/src/u_alias.c +++ b/src/u_alias.c @@ -18,7 +18,7 @@ #include "s_lalias.h" #include "s_struct.h" -uint8_t +size_t u_get_alias_value(char str[], const char name[], size_t dstsize, t_msh *msh) { t_lalias *ptr; @@ -34,13 +34,13 @@ uint8_t } if (ptr == NULL) { - return (1); + return (0); } if (str != NULL) { ft_strlcpy(str, ptr->val, dstsize); } - return (0); + return (ptr->id); } void @@ -48,7 +48,7 @@ void { t_lalias *new; - if (u_get_alias_value(NULL, name, 0, msh) == 0) + if (u_get_alias_value(NULL, name, 0, msh) != 0) { s_lalias_rebind(&msh->alias, name, value); } |