diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-10-30 17:05:31 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-10-30 17:05:31 +0100 |
commit | 3051df7c3e57d5645a78d87fa63ff1144fd8699a (patch) | |
tree | 5676fe8501f965cc9e62b8c25791ce1c9a04b0f4 | |
parent | work work (diff) | |
download | 42-minishell-3051df7c3e57d5645a78d87fa63ff1144fd8699a.tar.gz 42-minishell-3051df7c3e57d5645a78d87fa63ff1144fd8699a.tar.bz2 42-minishell-3051df7c3e57d5645a78d87fa63ff1144fd8699a.tar.xz 42-minishell-3051df7c3e57d5645a78d87fa63ff1144fd8699a.tar.zst 42-minishell-3051df7c3e57d5645a78d87fa63ff1144fd8699a.zip |
exit function works
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | inc/minishell.h | 2 | ||||
-rw-r--r-- | libft/Makefile | 1 | ||||
-rw-r--r-- | libft/src/ft_itoa.c | 4 | ||||
-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 |
7 files changed, 26 insertions, 10 deletions
@@ -23,7 +23,7 @@ SRCS = \ OBJS_DIR = obj/ OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS}) -INCS_DIR = -Iinc/ -Ilibft/ +INCS_DIR = -Iinc/ -Ilibft/inc/ LIB_DIR = -Llibft/ LIB = -lft @@ -40,7 +40,7 @@ RM = rm -rf MKDIR = mkdir -p -${OBJS_DIR}%.o: ${SRCS_DIR}%.c inc/minishell.h libft/libft.h +${OBJS_DIR}%.o: ${SRCS_DIR}%.c inc/minishell.h libft/inc/libft.h @${MKDIR} ${OBJS_DIR} ${CC} ${CFLAGS} ${DEBUG} ${INCS_DIR} -o $@ -c $< @@ -52,10 +52,12 @@ all: ${NAME} clean: ${RM} ${OBJS} ${B_OBJS} -fclean: clean +xclean: ${RM} ${NAME} ${RM} ${NAME}.dSYM +fclean: clean xclean + re: fclean all build: ${OBJS} @@ -63,4 +65,4 @@ build: ${OBJS} default: all -.PHONY: all clean clean fclean re bonus run +.PHONY: all clean clean fclean re diff --git a/inc/minishell.h b/inc/minishell.h index ef33b88..ecc693a 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -6,7 +6,7 @@ int ft_process_arg(const char *arg); int ft_echo(char **com, uint8_t n); int ft_pwd(void); -uint8_t ft_exit(const char **com); +uint8_t ft_exit(char **com); int ft_error(const char *com, int errno); #endif diff --git a/libft/Makefile b/libft/Makefile index 83c4b54..1b41ad7 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -86,6 +86,7 @@ NAME = libft.a MKDIR = mkdir -p RM = rm -rf + ${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS} @if [ ! -a ${OBJS_DIR} ]; then \ ${MKDIR} ${OBJS_DIR}; \ diff --git a/libft/src/ft_itoa.c b/libft/src/ft_itoa.c index bf3c0c8..98f33f2 100644 --- a/libft/src/ft_itoa.c +++ b/libft/src/ft_itoa.c @@ -16,7 +16,7 @@ #include <stdlib.h> static uint8_t - ft_intlen(int n) + ft_intllen(int n) { uint8_t len; @@ -40,7 +40,7 @@ char unsigned int nb; uint8_t i; - i = ft_intlen(n) - 1; + i = ft_intllen(n) - 1; if (!(s = (char*)malloc((i + 2) * sizeof(char)))) return (NULL); if (!n) 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); } |