This commit is contained in:
2024-05-06 10:58:42 +02:00
parent 57ad83c2aa
commit 6cfc2beff4
5 changed files with 74 additions and 69 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
/* Updated: 2024/05/06 10:36:45 by tomoron ### ########.fr */
/* Updated: 2024/05/06 10:58:08 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
@ -48,8 +48,7 @@ char *get_token(char **cmd, int quotes[2])
quotes[0] = !quotes[0];
else if (**cmd == '~' && !quotes[0] && !quotes[1])
i += add_home_to_str(res + i);
else if (((**cmd == '\'' && quotes[1])
|| (**cmd == '"' && quotes[0]))
else if (((**cmd == '\'' && quotes[1]) || (**cmd == '"' && quotes[0]))
|| (**cmd != '\'' && **cmd != '"'))
res[i++] = **cmd;
(*cmd)++;
@ -57,59 +56,6 @@ char *get_token(char **cmd, int quotes[2])
return (res);
}
int get_variable_expantion_len(char *command , t_env *env)
{
int in_quote;
int in_dquote;
int i;
i = 0;
in_dquote = 0;
in_quote = 0;
while(*command)
{
if(*command == '\'' && !in_dquote)
in_quote = !in_quote;
if(*command == '"' && !in_quote)
in_dquote = !in_dquote;
if(*command == '$' && !in_quote)
i+= get_var_len(&command, env, in_dquote);
else
i++;
command++;
}
return(i);
}
char *expand_variables(char *command, t_env *env, int *is_var)
{
char *res;
int i;
int in_dquote;
int in_quote;
if(!command)
return(0);
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)
{
if(*command == '\'' && !in_dquote)
in_quote = !in_quote;
if(*command == '"' && !in_quote)
in_dquote = !in_dquote;
if(*command == '$' && !in_quote)
i+= add_var_to_str(res + i, &command ,env, in_dquote);
else
res[i++] = *command;
command++;
}
return(res);
}
t_token *parse_tokens(char *command, t_env *env)
{
int quotes[2];