Commit 7e4da298 authored by abenoit's avatar abenoit
Browse files

full clean before last tests

parent bab2c59d
......@@ -11,6 +11,8 @@ SRC += free_utils.c
SRC += var_utils.c
SRC += check_syntax.c
SRC += syntax_utils_1.c
SRC += syntax_utils_2.c
SRC += parsing_handler.c
SRC += parsing_states1.c
SRC += parsing_states2.c
......@@ -35,6 +37,7 @@ SRC += ft_env.c
SRC += ft_exit.c
SRC += ft_error.c
SRC += error_utils.c
vpath %.c $(SRC_DIR)
......
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 16:42:53 by mvidal-a #+# #+# */
/* Updated: 2021/02/11 18:39:06 by abenoit ### ########.fr */
/* Updated: 2021/02/11 18:55:40 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -25,13 +25,13 @@
** builtins
*/
int ft_echo(char **args, t_xe *xe);
int ft_pwd(char **args, t_xe *xe);
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(char **args, t_xe *xe);
int ft_echo(char **args, t_xe *xe);
int ft_pwd(char **args, t_xe *xe);
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(char **args, t_xe *xe);
/*
** utils
......
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 16:52:06 by mvidal-a #+# #+# */
/* Updated: 2021/02/11 16:52:07 by mvidal-a ### ########.fr */
/* Updated: 2021/02/11 18:53:02 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -51,8 +51,21 @@ enum e_retcode
EMPTY_CMD,
};
/*
** ft_error.c
*/
int exit_trigger(int ret, t_xe *xe);
int clean_and_exit(int ret, t_xe *xe);
int ft_error(int ret, t_xe *xe);
int error_and_exit(enum e_retcode ret, t_xe *xe);
/*
** ft_error.c
*/
int parsing_error(int err_code, t_xe *xe);
int exec_error(int err_code, t_xe *xe);
int err_output(int err_code, t_xe *xe);
#endif
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 16:49:21 by mvidal-a #+# #+# */
/* Updated: 2021/02/11 16:55:00 by mvidal-a ### ########.fr */
/* Updated: 2021/02/11 18:57:12 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -36,27 +36,29 @@ enum e_cmd_code
ELSE
};
typedef int (*t_exec)(char **args, t_xe *xe);
int handle_execution(t_xe *xe, int fd_in, int proc);
typedef int (*t_exec)(char **args, t_xe *xe);
/*
** main function
*/
int handle_execution(t_xe *xe, int fd_in, int proc);
int parent_pipe_end(t_command *cur_command, t_xe *xe,
int fd_in, int proc);
int fd_in, int proc);
int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types, t_xe *xe);
int execute_cmd(char **args, char **redir_paths,
enum e_redir_op *redir_types, t_xe *xe);
int apply_redirs(char **redir_paths, enum e_redir_op *redir_types, t_xe *xe);
int find_ambig_redir(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 find_ambig_redir(char **redir_paths, enum e_redir_op *redir_types);
/*
** main function
*/
int create_cmd(char **tmp, char **path, char **args);
char **create_path_array(t_xe *xe);
int create_cmd(char **tmp, char **path, char **args);
char **create_path_array(t_xe *xe);
#endif
......@@ -6,15 +6,13 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 16:52:23 by mvidal-a #+# #+# */
/* Updated: 2021/02/11 16:57:03 by mvidal-a ### ########.fr */
/* Updated: 2021/02/11 18:57:29 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
#include <stdio.h> // temp, for printf
/*
** **********************************
** ** GENERAL INCLUDES **
......
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 18:50:30 by abenoit #+# #+# */
/* Updated: 2021/02/11 18:54:13 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
#include "execution.h"
#include "parsing.h"
int parsing_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"No matching single quote",
"No matching double quote",
"Multiline inputs are currently not supported",
"Redirection path invalid",
"No redirection path specified",
"Empty command before ; or |"};
ft_putstr_fd("syntax error: ", STDERR_FILENO);
ft_putendl_fd(err_msg[err_code - _PARSING_ERROR_ - 1], STDERR_FILENO);
xe->stat_loc = 2;
return (SUCCESS);
}
int exec_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"Ambiguous redirection",
"Commmand not found",
"export: Variable identifier (name) invalid",
"unset: Variable identifier (name) invalid",
"HOME not set",
"cd: too many arguments",
"exit: too many arguments"};
ft_putstr_fd("command error: ", STDERR_FILENO);
ft_putendl_fd(err_msg[err_code - _EXEC_ERROR_ - 1], STDERR_FILENO);
if (err_code == CMD_NOT_FOUND)
xe->stat_loc = 127;
if (xe->flags & EXEC_PIPE || xe->flags & CHILD)
xe->flags = 0;
else if (err_code == EXIT_ARG_ERR)
xe->flags = RUN;
return (SUCCESS);
}
static int ext_cmd_exit(t_xe *xe)
{
if (errno == ENOENT)
xe->stat_loc = 127;
else if (errno == EACCES || errno == ENOEXEC)
xe->stat_loc = 126;
return (exit_trigger(xe->stat_loc, xe));
}
int err_output(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"Memory allocation failure",
"Cannot write on standard output",
"Cannot read standard input (GNL error)",
"cd: cannot change directory",
"cd: cannot set variable PWD",
"pwd: cannot get current directory path",
"Error reading a directory in PATH",
"fd issue",
"external command error",
"fork failure",
"wait failure"};
(void)xe;
ft_putstr_fd("error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - _ERRNO_MSG_ - 1], STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO);
ft_putendl_fd(strerror(errno), STDERR_FILENO);
if (err_code == EXT_CMD_ERROR)
return (ext_cmd_exit(xe));
else if (err_code == FORK_ERROR || err_code == WAIT_ERROR)
xe->stat_loc = 1;
return (SUCCESS);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 18:41:13 by abenoit #+# #+# */
/* Updated: 2021/02/11 18:50:48 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
#include "execution.h"
#include "parsing.h"
int parsing_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"No matching single quote",
"No matching double quote",
"Multiline inputs are currently not supported",
"Redirection path invalid",
"No redirection path specified",
"Empty command before ; or |"};
ft_putstr_fd("syntax error: ", STDERR_FILENO);
ft_putendl_fd(err_msg[err_code - _PARSING_ERROR_ - 1], STDERR_FILENO);
xe->stat_loc = 2;
return (SUCCESS);
}
int exec_error(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"Ambiguous redirection",
"Commmand not found",
"export: Variable identifier (name) invalid",
"unset: Variable identifier (name) invalid",
"HOME not set",
"cd: too many arguments",
"exit: too many arguments"};
ft_putstr_fd("command error: ", STDERR_FILENO);
ft_putendl_fd(err_msg[err_code - _EXEC_ERROR_ - 1], STDERR_FILENO);
if (err_code == CMD_NOT_FOUND)
xe->stat_loc = 127;
if (xe->flags & EXEC_PIPE || xe->flags & CHILD)
xe->flags = 0;
else if (err_code == EXIT_ARG_ERR)
xe->flags = RUN;
return (SUCCESS);
}
static int err_output(int err_code, t_xe *xe)
{
const char *err_msg[] = {
"Memory allocation failure",
"Cannot write on standard output",
"Cannot read standard input (GNL error)",
"cd: cannot change directory",
"cd: cannot set variable PWD",
"pwd: cannot get current directory path",
"Error reading a directory in PATH",
"fd issue",
"external command error",
"fork failure",
"wait failure"};
(void)xe;
ft_putstr_fd("error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - _ERRNO_MSG_ - 1], STDERR_FILENO);
ft_putstr_fd(": ", STDERR_FILENO);
ft_putendl_fd(strerror(errno), STDERR_FILENO);
if (err_code == EXT_CMD_ERROR)
{
if (errno == ENOENT)
xe->stat_loc = 127;
else if (errno == EACCES || errno == ENOEXEC)
xe->stat_loc = 126;
exit(xe->stat_loc);
}
else if (err_code == FORK_ERROR || err_code == WAIT_ERROR)
xe->stat_loc = 1;
return (SUCCESS);
}
int exit_trigger(int ret, t_xe *xe)
{
if (!(xe->flags & EXIT_ABORT))
......
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 18:47:33 by abenoit #+# #+# */
/* Updated: 2021/02/11 18:48:17 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "error.h"
#include "parsing.h"
#include "execution.h"
#include "builtins.h"
static int get_input(char **line, t_xe *xe)
static int get_input(char **line, t_xe *xe)
{
int ret;
......@@ -24,7 +36,7 @@ static int get_input(char **line, t_xe *xe)
return (SUCCESS);
}
static int main_loop(t_xe *xe)
static int main_loop(t_xe *xe)
{
int ret;
char *line;
......@@ -42,7 +54,7 @@ static int main_loop(t_xe *xe)
return (ret);
}
int exec_env_init(t_xe *xe, char **env_source)
int exec_env_init(t_xe *xe, char **env_source)
{
char *shlvl;
int tmp;
......@@ -70,7 +82,7 @@ int exec_env_init(t_xe *xe, char **env_source)
return (SUCCESS);
}
int main(int argc, char **argv, char **env_source)
int main(int argc, char **argv, char **env_source)
{
int ret;
t_xe *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