summaryrefslogtreecommitdiffstats
path: root/src/b_export.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-30 17:39:59 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-30 17:39:59 +0200
commitcc81be8051e0206cdd7aa83766dafa4d6defad0c (patch)
treec693f0933e0fdad8b84d0e1468dfe1e3a31947ce /src/b_export.c
parentNorming b_export (diff)
download42-minishell-cc81be8051e0206cdd7aa83766dafa4d6defad0c.tar.gz
42-minishell-cc81be8051e0206cdd7aa83766dafa4d6defad0c.tar.bz2
42-minishell-cc81be8051e0206cdd7aa83766dafa4d6defad0c.tar.xz
42-minishell-cc81be8051e0206cdd7aa83766dafa4d6defad0c.tar.zst
42-minishell-cc81be8051e0206cdd7aa83766dafa4d6defad0c.zip
Normed b_export
Diffstat (limited to '')
-rw-r--r--src/b_export.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/b_export.c b/src/b_export.c
index 411f142..8b72b64 100644
--- a/src/b_export.c
+++ b/src/b_export.c
@@ -80,12 +80,30 @@ void b_add_to_env_from_globals(const char varname[],
msh->envp = nenvp;
}
-uint8_t b_export(char *args[], t_msh *msh)
+static void b_classic_export(char *ptr[], t_msh *msh)
{
- /* TODO: norme */
- char **ptr;
char varval[4096];
char fmt[4096];
+
+ if (check_equals(*ptr) == FALSE)
+ {
+ ft_sprintf(fmt, "$%s", *ptr);
+ u_get_custom_var(varval, fmt, 4096, msh);
+ if (varval[0] != C_NUL)
+ {
+ ft_sprintf(fmt, "%s=%s", *ptr, varval);
+ b_add_to_env_from_globals(*ptr, fmt, msh);
+ }
+ }
+ else
+ {
+ b_export_with_equals(*ptr, msh);
+ }
+}
+
+uint8_t b_export(char *args[], t_msh *msh)
+{
+ char **ptr;
uint8_t r;
if (args[0] == NULL)
@@ -101,18 +119,7 @@ uint8_t b_export(char *args[], t_msh *msh)
ptr++;
continue ;
}
- if (check_equals(*ptr) == FALSE)
- {
- ft_sprintf(fmt, "$%s", *ptr);
- u_get_custom_var(varval, fmt, 4096, msh);
- if (varval[0] != C_NUL)
- {
- ft_sprintf(fmt, "%s=%s", *ptr, varval);
- b_add_to_env_from_globals(*ptr, fmt, msh);
- }
- }
- else if (check_equals(*ptr) == TRUE)
- b_export_with_equals(*ptr, msh);
+ b_classic_export(ptr, msh);
ptr++;
}
return (r);