diff --git a/Makefile b/Makefile index 5eb1183..05b660b 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: marde-vr +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/02/15 14:44:14 by tomoron ### ########.fr # +# Updated: 2024/02/16 14:26:43 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -21,6 +21,7 @@ SRCS = main.c\ pwd.c\ parsing.c\ debug.c\ + env_to_char_tab.c\ parsing_var.c OBJS = $(SRCS:.c=.o) diff --git a/env_to_char_tab.c b/env_to_char_tab.c new file mode 100644 index 0000000..846355d --- /dev/null +++ b/env_to_char_tab.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env_to_char_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */ +/* Updated: 2024/02/16 14:31:07 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int get_env_len(t_env *env) +{ + int res; + + res = 0; + while(env) + { + res++; + env = env->next; + } + return(res); +} + +char **env_to_char_tab(t_env *env) +{ + char **res; + int i; + char *tmp; + + res = ft_calloc(get_env_len(env) + 1, sizeof(char *)); + i = 0; + while(res && env) + { + tmp = ft_strjoin(env->name, "="); + tmp = ft_strjoin_free(tmp, env->value, 1); + res[i] = tmp; + i++; + env = env->next; + } + return(res); +} diff --git a/minishell.h b/minishell.h index 398d878..55c24fb 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/02/16 12:50:33 by tomoron ### ########.fr */ +/* Updated: 2024/02/16 13:15:22 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,8 @@ typedef enum e_token_type ARG, PIPE, RED_O, + RED_O_APP, RED_I, - RED_I_APP, HERE_DOC, OR, AND diff --git a/parsing.c b/parsing.c index 946d1f9..9a44d82 100755 --- a/parsing.c +++ b/parsing.c @@ -6,14 +6,14 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/02/13 18:22:38 by tomoron ### ########.fr */ +/* Updated: 2024/02/16 14:25:36 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int is_cmd_char(char c) { - return(!ft_isspace(c) && c != '|' && c != '&'); + return(!ft_isspace(c) && c != '|' && c != '&' && c != '<' && c != '>'); } char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) @@ -46,23 +46,25 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) t_token_type get_token_type(char **command) { + t_token_type res; + while (ft_isspace(**command)) (*command)++; if((*command)[0] == '|' && (*command)[1] == '|') - { - (*command) += 2; - return(OR); - } - if((*command)[0] == '&' && (*command)[1] == '&') - { - (*command) += 2; - return(AND); - } - if((*command)[0] == '|') - { - (*command) += 1; - return(PIPE); - } + res = OR; + else if((*command)[0] == '&' && (*command)[1] == '&') + res = AND; + else if ((*command)[0] == '>' && (*command)[1] == '>') + res = RED_O_APP; + else if((*command)[0] == '<' && (*command)[1] == '<') + res = HERE_DOC; + else if((*command)[0] == '>') + res = RED_O; + else if((*command)[0] == '<') + res = RED_I; + else if((*command)[0] == '|') + res = PIPE; + return (ARG); }