Commit c4f2c88f authored by abenoit's avatar abenoit
Browse files

ambiguous redirs error setup

parent aa54197d
......@@ -12,7 +12,7 @@
enum e_exec_errcode
{
HOME_NOT_SET = 8,
HOME_NOT_SET = 9,
NO_SUCH_FILE
};
......
......@@ -62,7 +62,8 @@ enum e_redir_op
NO_REDIR,
FILEIN,
FILEOUT,
APPEND
APPEND,
AMBIG
};
typedef struct s_command
......
......@@ -31,7 +31,7 @@ enum e_state
enum e_parsing_error
{
SQUOTE_MISSING = 10,
SQUOTE_MISSING = 11,
DQUOTE_MISSING,
ESCAPE_NL,
REDIR_PATH_INVALID,
......
......@@ -103,6 +103,11 @@ int handle_execution(t_xe *xe, int fd_in, int proc)
cur_command = parse_one_command(xe);
if (cur_command == NULL)
return (MALLOC_ERR);
if (cur_command->redir_types != NULL && cur_command->redir_types[0] == AMBIG)
{
free_command(cur_command);
return (AMBIG_REDIR);
}
if (cur_command->args != NULL)
{
return (handle_command(cur_command, xe, fd_in, proc));
......
......@@ -24,7 +24,7 @@ int parsing_error(int err_code, t_xe *xe)
(void)err_msg;
ft_putstr_fd("minishell: syntax error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code], STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 11], STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
xe->stat_loc = 2;
return (SUCCESS);
......@@ -39,7 +39,7 @@ int exec_error(int err_code, t_xe *xe)
(void)err_msg;
ft_putstr_fd("minishell: command error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 8], STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 9], STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
// have to set stat_loc as well !!!
if (err_code == HOME_NOT_SET)
......@@ -54,11 +54,12 @@ int exec_error(int err_code, t_xe *xe)
static const char *err_msg(int err_code)
{
const char *msg[] = {
const char *msg[5] = {
"Minishell takes no argument",
"Memory allocation failure",
"Cannot write on standard output",
"Cannot read standard input (GNL error)"};
"Cannot read standard input (GNL error)"
"Ambiguous redirection"};
return (msg[err_code]);
}
......@@ -91,7 +92,7 @@ int ft_error(int ret, t_xe *xe)
if (ret == CLEAN_EXIT || ret == CHILD_EXIT)
return (clean_and_exit(ret, xe));
else if (ret >= SQUOTE_MISSING)// temp
return (parsing_error(ret - 10, xe));
return (parsing_error(ret, xe));
else if (ret >= HOME_NOT_SET)
return (exec_error(ret, xe));
else if (ret > CHILD_EXIT)
......
......@@ -209,6 +209,6 @@ t_command *parse_one_command(t_xe *xe)
return (NULL);
}
else if (ret == AMBIG_REDIR)
;
cur_command->redir_types[0] = AMBIG;
return (cur_command);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment