AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

This commit is contained in:
2024-04-23 16:35:34 +02:00
parent b2ff5bcf22
commit b7755111f6
3 changed files with 15 additions and 15 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/23 14:45:42 by tomoron ### ########.fr */ /* Updated: 2024/04/23 16:32:16 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,7 +52,7 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
if (!cmd_str) if (!cmd_str)
return ; return ;
cmds = parsing_bonus(cmd_str); cmds = parsing_bonus(cmd_str);
tmp = check_cmds_syntax(cmds); tmp = check_cmds_syntax(cmds, msh->env);
if (tmp) if (tmp)
{ {
print_syntax_error_bonus(tmp); print_syntax_error_bonus(tmp);

View File

@ -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/04/23 13:44:49 by tomoron ### ########.fr */ /* Updated: 2024/04/23 16:31:56 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -118,7 +118,7 @@ void parse_var(t_msh *msh, char *line);
void print_parsed_token(t_token *cmd);//debug void print_parsed_token(t_token *cmd);//debug
int get_var_name_len(char *command); int get_var_name_len(char *command);
void handle_minishellrc(t_msh *msh); void handle_minishellrc(t_msh *msh);
t_cmd *check_cmds_syntax(t_cmd *cmds); t_cmd *check_cmds_syntax(t_cmd *cmds, t_env *env);
char *get_tmp_file_name(t_msh *msh); char *get_tmp_file_name(t_msh *msh);
int get_args_count(t_token *cmds); int get_args_count(t_token *cmds);
char **env_to_char_tab(t_env *env); char **env_to_char_tab(t_env *env);

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */ /* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
/* Updated: 2024/04/23 16:00:00 by tomoron ### ########.fr */ /* Updated: 2024/04/23 16:34:20 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -142,7 +142,7 @@ void print_syntax_error_bonus(t_cmd *cmd)
} }
int check_parens_syntax(t_cmd *cmd, t_cmd *last) int check_parens_syntax(t_cmd *cmd, t_cmd *last, t_env *env)
{ {
t_cmd *parsed_cmd; t_cmd *parsed_cmd;
t_cmd *tmp; t_cmd *tmp;
@ -158,14 +158,14 @@ int check_parens_syntax(t_cmd *cmd, t_cmd *last)
ft_putstr_fd("minishell: syntax error\n", 2); ft_putstr_fd("minishell: syntax error\n", 2);
return(0); return(0);
} }
tmp = check_cmds_syntax(parsed_cmd); tmp = check_cmds_syntax(parsed_cmd, env);
if(tmp) if(tmp)
print_syntax_error_bonus(tmp); print_syntax_error_bonus(tmp);
free_cmd(parsed_cmd); free_cmd(parsed_cmd);
return(tmp == 0); return(tmp == 0);
} }
int check_tokens_syntax(t_cmd *cmd, t_cmd *last) int check_tokens_syntax(t_cmd *cmd, t_cmd *last, t_env *env)
{ {
t_token *token; t_token *token;
@ -174,29 +174,29 @@ int check_tokens_syntax(t_cmd *cmd, t_cmd *last)
ft_putstr_fd("minishell : syntax error\n", 2); ft_putstr_fd("minishell : syntax error\n", 2);
return (0); return (0);
} }
token = parse_cmds_to_token(cmd, 0); token = parse_cmds_to_token(cmd, env);
if (!token) if (!token)
return (0); return (0);
free_token(token); free_token(token);
return (1); return (1);
} }
int check_cmd_type_syntax(t_cmd *cmds, t_cmd *last) int check_cmd_type_syntax(t_cmd *cmds, t_cmd *last, t_env *env)
{ {
if (cmds->cmd_type == CMD) if (cmds->cmd_type == CMD)
{ {
if (!check_tokens_syntax(cmds, last)) if (!check_tokens_syntax(cmds, last, env))
return (0); return (0);
} }
else if(cmds->cmd_type == PAREN) else if(cmds->cmd_type == PAREN)
{ {
if(!check_parens_syntax(cmds, last)) if(!check_parens_syntax(cmds, last, env))
return(0); return(0);
} }
return(1); return(1);
} }
t_cmd *check_cmds_syntax(t_cmd *cmds) t_cmd *check_cmds_syntax(t_cmd *cmds, t_env *env)
{ {
t_cmd *last; t_cmd *last;
@ -205,7 +205,7 @@ t_cmd *check_cmds_syntax(t_cmd *cmds)
if (!is_operand_type(cmds) && cmds->cmd_type != PIPE && cmds->value == 0) if (!is_operand_type(cmds) && cmds->cmd_type != PIPE && cmds->value == 0)
return (cmds); return (cmds);
last = cmds; last = cmds;
if(is_cmd_type(cmds) && !check_cmd_type_syntax(cmds, 0)) if(is_cmd_type(cmds) && !check_cmd_type_syntax(cmds, 0, env))
return(cmds); return(cmds);
cmds = cmds->next; cmds = cmds->next;
while (cmds) while (cmds)
@ -216,7 +216,7 @@ t_cmd *check_cmds_syntax(t_cmd *cmds)
if (is_operand_type(cmds) || cmds->cmd_type == PIPE) if (is_operand_type(cmds) || cmds->cmd_type == PIPE)
if ((!is_cmd_type(last) && !is_output_type(last) && !is_input_type(last)) || !cmds->next || (!is_cmd_type(cmds->next) && !is_output_type(cmds->next) && !is_input_type(cmds->next))) if ((!is_cmd_type(last) && !is_output_type(last) && !is_input_type(last)) || !cmds->next || (!is_cmd_type(cmds->next) && !is_output_type(cmds->next) && !is_input_type(cmds->next)))
return (cmds); return (cmds);
if(is_cmd_type(cmds) && !check_cmd_type_syntax(cmds, last)) if(is_cmd_type(cmds) && !check_cmd_type_syntax(cmds, last, env))
return(cmds); return(cmds);
last = cmds; last = cmds;
cmds = cmds->next; cmds = cmds->next;