fix is_var

This commit is contained in:
tom moron
2024-05-08 11:57:49 +02:00
parent e986d8692b
commit d1681dafe3
3 changed files with 7 additions and 7 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/05/07 17:34:59 by tomoron ### ########.fr */
/* Updated: 2024/05/08 11:56:37 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 dquote);
int add_var_to_str(char *res, char **cmd, t_env *env, int quote, int *i_v);
t_env *export_set_env(t_env *env, char *name, char *value, int append);
t_env *env_add_back(t_env *env, char *name, char *value, int empty);
void parent(t_msh *msh, int i, int cmd_count, char **cmd_args);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
/* Updated: 2024/05/06 16:27:54 by tomoron ### ########.fr */
/* Updated: 2024/05/08 11:55:37 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -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 dquote)
int add_var_to_str(char *res, char **command, t_env *env, int dquote, int *i_v)
{
char *var_name;
char *var;
@ -93,6 +93,7 @@ int add_var_to_str(char *res, char **command, t_env *env, int dquote)
i = 0;
(*command)++;
*i_v = 1;
if (**command == '\'' || **command == '"' || !**command)
{
if ((**command != '\'' && **command != '"') || dquote)

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/06 10:57:33 by tomoron #+# #+# */
/* Updated: 2024/05/06 10:57:39 by tomoron ### ########.fr */
/* Updated: 2024/05/08 11:54:17 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
@ -47,7 +47,6 @@ char *expand_variables(char *command, t_env *env, int *is_var)
res = ft_calloc(get_variable_expantion_len(command, env) + 1, 1);
in_quote = 0;
in_dquote = 0;
*is_var = 1;
i = 0;
while (res && *command)
{
@ -56,7 +55,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, in_dquote);
i += add_var_to_str(res + i, &command, env, in_dquote, is_var);
else
res[i++] = *command;
command++;