diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_error.c | 4 | ||||
-rw-r--r-- | src/ft_exit.c | 13 | ||||
-rw-r--r-- | src/ft_process_arg.c | 2 |
3 files changed, 16 insertions, 3 deletions
diff --git a/src/ft_error.c b/src/ft_error.c index 2cc9cb6..2216eae 100644 --- a/src/ft_error.c +++ b/src/ft_error.c @@ -1,7 +1,7 @@ #include <libft.h> #include <minishell.h> -void +int ft_error(const char *com, int errno) { ft_putstr("joe-sh: "); @@ -10,5 +10,7 @@ ft_error(const char *com, int errno) ft_putendl(": too many arguments"); else if (errno == 127) ft_putendl(": command not found"); + else if (errno == 255) + ft_putendl(": numeric argument required"); return (errno); } diff --git a/src/ft_exit.c b/src/ft_exit.c index e09212c..513b4d1 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -16,7 +16,7 @@ #include <stdlib.h> uint8_t -ft_exit(const char **com) +ft_exit(char **com) { uint8_t i; @@ -26,4 +26,15 @@ ft_exit(const char **com) i++; if (i > 2) return (ft_error(com[0], 1)); + else if (com[1]) + { + i = 0; + while (ft_isdigit(com[1][i])) + i++; + if (i != ft_strlen(com[1])) + return (ft_error(com[0], 255)); + else + exit((uint8_t)ft_atoi(com[1])); + } + exit(0); } diff --git a/src/ft_process_arg.c b/src/ft_process_arg.c index 4f6ccf6..9a1b620 100644 --- a/src/ft_process_arg.c +++ b/src/ft_process_arg.c @@ -21,6 +21,6 @@ ft_process_arg(const char *arg) else if (!ft_strncmp(com[0], "pwd", ft_strlen(com[0]))) return (ft_pwd()); else - return (ft_error(com[0]), 127); + return (ft_error(com[0], 127)); return (0); } |