diff --git a/Makefile b/Makefile index d3c885d..f91bfad 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tomoron +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/02/08 16:18:42 by tomoron ### ########.fr # +# Updated: 2024/02/09 18:13:02 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,9 @@ SRCS = main.c\ ft_lst_env.c\ ft_exec.c\ ft_exit.c\ - ft_echo.c + ft_echo.c\ + ft_parsing.c\ + ft_parsing_var.c OBJS = $(SRCS:.c=.o) diff --git a/ft_parsing.c b/ft_parsing.c index 885b925..92536a1 100644 --- a/ft_parsing.c +++ b/ft_parsing.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/02/09 16:40:07 by tomoron ### ########.fr */ +/* Updated: 2024/02/09 18:15:45 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -32,7 +32,7 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) i += ft_add_var_to_str(res + i, cmd, env); } else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) - || (**cmd != '\'' && **command != '"')) + || (**cmd != '\'' && **cmd != '"')) res[i++] = **cmd; (*cmd)++; } diff --git a/ft_parsing_var.c b/ft_parsing_var.c index 9fb4aea..ff94841 100644 --- a/ft_parsing_var.c +++ b/ft_parsing_var.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/02/09 15:24:43 by tomoron ### ########.fr */ +/* Updated: 2024/02/09 18:22:16 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,3 +62,37 @@ int ft_get_token_len(char *command, t_env *env) res++; else if ((*command == '\'' && in_dquote) || (*command == '"' && in_quote)) + res++; + command++; + } + return (res); +} + +int ft_add_var_to_str(char *res, char **command, t_env *env) +{ + char *var_name; + char *var; + int i; + + i = -1; + if (!ft_isalnum(**command) && **command != '_' && **command != '?') + { + *res = '$'; + return (1); + } + if (**command == '?') + { + var = ft_itoa(g_return_code); + while (var && var[++i]) + res[i] = var[i]; + free(var); + return (i + 1); + } + var_name = get_var_name(*command); + var = ft_getenv(env, var_name); + free(var_name); + while (var && var[++i]) + res[i] = var[i]; + *command += get_var_name_len(*command) - 1; + return (i + !var); +} diff --git a/minishell.h b/minishell.h index eb52d9c..326b130 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/02/09 14:58:21 by tomoron ### ########.fr */ +/* Updated: 2024/02/09 18:17:30 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,4 +40,9 @@ void ft_exit(t_cmd *args, t_env *env); t_env *ft_env_add_back(t_env *env, char *name, char *value); void ft_free_env(t_env *env); int ft_print_env(t_env *env); +t_cmd *ft_parse_command(char *command, t_env *env); +int ft_get_token_len(char *cmd, t_env *env); +int ft_add_var_to_str(char *res, char **command, t_env *env); +int get_var_name_len(char *command); +char *ft_getenv(t_env *env, char *var_name); #endif