summaryrefslogtreecommitdiffstats
path: root/src/b_export.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/b_export.c')
-rw-r--r--src/b_export.c35
1 files changed, 13 insertions, 22 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);
}