diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-11-01 18:57:16 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-11-01 18:57:16 +0100 |
commit | 7cbf04d592608cf36832e25f9b41619df733e0ae (patch) | |
tree | 96c0d2006cd53fcbc2a628795b45b118ba9f3189 | |
parent | Now deals with history (diff) | |
download | 42-minishell-7cbf04d592608cf36832e25f9b41619df733e0ae.tar.gz 42-minishell-7cbf04d592608cf36832e25f9b41619df733e0ae.tar.bz2 42-minishell-7cbf04d592608cf36832e25f9b41619df733e0ae.tar.xz 42-minishell-7cbf04d592608cf36832e25f9b41619df733e0ae.tar.zst 42-minishell-7cbf04d592608cf36832e25f9b41619df733e0ae.zip |
commit
-rw-r--r-- | inc/minishell.h | 15 | ||||
-rw-r--r-- | src/ft_echo.c | 13 | ||||
-rw-r--r-- | src/ft_error.c | 9 | ||||
-rw-r--r-- | src/ft_exec.c | 27 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_process_arg.c | 17 | ||||
-rw-r--r-- | src/ft_pwd.c | 13 |
7 files changed, 86 insertions, 10 deletions
diff --git a/inc/minishell.h b/inc/minishell.h index 848811f..fd207de 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -1,3 +1,16 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* minishell.h .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/11/01 18:46:43 by rbousset #+# ## ## #+# */ +/* Updated: 2019/11/01 18:46:44 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #ifndef _MINISHELL_H__ #define _MINISHELL_H__ @@ -10,7 +23,7 @@ int ft_echo(char **com, uint8_t n); int ft_pwd(void); uint8_t ft_exit(char **com); int ft_error(const char *com, int errno); -int ft_exec(char **app); +int ft_exec(char **com); int ft_history(char *arg); char *ft_get_last_line(void); diff --git a/src/ft_echo.c b/src/ft_echo.c index 08fac36..22c1ec6 100644 --- a/src/ft_echo.c +++ b/src/ft_echo.c @@ -1,3 +1,16 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_echo.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/11/01 18:46:54 by rbousset #+# ## ## #+# */ +/* Updated: 2019/11/01 18:46:55 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <minishell.h> #include <inttypes.h> diff --git a/src/ft_error.c b/src/ft_error.c index 7a2b61a..933a22b 100644 --- a/src/ft_error.c +++ b/src/ft_error.c @@ -6,7 +6,7 @@ /* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2019/10/30 17:21:53 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/30 17:21:55 by rbousset ### #+. /#+ ###.fr */ +/* Updated: 2019/11/01 18:47:03 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ @@ -22,7 +22,12 @@ ft_error(const char *com, int err) if (err == 1) ft_putendl(": too many arguments"); else if (err == 127) - ft_putendl(": command not found"); + { + if (!ft_strncmp(com, "./", 2)) + ft_putendl(": no such file or directory"); + else + ft_putendl(": command not found"); + } else if (err == 255) ft_putendl(": numeric argument required"); return (err); diff --git a/src/ft_exec.c b/src/ft_exec.c index b9d50cf..dffaf3d 100644 --- a/src/ft_exec.c +++ b/src/ft_exec.c @@ -1,14 +1,35 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_exec.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/11/01 18:46:50 by rbousset #+# ## ## #+# */ +/* Updated: 2019/11/01 18:47:21 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <minishell.h> #include <unistd.h> int -ft_exec(char **app) +ft_exec(char **com) { uint8_t i; i = 0; - while (app[i]) + while (com[i]) i++; - return (execve(app[0] + 2, app, NULL)); + if (!ft_strncmp(com[0], "./", 2)) + { + if ((execve(com[0] + 2, com, NULL)) != 0) + return (ft_error(com[0], 127)); + } + else + if ((execve(com[0] + 2, com, NULL)) != 0) + return (ft_error(com[0], 127)); + return (0); } diff --git a/src/ft_exit.c b/src/ft_exit.c index f91183d..1d84615 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -6,7 +6,7 @@ /* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2019/10/30 16:05:48 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/30 16:05:50 by rbousset ### #+. /#+ ###.fr */ +/* Updated: 2019/11/01 18:47:18 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ diff --git a/src/ft_process_arg.c b/src/ft_process_arg.c index 6a2d155..8057e42 100644 --- a/src/ft_process_arg.c +++ b/src/ft_process_arg.c @@ -1,3 +1,16 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_process_arg.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/11/01 18:47:30 by rbousset #+# ## ## #+# */ +/* Updated: 2019/11/01 18:47:32 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <stdlib.h> #include <minishell.h> @@ -32,9 +45,7 @@ ft_process_arg(char *arg) ft_process_arg(prev); free(prev); } - else if (!ft_strncmp(com[0], "./", 2)) - ft_exec(com); else - return (ft_error(com[0], 127)); + return (ft_exec(com)); return (0); } diff --git a/src/ft_pwd.c b/src/ft_pwd.c index bd67873..07e5622 100644 --- a/src/ft_pwd.c +++ b/src/ft_pwd.c @@ -1,3 +1,16 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_pwd.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/11/01 18:47:41 by rbousset #+# ## ## #+# */ +/* Updated: 2019/11/01 18:47:47 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <stddef.h> #include <unistd.h> |