summaryrefslogtreecommitdiffstats
path: root/src/b_export.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-07-27 18:55:07 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-07-27 18:55:07 +0200
commit487a66394061f2d14a2fa421302966b5442d643f (patch)
tree34237d4e9cb85f94bcefd46f399d2224dff3f6b3 /src/b_export.c
parentCorrect shell prompt (diff)
download42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.gz
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.bz2
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.xz
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.zst
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.zip
I couldn't see shit
Diffstat (limited to 'src/b_export.c')
-rw-r--r--src/b_export.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/b_export.c b/src/b_export.c
new file mode 100644
index 0000000..5e7ee14
--- /dev/null
+++ b/src/b_export.c
@@ -0,0 +1,80 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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 "b_env.h"
+#include "f_fail.h"
+#include "s_struct.h"
+#include "u_utils.h"
+
+static int8_t
+ check_valid_identifier(const char *arg)
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ if (ft_isalpha(ptr[0]))
+ {
+ return (1);
+ }
+ return (0);
+}
+
+static int8_t
+ check_equals(const char *arg)
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ while (*ptr)
+ {
+ if (*ptr == '=')
+ return (1);
+ ptr++;
+ }
+ return (0);
+}
+
+uint8_t
+ b_export(char *args[],
+ t_msh *msh)
+{
+ const uint64_t argc = get_argc((const char**)args);
+ char **ptr;
+ int8_t next;
+ uint8_t r;
+
+ if (argc == 0)
+ {
+ return (b_env(NULL, msh));
+ }
+ ptr = args;
+ r = 0;
+ while (*ptr)
+ {
+ next = 0;
+ if (!check_valid_identifier(*ptr))
+ {
+ fail_identifier("export", *ptr, msh);
+ next = 1;
+ r = 1;
+ }
+ if (next == 0 && !check_equals(*ptr))
+ next = 1;
+ ptr++;
+ }
+ /* TODO: finish export */
+ return (r);
+}