fix "$"
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* 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;
|
extern int g_return_code;
|
||||||
|
|
||||||
int get_in_type(t_msh *msh, t_cmd *t_strt, t_cmd *tokens, int here_doc);
|
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);
|
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);
|
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);
|
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 handle_here_doc(t_msh *msh, char *eof);
|
||||||
void signal_handler_interactive(int signum);
|
void signal_handler_interactive(int signum);
|
||||||
int get_token_len(char *cmd);
|
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);
|
void signal_handler_here_doc(int signum);
|
||||||
t_token *parsing_syntax_error(t_token *res);
|
t_token *parsing_syntax_error(t_token *res);
|
||||||
int file_access(t_msh *msh, int *found);
|
int file_access(t_msh *msh, int *found);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
/* 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"
|
#include "minishell.h"
|
||||||
@ -73,7 +73,7 @@ int get_variable_expantion_len(char *command , t_env *env)
|
|||||||
if(*command == '"' && !in_quote)
|
if(*command == '"' && !in_quote)
|
||||||
in_dquote = !in_dquote;
|
in_dquote = !in_dquote;
|
||||||
if(*command == '$' && !in_quote)
|
if(*command == '$' && !in_quote)
|
||||||
i+= get_var_len(&command, env);
|
i+= get_var_len(&command, env, in_dquote);
|
||||||
else
|
else
|
||||||
i++;
|
i++;
|
||||||
command++;
|
command++;
|
||||||
@ -102,7 +102,7 @@ char *expand_variables(char *command, t_env *env, int *is_var)
|
|||||||
if(*command == '"' && !in_quote)
|
if(*command == '"' && !in_quote)
|
||||||
in_dquote = !in_dquote;
|
in_dquote = !in_dquote;
|
||||||
if(*command == '$' && !in_quote)
|
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
|
else
|
||||||
res[i++] = *command;
|
res[i++] = *command;
|
||||||
command++;
|
command++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
|
/* 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);
|
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 *var_name;
|
||||||
char *env_var;
|
char *env_var;
|
||||||
|
|
||||||
(*command)++;
|
(*command)++;
|
||||||
if (**command == '\'' || **command == '"')
|
if ((**command == '\'' || **command == '"') && !in_dquote)
|
||||||
{
|
{
|
||||||
(*command)--;
|
(*command)--;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (!**command)
|
if (!**command || (**command == '"' && in_dquote))
|
||||||
{
|
{
|
||||||
(*command)--;
|
(*command)--;
|
||||||
return (1);
|
return (1);
|
||||||
@ -85,7 +85,7 @@ int invalid_variable_char(char *res, char c)
|
|||||||
return (2);
|
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_name;
|
||||||
char *var;
|
char *var;
|
||||||
@ -95,10 +95,10 @@ int add_var_to_str(char *res, char **command, t_env *env)
|
|||||||
(*command)++;
|
(*command)++;
|
||||||
if (**command == '\'' || **command == '"' || !**command)
|
if (**command == '\'' || **command == '"' || !**command)
|
||||||
{
|
{
|
||||||
if (**command != '\'' && **command != '"')
|
if ((**command != '\'' && **command != '"') || dquote)
|
||||||
*res = '$';
|
*res = '$';
|
||||||
(*command)--;
|
(*command)--;
|
||||||
return (*(*command + 1) != '\'' && *(*command + 1) != '"');
|
return ((*(*command + 1) != '\'' && *(*command + 1) != '"') || dquote);
|
||||||
}
|
}
|
||||||
if (!ft_isalnum(**command) && **command != '_' && **command != '?')
|
if (!ft_isalnum(**command) && **command != '_' && **command != '?')
|
||||||
return (invalid_variable_char(res, **command));
|
return (invalid_variable_char(res, **command));
|
||||||
|
Reference in New Issue
Block a user