Commit 34b1c107 authored by abenoit's avatar abenoit
Browse files

few error fixes

parent df45bf93
......@@ -31,6 +31,6 @@ typedef int (*t_exec)(char **args, t_xe *xe);
int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types, t_xe *xe);
void apply_redirs(char **redir_paths, enum e_redir_op *redir_types);
int apply_redirs(char **redir_paths, enum e_redir_op *redir_types, t_xe *xe);
#endif
......@@ -61,6 +61,7 @@ enum e_retcode
GNL_ERR,
INVALID_CD_PATH,
INVALID_PWD_PATH,
FD_ERROR,
_EXEC_ERROR_,
AMBIG_REDIR,
HOME_NOT_SET,
......
============= Resolu ?
"exit 42" doit exit en renvoyant 42
et tester sur bash "exit 42 1431" ou "exit fds"
......@@ -11,29 +12,8 @@ et CTRL-\ ne fait rien sans commande en boucle inf
===========================??? oui on peut pas delete l'input en cours, et ensuite si on fait CTRL-C on peut plus refaire tout de suite CTRL-D, et y'a des leaks
CTRL-D apres avoir ecrit un debut de cmd
====================Strerror added
error when redir_in file does not exist ("< unknown_file")
-> tests:
< e
echo < e
echo fds < e
ls < e
====================Strerror added
error when redir_out file does not have write permission
-> memes tests que pour redir_in ci-dessus, en remplacant < par >
"cat | exit"======>ne devrait pas exit
check_syntax:
echo "'"
echo '\'
echo '"'
"cat |"======>multiline error
masaki:
......
......@@ -127,7 +127,11 @@ int handle_execution(t_xe *xe, int fd_in, int proc)
}
if (cur_command->args == NULL)
{
apply_redirs(cur_command->redir_paths, cur_command->redir_types);
if (apply_redirs(cur_command->redir_paths, cur_command->redir_types, xe))
{
free_command(cur_command);
return (FD_ERROR);
}
free_command(cur_command);
return (handle_execution(xe, fd_in, proc));
}
......
......@@ -194,7 +194,7 @@ enum e_cmd_code get_cmd_code(char *arg)
return (ELSE);
}
void apply_redir(char *cur_arg, enum e_redir_op redir)
int apply_redir(char *cur_arg, enum e_redir_op redir, t_xe *xe)
{
int src_fd;
int redir_fd;
......@@ -222,22 +222,26 @@ void apply_redir(char *cur_arg, enum e_redir_op redir)
}
else
{
ft_putstr_fd(cur_arg, STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO);
ft_putstr_fd(strerror(errno), STDERR_FILENO);
xe->stat_loc = 1;
return (FD_ERROR);
}
return (SUCCESS);
}
void apply_redirs(char **redir_paths, enum e_redir_op *redir_types)
int apply_redirs(char **redir_paths, enum e_redir_op *redir_types, t_xe *xe)
{
int i;
int ret;
i = 0;
while (redir_paths[i] != NULL)
{
apply_redir(redir_paths[i], redir_types[i]);
ret = apply_redir(redir_paths[i], redir_types[i], xe);
if (ret != SUCCESS)
return (ret);
i++;
}
return (SUCCESS);
}
int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types, t_xe *xe)
......@@ -251,7 +255,11 @@ int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types,
i = 0;
if (redir_paths != NULL)
apply_redirs(redir_paths, redir_types);
{
ret = apply_redirs(redir_paths, redir_types, xe);
if (ret != SUCCESS)
return (ret);
}
// printf("arg0 = %s\n", args[0]);
cmd_code = get_cmd_code(args[0]);
if (cmd_code == M_ERROR)
......
......@@ -54,7 +54,8 @@ static int err_output(int err_code)
"Cannot write on standard output",
"Cannot read standard input (GNL error)",
"cd",
"pwd"};
"pwd",
"fd"};
ft_putstr_fd("error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - _ERRNO_MSG_ -1], STDERR_FILENO);
......
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/01 11:25:20 by mvidal-a #+# #+# */
/* Updated: 2021/02/02 14:34:28 by abenoit ### ########.fr */
/* Updated: 2021/02/02 15:06:21 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -87,19 +87,25 @@ int check_bsl_and_quotes(unsigned int *flags, char c)
{
if (c == '\\')
{
if (*flags & S_QUOTE)
return (SUCCESS);
if (!(*flags & S_BACKSL))
*flags += S_BACKSL;
}
else if (c == '\'')
{
if (!(*flags & S_QUOTE))
if (*flags & S_DQUOTE)
return (SUCCESS);
else if (!(*flags & S_QUOTE))
*flags += S_QUOTE;
else
*flags -= S_QUOTE;
}
else if (c == '\"')
{
if (!(*flags & S_DQUOTE))
if (*flags & S_QUOTE)
return (SUCCESS);
else if (!(*flags & S_DQUOTE))
*flags += S_DQUOTE;
else
*flags -= S_DQUOTE;
......
Markdown is supported
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