diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/caller.c b/caller.c old mode 100644 new mode 100755 diff --git a/lexer.c b/lexer.c old mode 100644 new mode 100755 index dded372..3ffc5fa --- a/lexer.c +++ b/lexer.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* lexer.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: narnaud +#+ +:+ +#+ */ +/* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ -/* Updated: 2022/05/05 11:47:15 by narnaud ### ########.fr */ +/* Updated: 2022/05/05 13:12:49 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,23 +85,13 @@ int check_register(t_lexer *lex, char **line, char *tmp) return (create_token(lex, tmp)); } -char *ft_strreplace(char *dest, char *src) -{ - int len; - - len = ft_strlen(src); - while (*src) - *(dest++) = *(src++); - return (dest); -} - int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i) { int name_len; int i; char *var_name; char *value; - + char **env; i = 1; if ((*line)[1] == '?') { @@ -113,7 +103,18 @@ int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i) while (ft_isalpha((*line)[i]) || ft_isdigit((*line)[i]) || (*line)[i] == '_') i++; var_name = ft_substr(*line, 1, i - 1); - value = getenv(var_name); + i = 0; + while (datas->envp[i]) + { + env = ft_split(datas->envp[i], '='); + if (!ft_strncmp(var_name, env[0], ft_strlen(var_name) + 1)) + break ; + i++; + } + if (!datas->envp[i]) + value = strdup(""); + else + value = env[1]; name_len = ft_strlen(var_name) + 1; } i = 0; diff --git a/libft/conv/ft_itox.c b/libft/conv/ft_itox.c old mode 100644 new mode 100755 diff --git a/libft/conv/ft_utoa.c b/libft/conv/ft_utoa.c old mode 100644 new mode 100755 diff --git a/libft/dlist/ft_add.c b/libft/dlist/ft_add.c old mode 100644 new mode 100755 diff --git a/libft/dlist/ft_n.c b/libft/dlist/ft_n.c old mode 100644 new mode 100755 diff --git a/libft/dlist/ft_to_arr.c b/libft/dlist/ft_to_arr.c old mode 100644 new mode 100755 diff --git a/libft/i_slist/ft_first.c b/libft/i_slist/ft_first.c old mode 100644 new mode 100755 diff --git a/libft/i_slist/ft_free.c b/libft/i_slist/ft_free.c old mode 100644 new mode 100755 diff --git a/libft/i_slist/ft_is_in.c b/libft/i_slist/ft_is_in.c old mode 100644 new mode 100755 diff --git a/libft/is/ft_islower.c b/libft/is/ft_islower.c old mode 100644 new mode 100755 diff --git a/libft/is/ft_isspace.c b/libft/is/ft_isspace.c old mode 100644 new mode 100755 diff --git a/libft/is/ft_isupper.c b/libft/is/ft_isupper.c old mode 100644 new mode 100755 diff --git a/libft/mem/ft_free_split.c b/libft/mem/ft_free_split.c old mode 100644 new mode 100755 diff --git a/libft/nbr/ft_croissant.c b/libft/nbr/ft_croissant.c old mode 100644 new mode 100755 diff --git a/libft/nbr/ft_decroissant.c b/libft/nbr/ft_decroissant.c old mode 100644 new mode 100755 diff --git a/libft/nbr/ft_max.c b/libft/nbr/ft_max.c old mode 100644 new mode 100755 diff --git a/libft/nbr/ft_nbrlen.c b/libft/nbr/ft_nbrlen.c old mode 100644 new mode 100755 diff --git a/libft/str/ft_rev.c b/libft/str/ft_rev.c old mode 100644 new mode 100755 diff --git a/minishell.c b/minishell.c old mode 100644 new mode 100755 index 55bdbaa..bf06f07 --- a/minishell.c +++ b/minishell.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: narnaud +#+ +:+ +#+ */ +/* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */ -/* Updated: 2022/05/05 11:49:53 by narnaud ### ########.fr */ +/* Updated: 2022/05/05 14:02:48 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -127,8 +127,17 @@ int main(int argc, char **argv, char **envp) { t_datas datas; char *line; + char **env_copy; + int i; - datas.envp = envp; + env_copy = ft_calloc(1024, sizeof(char *)); + i = 0; + while (envp[i]) + { + env_copy[i] = ft_strdup(envp[i]); + i++; + } + datas.envp = env_copy; datas.exit_code = 0; if (argc < 2) (void)argv; diff --git a/minishell.h b/minishell.h old mode 100644 new mode 100755 index 2b14e9a..635552b --- a/minishell.h +++ b/minishell.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: narnaud +#+ +:+ +#+ */ +/* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/05 11:35:09 by narnaud ### ########.fr */ +/* Updated: 2022/05/05 12:34:17 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,6 +70,8 @@ int command_call(t_datas *datas, t_command *cmd); // ----------------------------------Parser.c +char *expend_str(t_datas *datas, char *line); + typedef enum e_type { WORD, diff --git a/parser.c b/parser.c old mode 100644 new mode 100755 index 6ecc855..8243792 --- a/parser.c +++ b/parser.c @@ -3,15 +3,35 @@ /* ::: :::::::: */ /* parser.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: narnaud +#+ +:+ +#+ */ +/* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 16:09:25 by narnaud #+# #+# */ -/* Updated: 2022/05/05 08:28:41 by narnaud ### ########.fr */ +/* Updated: 2022/05/05 13:02:33 by mea ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +char *expend_str(t_datas *datas, char *line) +{ + char *tmp; + int tmp_i; + + tmp = ft_calloc(1024, sizeof *tmp); + if (!tmp) + free(tmp); + tmp_i = 0; + while (*line) + { + if (*line == '$') + tmp_i = replace_var(datas, &line, tmp, tmp_i); + tmp[tmp_i] = *line; + line++; + tmp_i++; + } + return (tmp); +} + int push_heredoc(char *str) { char *line; diff --git a/utils.c b/utils.c old mode 100644 new mode 100755