summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/b_exit.c7
-rw-r--r--src/b_export.c8
-rw-r--r--src/b_export.h8
-rw-r--r--src/b_export_mute.c71
-rw-r--r--src/b_export_mute.h24
-rw-r--r--src/e_builtins.c14
6 files changed, 120 insertions, 12 deletions
diff --git a/src/b_exit.c b/src/b_exit.c
index 5384d25..8e912a6 100644
--- a/src/b_exit.c
+++ b/src/b_exit.c
@@ -23,7 +23,7 @@
uint8_t
b_exit(char *args[],
- t_msh *msh)
+ t_msh *msh)
{
uint8_t ret;
const uint64_t argc = u_builtins_get_argc((const char**)args);
@@ -41,8 +41,5 @@ uint8_t
else
ret = msh->ret;
ft_dprintf(STDERR_FILENO, "exit\n");
- lcom_clear(&msh->curr);
- s_destroy(msh);
- exit(ret);
- return (0);
+ return (ret);
}
diff --git a/src/b_export.c b/src/b_export.c
index 4e3b4c7..0b5dbf6 100644
--- a/src/b_export.c
+++ b/src/b_export.c
@@ -25,7 +25,7 @@
#include "u_utils.h"
#include "u_vars.h"
-static t_bool
+t_bool
check_valid_identifier(const char arg[])
{
char *ptr;
@@ -38,7 +38,7 @@ static t_bool
return (FALSE);
}
-static t_bool
+t_bool
check_equals(const char *arg)
{
char *ptr;
@@ -55,7 +55,7 @@ static t_bool
return (FALSE);
}
-static void
+void
b_add_to_env_from_globals(const char varname[],
const char var[],
t_msh *msh)
@@ -95,9 +95,7 @@ uint8_t
uint8_t r;
if (args[0] == NULL)
- {
return (b_env(NULL, msh));
- }
r = 0;
ptr = args;
while (*ptr != NULL)
diff --git a/src/b_export.h b/src/b_export.h
index be703c2..2634349 100644
--- a/src/b_export.h
+++ b/src/b_export.h
@@ -13,8 +13,16 @@
#ifndef B_EXPORT_H
#define B_EXPORT_H
+#include <libft.h>
+#include <stdint.h>
+
#include "s_struct.h"
+t_bool check_valid_identifier(const char arg[]);
+t_bool check_equals(const char *arg);
+void b_add_to_env_from_globals(const char varname[],
+ const char var[],
+ t_msh *msh);
uint8_t b_export(char *args[], t_msh *msh);
#endif
diff --git a/src/b_export_mute.c b/src/b_export_mute.c
new file mode 100644
index 0000000..eed7f60
--- /dev/null
+++ b/src/b_export_mute.c
@@ -0,0 +1,71 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_export_mute.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 "b_export.h"
+#include "b_export_next.h"
+#include "d_enum.h"
+#include "f_fail.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_lvars.h"
+#include "s_struct.h"
+#include "u_utils.h"
+#include "u_vars.h"
+
+uint8_t
+ b_export_mute(char *args[],
+ t_msh *msh)
+{
+ /* TODO: norme */
+ char **ptr;
+ char *varval;
+ char fmt[4096];
+ t_bool next;
+ uint8_t r;
+
+ if (args[0] == NULL)
+ return (0);
+ r = 0;
+ ptr = args;
+ while (*ptr != NULL)
+ {
+ next = FALSE;
+ if (check_valid_identifier(*ptr) == FALSE)
+ {
+ next = TRUE;
+ r = 1;
+ }
+ if (next == FALSE && check_equals(*ptr) == FALSE)
+ {
+ next = TRUE;
+ ft_sprintf(fmt, "$%s", *ptr);
+ varval = u_get_cstm_vr(fmt, msh);
+ if (varval != NULL)
+ {
+ ft_sprintf(fmt, "%s=%s", *ptr, varval);
+ b_add_to_env_from_globals(*ptr, fmt, msh);
+ ft_memdel((void*)&varval);
+ }
+ }
+ else if (next == FALSE && check_equals(*ptr) == TRUE)
+ {
+ b_export_with_equals(*ptr, msh);
+ }
+ ptr++;
+ }
+ /* TODO: finish export */
+ return (r);
+}
diff --git a/src/b_export_mute.h b/src/b_export_mute.h
new file mode 100644
index 0000000..7253f23
--- /dev/null
+++ b/src/b_export_mute.h
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_export_mute.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 B_EXPORT_MUTE_H
+#define B_EXPORT_MUTE_H
+
+#include <stdint.h>
+
+#include "b_export.h"
+#include "s_struct.h"
+
+uint8_t b_export_mute(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/e_builtins.c b/src/e_builtins.c
index 607292e..bc348fd 100644
--- a/src/e_builtins.c
+++ b/src/e_builtins.c
@@ -16,6 +16,7 @@
#include <stdint.h>
#include <unistd.h>
+#include "b_export_mute.h"
#include "m_redirs.h"
#include "s_destroy.h"
#include "s_lcom.h"
@@ -48,8 +49,17 @@ static void
while (wait(&status) != pid)
;
ret = WEXITSTATUS(status);
- if (bu_id != FT_ID_EXIT)
- msh->ret = ret;
+ msh->ret = ret;
+ if (bu_id == FT_ID_CD && ret == 0)
+ msh->bu_ptr[bu_id](ptr->argv + 1, msh);
+ else if (bu_id == FT_ID_EXPORT)
+ b_export_mute(ptr->argv + 1, msh);
+ else if (bu_id == FT_ID_EXIT && ret == 0)
+ {
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ exit(ret);
+ }
}
void