From 57ad83c2aaaf26c3fe9f77c8d700f3fc6b9e5b15 Mon Sep 17 00:00:00 2001 From: tomoron Date: Mon, 6 May 2024 10:56:13 +0200 Subject: [PATCH] fix "$" --- srcs/minishell.h | 6 +++--- srcs/parsing.c | 6 +++--- srcs/parsing_var.c | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/srcs/minishell.h b/srcs/minishell.h index 8d5b8d2..0333881 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/05/04 14:11:35 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 10:54:21 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,7 +81,7 @@ typedef struct s_msh extern int g_return_code; int get_in_type(t_msh *msh, t_cmd *t_strt, t_cmd *tokens, int here_doc); -int add_var_to_str(char *res, char **command, t_env *env); +int add_var_to_str(char *res, char **command, t_env *env, int dquote); t_env *export_set_env(t_env *env, char *name, char *value, int append); void parent(t_msh *msh, int i, int cmd_count, char **cmd_args); t_token *expand_wildcards(t_token *res, char *value, int is_var); @@ -116,7 +116,7 @@ int get_out_type(t_msh *msh, t_cmd *cmds); void handle_here_doc(t_msh *msh, char *eof); void signal_handler_interactive(int signum); int get_token_len(char *cmd); -int get_var_len(char **command, t_env *env); +int get_var_len(char **command, t_env *env, int dquote); void signal_handler_here_doc(int signum); t_token *parsing_syntax_error(t_token *res); int file_access(t_msh *msh, int *found); diff --git a/srcs/parsing.c b/srcs/parsing.c index bf063c8..838243f 100755 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/05/04 18:31:41 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 10:36:45 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -73,7 +73,7 @@ int get_variable_expantion_len(char *command , t_env *env) if(*command == '"' && !in_quote) in_dquote = !in_dquote; if(*command == '$' && !in_quote) - i+= get_var_len(&command, env); + i+= get_var_len(&command, env, in_dquote); else i++; command++; @@ -102,7 +102,7 @@ char *expand_variables(char *command, t_env *env, int *is_var) if(*command == '"' && !in_quote) in_dquote = !in_dquote; if(*command == '$' && !in_quote) - i+= add_var_to_str(res + i, &command ,env); + i+= add_var_to_str(res + i, &command ,env, in_dquote); else res[i++] = *command; command++; diff --git a/srcs/parsing_var.c b/srcs/parsing_var.c index 54eb6f6..5132404 100755 --- a/srcs/parsing_var.c +++ b/srcs/parsing_var.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/05/05 20:36:59 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 10:52:37 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,18 +22,18 @@ char *get_var_name(char *command) return (res); } -int get_var_len(char **command, t_env *env) +int get_var_len(char **command, t_env *env, int in_dquote) { char *var_name; char *env_var; (*command)++; - if (**command == '\'' || **command == '"') + if ((**command == '\'' || **command == '"') && !in_dquote) { (*command)--; return (0); } - if (!**command) + if (!**command || (**command == '"' && in_dquote)) { (*command)--; return (1); @@ -85,7 +85,7 @@ int invalid_variable_char(char *res, char c) return (2); } -int add_var_to_str(char *res, char **command, t_env *env) +int add_var_to_str(char *res, char **command, t_env *env, int dquote) { char *var_name; char *var; @@ -95,10 +95,10 @@ int add_var_to_str(char *res, char **command, t_env *env) (*command)++; if (**command == '\'' || **command == '"' || !**command) { - if (**command != '\'' && **command != '"') + if ((**command != '\'' && **command != '"') || dquote) *res = '$'; (*command)--; - return (*(*command + 1) != '\'' && *(*command + 1) != '"'); + return ((*(*command + 1) != '\'' && *(*command + 1) != '"') || dquote); } if (!ft_isalnum(**command) && **command != '_' && **command != '?') return (invalid_variable_char(res, **command));