Browse Source

wip -stacked env -replacevar fixed

master
Michael Ea 3 years ago
parent
commit
d360cec7c0
  1. 0
      LICENSE
  2. 0
      README.md
  3. 0
      caller.c
  4. 29
      lexer.c
  5. 0
      libft/conv/ft_itox.c
  6. 0
      libft/conv/ft_utoa.c
  7. 0
      libft/dlist/ft_add.c
  8. 0
      libft/dlist/ft_n.c
  9. 0
      libft/dlist/ft_to_arr.c
  10. 0
      libft/i_slist/ft_first.c
  11. 0
      libft/i_slist/ft_free.c
  12. 0
      libft/i_slist/ft_is_in.c
  13. 0
      libft/is/ft_islower.c
  14. 0
      libft/is/ft_isspace.c
  15. 0
      libft/is/ft_isupper.c
  16. 0
      libft/mem/ft_free_split.c
  17. 0
      libft/nbr/ft_croissant.c
  18. 0
      libft/nbr/ft_decroissant.c
  19. 0
      libft/nbr/ft_max.c
  20. 0
      libft/nbr/ft_nbrlen.c
  21. 0
      libft/str/ft_rev.c
  22. 15
      minishell.c
  23. 6
      minishell.h
  24. 24
      parser.c
  25. 0
      utils.c

0
LICENSE

0
README.md

0
caller.c

29
lexer.c

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* lexer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

0
libft/conv/ft_itox.c

0
libft/conv/ft_utoa.c

0
libft/dlist/ft_add.c

0
libft/dlist/ft_n.c

0
libft/dlist/ft_to_arr.c

0
libft/i_slist/ft_first.c

0
libft/i_slist/ft_free.c

0
libft/i_slist/ft_is_in.c

0
libft/is/ft_islower.c

0
libft/is/ft_isspace.c

0
libft/is/ft_isupper.c

0
libft/mem/ft_free_split.c

0
libft/nbr/ft_croissant.c

0
libft/nbr/ft_decroissant.c

0
libft/nbr/ft_max.c

0
libft/nbr/ft_nbrlen.c

0
libft/str/ft_rev.c

15
minishell.c

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

6
minishell.h

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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,

24
parser.c

@ -3,15 +3,35 @@
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

0
utils.c

Loading…
Cancel
Save