summaryrefslogtreecommitdiffstats
path: root/src/ft_b_export.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-21 22:15:20 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-21 22:15:20 +0200
commitd54384fef56237ea8a88efe0a4fcd7f558c66252 (patch)
tree61f09270dca5273dbe63bbdd19141ff00ad76577 /src/ft_b_export.c
parentCool (diff)
download42-minishell-d54384fef56237ea8a88efe0a4fcd7f558c66252.tar.gz
42-minishell-d54384fef56237ea8a88efe0a4fcd7f558c66252.tar.bz2
42-minishell-d54384fef56237ea8a88efe0a4fcd7f558c66252.tar.xz
42-minishell-d54384fef56237ea8a88efe0a4fcd7f558c66252.tar.zst
42-minishell-d54384fef56237ea8a88efe0a4fcd7f558c66252.zip
Tryna export
Diffstat (limited to 'src/ft_b_export.c')
-rw-r--r--src/ft_b_export.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/ft_b_export.c b/src/ft_b_export.c
new file mode 100644
index 0000000..be4d94d
--- /dev/null
+++ b/src/ft_b_export.c
@@ -0,0 +1,74 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_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 "ft_b_env.h"
+#include "ft_f_fail.h"
+#include "ft_s_struct.h"
+#include "ft_u_utils.h"
+
+static int8_t
+ ft_check_valid_identifier(const char *arg)
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ if (ft_isalpha(ptr[0]))
+ {
+ return (1);
+ }
+ return (0);
+}
+
+static int8_t
+ ft_check_equals(const char *arg)
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ while (*ptr)
+ {
+ if (*ptr == '=')
+ return (1);
+ ptr++;
+ }
+ return (0);
+}
+
+uint8_t
+ ft_b_export(char *args[],
+ t_msh *msh)
+{
+ char **ptr;
+ const uint64_t argc = ft_get_argc((const char**)args);
+ int8_t next;
+
+ if (argc == 0)
+ {
+ return (ft_b_env(NULL, msh));
+ }
+ ptr = args;
+ while (*ptr)
+ {
+ next = 0;
+ if (!ft_check_valid_identifier(*ptr))
+ {
+ ft_fail_identifier("export", *ptr);
+ }
+ ft_check_equals(*ptr);
+ ptr++;
+ }
+ /* TODO: finish export */
+ return (0);
+}