Commit 94a50b82 authored by abenoit's avatar abenoit
Browse files

exit argument handling added

parent 955b71f6
......@@ -52,6 +52,7 @@ enum e_retcode
_EXIT_CODE_ = 2,
CLEAN_EXIT,
ARG_ERR,
FT_EXIT,
CHILD_EXIT,
CHILD_ERROR,
_ERRNO_MSG_,
......@@ -66,6 +67,7 @@ enum e_retcode
INVALID_EXP_ID,
INVALID_UNS_ID,
INVALID_PWD_PATH,
EXIT_ARG_ERR,
_PARSING_ERROR_,
SQUOTE_MISSING,
DQUOTE_MISSING,
......
......@@ -3,9 +3,13 @@
static int launch_exit(char **args, t_xe *xe)
{
(void)args;
(void)xe;
return (CLEAN_EXIT);
if (args != NULL)
{
if (ft_arraylen(args) != 2)
return (EXIT_ARG_ERR);
xe->stat_loc = ft_atoi(args[1]) % 256;
}
return (FT_EXIT);
}
static int search_path(DIR *dirp, char *name)
......
......@@ -30,7 +30,9 @@ int exec_error(int err_code, t_xe *xe)
"No such file or directory",
"export: Variable identifier (name) invalid",
"unset: Variable identifier (name) invalid",
"pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type"};
"pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type",
"exit: too many arguments"};
ft_putstr_fd("command error: ", STDERR_FILENO);
ft_putendl_fd(err_msg[err_code - _EXEC_ERROR_ - 1], STDERR_FILENO);
......@@ -69,7 +71,7 @@ int clean_and_exit(int err_code, t_xe *xe)
if (ft_putstr_fd("Minishell takes no argument", STDERR_FILENO) != WRITE_SUCCESS)
ft_error(WRITE_ERR, xe); // possible?
}
if (err_code < CHILD_EXIT)
if (err_code < FT_EXIT)
ret = EXIT_SUCCESS;
else
{
......@@ -85,7 +87,7 @@ int clean_and_exit(int err_code, t_xe *xe)
free(xe);
if (isatty(STDIN_FILENO)) // temp pour le testeur
{
if (err_code == CLEAN_EXIT)
if (err_code == CLEAN_EXIT || err_code == FT_EXIT)
{
if (ft_putstr_fd("exit\n", STDOUT_FILENO) != WRITE_SUCCESS)
return (WRITE_ERR); // possible?
......
......@@ -126,7 +126,7 @@ int main(int argc, char **argv, char **env_source)
ret = exec_env_init(xe, env_source);
if (ret != SUCCESS) // needed?
return (ft_exit(ret, xe)); // needed?
while (ret != CLEAN_EXIT && ret != FAILURE && ret != CHILD_EXIT) // why not while (ret == SUCCESS) ?
while (ret != CLEAN_EXIT && ret != FAILURE && ret != CHILD_EXIT && ret != FT_EXIT) // why not while (ret == SUCCESS) ?
ret = main_loop(xe);
}
return (ft_exit(ret, xe));
......
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