norme
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/04/24 10:46:28 by marde-vr #+# #+# */
|
/* Created: 2024/04/24 10:46:28 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/05/06 10:13:22 by tomoron ### ########.fr */
|
/* Updated: 2024/05/06 10:56:52 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -53,14 +53,6 @@ int get_cmd_count(t_cmd *cmds)
|
|||||||
nb = 1;
|
nb = 1;
|
||||||
while (cmds && !is_operand_type(cmds))
|
while (cmds && !is_operand_type(cmds))
|
||||||
{
|
{
|
||||||
/*while (cmds && (is_output_type(cmds) || is_input_type(cmds)))
|
|
||||||
cmds = cmds->next;
|
|
||||||
if (cmds && is_cmd_type(cmds))
|
|
||||||
nb++;
|
|
||||||
while (cmds && (is_output_type(cmds) || is_input_type(cmds)
|
|
||||||
|| is_cmd_type(cmds)))
|
|
||||||
cmds = cmds->next;
|
|
||||||
*/
|
|
||||||
if (cmds && cmds->cmd_type == PIPE)
|
if (cmds && cmds->cmd_type == PIPE)
|
||||||
{
|
{
|
||||||
nb++;
|
nb++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/05/03 14:20:04 by tomoron ### ########.fr */
|
/* Updated: 2024/05/06 10:56:39 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -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/06 10:54:21 by tomoron ### ########.fr */
|
/* Updated: 2024/05/06 10:57:52 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -82,6 +82,8 @@ 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 dquote);
|
int add_var_to_str(char *res, char **command, t_env *env, int dquote);
|
||||||
|
int get_variable_expantion_len(char *command, t_env *env);
|
||||||
|
char *expand_variables(char *command, t_env *env, int *is_var);
|
||||||
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);
|
||||||
|
@ -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/06 10:36:45 by tomoron ### ########.fr */
|
/* Updated: 2024/05/06 10:58:08 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -48,8 +48,7 @@ char *get_token(char **cmd, int quotes[2])
|
|||||||
quotes[0] = !quotes[0];
|
quotes[0] = !quotes[0];
|
||||||
else if (**cmd == '~' && !quotes[0] && !quotes[1])
|
else if (**cmd == '~' && !quotes[0] && !quotes[1])
|
||||||
i += add_home_to_str(res + i);
|
i += add_home_to_str(res + i);
|
||||||
else if (((**cmd == '\'' && quotes[1])
|
else if (((**cmd == '\'' && quotes[1]) || (**cmd == '"' && quotes[0]))
|
||||||
|| (**cmd == '"' && quotes[0]))
|
|
||||||
|| (**cmd != '\'' && **cmd != '"'))
|
|| (**cmd != '\'' && **cmd != '"'))
|
||||||
res[i++] = **cmd;
|
res[i++] = **cmd;
|
||||||
(*cmd)++;
|
(*cmd)++;
|
||||||
@ -57,59 +56,6 @@ char *get_token(char **cmd, int quotes[2])
|
|||||||
return (res);
|
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)
|
t_token *parse_tokens(char *command, t_env *env)
|
||||||
{
|
{
|
||||||
int quotes[2];
|
int quotes[2];
|
||||||
|
65
srcs/variable_expantion.c
Normal file
65
srcs/variable_expantion.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* variable_expantion.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/06 10:57:33 by tomoron #+# #+# */
|
||||||
|
/* Updated: 2024/05/06 10:57:39 by tomoron ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Reference in New Issue
Block a user