diff --git a/format/format.c b/format/format.c index de82726..915ddcb 100644 --- a/format/format.c +++ b/format/format.c @@ -95,7 +95,7 @@ static void ft_space_simplifier(char *str) } } -char *ft_formater(char *str) +char *ft_formater(t_data *data, const char *str) { char *out; char *temp; @@ -112,5 +112,7 @@ char *ft_formater(char *str) ft_space_simplifier(out); if (out[ft_strlen(out) - 1] == ' ') out[ft_strlen(out) - 1] = '\0'; - return (out); + temp = ft_env_filler(data, out); + free(out); + return (temp); } diff --git a/format/format.h b/format/format.h index fe79e26..f47db9e 100644 --- a/format/format.h +++ b/format/format.h @@ -1,6 +1,7 @@ #ifndef FORMAT_H # define FORMAT_H +# include "../data/data.h" -char *ft_formater(char *str); +char *ft_formater(t_data *data, const char *str); #endif diff --git a/main.c b/main.c index 977ce93..05ccd58 100644 --- a/main.c +++ b/main.c @@ -43,7 +43,7 @@ static int ft_minishell(t_data *data, char *line) if (ft_syntax_verif(data, line)) return (0); - line_clean = ft_formater(line); + line_clean = ft_formater(data, line); if (line_clean == NULL) return (0); if (ft_cmds_parser(data, line_clean)) diff --git a/parse/parse.c b/parse/parse.c index cb324e6..1c69a2c 100644 --- a/parse/parse.c +++ b/parse/parse.c @@ -1,9 +1,8 @@ #include "./parse_private.h" -int ft_args_parse(t_data *data, char *cmd_str, t_cmd *cmd) +static int ft_args_parse(char *cmd_str, t_cmd *cmd) { char **tab; - char *str; size_t i; tab = ft_split_quoted(cmd_str, ' '); @@ -12,22 +11,14 @@ int ft_args_parse(t_data *data, char *cmd_str, t_cmd *cmd) i = 0; while (tab[i] != NULL) { - str = ft_env_filler(data, tab[i]); - if (str == NULL) - { - ft_freer_tab_ultimate(1, tab); - return (1); - } - ft_quote_remover(str); - free(tab[i]); - tab[i] = str; + ft_quote_remover(tab[i]); i++; } cmd->args = tab; return (0); } -int ft_executable_parse(t_data *data, t_cmd *cmd) +static int ft_executable_parse(t_data *data, t_cmd *cmd) { bool own; char *path; @@ -76,7 +67,7 @@ int ft_cmd_parser(t_data *data, char *cmd_str) ft_cmddel(cmd); return (1); } - if (ft_args_parse(data, cmd_str, cmd)) + if (ft_args_parse(cmd_str, cmd)) { ft_cmddel(cmd); return (1); @@ -100,6 +91,7 @@ int ft_cmds_parser(t_data *data, const char *line) tab = ft_split_quoted(line, '|'); if (tab == NULL) { + ft_freer_tab_ultimate(1, tab); ft_eprintf("minishell: malloc failed\n"); return (1); } diff --git a/redirection/redirection.c b/redirection/redirection.c index c9fa7d1..93855c2 100644 --- a/redirection/redirection.c +++ b/redirection/redirection.c @@ -38,6 +38,8 @@ void ft_remove_redirection(char *cmd_str) i++; if (ft_is_in("<>", cmd_str[i])) start = i; + if (start == -1) + continue ; while (cmd_str[i] == cmd_str[start]) i++; i++; diff --git a/t b/t deleted file mode 100755 index 9b47f86..0000000 --- a/t +++ /dev/null @@ -1 +0,0 @@ -bozo diff --git a/utils/ft_quote_remover.c b/utils/ft_quote_remover.c index 535de29..2a26475 100644 --- a/utils/ft_quote_remover.c +++ b/utils/ft_quote_remover.c @@ -36,7 +36,7 @@ char *ft_quote_remover(char *str) ft_strshift(str + stop - 1, -1); start = -1; stop = -1; - i = i - 2; + i = i - 1; } else i++;