fixed syntax error error code and exit too big

This commit is contained in:
mdev9
2024-04-25 13:45:13 +02:00
parent 7f85951e43
commit bee12290d5
4 changed files with 13 additions and 5 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 14:50:15 by tomoron #+# #+# */ /* Created: 2024/04/24 14:50:15 by tomoron #+# #+# */
/* Updated: 2024/04/24 15:00:00 by tomoron ### ########.fr */ /* Updated: 2024/04/25 13:02:46 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,12 +20,14 @@ int check_parens_syntax(t_cmd *cmd, t_cmd *last, t_env *env)
if (last && is_cmd_type(last)) if (last && is_cmd_type(last))
{ {
ft_putstr_fd("minishell: syntax error\n", 2); ft_putstr_fd("minishell: syntax error\n", 2);
g_return_code = 2;
return (0); return (0);
} }
parsed_cmd = parsing_bonus(cmd->value); parsed_cmd = parsing_bonus(cmd->value);
if (!parsed_cmd) if (!parsed_cmd)
{ {
ft_putstr_fd("minishell: syntax error\n", 2); ft_putstr_fd("minishell: syntax error\n", 2);
g_return_code = 2;
return (0); return (0);
} }
tmp = check_cmds_syntax(parsed_cmd, env); tmp = check_cmds_syntax(parsed_cmd, env);
@ -110,6 +112,9 @@ int check_str_syntax(char *cmd)
cmd++; cmd++;
} }
if (in_quote || in_dquote || parenthesis) if (in_quote || in_dquote || parenthesis)
{
ft_putstr_fd("minishell: syntax error\n", 2); ft_putstr_fd("minishell: syntax error\n", 2);
g_return_code = 2;
}
return (!(in_quote || in_dquote || parenthesis)); return (!(in_quote || in_dquote || parenthesis));
} }

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 14:54:53 by tomoron #+# #+# */ /* Created: 2024/04/24 14:54:53 by tomoron #+# #+# */
/* Updated: 2024/04/24 18:57:48 by marde-vr ### ########.fr */ /* Updated: 2024/04/25 13:03:37 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,7 @@ void print_syntax_error_bonus(t_cmd *cmd)
if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN) if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN)
return ; return ;
ft_printf_fd(2, "minishell : syntax error near unexpected token `"); ft_printf_fd(2, "minishell : syntax error near unexpected token `");
g_return_code = 2;
if (cmd->cmd_type == AND) if (cmd->cmd_type == AND)
ft_printf_fd(2, "&&"); ft_printf_fd(2, "&&");
if (cmd->cmd_type == OR) if (cmd->cmd_type == OR)
@ -35,6 +36,7 @@ int check_tokens_syntax(t_cmd *cmd, t_cmd *last, t_env *env)
if (last && is_cmd_type(last)) if (last && is_cmd_type(last))
{ {
ft_putstr_fd("minishell : syntax error\n", 2); ft_putstr_fd("minishell : syntax error\n", 2);
g_return_code = 2;
return (0); return (0);
} }
token = parse_cmds_to_token(cmd, env); token = parse_cmds_to_token(cmd, env);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
/* Updated: 2024/04/24 19:14:52 by tomoron ### ########.fr */ /* Updated: 2024/04/25 13:10:36 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
t_token *cur_cmd; t_token *cur_cmd;
cur_cmd = msh->tokens->next; cur_cmd = msh->tokens->next;
if (cur_cmd && !ft_strisnbr(cur_cmd->value)) if (cur_cmd && (!ft_strisnbr(cur_cmd->value) || ft_strlen(cur_cmd->value) > 18))
numeric_arg_err(cur_cmd->value, exit_code); numeric_arg_err(cur_cmd->value, exit_code);
else if (cur_cmd) else if (cur_cmd)
*exit_code = (unsigned char)ft_atoi(cur_cmd->value); *exit_code = (unsigned char)ft_atoi(cur_cmd->value);

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */ /* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */
/* Updated: 2024/04/24 18:59:26 by marde-vr ### ########.fr */ /* Updated: 2024/04/25 13:03:18 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ t_token *parsing_syntax_error(t_token *res)
{ {
free_token(res); free_token(res);
ft_putstr_fd("minishell: syntax error\n", 2); ft_putstr_fd("minishell: syntax error\n", 2);
g_return_code = 2;
return ((void *)1); return ((void *)1);
} }