Commit 60f878b2 authored by komask's avatar komask
Browse files

reorg errors and exit

parent 12f12041
......@@ -37,6 +37,8 @@ INC_DIR = inc/
HDR += minishell.h
HDR += parsing.h
HDR += execution.h
HDR += builtins.h
HDR += error.h
vpath %.h $(INC_DIR)
......
......@@ -2,6 +2,7 @@
# define BUILTINS_H
# include "execution.h"
# include "error.h"
# define ECHO_OPTIONS "n"
# define ECHO_N_OPTION 0b00000001
......@@ -18,7 +19,7 @@ int ft_cd(char **args, t_xe *xe);
int ft_export(char **args, t_xe *xe);
int ft_unset(char **args, t_xe *xe);
int ft_env(char **args, t_xe *xe);
int ft_exit(enum e_retcode ret, t_xe *xe);
int launch_exit(char **args, t_xe *xe);
/*
** utils
......
#ifndef ERROR_H
# define ERROR_H
#include <string.h>
#include "minishell.h"
enum e_retcode
{
_EXIT_CODE_ = 2,
CLEAN_EXIT,
ARG_ERR,
FT_EXIT,
CHILD_EXIT,
CHILD_ERROR,
_ERRNO_MSG_,
MALLOC_ERR,
WRITE_ERR,
GNL_ERR,
INVALID_CD_PATH,
INVALID_CD_NEW_PATH,
INVALID_PWD_PATH,
INVALID_PATH_DIR,
FD_ERROR,
_EXEC_ERROR_,
AMBIG_REDIR,
HOME_NOT_SET,
NO_SUCH_FILE,
INVALID_EXP_ID,
INVALID_UNS_ID,
CD_ARG_ERR,
EXIT_ARG_ERR,
_PARSING_ERROR_,
SQUOTE_MISSING,
DQUOTE_MISSING,
ESCAPE_NL,
REDIR_PATH_INVALID,
REDIR_PATH_MISSING,
EMPTY_CMD
};
int clean_and_exit(int ret, t_xe *xe);
void putstr_stderr(const char *str);
int ft_error(int ret, t_xe *xe);
int ft_exit(enum e_retcode ret, t_xe *xe);
#endif
......@@ -7,6 +7,7 @@
#include <dirent.h> // readdir, opendir
# include "minishell.h"
# include "error.h"
# define NOT_FOUND -1
......
......@@ -47,40 +47,6 @@
** **********************************
*/
enum e_retcode
{
_EXIT_CODE_ = 2,
CLEAN_EXIT,
ARG_ERR,
FT_EXIT,
CHILD_EXIT,
CHILD_ERROR,
_ERRNO_MSG_,
MALLOC_ERR,
WRITE_ERR,
GNL_ERR,
INVALID_CD_PATH,
INVALID_CD_NEW_PATH,
INVALID_PWD_PATH,
INVALID_PATH_DIR,
FD_ERROR,
_EXEC_ERROR_,
AMBIG_REDIR,
HOME_NOT_SET,
NO_SUCH_FILE,
INVALID_EXP_ID,
INVALID_UNS_ID,
CD_ARG_ERR,
EXIT_ARG_ERR,
_PARSING_ERROR_,
SQUOTE_MISSING,
DQUOTE_MISSING,
ESCAPE_NL,
REDIR_PATH_INVALID,
REDIR_PATH_MISSING,
EMPTY_CMD
};
enum e_redir_op
{
NO_REDIR,
......@@ -135,12 +101,4 @@ void free_token(void *content);
void free_command(void *content);
void free_commands(t_list **commands);
/*
** ft_exit.c
*/
int clean_and_exit(int ret, t_xe *xe);
void putstr_stderr(const char *str);
int ft_error(int ret, t_xe *xe);
#endif
......@@ -2,6 +2,7 @@
# define PARSING_H
# include "minishell.h"
# include "error.h"
# define BUF_SIZE 4096
......
#include "builtins.h"
int ft_exit(enum e_retcode ret, t_xe *xe)
int launch_exit(char **args, t_xe *xe)
{
ft_error(ret, xe);
return (clean_and_exit(ret, xe));
if (args != NULL) // necessaire?
{
if (args[1] != NULL)
{
if (ft_isnumber(args[1]) == TRUE)
{
if (args[2] != NULL)
{
xe->stat_loc = 1;
return (EXIT_ARG_ERR);
}
xe->stat_loc = ft_atoi(args[1]) % 256;
}
else // "exit NaN"
{
xe->stat_loc = 2;
return (FT_EXIT);//another error, to print like bash
}
}
}
return (FT_EXIT);
}
#include "minishell.h"
#include "parsing.h"
#include "execution.h"
......
#include "execution.h"
#include "builtins.h"
#include <string.h>// dans un header
static int launch_exit(char **args, t_xe *xe)
{
if (args != NULL) // necessaire?
{
if (args[1] != NULL)
{
if (ft_isnumber(args[1]) == TRUE)
{
if (args[2] != NULL)
{
xe->stat_loc = 1;
return (EXIT_ARG_ERR);
}
xe->stat_loc = ft_atoi(args[1]) % 256;
}
else // "exit NaN"
{
xe->stat_loc = 2;
return (FT_EXIT);//another error, to print like bash
}
}
else
xe->stat_loc = 0;
}
return (FT_EXIT);
}
static int search_path(DIR *dirp, char *name)
{
struct dirent *buf;
......
#include "minishell.h"
#include "execution.h"
#include "parsing.h"
#include <string.h> // strerror
// -> header error.h?
int parsing_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
......@@ -117,3 +113,9 @@ int ft_error(int ret, t_xe *xe)
ft_putstr_fd("ERROR CODE ERROR (printed for debug)", STDERR_FILENO);// temp
return (SUCCESS);
}
int ft_exit(enum e_retcode ret, t_xe *xe)
{
ft_error(ret, xe);
return (clean_and_exit(ret, xe));
}
#include "minishell.h"
#include "error.h"
#include "parsing.h"
#include "execution.h"
#include "builtins.h"
......
#include "minishell.h"
#include "builtins.h"
static char *create_export_string(char *var_name, char *value)
......
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