diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 17:35:31 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-30 17:35:31 +0200 |
commit | bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2 (patch) | |
tree | 25c2442b74fd886c7970a0fe588bd9c7247abf98 | |
parent | Normed b_exit (diff) | |
download | 42-minishell-bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2.tar.gz 42-minishell-bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2.tar.bz2 42-minishell-bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2.tar.xz 42-minishell-bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2.tar.zst 42-minishell-bacf22e200cbf5d6ccfa82d6ad7776613b98c4a2.zip |
Norming b_export
-rw-r--r-- | src/b_export.c | 35 | ||||
-rw-r--r-- | src/b_export.h | 10 |
2 files changed, 18 insertions, 27 deletions
diff --git a/src/b_export.c b/src/b_export.c index aa0c5d0..411f142 100644 --- a/src/b_export.c +++ b/src/b_export.c @@ -25,8 +25,7 @@ #include "u_utils.h" #include "u_vars.h" -t_bool - check_valid_identifier(const char arg[]) +t_bool check_valid_identifier(const char arg[]) { char *ptr; @@ -38,8 +37,7 @@ t_bool return (FALSE); } -t_bool - check_equals(const char *arg) +t_bool check_equals(const char *arg) { char *ptr; @@ -55,10 +53,9 @@ t_bool return (FALSE); } -void - b_add_to_env_from_globals(const char varname[], - const char var[], - t_msh *msh) +void b_add_to_env_from_globals(const char varname[], + const char var[], + t_msh *msh) { size_t i; char **nenvp; @@ -66,16 +63,16 @@ void i = 0; while (msh->envp[i] != NULL) i++; - if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*)))) + if ((nenvp = (char**)malloc((i + 2) * sizeof(char*))) == NULL) f_alloc_and_destroy_msh(msh); i = 0; while (msh->envp[i] != NULL) { - if (!(nenvp[i] = ft_strdup(msh->envp[i]))) + if ((nenvp[i] = ft_strdup(msh->envp[i])) == NULL) f_alloc_and_destroy_msh(msh); i++; } - if (!(nenvp[i] = ft_strdup(var))) + if ((nenvp[i] = ft_strdup(var)) == NULL) f_alloc_and_destroy_msh(msh); nenvp[i + 1] = 0; ft_delwords(msh->envp); @@ -83,14 +80,12 @@ void msh->envp = nenvp; } -uint8_t - b_export(char *args[], t_msh *msh) +uint8_t b_export(char *args[], t_msh *msh) { /* TODO: norme */ char **ptr; char varval[4096]; char fmt[4096]; - t_bool next; uint8_t r; if (args[0] == NULL) @@ -99,16 +94,15 @@ uint8_t ptr = args; while (*ptr != NULL) { - next = FALSE; if (check_valid_identifier(*ptr) == FALSE) { f_fail_identifier("export", *ptr); - next = TRUE; r = 1; + ptr++; + continue ; } - if (next == FALSE && check_equals(*ptr) == FALSE) + if (check_equals(*ptr) == FALSE) { - next = TRUE; ft_sprintf(fmt, "$%s", *ptr); u_get_custom_var(varval, fmt, 4096, msh); if (varval[0] != C_NUL) @@ -117,12 +111,9 @@ uint8_t b_add_to_env_from_globals(*ptr, fmt, msh); } } - else if (next == FALSE && check_equals(*ptr) == TRUE) - { + else if (check_equals(*ptr) == TRUE) b_export_with_equals(*ptr, msh); - } ptr++; } - /* TODO: finish export */ return (r); } diff --git a/src/b_export.h b/src/b_export.h index 2634349..165fae4 100644 --- a/src/b_export.h +++ b/src/b_export.h @@ -10,13 +10,13 @@ /* */ /* ************************************************************************** */ -#ifndef B_EXPORT_H -#define B_EXPORT_H +#ifndef FT_B_EXPORT_H +# define FT_B_EXPORT_H -#include <libft.h> -#include <stdint.h> +# include <libft.h> +# include <stdint.h> -#include "s_struct.h" +# include "s_struct.h" t_bool check_valid_identifier(const char arg[]); t_bool check_equals(const char *arg); |