diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | src/ft_b_builtins.h | 20 | ||||
| -rw-r--r-- | src/ft_b_env.c | 1 | ||||
| -rw-r--r-- | src/ft_b_exit.c | 47 | ||||
| -rw-r--r-- | src/ft_b_exit.h | 22 | ||||
| -rw-r--r-- | src/ft_d_define.h | 9 | ||||
| -rw-r--r-- | src/ft_e_lcom.c | 2 | ||||
| -rw-r--r-- | src/ft_f_fail.c | 8 | ||||
| -rw-r--r-- | src/ft_f_fail.h | 1 | ||||
| -rw-r--r-- | src/ft_m_funptr.c | 7 | 
10 files changed, 109 insertions, 12 deletions
| @@ -17,6 +17,7 @@ LFT_SRCS_DIR	= ${LFT_DIR}src/  SRCS_NAME		 = minishell.c  SRCS_NAME		+= ft_b_echo.c  SRCS_NAME		+= ft_b_env.c +SRCS_NAME		+= ft_b_exit.c  SRCS_NAME		+= ft_e_lcom.c  SRCS_NAME		+= ft_f_fail.c  SRCS_NAME		+= ft_m_funptr.c @@ -31,7 +32,8 @@ SRCS_NAME		+= ft_u_utils.c  #------------------------------------------------------------------------------#  SRCS			= $(addprefix ${SRCS_DIR}, ${SRCS_NAME})  #------------------------------------------------------------------------------# -INCS_NAME		 = ft_d_enum.h +INCS_NAME		 = ft_b_builtins.h +INCS_NAME		+= ft_d_enum.h  INCS_NAME		+= ft_d_define.h  INCS_NAME		+= ft_s_struct.h  INCS_NAME		+= $(patsubst %.c,%.h,${SRCS_NAME}) diff --git a/src/ft_b_builtins.h b/src/ft_b_builtins.h new file mode 100644 index 0000000..8a58f9d --- /dev/null +++ b/src/ft_b_builtins.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_b_builtins.h                                    :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#ifndef FT_B_BUILTINS_H +#define FT_B_BUILTINS_H + +#include "ft_b_echo.h" +#include "ft_b_env.h" +#include "ft_b_exit.h" + +#endif diff --git a/src/ft_b_env.c b/src/ft_b_env.c index d3df62d..2ac4000 100644 --- a/src/ft_b_env.c +++ b/src/ft_b_env.c @@ -12,7 +12,6 @@  #include <libft.h>  #include <stdint.h> -#include "ft_b_env.h"  #include "ft_f_fail.h"  #include "ft_s_struct.h" diff --git a/src/ft_b_exit.c b/src/ft_b_exit.c new file mode 100644 index 0000000..44efa80 --- /dev/null +++ b/src/ft_b_exit.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_b_exit.c                                        :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> +#include <stdint.h> +#include "ft_f_fail.h" +#include "ft_s_lcom.h" +#include "ft_s_destroy.h" +#include "ft_s_struct.h" +#include "ft_u_utils.h" + +uint8_t +	ft_b_exit(char *args[], +			t_msh *msh) +{ +	uint8_t			ret; +	const uint64_t	argc = ft_get_argc((const char**)args); + +	if (argc > 1) +	{ +		ft_fail_too_many_args("exit"); +		return (1); +	} +	if (argc == 1) +	{ +		ret = ft_atoi(args[0]); +	} +	else +	{ +		ret = msh->ret; +	} +	ft_lcom_clear(&msh->curr); +	ft_s_destroy(msh); +	ft_printf("exit\n"); +	exit(ret); +	return (0); +} diff --git a/src/ft_b_exit.h b/src/ft_b_exit.h new file mode 100644 index 0000000..5dd2a07 --- /dev/null +++ b/src/ft_b_exit.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_b_exit.h                                        :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#ifndef FT_B_EXIT_H +#define FT_B_EXIT_H + +#include <stdint.h> + +uint8_t +	ft_b_exit(char *args[], +			  t_msh *msh); + +#endif diff --git a/src/ft_d_define.h b/src/ft_d_define.h index e5ef970..2a8002d 100644 --- a/src/ft_d_define.h +++ b/src/ft_d_define.h @@ -20,14 +20,15 @@  */  #define FT_PS_ONE			"minishell ~> " -#define FT_BUILTINS			"echo|cd|pwd|export|unset|env|exit|cat" -#define FT_BUILTINS_COUNT	8 +#define FT_BUILTINS			"echo|cd|pwd|export|unset|env|exit" +#define FT_BUILTINS_COUNT	7  /*  ** ====== FAIL MSG ======  */ -#define FT_FAIL_ALLOC		"failed to allocate memory" -#define FT_FAIL_NO_OPTIONS	"no options required" +#define FT_FAIL_ALLOC			"failed to allocate memory" +#define FT_FAIL_NO_OPTIONS		"no options required" +#define FT_FAIL_TOO_MANY_ARGS	"too many arguments"  #endif diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index 409cbb1..69cdf35 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -41,7 +41,7 @@ uint8_t  		if ((bu_id = ft_get_builtin_id(ptr->com, msh))  			< FT_BUILTINS_COUNT)  		{ -			msh->bu_ptr[bu_id](ptr->args, msh); +			msh->ret = msh->bu_ptr[bu_id](ptr->args, msh);  		}  		else  		{ diff --git a/src/ft_f_fail.c b/src/ft_f_fail.c index aed16d0..3459702 100644 --- a/src/ft_f_fail.c +++ b/src/ft_f_fail.c @@ -19,7 +19,7 @@ static void  	ft_write_fail(const char concern[],  				const char msg[])  { -	ft_dprintf(STDERR_FILENO, "%s: %s\n", concern, msg); +	ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", concern, msg);  }  void @@ -29,6 +29,12 @@ void  }  void +	ft_fail_too_many_args(const char concern[]) +{ +	ft_write_fail(concern, FT_FAIL_TOO_MANY_ARGS); +} + +void  	ft_fail_alloc(void)  {  	ft_write_fail("minishell", FT_FAIL_ALLOC); diff --git a/src/ft_f_fail.h b/src/ft_f_fail.h index f34fd25..85d0c30 100644 --- a/src/ft_f_fail.h +++ b/src/ft_f_fail.h @@ -14,6 +14,7 @@  #define FT_F_FAIL_H  void	ft_fail_no_options(const char concern[]); +void	ft_fail_too_many_args(const char concern[]);  void	ft_fail_alloc(void);  #endif diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c index 813e5a3..bf2824e 100644 --- a/src/ft_m_funptr.c +++ b/src/ft_m_funptr.c @@ -12,9 +12,8 @@  #include <libft.h>  #include <stdlib.h> -#include "ft_b_echo.h" -#include "ft_b_env.h"  #include "ft_d_enum.h" +#include "ft_b_builtins.h"  #include "ft_f_fail.h"  #include "ft_m_funptr.h"  #include "ft_s_struct.h" @@ -28,8 +27,8 @@ void  	/* msh->bu_ptr[3] = ft_b_export; */  	/* msh->bu_ptr[4] = ft_b_unset; */  	msh->bu_ptr[5] = ft_b_env; -	/* msh->bu_ptr[6] = ft_b_exit; */ -	/* msh->bu_ptr[7] = ft_b_cat; */ +	msh->bu_ptr[6] = ft_b_exit; +	/* TODO: them builtins */  	if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))  	{  		ft_fail_alloc(); | 
