diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/ft_b_builtins.h | 1 | ||||
-rw-r--r-- | src/ft_b_env.c | 2 | ||||
-rw-r--r-- | src/ft_b_export.c | 74 | ||||
-rw-r--r-- | src/ft_b_export.h | 20 | ||||
-rw-r--r-- | src/ft_f_fail.c | 9 | ||||
-rw-r--r-- | src/ft_f_fail.h | 2 | ||||
-rw-r--r-- | src/ft_m_funptr.c | 2 |
8 files changed, 109 insertions, 2 deletions
@@ -18,6 +18,7 @@ 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_b_export.c SRCS_NAME += ft_e_lcom.c SRCS_NAME += ft_f_fail.c SRCS_NAME += ft_m_funptr.c diff --git a/src/ft_b_builtins.h b/src/ft_b_builtins.h index 8a58f9d..21ffe0b 100644 --- a/src/ft_b_builtins.h +++ b/src/ft_b_builtins.h @@ -16,5 +16,6 @@ #include "ft_b_echo.h" #include "ft_b_env.h" #include "ft_b_exit.h" +#include "ft_b_export.h" #endif diff --git a/src/ft_b_env.c b/src/ft_b_env.c index 2ac4000..c602c13 100644 --- a/src/ft_b_env.c +++ b/src/ft_b_env.c @@ -21,7 +21,7 @@ uint8_t { char **ptr; - if (args[0]) + if (args && args[0]) { ft_fail_no_options("env"); return (127); diff --git a/src/ft_b_export.c b/src/ft_b_export.c new file mode 100644 index 0000000..be4d94d --- /dev/null +++ b/src/ft_b_export.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_b_export.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_b_env.h" +#include "ft_f_fail.h" +#include "ft_s_struct.h" +#include "ft_u_utils.h" + +static int8_t + ft_check_valid_identifier(const char *arg) +{ + char *ptr; + + ptr = (char*)arg; + if (ft_isalpha(ptr[0])) + { + return (1); + } + return (0); +} + +static int8_t + ft_check_equals(const char *arg) +{ + char *ptr; + + ptr = (char*)arg; + while (*ptr) + { + if (*ptr == '=') + return (1); + ptr++; + } + return (0); +} + +uint8_t + ft_b_export(char *args[], + t_msh *msh) +{ + char **ptr; + const uint64_t argc = ft_get_argc((const char**)args); + int8_t next; + + if (argc == 0) + { + return (ft_b_env(NULL, msh)); + } + ptr = args; + while (*ptr) + { + next = 0; + if (!ft_check_valid_identifier(*ptr)) + { + ft_fail_identifier("export", *ptr); + } + ft_check_equals(*ptr); + ptr++; + } + /* TODO: finish export */ + return (0); +} diff --git a/src/ft_b_export.h b/src/ft_b_export.h new file mode 100644 index 0000000..3a28562 --- /dev/null +++ b/src/ft_b_export.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_b_export.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_EXPORT_H +#define FT_B_EXPORT_H + +uint8_t + ft_b_export(char *args[], + t_msh *msh); + +#endif diff --git a/src/ft_f_fail.c b/src/ft_f_fail.c index 3459702..9a826ed 100644 --- a/src/ft_f_fail.c +++ b/src/ft_f_fail.c @@ -28,6 +28,15 @@ void ft_write_fail(concern, FT_FAIL_NO_OPTIONS); } + /* TODO: export failed identifier `123' */ +void + ft_fail_identifier(const char concern[], + const char identifier[]) +{ + ft_dprintf(STDERR_FILENO, + "minishell: %s: `%s': not a valid identifier\n", concern, identifier); +} + void ft_fail_too_many_args(const char concern[]) { diff --git a/src/ft_f_fail.h b/src/ft_f_fail.h index 85d0c30..60f989d 100644 --- a/src/ft_f_fail.h +++ b/src/ft_f_fail.h @@ -15,6 +15,8 @@ void ft_fail_no_options(const char concern[]); void ft_fail_too_many_args(const char concern[]); +void ft_fail_identifier(const char concern[], + const char identifier[]); void ft_fail_alloc(void); #endif diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c index bf2824e..22b390f 100644 --- a/src/ft_m_funptr.c +++ b/src/ft_m_funptr.c @@ -24,7 +24,7 @@ void msh->bu_ptr[0] = ft_b_echo; /* msh->bu_ptr[1] = ft_b_cd; */ /* msh->bu_ptr[2] = ft_b_pwd; */ - /* msh->bu_ptr[3] = ft_b_export; */ + 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; |