summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-04 15:52:47 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-04 15:52:47 +0200
commit5cb3373a2e5a5109a5d3b72ef45978b98f885706 (patch)
tree11a0a6f467da3ddf227d2eaf6824c4509242025e /src
parentok nice (diff)
parent$? fix (diff)
download42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.gz
42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.bz2
42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.xz
42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.tar.zst
42-minishell-5cb3373a2e5a5109a5d3b72ef45978b98f885706.zip
Merge branch 'master' into fix-pwd
Diffstat (limited to 'src')
-rw-r--r--src/b_builtins.h25
-rw-r--r--src/b_cd.c (renamed from src/ft_b_cd.c)36
-rw-r--r--src/b_cd.h (renamed from src/ft_m_loop.h)10
-rw-r--r--src/b_echo.c (renamed from src/ft_b_echo.c)20
-rw-r--r--src/b_echo.h22
-rw-r--r--src/b_env.c (renamed from src/ft_b_env.c)11
-rw-r--r--src/b_env.h22
-rw-r--r--src/b_exit.c (renamed from src/ft_b_exit.c)23
-rw-r--r--src/b_exit.h22
-rw-r--r--src/b_export.c131
-rw-r--r--src/b_export.h20
-rw-r--r--src/b_export_next.c114
-rw-r--r--src/b_export_next.h27
-rw-r--r--src/b_pwd.c (renamed from src/ft_b_pwd.c)6
-rw-r--r--src/b_pwd.h22
-rw-r--r--src/b_type.c (renamed from src/ft_b_type.c)34
-rw-r--r--src/b_type.h22
-rw-r--r--src/b_unset.c138
-rw-r--r--src/b_unset.h22
-rw-r--r--src/d_define.h (renamed from src/ft_d_define.h)24
-rw-r--r--src/d_enum.h (renamed from src/ft_d_enum.h)25
-rw-r--r--src/e_builtins.c35
-rw-r--r--src/e_builtins.h (renamed from src/ft_m_comm.h)11
-rw-r--r--src/e_externs.c (renamed from src/ft_e_externs.c)41
-rw-r--r--src/e_externs.h (renamed from src/ft_s_destroy.h)10
-rw-r--r--src/e_externs_next.c (renamed from src/ft_e_externs_next.c)34
-rw-r--r--src/e_externs_next.h21
-rw-r--r--src/e_externs_pipes.c (renamed from src/ft_e_externs_pipes.c)42
-rw-r--r--src/e_externs_pipes.h (renamed from src/ft_b_cd.h)12
-rw-r--r--src/e_lcom.c (renamed from src/ft_e_lcom.c)24
-rw-r--r--src/e_lcom.h (renamed from src/ft_u_utils.h)9
-rw-r--r--src/e_pipes.c (renamed from src/ft_e_pipes.c)22
-rw-r--r--src/e_pipes.h (renamed from src/ft_m_funptr.h)10
-rw-r--r--src/f_alloc.c36
-rw-r--r--src/f_alloc.h (renamed from src/ft_b_pwd.h)13
-rw-r--r--src/f_chdir.c (renamed from src/ft_f_chdir.c)6
-rw-r--r--src/f_chdir.h (renamed from src/ft_e_externs.h)11
-rw-r--r--src/f_com.c23
-rw-r--r--src/f_com.h20
-rw-r--r--src/f_errno.c (renamed from src/ft_f_errno.c)6
-rw-r--r--src/f_errno.h (renamed from src/ft_p_line.h)11
-rw-r--r--src/f_fail.c (renamed from src/ft_f_fail.c)32
-rw-r--r--src/f_fail.h27
-rw-r--r--src/f_redir.c (renamed from src/ft_f_redir.c)12
-rw-r--r--src/f_redir.h20
-rw-r--r--src/ft_b_builtins.h25
-rw-r--r--src/ft_b_export.c79
-rw-r--r--src/ft_b_type.h22
-rw-r--r--src/ft_b_unset.c24
-rw-r--r--src/ft_b_unset.h22
-rw-r--r--src/ft_e_builtins.c90
-rw-r--r--src/ft_e_builtins.h23
-rw-r--r--src/ft_e_externs_next.h23
-rw-r--r--src/ft_e_externs_pipes.h20
-rw-r--r--src/ft_f_chdir.h22
-rw-r--r--src/ft_f_fail.h30
-rw-r--r--src/ft_f_redir.h21
-rw-r--r--src/ft_m_prompt.h20
-rw-r--r--src/ft_m_redirs.h21
-rw-r--r--src/ft_p_lcom_next.h25
-rw-r--r--src/ft_s_lcom.h23
-rw-r--r--src/ft_s_lvars.h29
-rw-r--r--src/ft_u_vars.h21
-rw-r--r--src/m_argv.c (renamed from src/ft_m_argv.c)16
-rw-r--r--src/m_argv.h (renamed from src/ft_b_env.h)12
-rw-r--r--src/m_comm.c (renamed from src/ft_m_comm.c)20
-rw-r--r--src/m_comm.h22
-rw-r--r--src/m_funptr.c (renamed from src/ft_m_funptr.c)32
-rw-r--r--src/m_funptr.h (renamed from src/ft_b_export.h)12
-rw-r--r--src/m_loop.c (renamed from src/ft_m_loop.c)39
-rw-r--r--src/m_loop.h (renamed from src/ft_b_exit.h)12
-rw-r--r--src/m_minishell.c (renamed from src/minishell.c)26
-rw-r--r--src/m_minishell.h (renamed from src/minishell.h)6
-rw-r--r--src/m_prompt.c (renamed from src/ft_m_prompt.c)10
-rw-r--r--src/m_prompt.h21
-rw-r--r--src/m_redirs.c (renamed from src/ft_m_redirs.c)18
-rw-r--r--src/m_redirs.h (renamed from src/ft_e_pipes.h)10
-rw-r--r--src/p_lcom.c (renamed from src/ft_p_lcom.c)37
-rw-r--r--src/p_lcom.h (renamed from src/ft_m_argv.h)13
-rw-r--r--src/p_lcom_next.c (renamed from src/ft_p_lcom_next.c)132
-rw-r--r--src/p_lcom_next.h (renamed from src/ft_p_lcom.h)16
-rw-r--r--src/p_line.c (renamed from src/ft_p_line.c)22
-rw-r--r--src/p_line.h20
-rw-r--r--src/s_destroy.c (renamed from src/ft_s_destroy.c)10
-rw-r--r--src/s_destroy.h20
-rw-r--r--src/s_init.c (renamed from src/ft_s_init.c)39
-rw-r--r--src/s_init.h (renamed from src/ft_s_init.h)12
-rw-r--r--src/s_lcom.c (renamed from src/ft_s_lcom.c)34
-rw-r--r--src/s_lcom.h23
-rw-r--r--src/s_lpipes.c (renamed from src/ft_s_lpipes.c)28
-rw-r--r--src/s_lpipes.h (renamed from src/ft_s_lpipes.h)18
-rw-r--r--src/s_lvars.c (renamed from src/ft_s_lvars.c)26
-rw-r--r--src/s_lvars.h24
-rw-r--r--src/s_struct.h (renamed from src/ft_s_struct.h)8
-rw-r--r--src/u_utils.c (renamed from src/ft_u_utils.c)4
-rw-r--r--src/u_utils.h (renamed from src/ft_e_lcom.h)9
-rw-r--r--src/u_vars.c (renamed from src/ft_u_vars.c)118
-rw-r--r--src/u_vars.h (renamed from src/ft_b_echo.h)13
-rw-r--r--src/u_vars_next.c102
-rw-r--r--src/u_vars_next.h (renamed from src/ft_f_errno.h)11
100 files changed, 1705 insertions, 1094 deletions
diff --git a/src/b_builtins.h b/src/b_builtins.h
new file mode 100644
index 0000000..f7e7e99
--- /dev/null
+++ b/src/b_builtins.h
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_builtins.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_BUILTINS_H
+#define B_BUILTINS_H
+
+#include "b_cd.h"
+#include "b_echo.h"
+#include "b_env.h"
+#include "b_exit.h"
+#include "b_export.h"
+#include "b_pwd.h"
+#include "b_type.h"
+#include "b_unset.h"
+
+#endif
diff --git a/src/ft_b_cd.c b/src/b_cd.c
index 9a93144..c4b5c1b 100644
--- a/src/ft_b_cd.c
+++ b/src/b_cd.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_cd.c :+: :+: :+: */
+/* b_cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,55 +14,55 @@
#include <stdint.h>
#include <unistd.h>
-#include "ft_f_fail.h"
-#include "ft_s_destroy.h"
-#include "ft_s_struct.h"
-#include "ft_u_utils.h"
-#include "ft_u_vars.h"
+#include "f_fail.h"
+#include "s_destroy.h"
+#include "s_struct.h"
+#include "u_utils.h"
+#include "u_vars.h"
static void
- ft_set_path(char **path,
+ set_path(char **path,
char *args[],
t_msh *msh)
{
if (!(*path = ft_strdup(*args)))
{
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
if (!ft_strncmp("~/", *path, 2) || !ft_strncmp("~", *path, 2))
{
if (!(*path = ft_strsubst(*path,
- "~", ft_subst_var_value("$HOME", msh))))
+ "~", u_get_var_value("$HOME", msh))))
{
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
}
}
uint8_t
- ft_b_cd(char *args[],
+ b_cd(char *args[],
t_msh *msh)
{
- const uint64_t argc = ft_get_argc((const char**)args);
+ const uint64_t argc = u_builtins_get_argc((const char**)args);
char *path;
if (argc >= 2)
{
- ft_fail_too_many_args("cd", msh);
+ f_fail_too_many_args("cd", msh);
return (1);
}
else if (argc == 0)
{
- if (!(path = ft_subst_var_value("$HOME", msh)))
+ if (!(path = u_get_var_value("$HOME", msh)))
return (1);
}
else
- ft_set_path(&path, args, msh);
+ set_path(&path, args, msh);
if (chdir(path) != 0)
{
- ft_fail_chd("cd", path, msh);
+ f_fail_chd("cd", path, msh);
ft_memdel((void*)&path);
return (1);
}
diff --git a/src/ft_m_loop.h b/src/b_cd.h
index 4dd1873..977afd7 100644
--- a/src/ft_m_loop.h
+++ b/src/b_cd.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_loop.h :+: :+: :+: */
+/* b_cd.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_M_LOOP
-#define FT_M_LOOP
+#ifndef B_CD_H
+#define B_CD_H
#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_m_loop(t_msh *msh);
+uint8_t b_cd(char *args[], t_msh *msh);
#endif
diff --git a/src/ft_b_echo.c b/src/b_echo.c
index de5431f..7b998d7 100644
--- a/src/ft_b_echo.c
+++ b/src/b_echo.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_echo.c :+: :+: :+: */
+/* b_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,15 +15,15 @@
#include <stdio.h>
#include <stdlib.h>
-#include "ft_s_struct.h"
-#include "ft_u_utils.h"
+#include "s_struct.h"
+#include "u_utils.h"
/* TODO: echo "quoted text", echo 'quoted text', done*/
/* echo kill\nbackslash\nbut\nnot\nn, echo "quoted\nnew\nlines", done */
/* full buffer */
void
- ft_e_put(char *str,
+ e_put(char *str,
uint8_t op)
{
size_t i;
@@ -39,7 +39,7 @@ void
}
char
- *ft_e_initb(char *ptr[],
+ *e_initb(char *ptr[],
char *str)
{
size_t len;
@@ -58,7 +58,7 @@ char
/***********************************************/
/* void */
-/* ft_e_fill(char *ptr[], char **str) */
+/* e_fill(char *ptr[], char **str) */
/* { */
/* char *bs; */
/* */
@@ -70,7 +70,7 @@ char
/* } */
/* else if ((bs = ft_strrchr(*str, '\\'))) */
/* { */
-/* ft_e_put(*str, 0); */
+/* e_put(*str, 0); */
/* } */
/* else */
/* ft_printf("%s", *str); */
@@ -78,10 +78,10 @@ char
/***********************************************/
uint8_t
- ft_b_echo(char *args[],
+ b_echo(char *args[],
t_msh *msh)
{
- const uint64_t argc = ft_get_argc((const char **)args);
+ const uint64_t argc = u_builtins_get_argc((const char **)args);
char **ptr;
char *str;
int8_t nopt;
@@ -90,7 +90,7 @@ uint8_t
ptr = args;
nopt = 0;
str = NULL;
- str = ft_e_initb(ptr, str);
+ str = e_initb(ptr, str);
if (argc >= 1)
{
if (ft_strncmp(ptr[0], "-n", 2) == 0)
diff --git a/src/b_echo.h b/src/b_echo.h
new file mode 100644
index 0000000..ba4698e
--- /dev/null
+++ b/src/b_echo.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_echo.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_ECHO_H
+#define B_ECHO_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_echo(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/ft_b_env.c b/src/b_env.c
index 14d05a2..8f0a974 100644
--- a/src/ft_b_env.c
+++ b/src/b_env.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_env.c :+: :+: :+: */
+/* b_env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -12,18 +12,19 @@
#include <libft.h>
#include <stdint.h>
-#include "ft_f_fail.h"
-#include "ft_s_struct.h"
+
+#include "f_fail.h"
+#include "s_struct.h"
uint8_t
- ft_b_env(char *args[],
+ b_env(char *args[],
t_msh *msh)
{
char **ptr;
if (args && args[0])
{
- ft_fail_no_options("env", msh);
+ f_fail_no_options("env", msh);
return (127);
}
ptr = msh->envp;
diff --git a/src/b_env.h b/src/b_env.h
new file mode 100644
index 0000000..6ad2800
--- /dev/null
+++ b/src/b_env.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_env.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_ENV_H
+#define B_ENV_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_env(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/ft_b_exit.c b/src/b_exit.c
index 7a7e5e8..5384d25 100644
--- a/src/ft_b_exit.c
+++ b/src/b_exit.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_exit.c :+: :+: :+: */
+/* b_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,22 +15,22 @@
#include <stdint.h>
#include <unistd.h>
-#include "ft_f_fail.h"
-#include "ft_s_lcom.h"
-#include "ft_s_destroy.h"
-#include "ft_s_struct.h"
-#include "ft_u_utils.h"
+#include "f_fail.h"
+#include "s_lcom.h"
+#include "s_destroy.h"
+#include "s_struct.h"
+#include "u_utils.h"
uint8_t
- ft_b_exit(char *args[],
+ b_exit(char *args[],
t_msh *msh)
{
uint8_t ret;
- const uint64_t argc = ft_get_argc((const char**)args);
+ const uint64_t argc = u_builtins_get_argc((const char**)args);
if (argc > 1)
{
- ft_fail_too_many_args("exit", msh);
+ f_fail_too_many_args("exit", msh);
return (1);
}
if (argc == 1)
@@ -38,6 +38,11 @@ uint8_t
ret = ft_atoi(args[0]);
/* TODO: non numeric args[0] */
}
+ else
+ ret = msh->ret;
ft_dprintf(STDERR_FILENO, "exit\n");
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ exit(ret);
return (0);
}
diff --git a/src/b_exit.h b/src/b_exit.h
new file mode 100644
index 0000000..1c6ec05
--- /dev/null
+++ b/src/b_exit.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_exit.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_EXIT_H
+#define B_EXIT_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_exit(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/b_export.c b/src/b_export.c
new file mode 100644
index 0000000..fa9a6d1
--- /dev/null
+++ b/src/b_export.c
@@ -0,0 +1,131 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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 "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"
+
+static t_bool
+ check_valid_identifier(const char arg[])
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ if (ft_isalpha(ptr[0]) || ptr[0] == '_')
+ {
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+static t_bool
+ check_equals(const char *arg)
+{
+ char *ptr;
+
+ ptr = (char*)arg;
+ while (*ptr != '\0')
+ {
+ if (*ptr == '=')
+ {
+ return (TRUE);
+ }
+ ptr++;
+ }
+ return (FALSE);
+}
+
+static void
+ b_add_to_env_from_globals(const char varname[],
+ const char var[],
+ t_msh *msh)
+{
+ size_t i;
+ char **nenvp;
+
+ i = 0;
+ while (msh->envp[i] != NULL)
+ i++;
+ if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*))))
+ f_fail_alloc_and_destroy(msh);
+ i = 0;
+ while (msh->envp[i] != NULL)
+ {
+ if (!(nenvp[i] = ft_strdup(msh->envp[i])))
+ f_fail_alloc_and_destroy(msh);
+ i++;
+ }
+ if (!(nenvp[i] = ft_strdup(var)))
+ f_fail_alloc_and_destroy(msh);
+ nenvp[i + 1] = 0;
+ ft_delwords(msh->envp);
+ lvars_delone(&msh->vars, varname);
+ msh->envp = nenvp;
+}
+
+uint8_t
+ b_export(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 (b_env(NULL, msh));
+ }
+ r = 0;
+ ptr = args;
+ while (*ptr != NULL)
+ {
+ next = FALSE;
+ if (check_valid_identifier(*ptr) == FALSE)
+ {
+ f_fail_identifier("export", *ptr);
+ 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);
+ }
+ }
+ 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.h b/src/b_export.h
new file mode 100644
index 0000000..be703c2
--- /dev/null
+++ b/src/b_export.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_export.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_H
+#define B_EXPORT_H
+
+#include "s_struct.h"
+
+uint8_t b_export(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/b_export_next.c b/src/b_export_next.c
new file mode 100644
index 0000000..0a56968
--- /dev/null
+++ b/src/b_export_next.c
@@ -0,0 +1,114 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_export_next.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 "b_export_next.h"
+#include "f_fail.h"
+#include "s_lvars.h"
+#include "s_struct.h"
+#include "u_vars.h"
+
+static char
+ **b_get_var(const char arg[],
+ t_msh *msh)
+{
+ size_t len;
+ char **var;
+
+ if ((var = (char**)malloc(3 * sizeof(char*))) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ len = 0;
+ while (arg[len] != '=' && arg[len] != '\0')
+ len++;
+ len += 1;
+ if ((var[FT_VAR_NAME] = (char*)malloc((len + 1) * sizeof(char))) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ var[FT_VAR_NAME][0] = '$';
+ ft_strlcpy(var[FT_VAR_NAME] + 1, arg, len);
+ if ((var[FT_VAR_VAL] = ft_strdup(arg + len)) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ var[FT_VAR_NULL] = NULL;
+ return (var);
+}
+
+static int64_t
+ b_is_it_in_env(const char varname[],
+ t_msh *msh)
+{
+ char **p_env;
+
+ p_env = msh->envp;
+ while (*p_env != NULL)
+ {
+ if (ft_strncmp(varname, *p_env, ft_strclen(*p_env, '=')) == 0)
+ {
+ return (p_env - msh->envp);
+ }
+ p_env++;
+ }
+ return (-1);
+}
+
+static void
+ b_add_to_env(const char arg[],
+ t_msh *msh)
+{
+ size_t i;
+ char **nenvp;
+
+ i = 0;
+ while (msh->envp[i] != NULL)
+ i++;
+ if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*))))
+ f_fail_alloc_and_destroy(msh);
+ i = 0;
+ while (msh->envp[i] != NULL)
+ {
+ if (!(nenvp[i] = ft_strdup(msh->envp[i])))
+ f_fail_alloc_and_destroy(msh);
+ i++;
+ }
+ if (!(nenvp[i] = ft_strdup(arg)))
+ f_fail_alloc_and_destroy(msh);
+ nenvp[i + 1] = 0;
+ ft_delwords(msh->envp);
+ msh->envp = nenvp;
+}
+
+void
+ b_export_with_equals(const char arg[],
+ t_msh *msh)
+{
+ char *varval;
+ char **var;
+ int64_t env_i;
+
+ var = b_get_var(arg, msh);
+ if ((env_i = b_is_it_in_env(var[FT_VAR_NAME] + 1, msh)) != -1)
+ {
+ ft_memdel((void*)&msh->envp[env_i]);
+ if ((msh->envp[env_i] = ft_strdup(arg)) == NULL)
+ f_fail_alloc_and_destroy(msh);
+ }
+ else if ((varval = u_get_cstm_vr(var[FT_VAR_NAME], msh)) != NULL)
+ {
+ b_add_to_env(arg, msh);
+ lvars_delone(&msh->vars, var[FT_VAR_NAME] + 1);
+ }
+ else
+ {
+ b_add_to_env(arg, msh);
+ }
+ ft_delwords(var);
+}
diff --git a/src/b_export_next.h b/src/b_export_next.h
new file mode 100644
index 0000000..c9d53ea
--- /dev/null
+++ b/src/b_export_next.h
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_export_next.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_NEXT_H
+#define B_EXPORT_NEXT_H
+
+#include "s_struct.h"
+
+enum
+{
+ FT_VAR_NAME,
+ FT_VAR_VAL,
+ FT_VAR_NULL
+};
+
+void b_export_with_equals(const char arg[], t_msh *msh);
+
+#endif
diff --git a/src/ft_b_pwd.c b/src/b_pwd.c
index d47600f..78ef128 100644
--- a/src/ft_b_pwd.c
+++ b/src/b_pwd.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_pwd.c :+: :+: :+: */
+/* b_pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,10 +13,10 @@
#include <libft.h>
#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
uint8_t
- ft_b_pwd(char *args[],
+ b_pwd(char *args[],
t_msh *msh)
{
(void)args;
diff --git a/src/b_pwd.h b/src/b_pwd.h
new file mode 100644
index 0000000..649ce8e
--- /dev/null
+++ b/src/b_pwd.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_pwd.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_PWD_H
+#define B_PWD_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_pwd(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/ft_b_type.c b/src/b_type.c
index 4338b32..00bad1a 100644
--- a/src/ft_b_type.c
+++ b/src/b_type.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_type.c :+: :+: :+: */
+/* b_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,14 +16,14 @@
#include <fcntl.h>
#include <unistd.h>
-#include "ft_f_fail.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
-#include "ft_e_externs_next.h"
-#include "ft_u_utils.h"
+#include "f_fail.h"
+#include "s_lcom.h"
+#include "s_struct.h"
+#include "e_externs_next.h"
+#include "u_utils.h"
static int8_t
- ft_absolute_path_exists(char com[])
+ absolute_path_exists(char com[])
{
int32_t fd;
DIR *dir;
@@ -42,7 +42,7 @@ static int8_t
}
static char
- *ft_type_get_path(char com[],
+ *type_get_path(char com[],
t_msh *msh)
{
char **envpath;
@@ -52,34 +52,34 @@ static char
fullpath = NULL;
if (ft_ischarset("/.", com[0]))
{
- if (ft_absolute_path_exists(com))
+ if (absolute_path_exists(com))
{
if (!(fullpath = ft_strdup(com)))
{
- ft_lcom_clear(&msh->curr);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ f_fail_alloc(msh);
}
return (fullpath);
}
return (NULL);
}
- else if ((envpath = ft_get_env_path(msh)) != NULL)
+ else if ((envpath = get_env_path(msh)) != NULL)
{
- fullpath = ft_search_in_path(com, envpath, msh);
+ fullpath = search_in_path(com, envpath, msh);
ft_delwords(envpath);
}
return (fullpath);
}
static uint8_t
- ft_chk_nonbuilt(char **ptr,
+ chk_nonbuilt(char **ptr,
t_msh *msh)
{
char *fullpath;
int32_t ret;
ret = 0;
- fullpath = ft_type_get_path(*ptr, msh);
+ fullpath = type_get_path(*ptr, msh);
if (fullpath)
ft_printf("%s is %s\n", *ptr, fullpath);
else
@@ -92,7 +92,7 @@ static uint8_t
}
uint8_t
- ft_b_type(char *args[],
+ b_type(char *args[],
t_msh *msh)
{
char **ptr;
@@ -112,7 +112,7 @@ uint8_t
ft_printf("%s is a shell builtin\n", *ptr);
else
{
- ret = ft_chk_nonbuilt(ptr, msh);
+ ret = chk_nonbuilt(ptr, msh);
}
ptr++;
}
diff --git a/src/b_type.h b/src/b_type.h
new file mode 100644
index 0000000..474ba26
--- /dev/null
+++ b/src/b_type.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_type.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_TYPE_H
+#define B_TYPE_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_type(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/b_unset.c b/src/b_unset.c
new file mode 100644
index 0000000..03fd2a8
--- /dev/null
+++ b/src/b_unset.c
@@ -0,0 +1,138 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_unset.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 <stdint.h>
+#include <stdlib.h>
+
+#include "f_fail.h"
+#include "s_lvars.h"
+#include "s_struct.h"
+
+static t_bool
+ check_valid_identifier(const char arg[])
+{
+ char *ptr;
+ t_bool r;
+
+ ptr = (char*)arg;
+ r = TRUE;
+ if (ft_isalpha(ptr[0]) == 0)
+ {
+ r = FALSE;
+ }
+ if (ptr[0] == '_')
+ {
+ r = TRUE;
+ }
+ while (*ptr != '\0')
+ {
+ if (*ptr == '=')
+ {
+ r = FALSE;
+ }
+ ptr++;
+ }
+ return (r);
+}
+
+static void
+ b_realloc_env(size_t skip,
+ t_msh *msh)
+{
+ char **nenvp;
+ int8_t skipped;
+ size_t i;
+
+ i = 0;
+ while (msh->envp[i] != NULL)
+ i++;
+ if (!(nenvp = (char**)malloc(i * sizeof(char*))))
+ f_fail_alloc_and_destroy(msh);
+ i = 0;
+ skipped = 0;
+ while (msh->envp[i] != NULL)
+ {
+ if (i == skip)
+ {
+ i += 1;
+ if (msh->envp[i] == NULL)
+ break ;
+ skipped = 1;
+ }
+ if (!(nenvp[i - skipped] = ft_strdup(msh->envp[i])))
+ f_fail_alloc_and_destroy(msh);
+ i++;
+ }
+ nenvp[i - 1] = 0;
+ ft_delwords(msh->envp);
+ msh->envp = nenvp;
+}
+
+static t_bool
+ b_removed_from_env(const char arg[],
+ t_msh *msh)
+{
+ size_t i;
+
+ i = 0;
+ while (msh->envp[i] != NULL)
+ {
+ if (ft_strncmp(arg, msh->envp[i], ft_strclen(msh->envp[i], '=')) == 0)
+ {
+ b_realloc_env(i, msh);
+ return (TRUE);
+ }
+ i++;
+ }
+ return (FALSE);
+}
+
+static void
+ b_remove_it(const char arg[],
+ t_msh *msh)
+{
+ if (b_removed_from_env(arg, msh) == FALSE)
+ {
+ lvars_delone(&msh->vars, arg);
+ }
+}
+
+uint8_t
+ b_unset(char *args[],
+ t_msh *msh)
+{
+ char **ptr;
+ t_bool next;
+ int8_t r;
+
+ if (args[0] == NULL)
+ return (0);
+ r = 0;
+ ptr = args;
+ while (*ptr != NULL)
+ {
+ next = FALSE;
+ if (check_valid_identifier(*ptr) == FALSE)
+ {
+ f_fail_identifier("unset", *ptr);
+ next = TRUE;
+ r = 1;
+ }
+ if (next == FALSE)
+ {
+ b_remove_it(*ptr, msh);
+ }
+ ptr++;
+ }
+ return (r);
+}
diff --git a/src/b_unset.h b/src/b_unset.h
new file mode 100644
index 0000000..fa89161
--- /dev/null
+++ b/src/b_unset.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_unset.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_UNSET_H
+#define B_UNSET_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_unset(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/ft_d_define.h b/src/d_define.h
index 4152e0d..899a2e7 100644
--- a/src/ft_d_define.h
+++ b/src/d_define.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_d_define.h :+: :+: :+: */
+/* d_define.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,26 +10,25 @@
/* */
/* ************************************************************************** */
-#ifndef FT_D_DEFINE_H
-#define FT_D_DEFINE_H
+#ifndef D_DEFINE_H
+#define D_DEFINE_H
-#include "ft_d_enum.h"
+#include "d_enum.h"
/*
** ====== CLASSICS ======
*/
-#define FT_PS_ONE "minishell ~> "
-#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type"
-#define FT_BUILTINS_COUNT 8
-#define FT_HISTFILE "minishell_history"
+#define FT_PS_ONE "minishell ~> "
+#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type"
+#define FT_HISTFILE "minishell_history"
/*
** ====== OPTIONS ======
*/
-#define FT_OPT_INTERACT "-i"
-#define FT_OPT_COMMAND "-c"
+#define FT_OPT_INTERACT "-i"
+#define FT_OPT_COMMAND "-c"
/*
** ====== VARS ======
@@ -43,7 +42,8 @@
** ====== FAIL MSG ======
*/
-#define FT_FAIL_NO_OPTIONS "no options required"
-#define FT_FAIL_TOO_MANY_ARGS "too many arguments"
+#define FT_FAIL_COMMAND_NOT_FOUND "command not found"
+#define FT_FAIL_NO_OPTIONS "no options required"
+#define FT_FAIL_TOO_MANY_ARGS "too many arguments"
#endif
diff --git a/src/ft_d_enum.h b/src/d_enum.h
index 680ff00..921195f 100644
--- a/src/ft_d_enum.h
+++ b/src/d_enum.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_d_enum.h :+: :+: :+: */
+/* d_enum.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,8 +10,8 @@
/* */
/* ************************************************************************** */
-#ifndef FT_D_ENUM_H
-#define FT_D_ENUM_H
+#ifndef D_ENUM_H
+#define D_ENUM_H
/*
** ret vals:
@@ -20,12 +20,6 @@
** 1: alloc err
*/
-typedef enum
-{
- FALSE,
- TRUE
-} t_bool;
-
enum
{
FT_RET_FINE,
@@ -38,4 +32,17 @@ enum
FT_READ_END
};
+enum
+{
+ FT_ID_ECHO,
+ FT_ID_CD,
+ FT_ID_PWD,
+ FT_ID_EXPORT,
+ FT_ID_UNSET,
+ FT_ID_ENV,
+ FT_ID_EXIT,
+ FT_ID_TYPE,
+ FT_BUILTINS_COUNT
+};
+
#endif
diff --git a/src/e_builtins.c b/src/e_builtins.c
new file mode 100644
index 0000000..5f53f90
--- /dev/null
+++ b/src/e_builtins.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* e_builtins.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 <sys/wait.h>
+#include <libft.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "m_redirs.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
+
+void
+ e_builtin(const t_lcom *ptr,
+ uint8_t bu_id,
+ t_msh *msh)
+{
+ int32_t ret;
+
+ dup_redirs(ptr, msh);
+ ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh);
+ /* lcom_clear(&msh->curr); */
+ msh->ret = ret;
+}
diff --git a/src/ft_m_comm.h b/src/e_builtins.h
index 5b22f3a..25026cc 100644
--- a/src/ft_m_comm.h
+++ b/src/e_builtins.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_comm.h :+: :+: :+: */
+/* e_builtins.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_M_COMM_H
-#define FT_M_COMM_H
+#ifndef E_BUILTINS_H
+#define E_BUILTINS_H
#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_m_comm(const char line[],
- t_msh *msh);
+void e_builtin(const t_lcom *ptr, uint8_t bu_id, t_msh *msh);
#endif
diff --git a/src/ft_e_externs.c b/src/e_externs.c
index 9302d18..93d989f 100644
--- a/src/ft_e_externs.c
+++ b/src/e_externs.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_externs.c :+: :+: :+: */
+/* e_externs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,24 +16,25 @@
#include <stdint.h>
#include <unistd.h>
-#include "ft_e_externs_next.h"
-#include "ft_m_redirs.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
+#include "e_externs_next.h"
+#include "f_fail.h"
+#include "m_redirs.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
static void
- ft_e_extern_child(const char *fullpath,
+ e_extern_child(const char *fullpath,
t_lcom *ptr,
t_msh *msh)
{
- ft_dup_redirs(ptr, msh);
+ dup_redirs(ptr, msh);
execve(fullpath, ptr->argv, msh->envp);
/* TODO: handle execve failed */
}
static void
- ft_exec_path(const char fullpath[],
+ exec_path(const char fullpath[],
t_lcom *ptr,
t_msh *msh)
{
@@ -42,7 +43,7 @@ static void
if ((pid = fork()) == 0)
{
- ft_e_extern_child(fullpath, ptr, msh);
+ e_extern_child(fullpath, ptr, msh);
}
else if (pid < 0)
{
@@ -57,7 +58,7 @@ static void
}
void
- ft_e_extern(t_lcom *ptr,
+ e_extern(t_lcom *ptr,
t_msh *msh)
{
char **envpath;
@@ -65,15 +66,21 @@ void
if (ft_ischarset("/.", ptr->com[0]))
{
- ft_exec_path(ptr->com, ptr, msh);
+ exec_path(ptr->com, ptr, msh);
return ;
}
- else if ((envpath = ft_get_env_path(msh)) != NULL)
+ else if ((envpath = get_env_path(msh)) != NULL)
{
- fullpath = ft_search_in_path(ptr->com, envpath, msh);
+ fullpath = search_in_path(ptr->com, envpath, msh);
ft_delwords(envpath);
+ if (fullpath == NULL)
+ {
+ f_fail_command_not_found(ptr->com);
+ }
+ else
+ {
+ exec_path(fullpath, ptr, msh);
+ ft_memdel((void*)&fullpath);
+ }
}
- /* TODO: deal if not found etc */
- ft_exec_path(fullpath, ptr, msh);
- ft_memdel((void*)&fullpath);
}
diff --git a/src/ft_s_destroy.h b/src/e_externs.h
index 68a5c09..878bb83 100644
--- a/src/ft_s_destroy.h
+++ b/src/e_externs.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_destroy.h :+: :+: :+: */
+/* e_externs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,11 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_S_DESTROY_H
-#define FT_S_DESTROY_H
+#ifndef E_EXTERNS_H
+#define E_EXTERNS_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_s_destroy(t_msh *msh);
+void e_extern(t_lcom *ptr, t_msh *msh);
#endif
diff --git a/src/ft_e_externs_next.c b/src/e_externs_next.c
index 36bf5e6..e33405c 100644
--- a/src/ft_e_externs_next.c
+++ b/src/e_externs_next.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_externs_next.c :+: :+: :+: */
+/* e_externs_next.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,13 +15,13 @@
#include <stdlib.h>
#include <stddef.h>
-#include "ft_f_fail.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
+#include "f_fail.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
static char
- *ft_get_fullpath(const char p_path[],
+ *get_fullpath(const char p_path[],
const char d_name[],
t_msh *msh)
{
@@ -31,19 +31,19 @@ static char
if (!(fullpath = (char*)malloc((path_len + name_len + 2) * sizeof(char))))
{
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
- ft_memcpy(fullpath, p_path, path_len);
+ (void)ft_memcpy(fullpath, p_path, path_len);
*(fullpath + (path_len)) = '/';
- ft_memcpy(fullpath + path_len + 1, d_name, name_len);
+ (void)ft_memcpy(fullpath + path_len + 1, d_name, name_len);
*(fullpath + (path_len + name_len + 1)) = '\0';
return (fullpath);
}
char
- *ft_search_in_path(const char com[],
+ *search_in_path(const char com[],
char *envpath[],
t_msh *msh)
{
@@ -63,7 +63,7 @@ char
/* TODO: check for not bins (dirs, etc) */
if (ft_strncmp(com, ent->d_name, ft_strlen(com) + 1) == 0)
{
- fullpath = ft_get_fullpath(*p_path, ent->d_name, msh);
+ fullpath = get_fullpath(*p_path, ent->d_name, msh);
closedir(dir);
return (fullpath);
}
@@ -76,7 +76,7 @@ char
}
char
- **ft_get_env_path(t_msh *msh)
+ **get_env_path(t_msh *msh)
{
char **p_env;
char **envpath;
@@ -95,9 +95,9 @@ char
{
if (!(envpath = ft_split(envline, ':')))
{
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
return (envpath);
}
diff --git a/src/e_externs_next.h b/src/e_externs_next.h
new file mode 100644
index 0000000..db03bac
--- /dev/null
+++ b/src/e_externs_next.h
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* e_externs_next.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 E_EXTERNS_NEXT_H
+#define E_EXTERNS_NEXT_H
+
+#include "s_struct.h"
+
+char **get_env_path(t_msh *msh);
+char *search_in_path(const char com[], char *envpath[], t_msh *msh);
+
+#endif
diff --git a/src/ft_e_externs_pipes.c b/src/e_externs_pipes.c
index c1c57b5..a5ee696 100644
--- a/src/ft_e_externs_pipes.c
+++ b/src/e_externs_pipes.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_externs_pipes.c :+: :+: :+: */
+/* e_externs_pipes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -18,26 +18,26 @@
#include <string.h>
#include <errno.h>
-#include "ft_d_define.h"
-#include "ft_e_externs_next.h"
-#include "ft_f_fail.h"
-#include "ft_m_redirs.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
+#include "d_define.h"
+#include "e_externs_next.h"
+#include "f_fail.h"
+#include "m_redirs.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
static void
- ft_e_extern_child(const char *fullpath,
+ e_extern_child(const char *fullpath,
t_lcom *ptr,
t_msh *msh)
{
- ft_dup_redirs(ptr, msh);
+ dup_redirs(ptr, msh);
execve(fullpath, ptr->argv, msh->envp);
/* TODO: handle execve failed */
}
static size_t
-ft_e_get_pipes_count(struct s_lpipes *ptr)
+ e_get_pipes_count(struct s_lpipes *ptr)
{
struct s_lpipes *rptr;
size_t pipes;
@@ -53,7 +53,7 @@ ft_e_get_pipes_count(struct s_lpipes *ptr)
}
static void
- ft_exec_path(const char *fullpath[],
+ exec_path(const char *fullpath[],
struct s_lpipes *head,
t_msh *msh)
{
@@ -65,7 +65,7 @@ static void
int status;
/* TODO: norm, error mgmnt */
- pipes = ft_e_get_pipes_count(head);
+ pipes = e_get_pipes_count(head);
i = 0;
while (i < pipes)
{
@@ -88,7 +88,7 @@ static void
close(fd[j][FT_READ_END]);
j++;
}
- ft_e_extern_child(fullpath[i], head->one, msh);
+ e_extern_child(fullpath[i], head->one, msh);
}
head = head->next;
i++;
@@ -108,7 +108,7 @@ static void
}
void
- ft_e_externs_pipes(struct s_lpipes *ptr,
+ e_externs_pipes(struct s_lpipes *ptr,
t_msh *msh)
{
struct s_lpipes *head;
@@ -120,9 +120,9 @@ void
head = ptr;
rptr = ptr;
- pipes = ft_e_get_pipes_count(head);
+ pipes = e_get_pipes_count(head);
if (!(fullpath = (char **)malloc((pipes + 2) * sizeof(char *))))
- ft_fail_alloc(msh);
+ f_fail_alloc(msh);
fullpath[pipes + 1] = NULL;
i = 0;
while (rptr != NULL)
@@ -130,11 +130,11 @@ void
if (ft_ischarset("/.", rptr->one->com[0]))
{
if (!(fullpath[i] = ft_strdup(rptr->one->com)))
- ft_fail_alloc(msh);
+ f_fail_alloc(msh);
}
- else if ((envpath = ft_get_env_path(msh)) != NULL)
+ else if ((envpath = get_env_path(msh)) != NULL)
{
- fullpath[i] = ft_search_in_path(rptr->one->com, envpath, msh);
+ fullpath[i] = search_in_path(rptr->one->com, envpath, msh);
ft_delwords(envpath);
}
/* TODO: deal if not found etc */
@@ -142,6 +142,6 @@ void
rptr = rptr->next;
}
i = 0;
- ft_exec_path((const char**)fullpath, head, msh);
+ exec_path((const char**)fullpath, head, msh);
ft_delwords(fullpath);
}
diff --git a/src/ft_b_cd.h b/src/e_externs_pipes.h
index e789cc0..6c242fb 100644
--- a/src/ft_b_cd.h
+++ b/src/e_externs_pipes.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_cd.h :+: :+: :+: */
+/* e_externs_pipes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_CD_H
-#define FT_B_CD_H
+#ifndef E_EXTERNS_PIPES_H
+#define E_EXTERNS_PIPES_H
-#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_b_cd(char *args[],
- t_msh *msh);
+void e_externs_pipes(struct s_lpipes *ptr, t_msh *msh);
#endif
diff --git a/src/ft_e_lcom.c b/src/e_lcom.c
index 54db581..e8159fd 100644
--- a/src/ft_e_lcom.c
+++ b/src/e_lcom.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_lcom.c :+: :+: :+: */
+/* e_lcom.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,14 +13,14 @@
#include <libft.h>
#include <stdint.h>
-#include "ft_e_builtins.h"
-#include "ft_e_externs.h"
-#include "ft_e_pipes.h"
-#include "ft_s_lpipes.h"
-#include "ft_s_struct.h"
+#include "e_builtins.h"
+#include "e_externs.h"
+#include "e_pipes.h"
+#include "s_lpipes.h"
+#include "s_struct.h"
static uint8_t
- ft_get_builtin_id(const char com[],
+ get_builtin_id(const char com[],
t_msh *msh)
{
uint8_t i;
@@ -35,7 +35,7 @@ static uint8_t
}
void
- ft_e_lcom(t_msh *msh)
+ e_lcom(t_msh *msh)
{
t_lcom *ptr;
uint8_t bu_id;
@@ -45,14 +45,14 @@ void
{
if (ptr->pipes)
{
- ft_e_pipes(ptr, msh);
+ e_pipes(ptr, msh);
}
else if (ptr->com)
{
- if ((bu_id = ft_get_builtin_id(ptr->com, msh)) < FT_BUILTINS_COUNT)
- ft_e_builtin(ptr, bu_id, msh);
+ if ((bu_id = get_builtin_id(ptr->com, msh)) < FT_BUILTINS_COUNT)
+ e_builtin(ptr, bu_id, msh);
else
- ft_e_extern(ptr, msh);
+ e_extern(ptr, msh);
}
ptr = ptr->next;
}
diff --git a/src/ft_u_utils.h b/src/e_lcom.h
index 1a3b324..ab0368f 100644
--- a/src/ft_u_utils.h
+++ b/src/e_lcom.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_u_utils.h :+: :+: :+: */
+/* e_lcom.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,11 +10,12 @@
/* */
/* ************************************************************************** */
-#ifndef FT_U_UTILS_H
-#define FT_U_UTILS_H
+#ifndef E_LCOM_H
+#define E_LCOM_H
#include <stdint.h>
+#include "s_struct.h"
-uint64_t ft_get_argc(const char *args[]);
+void e_lcom(t_msh *msh);
#endif
diff --git a/src/ft_e_pipes.c b/src/e_pipes.c
index 581aec2..29ee5d4 100644
--- a/src/ft_e_pipes.c
+++ b/src/e_pipes.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_pipes.c :+: :+: :+: */
+/* e_pipes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,13 +14,13 @@
#include <stdint.h>
#include <unistd.h>
-#include "ft_e_builtins.h"
-#include "ft_e_externs_pipes.h"
-#include "ft_s_lpipes.h"
-#include "ft_s_struct.h"
+#include "e_builtins.h"
+#include "e_externs_pipes.h"
+#include "s_lpipes.h"
+#include "s_struct.h"
static uint8_t
- ft_get_builtin_id(const char com[],
+ get_builtin_id(const char com[],
t_msh *msh)
{
uint8_t i;
@@ -35,15 +35,15 @@ static uint8_t
}
void
- ft_e_pipes(t_lcom *ptr,
+ e_pipes(t_lcom *ptr,
t_msh *msh)
{
uint8_t bu_id;
- if ((bu_id = ft_get_builtin_id(ptr->pipes->one->com, msh))
+ if ((bu_id = get_builtin_id(ptr->pipes->one->com, msh))
< FT_BUILTINS_COUNT)
- ft_e_builtin(ptr->pipes->one, bu_id, msh);
+ e_builtin(ptr->pipes->one, bu_id, msh);
else
- ft_e_externs_pipes(ptr->pipes, msh);
- ft_lpipes_clear(&ptr->pipes);
+ e_externs_pipes(ptr->pipes, msh);
+ lpipes_clear(&ptr->pipes);
}
diff --git a/src/ft_m_funptr.h b/src/e_pipes.h
index 889c0af..d4de639 100644
--- a/src/ft_m_funptr.h
+++ b/src/e_pipes.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_funptr.h :+: :+: :+: */
+/* e_pipes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,11 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_M_FUNPTR_H
-#define FT_M_FUNPTR_H
+#ifndef E_PIPES_H
+#define E_PIPES_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_init_buptr(t_msh *msh);
+void e_pipes(t_lcom *ptr, t_msh *msh);
#endif
diff --git a/src/f_alloc.c b/src/f_alloc.c
new file mode 100644
index 0000000..bfa75c3
--- /dev/null
+++ b/src/f_alloc.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_alloc.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 <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
+
+void
+ f_fail_alloc(t_msh *msh)
+{
+ ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno));
+ exit(FT_RET_ALLOC);
+}
+
+void
+ f_fail_alloc_and_destroy(t_msh *msh)
+{
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
+}
diff --git a/src/ft_b_pwd.h b/src/f_alloc.h
index 653c9e4..34a5e7d 100644
--- a/src/ft_b_pwd.h
+++ b/src/f_alloc.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_pwd.h :+: :+: :+: */
+/* f_alloc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,12 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_PWD_H
-#define FT_B_PWD_H
+#ifndef F_ALLOC_H
+#define F_ALLOC_H
-#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_b_pwd(char *args[],
- t_msh *msh);
+void f_fail_alloc(t_msh *msh);
+void f_fail_alloc_and_destroy(t_msh *msh);
#endif
diff --git a/src/ft_f_chdir.c b/src/f_chdir.c
index 1386626..4623c82 100644
--- a/src/ft_f_chdir.c
+++ b/src/f_chdir.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_f_chdir.c :+: :+: :+: */
+/* f_chdir.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,10 +15,10 @@
#include <errno.h>
#include <unistd.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
void
- ft_fail_chd(const char concern[],
+ f_fail_chd(const char concern[],
const char path[],
t_msh *msh)
{
diff --git a/src/ft_e_externs.h b/src/f_chdir.h
index 5e02353..c4136af 100644
--- a/src/ft_e_externs.h
+++ b/src/f_chdir.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_externs.h :+: :+: :+: */
+/* f_chdir.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,12 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_E_EXTERNS_H
-#define FT_E_EXTERNS_H
+#ifndef F_CHDIR_H
+#define F_CHDIR_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_e_extern(t_lcom *ptr,
- t_msh *msh);
+void f_fail_chd(const char concern[], const char pathp[], t_msh *msh);
#endif
diff --git a/src/f_com.c b/src/f_com.c
new file mode 100644
index 0000000..9c4e02a
--- /dev/null
+++ b/src/f_com.c
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_com.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 <unistd.h>
+
+#include "d_define.h"
+#include "s_struct.h"
+
+void
+ f_fail_command_not_found(const char command[])
+{
+ ft_dprintf(STDERR_FILENO, "%s: %s: %s\n", "minishell", command, FT_FAIL_COMMAND_NOT_FOUND);
+}
diff --git a/src/f_com.h b/src/f_com.h
new file mode 100644
index 0000000..12023f6
--- /dev/null
+++ b/src/f_com.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_com.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 F_COM_H
+#define F_COM_H
+
+#include "s_struct.h"
+
+void f_fail_command_not_found(const char command[]);
+
+#endif
diff --git a/src/ft_f_errno.c b/src/f_errno.c
index 22ee7a9..360cf9f 100644
--- a/src/ft_f_errno.c
+++ b/src/f_errno.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_f_errno.c :+: :+: :+: */
+/* f_errno.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,10 +15,10 @@
#include <errno.h>
#include <unistd.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
void
- ft_f_dump_errno(const char concern[],
+ f_dump_errno(const char concern[],
t_msh *msh)
{
ft_dprintf(STDERR_FILENO, "%s: %s: %s\n",
diff --git a/src/ft_p_line.h b/src/f_errno.h
index 076be42..bf9e36b 100644
--- a/src/ft_p_line.h
+++ b/src/f_errno.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_p_line.h :+: :+: :+: */
+/* f_errno.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,12 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_P_LINE_H
-#define FT_P_LINE_H
+#ifndef F_ERRNO_H
+#define F_ERRNO_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_p_line(char *line,
- t_msh *msh);
+void f_dump_errno(const char concern[], t_msh *msh);
#endif
diff --git a/src/ft_f_fail.c b/src/f_fail.c
index 3f43bae..3704b1f 100644
--- a/src/ft_f_fail.c
+++ b/src/f_fail.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_f_fail.c :+: :+: :+: */
+/* f_fail.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,11 +16,11 @@
#include <unistd.h>
#include <errno.h>
-#include "ft_d_define.h"
-#include "ft_s_struct.h"
+#include "d_define.h"
+#include "s_struct.h"
static void
- ft_write_fail(const char concern[],
+ write_fail(const char concern[],
const char msg[],
t_msh *msh)
{
@@ -28,31 +28,23 @@ static void
}
void
- ft_fail_no_options(const char concern[],
+ f_fail_no_options(const char concern[],
t_msh *msh)
{
- ft_write_fail(concern, FT_FAIL_NO_OPTIONS, msh);
+ write_fail(concern, FT_FAIL_NO_OPTIONS, msh);
}
void
- ft_fail_identifier(const char concern[],
- const char identifier[],
- t_msh *msh)
+ f_fail_identifier(const char concern[],
+ const char identifier[])
{
- ft_dprintf(STDERR_FILENO, "%s: %s: `%s': not a valid identifier\n",
- msh->shname, concern, identifier);
+ ft_dprintf(STDERR_FILENO, "minishell: %s: `%s': not a valid identifier\n",
+ concern, identifier);
}
void
- ft_fail_too_many_args(const char concern[],
+ f_fail_too_many_args(const char concern[],
t_msh *msh)
{
- ft_write_fail(concern, FT_FAIL_TOO_MANY_ARGS, msh);
-}
-
-void
- ft_fail_alloc(t_msh *msh)
-{
- ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno));
- exit(FT_RET_ALLOC);
+ write_fail(concern, FT_FAIL_TOO_MANY_ARGS, msh);
}
diff --git a/src/f_fail.h b/src/f_fail.h
new file mode 100644
index 0000000..0d3c19b
--- /dev/null
+++ b/src/f_fail.h
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_fail.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 F_FAIL_H
+#define F_FAIL_H
+
+#include "f_com.h"
+#include "f_alloc.h"
+#include "f_chdir.h"
+#include "f_errno.h"
+#include "f_redir.h"
+#include "s_struct.h"
+
+void f_fail_no_options(const char concern[], t_msh *msh);
+void f_fail_too_many_args(const char concern[], t_msh *msh);
+void f_fail_identifier(const char concern[], const char identifier[]);
+
+#endif
diff --git a/src/ft_f_redir.c b/src/f_redir.c
index 2cd7d58..3561272 100644
--- a/src/ft_f_redir.c
+++ b/src/f_redir.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_f_redir.c :+: :+: :+: */
+/* f_redir.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,16 +16,16 @@
#include <unistd.h>
#include <errno.h>
-#include "ft_s_lcom.h"
-#include "ft_s_destroy.h"
+#include "s_lcom.h"
+#include "s_destroy.h"
void
- ft_f_redir(const char path[],
+ f_redir(const char path[],
t_msh *msh)
{
ft_dprintf(STDERR_FILENO, "%s: %s: %s\n",
msh->shname, path, strerror(errno));
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
exit(1);
}
diff --git a/src/f_redir.h b/src/f_redir.h
new file mode 100644
index 0000000..450fce5
--- /dev/null
+++ b/src/f_redir.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_redir.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 F_REDIR_H
+#define F_REDIR_H
+
+#include "s_struct.h"
+
+void f_redir(const char path[], t_msh *msh);
+
+#endif
diff --git a/src/ft_b_builtins.h b/src/ft_b_builtins.h
deleted file mode 100644
index ed76f70..0000000
--- a/src/ft_b_builtins.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_b_builtins.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 FT_B_BUILTINS_H
-#define FT_B_BUILTINS_H
-
-#include "ft_b_cd.h"
-#include "ft_b_echo.h"
-#include "ft_b_env.h"
-#include "ft_b_exit.h"
-#include "ft_b_export.h"
-#include "ft_b_pwd.h"
-#include "ft_b_type.h"
-#include "ft_b_unset.h"
-
-#endif
diff --git a/src/ft_b_export.c b/src/ft_b_export.c
deleted file mode 100644
index fa2de45..0000000
--- a/src/ft_b_export.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* 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)
-{
- const uint64_t argc = ft_get_argc((const char**)args);
- char **ptr;
- int8_t next;
- uint8_t r;
-
- if (argc == 0)
- {
- return (ft_b_env(NULL, msh));
- }
- ptr = args;
- r = 0;
- while (*ptr)
- {
- next = 0;
- if (!ft_check_valid_identifier(*ptr))
- {
- ft_fail_identifier("export", *ptr, msh);
- next = 1;
- r = 1;
- }
- if (next == 0 && !ft_check_equals(*ptr))
- next = 1;
- ptr++;
- }
- /* TODO: finish export */
- return (r);
-}
diff --git a/src/ft_b_type.h b/src/ft_b_type.h
deleted file mode 100644
index c3d5dd6..0000000
--- a/src/ft_b_type.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_b_type.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 FT_B_TYPE_H
-#define FT_B_TYPE_H
-
-#include <stdint.h>
-#include "ft_s_struct.h"
-
-uint8_t ft_b_type(char *args[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_b_unset.c b/src/ft_b_unset.c
deleted file mode 100644
index a382aca..0000000
--- a/src/ft_b_unset.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_b_unset.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 <stdint.h>
-#include "ft_s_struct.h"
-
-uint8_t
- ft_b_unset(char *args[],
- t_msh *msh)
-{
- (void)args;
- (void)msh;
- /* TODO: do unset */
- return (0);
-}
diff --git a/src/ft_b_unset.h b/src/ft_b_unset.h
deleted file mode 100644
index 5ab1b2b..0000000
--- a/src/ft_b_unset.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_b_unset.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 FT_B_UNSET_H
-#define FT_B_UNSET_H
-
-#include <stdint.h>
-#include "ft_s_struct.h"
-
-uint8_t ft_b_unset(char *args[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_e_builtins.c b/src/ft_e_builtins.c
deleted file mode 100644
index 0792de3..0000000
--- a/src/ft_e_builtins.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_e_builtins.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 <sys/wait.h>
-#include <libft.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-
-#include "ft_m_redirs.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
-
-static void
- ft_e_builtin_child(const t_lcom *ptr,
- uint8_t bu_id,
- t_msh *msh)
-{
- int32_t ret;
-
- ft_dup_redirs(ptr, msh);
- ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh);
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- exit(ret);
-}
-
-static void
- ft_e_builtin_parent(pid_t pid,
- const t_lcom *ptr,
- uint8_t bu_id,
- t_msh *msh)
-{
- int32_t status;
- int32_t ret;
-
- while (wait(&status) != pid)
- ;
- ret = WEXITSTATUS(status);
- if (bu_id != 6)
- msh->ret = ret;
- if (bu_id == 1 && msh->ret == 0)
- {
- msh->bu_ptr[bu_id](ptr->argv + 1, msh);
- /* this must be cd */
- /* TODO: export $PWD */
- }
- else if (bu_id == 6 && ret == 0)
- {
- if (ptr->argv[1])
- ret = ft_atoi(ptr->argv[1]);
- else
- ret = msh->ret;
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- exit(ret);
- }
-}
-
-void
- ft_e_builtin(const t_lcom *ptr,
- uint8_t bu_id,
- t_msh *msh)
-{
- pid_t pid;
-
- /* TODO: find a way to handle exit | bu_id = 6 */
- if ((pid = fork()) == 0)
- {
- ft_e_builtin_child(ptr, bu_id, msh);
- }
- else if (pid < 0)
- {
- /* TODO: handle fork failed */
- }
- else
- {
- ft_e_builtin_parent(pid, ptr, bu_id, msh);
- }
-}
diff --git a/src/ft_e_builtins.h b/src/ft_e_builtins.h
deleted file mode 100644
index 21908b8..0000000
--- a/src/ft_e_builtins.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_e_builtins.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 FT_E_BUILTINS_H
-#define FT_E_BUILTINS_H
-
-#include <stdint.h>
-#include "ft_s_struct.h"
-
-void ft_e_builtin(const t_lcom *ptr,
- uint8_t bu_id,
- t_msh *msh);
-
-#endif
diff --git a/src/ft_e_externs_next.h b/src/ft_e_externs_next.h
deleted file mode 100644
index bc6272c..0000000
--- a/src/ft_e_externs_next.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_e_externs_next.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 FT_E_EXTERNS_NEXT_H
-#define FT_E_EXTERNS_NEXT_H
-
-#include "ft_s_struct.h"
-
-char **ft_get_env_path(t_msh *msh);
-char *ft_search_in_path(const char com[],
- char *envpath[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_e_externs_pipes.h b/src/ft_e_externs_pipes.h
deleted file mode 100644
index 435c795..0000000
--- a/src/ft_e_externs_pipes.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_e_externs_pipes.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 FT_E_EXTERNS_PIPES_H
-#define FT_E_EXTERNS_PIPES_H
-
-#include "ft_s_struct.h"
-
-void ft_e_externs_pipes(struct s_lpipes *ptr, t_msh *msh);
-
-#endif
diff --git a/src/ft_f_chdir.h b/src/ft_f_chdir.h
deleted file mode 100644
index fae82d7..0000000
--- a/src/ft_f_chdir.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_f_chdir.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 FT_F_CHDIR_H
-#define FT_F_CHDIR_H
-
-#include "ft_s_struct.h"
-
-void ft_fail_chd(const char concern[],
- const char pathp[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_f_fail.h b/src/ft_f_fail.h
deleted file mode 100644
index b176cbb..0000000
--- a/src/ft_f_fail.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_f_fail.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 FT_F_FAIL_H
-#define FT_F_FAIL_H
-
-#include "ft_f_chdir.h"
-#include "ft_f_errno.h"
-#include "ft_f_redir.h"
-#include "ft_s_struct.h"
-
-void ft_fail_no_options(const char concern[],
- t_msh *msh);
-void ft_fail_too_many_args(const char concern[],
- t_msh *msh);
-void ft_fail_identifier(const char concern[],
- const char identifier[],
- t_msh *msh);
-void ft_fail_alloc(t_msh *msh);
-
-#endif
diff --git a/src/ft_f_redir.h b/src/ft_f_redir.h
deleted file mode 100644
index 2b99da7..0000000
--- a/src/ft_f_redir.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_f_redir.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 FT_F_REDIR_H
-#define FT_F_REDIR_H
-
-#include "ft_s_struct.h"
-
-void ft_f_redir(const char path[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_m_prompt.h b/src/ft_m_prompt.h
deleted file mode 100644
index 2725539..0000000
--- a/src/ft_m_prompt.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_m_prompt.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 FT_M_PROMPT_H
-#define FT_M_PROMPT_H
-
-#include "ft_s_struct.h"
-
-void ft_m_prompt(t_msh *msh);
-void ft_m_cont_prompt(void);
-#endif
diff --git a/src/ft_m_redirs.h b/src/ft_m_redirs.h
deleted file mode 100644
index 9021cb8..0000000
--- a/src/ft_m_redirs.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_m_redirs.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 FT_M_REDIRS_H
-#define FT_M_REDIRS_H
-
-#include "ft_s_struct.h"
-
-void ft_dup_redirs(const t_lcom *ptr,
- t_msh *msh);
-
-#endif
diff --git a/src/ft_p_lcom_next.h b/src/ft_p_lcom_next.h
deleted file mode 100644
index 54eefd2..0000000
--- a/src/ft_p_lcom_next.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_p_lcom_next.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 FT_P_LCOM_NEXT_H
-#define FT_P_LCOM_NEXT_H
-
-#include <stdint.h>
-
-#include "ft_s_struct.h"
-
-char **ft_subst_vars(char *words[],
- t_msh *msh);
-char **ft_subst_args(const char word[],
- int8_t redir);
-
-#endif
diff --git a/src/ft_s_lcom.h b/src/ft_s_lcom.h
deleted file mode 100644
index ea78d6f..0000000
--- a/src/ft_s_lcom.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_s_lcom.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 FT_S_LCOM_H
-#define FT_S_LCOM_H
-
-#include "ft_s_struct.h"
-
-void ft_lcom_add_back(t_lcom **alcom, t_lcom *new);
-void ft_lcom_clear(t_lcom **lcom);
-t_lcom *ft_lcom_new(const char word[], t_msh *msh);
-t_lcom *ft_lcom_last(t_lcom *lcom);
-
-#endif
diff --git a/src/ft_s_lvars.h b/src/ft_s_lvars.h
deleted file mode 100644
index 0f46d7d..0000000
--- a/src/ft_s_lvars.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_s_lvars.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 FT_S_LVARS_H
-#define FT_S_LVARS_H
-
-#include "ft_s_struct.h"
-
-void ft_lvars_rebind(t_lvars **lvars,
- const char name[],
- const char newval[]);
-void ft_lvars_delone(t_lvars **lvars,
- const char name[]);
-void ft_lvars_add_front(t_lvars **alvars,
- t_lvars *new);
-void ft_lvars_clear(t_lvars **lvars);
-t_lvars *ft_lvars_new(const char name[],
- const char val[]);
-
-#endif
diff --git a/src/ft_u_vars.h b/src/ft_u_vars.h
deleted file mode 100644
index 82aa668..0000000
--- a/src/ft_u_vars.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_u_vars.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 FT_U_VARS_H
-#define FT_U_VARS_H
-
-#include "ft_s_struct.h"
-
-char *ft_subst_var_value(const char varname[],
- t_msh *msh);
-
-#endif
diff --git a/src/ft_m_argv.c b/src/m_argv.c
index 7b91fbb..6a79bd7 100644
--- a/src/ft_m_argv.c
+++ b/src/m_argv.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_argv.c :+: :+: :+: */
+/* m_argv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,20 +13,20 @@
#include <libft.h>
#include <stdint.h>
-#include "ft_d_define.h"
-#include "ft_m_comm.h"
-#include "ft_m_loop.h"
-#include "ft_s_struct.h"
+#include "d_define.h"
+#include "m_comm.h"
+#include "m_loop.h"
+#include "s_struct.h"
uint8_t
- ft_m_argv(int argc,
+ m_argv(int argc,
char *const argv[],
t_msh *msh)
{
/* TODO: better argv handling */
if (argc == 1)
{
- msh->ret = ft_m_loop(msh);
+ msh->ret = m_loop(msh);
return (msh->ret);
}
if (!ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3))
@@ -37,7 +37,7 @@ uint8_t
msh->shname, FT_OPT_COMMAND);
return (2);
}
- msh->ret = ft_m_comm(*(argv + 2), msh);
+ msh->ret = m_comm(*(argv + 2), msh);
}
return (msh->ret);
}
diff --git a/src/ft_b_env.h b/src/m_argv.h
index 192c5d9..8d12d05 100644
--- a/src/ft_b_env.h
+++ b/src/m_argv.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_env.h :+: :+: :+: */
+/* m_argv.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_ENV_H
-#define FT_B_ENV_H
+#ifndef M_ARGV_H
+#define M_ARGV_H
#include <stdint.h>
-#include "ft_s_struct.h"
-uint8_t ft_b_env(char *args[],
- t_msh *msh);
+#include "s_struct.h"
+
+uint8_t m_argv(int argc, char *const argv[], t_msh *msh);
#endif
diff --git a/src/ft_m_comm.c b/src/m_comm.c
index 5fca253..66e0ac2 100644
--- a/src/ft_m_comm.c
+++ b/src/m_comm.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_comm.c :+: :+: :+: */
+/* m_comm.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,21 +13,21 @@
#include <libft.h>
#include <stdint.h>
-#include "ft_d_enum.h"
-#include "ft_e_lcom.h"
-#include "ft_m_prompt.h"
-#include "ft_p_line.h"
-#include "ft_s_lcom.h"
+#include "d_enum.h"
+#include "e_lcom.h"
+#include "m_prompt.h"
+#include "p_line.h"
+#include "s_lcom.h"
uint8_t
- ft_m_comm(const char line[],
+ m_comm(const char line[],
t_msh *msh)
{
if (line[0] != '\0')
{
- ft_p_line((char*)line, msh);
- ft_e_lcom(msh);
- ft_lcom_clear(&msh->curr);
+ p_line((char*)line, msh);
+ e_lcom(msh);
+ lcom_clear(&msh->curr);
}
else
{
diff --git a/src/m_comm.h b/src/m_comm.h
new file mode 100644
index 0000000..3933cfe
--- /dev/null
+++ b/src/m_comm.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* m_comm.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 M_COMM_H
+#define M_COMM_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t m_comm(const char line[], t_msh *msh);
+
+#endif
diff --git a/src/ft_m_funptr.c b/src/m_funptr.c
index 305dfc9..3bd0969 100644
--- a/src/ft_m_funptr.c
+++ b/src/m_funptr.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_funptr.c :+: :+: :+: */
+/* m_funptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,25 +13,25 @@
#include <libft.h>
#include <stdlib.h>
-#include "ft_d_enum.h"
-#include "ft_b_builtins.h"
-#include "ft_f_fail.h"
-#include "ft_m_funptr.h"
-#include "ft_s_struct.h"
+#include "d_enum.h"
+#include "b_builtins.h"
+#include "f_fail.h"
+#include "m_funptr.h"
+#include "s_struct.h"
void
- ft_init_buptr(t_msh *msh)
+ init_buptr(t_msh *msh)
{
- msh->bu_ptr[0] = ft_b_echo;
- msh->bu_ptr[1] = ft_b_cd;
- msh->bu_ptr[2] = ft_b_pwd;
- msh->bu_ptr[3] = ft_b_export;
- msh->bu_ptr[4] = ft_b_unset;
- msh->bu_ptr[5] = ft_b_env;
- msh->bu_ptr[6] = ft_b_exit;
- msh->bu_ptr[7] = ft_b_type;
+ msh->bu_ptr[0] = b_echo;
+ msh->bu_ptr[1] = b_cd;
+ msh->bu_ptr[2] = b_pwd;
+ msh->bu_ptr[3] = b_export;
+ msh->bu_ptr[4] = b_unset;
+ msh->bu_ptr[5] = b_env;
+ msh->bu_ptr[6] = b_exit;
+ msh->bu_ptr[7] = b_type;
if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))
{
- ft_fail_alloc(msh);
+ f_fail_alloc(msh);
}
}
diff --git a/src/ft_b_export.h b/src/m_funptr.h
index 3a28562..1a0f198 100644
--- a/src/ft_b_export.h
+++ b/src/m_funptr.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_export.h :+: :+: :+: */
+/* m_funptr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,11 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_EXPORT_H
-#define FT_B_EXPORT_H
+#ifndef M_FUNPTR_H
+#define M_FUNPTR_H
-uint8_t
- ft_b_export(char *args[],
- t_msh *msh);
+#include "s_struct.h"
+
+void init_buptr(t_msh *msh);
#endif
diff --git a/src/ft_m_loop.c b/src/m_loop.c
index 3f40fba..143c25d 100644
--- a/src/ft_m_loop.c
+++ b/src/m_loop.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_loop.c :+: :+: :+: */
+/* m_loop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,14 +15,14 @@
#include <stdlib.h>
#include <unistd.h>
-#include "ft_e_lcom.h"
-#include "ft_m_prompt.h"
-#include "ft_p_line.h"
-#include "ft_s_lcom.h"
+#include "e_lcom.h"
+#include "m_prompt.h"
+#include "p_line.h"
+#include "s_lcom.h"
static char
- *ft_strjoin_m(char *s1,
+ *strjoin_m(char *s1,
char *s2,
uint8_t mode)
{
@@ -49,7 +49,7 @@ static char
}
void
- ft_m_loop_cont(t_msh *msh,
+ m_loop_cont(t_msh *msh,
char *line,
char *quote,
int8_t gnl)
@@ -65,24 +65,24 @@ void
while (gnl > 0 && ((!(quote = ft_strrchr(buf, '\"'))) &&
(!(quote = ft_strrchr(buf, '\'')))))
{
- ft_m_cont_prompt();
+ m_cont_prompt();
gnl = get_next_line(STDIN_FILENO, &line);
- buf = ft_strjoin_m(buf, line, 0);
+ buf = strjoin_m(buf, line, 0);
ft_memdel((void*)&line);
}
fin = ft_strtrim(buf, "\"'");
ft_memdel((void*)&buf);
fin = (ft_strrchr(fin, '\'')) ? ft_strsubst(fin, "\'", "") : fin;
- fin = ft_strjoin_m(prog, fin, 1);
- ft_p_line(fin, msh);
+ fin = strjoin_m(prog, fin, 1);
+ p_line(fin, msh);
ft_memdel((void*)&prog);
ft_memdel((void*)&fin);
- ft_e_lcom(msh);
- ft_lcom_clear(&msh->curr);
+ e_lcom(msh);
+ lcom_clear(&msh->curr);
}
uint8_t
- ft_m_loop(t_msh *msh)
+ m_loop(t_msh *msh)
{
char *line;
char *quote;
@@ -94,27 +94,26 @@ uint8_t
pipefd[1] = STDIN_FILENO;
while (gnl > 0)
{
- ft_m_prompt(msh);
+ m_prompt(msh);
gnl = get_next_line(STDIN_FILENO, &line);
if (line[0] != '\0')
{
if (!(quote = ft_strchr(line, '\'')) && !(quote = ft_strchr(line, '\"')))
{
- ft_p_line(line, msh);
+ p_line(line, msh);
ft_memdel((void*)&line);
- ft_e_lcom(msh);
- ft_lcom_clear(&msh->curr);
+ e_lcom(msh);
+ lcom_clear(&msh->curr);
}
else
{
- ft_m_loop_cont(msh, line, quote, 1);
+ m_loop_cont(msh, line, quote, 1);
if (line != NULL)
ft_memdel((void*)&line);
}
/* TODO: (null): Bad address on "msh ~> echo a > asd; cat < asd" but not on "msh ~> echo a > asd; cat asd" */
/* TODO: GNL 25 leak on "msh ~> exit" | gl hf */
/* TODO: "msh ~> some command \": re GNL into ft_nrealloc */
- /* TODO: the chad pipes | */
/* TODO: a histfile would be nice */
}
else
diff --git a/src/ft_b_exit.h b/src/m_loop.h
index 5dd2a07..1d665e3 100644
--- a/src/ft_b_exit.h
+++ b/src/m_loop.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_exit.h :+: :+: :+: */
+/* m_loop.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_EXIT_H
-#define FT_B_EXIT_H
+#ifndef M_LOOP
+#define M_LOOP
#include <stdint.h>
-uint8_t
- ft_b_exit(char *args[],
- t_msh *msh);
+#include "s_struct.h"
+
+uint8_t m_loop(t_msh *msh);
#endif
diff --git a/src/minishell.c b/src/m_minishell.c
index ee79f8f..dd47ac3 100644
--- a/src/minishell.c
+++ b/src/m_minishell.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* minishell.c :+: :+: :+: */
+/* m_minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,31 +16,30 @@
#include <string.h>
#include <errno.h>
-#include "ft_f_fail.h"
-#include "ft_m_argv.h"
-#include "ft_s_struct.h"
-#include "ft_s_init.h"
-#include "ft_s_destroy.h"
+#include "f_fail.h"
+#include "m_argv.h"
+#include "s_struct.h"
+#include "s_init.h"
+#include "s_destroy.h"
+#include "s_lvars.h"
int
main(int argc,
char *const argv[],
char *const envp[])
{
- t_msh *msh;
int32_t ret;
+ t_msh *msh;
- /* TODO: increment $SHLVL */
- /* TODO: also set $SHELL | maybe not bash does not set $SHELL */
- /* only zsh does */
/* TODO: handle general variables | $var */
- if (!(msh = ft_init_msh(argv, envp)))
+ if (!(msh = init_msh(argv, envp)))
{
ft_dprintf(2, "%s\n", strerror(errno));
return (FT_RET_ALLOC);
}
- ret = ft_m_argv(argc, argv, msh);
- ft_s_destroy(msh);
+ /* TODO: delet this */
+ ret = m_argv(argc, argv, msh);
+ s_destroy(msh);
return (ret);
}
@@ -48,7 +47,6 @@ int
** ====== INFO ======
** Files prefixes info
** -------------------
-** ft_ -> 42
** b_ -> builtins related
** d_ -> defines related
** e_ -> exec related
diff --git a/src/minishell.h b/src/m_minishell.h
index a30d8bc..06ecfed 100644
--- a/src/minishell.h
+++ b/src/m_minishell.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* minishell.h :+: :+: :+: */
+/* m_minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
-#ifndef MINISHELL_H
-#define MINISHELL_H
+#ifndef M_MINISHELL_H
+#define M_MINISHELL_H
#endif
diff --git a/src/ft_m_prompt.c b/src/m_prompt.c
index 4c4cc41..34aae09 100644
--- a/src/ft_m_prompt.c
+++ b/src/m_prompt.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_prompt.c :+: :+: :+: */
+/* m_prompt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,18 +13,18 @@
#include <libft.h>
#include <unistd.h>
-#include "ft_m_prompt.h"
-#include "ft_s_struct.h"
+#include "m_prompt.h"
+#include "s_struct.h"
void
- ft_m_cont_prompt(void)
+ m_cont_prompt(void)
{
ft_dprintf(STDIN_FILENO, "> ");
/* TODO :ft_printf("%s", msh->ps_two); */
}
void
- ft_m_prompt(t_msh *msh)
+ m_prompt(t_msh *msh)
{
ft_dprintf(STDIN_FILENO, "%s", msh->ps_one);
}
diff --git a/src/m_prompt.h b/src/m_prompt.h
new file mode 100644
index 0000000..3697fae
--- /dev/null
+++ b/src/m_prompt.h
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* m_prompt.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 M_PROMPT_H
+#define M_PROMPT_H
+
+#include "s_struct.h"
+
+void m_prompt(t_msh *msh);
+void m_cont_prompt(void);
+
+#endif
diff --git a/src/ft_m_redirs.c b/src/m_redirs.c
index 701a2a4..2414dcd 100644
--- a/src/ft_m_redirs.c
+++ b/src/m_redirs.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_redirs.c :+: :+: :+: */
+/* m_redirs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,13 +14,13 @@
#include <unistd.h>
#include <errno.h>
-#include "ft_f_fail.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
+#include "f_fail.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
void
- ft_dup_redirs(const t_lcom *ptr,
+ dup_redirs(const t_lcom *ptr,
t_msh *msh)
{
int32_t fd;
@@ -28,7 +28,7 @@ void
if (ptr->redir == -1)
{
if ((fd = open(ptr->rdrpath, O_RDONLY)) == -1)
- ft_f_redir(ptr->rdrpath, msh);
+ f_redir(ptr->rdrpath, msh);
dup2(fd, STDIN_FILENO);
close(fd);
}
@@ -36,7 +36,7 @@ void
{
if ((fd = open(ptr->rdrpath,
O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1)
- ft_f_redir(ptr->rdrpath, msh);
+ f_redir(ptr->rdrpath, msh);
dup2(fd, ptr->rdrfd);
close(fd);
}
@@ -44,7 +44,7 @@ void
{
if ((fd = open(ptr->rdrpath,
O_CREAT | O_APPEND | O_WRONLY, 0644)) == -1)
- ft_f_redir(ptr->rdrpath, msh);
+ f_redir(ptr->rdrpath, msh);
dup2(fd, ptr->rdrfd);
close(fd);
}
diff --git a/src/ft_e_pipes.h b/src/m_redirs.h
index f801b21..6d1b96a 100644
--- a/src/ft_e_pipes.h
+++ b/src/m_redirs.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_pipes.h :+: :+: :+: */
+/* m_redirs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,11 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_E_PIPES_H
-#define FT_E_PIPES_H
+#ifndef M_REDIRS_H
+#define M_REDIRS_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_e_pipes(t_lcom *ptr, t_msh *msh);
+void dup_redirs(const t_lcom *ptr, t_msh *msh);
#endif
diff --git a/src/ft_p_lcom.c b/src/p_lcom.c
index a8449ae..2dbd505 100644
--- a/src/ft_p_lcom.c
+++ b/src/p_lcom.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_p_lcom.c :+: :+: :+: */
+/* p_lcom.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -17,14 +17,14 @@
#include <unistd.h>
#include <errno.h>
-#include "ft_d_define.h"
-#include "ft_f_fail.h"
-#include "ft_s_lcom.h"
-#include "ft_s_lpipes.h"
-#include "ft_s_struct.h"
+#include "d_define.h"
+#include "f_fail.h"
+#include "s_lcom.h"
+#include "s_lpipes.h"
+#include "s_struct.h"
static void
- ft_rdr_err_check(char *ptr,
+ rdr_err_check(char *ptr,
t_lcom **link)
{
if ((*link)->redir == -1 && ft_ischarset("><", *(ptr + 1)))
@@ -42,7 +42,7 @@ static void
}
static int8_t
- ft_get_rdrpath(char *ptr,
+ get_rdrpath(char *ptr,
t_lcom **link)
{
char *p_rdrpath;
@@ -68,7 +68,7 @@ static int8_t
}
static void
- ft_get_rdrfd(const char *ptr,
+ get_rdrfd(const char *ptr,
t_lcom **link)
{
while (ft_isdigit(*ptr))
@@ -85,7 +85,7 @@ static void
}
int8_t
- ft_get_redir(const char word[],
+ get_redir(const char word[],
t_lcom **link)
{
/* TODO: norme */
@@ -112,18 +112,18 @@ int8_t
if ((*link)->redir > 0)
{
if (ft_isdigit(*(ptr - 1)))
- ft_get_rdrfd(ptr - 1, link);
+ get_rdrfd(ptr - 1, link);
else
(*link)->rdrfd = STDOUT_FILENO;
- ft_rdr_err_check(ptr, link);
- if (ft_get_rdrpath(ptr, link) != 0)
+ rdr_err_check(ptr, link);
+ if (get_rdrpath(ptr, link) != 0)
return (-1);
}
return (0);
}
int8_t
- ft_p_lcom(const char line[],
+ p_lcom(const char line[],
const uint64_t count,
t_msh *msh)
{
@@ -139,18 +139,17 @@ int8_t
while (i <= count && words[i])
{
next = FALSE;
- /* TODO: split pipes here */
if (ft_strchr(words[i], '|'))
{
- if (!(link = ft_lcom_new(NULL, msh)))
+ if (!(link = lcom_new(NULL, msh)))
return (-1);
- if (!(ft_split_pipes(words[i], link, msh)))
+ if (!(split_pipes(words[i], link, msh)))
return (-1);
next = TRUE;
}
- if (next == FALSE && !(link = ft_lcom_new(words[i], msh)))
+ if (next == FALSE && !(link = lcom_new(words[i], msh)))
return (-1);
- ft_lcom_add_back(&msh->curr, link);
+ lcom_add_back(&msh->curr, link);
i++;
}
ft_delwords(words);
diff --git a/src/ft_m_argv.h b/src/p_lcom.h
index 783c7e4..393d7e5 100644
--- a/src/ft_m_argv.h
+++ b/src/p_lcom.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_m_argv.h :+: :+: :+: */
+/* p_lcom.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,15 +10,14 @@
/* */
/* ************************************************************************** */
-#ifndef FT_M_ARGV_H
-#define FT_M_ARGV_H
+#ifndef P_LCOM_H
+#define P_LCOM_H
#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_m_argv(int argc,
- char *const argv[],
- t_msh *msh);
+int8_t get_redir(const char word[], t_lcom **link);
+int8_t p_lcom(const char line[], const uint64_t count, t_msh *msh);
#endif
diff --git a/src/ft_p_lcom_next.c b/src/p_lcom_next.c
index 8313b08..997878e 100644
--- a/src/ft_p_lcom_next.c
+++ b/src/p_lcom_next.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_p_lcom_next.c :+: :+: :+: */
+/* p_lcom_next.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,11 +14,17 @@
#include <stdlib.h>
#include <stdint.h>
-#include "ft_s_struct.h"
-#include "ft_u_vars.h"
+#include "d_enum.h"
+#include "s_destroy.h"
+#include "f_fail.h"
+#include "s_struct.h"
+#include "u_vars.h"
+#include "u_vars_next.h"
+
+/* TODO: norme */
static int8_t
- ft_subst_those_vars(int64_t i,
+ subst_those_vars(int64_t i,
char **p_words,
t_msh *msh)
{
@@ -30,11 +36,11 @@ static int8_t
s_varname = NULL;
varlen = i + 1;
while ((*p_words)[varlen] != '\0' &&
- !ft_ischarset("$=/#@%^*+{}[],.?-", (*p_words)[varlen]))
+ !ft_ischarset("$=/#@%^*+{}[],.-", (*p_words)[varlen]))
varlen += 1;
if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i)))
return (-1);
- varval = ft_subst_var_value(s_varname, msh);
+ varval = u_get_var_value(s_varname, msh);
*p_words = ft_strsubst(*p_words, s_varname, varval);
ft_memdel((void*)&s_varname);
ft_memdel((void*)&varval);
@@ -42,7 +48,7 @@ static int8_t
}
char
- **ft_subst_vars(char *words[],
+ **p_subst_vars(char *words[],
t_msh *msh)
{
char **p_words;
@@ -56,7 +62,7 @@ char
{
if (*(*p_words) + i - 1 != '\\')
{
- if (ft_subst_those_vars(i, p_words, msh) != 0)
+ if (subst_those_vars(i, p_words, msh) != 0)
return (NULL);
}
}
@@ -65,9 +71,8 @@ char
return (words);
}
-
char
- **ft_subst_args(const char word[],
+ **p_subst_args(const char word[],
int8_t redir)
{
char **words;
@@ -95,3 +100,110 @@ char
ft_memdel((void*)&subst);
return (words);
}
+
+static void
+ p_register_word(char word[],
+ t_msh *msh)
+{
+ char name[255];
+ char val[255];
+ char *ptr;
+ size_t i;
+
+ name[0] = '$';
+ ptr = word;
+ i = 1;
+ while (*ptr != '=' && *ptr != '\0')
+ {
+ name[i] = *ptr;
+ i++;
+ ptr++;
+ }
+ name[i] = '\0';
+ ptr++;
+ i = 0;
+ while (*ptr != '\0')
+ {
+ val[i] = *ptr;
+ i++;
+ ptr++;
+ }
+ val[i] = '\0';
+ u_subst_var_value(name, val, msh);
+}
+
+static char
+ **p_add_to_variables_and_delete(char *words[],
+ t_bool reg,
+ int64_t i,
+ t_msh *msh)
+{
+ int64_t j;
+ int64_t k;
+ char **rewords;
+
+ j = 0;
+ if (reg == TRUE)
+ {
+ while (words[j] && j < i)
+ {
+ p_register_word(words[j], msh);
+ j++;
+ }
+ }
+ j = 0;
+ while (words[i + j] != NULL)
+ j++;
+ if (!(rewords = (char**)malloc((j + 1) * sizeof(char*))))
+ {
+ ft_delwords(words);
+ s_destroy(msh);
+ f_fail_alloc(msh);
+ }
+ k = i;
+ while (i - k < j)
+ {
+ if (!(rewords[i - k] = ft_strdup(words[i])))
+ {
+ ft_delwords(words);
+ s_destroy(msh);
+ f_fail_alloc(msh);
+ }
+ i++;
+ }
+ rewords[i - k] = 0;
+ ft_delwords(words);
+ i++;
+ return (rewords);
+}
+
+char
+ **p_check_args_equals(char *words[],
+ t_msh *msh)
+{
+ char *ptr;
+ t_bool reg;
+ t_bool isvar;
+ int64_t i;
+
+ i = 0;
+ reg = TRUE;
+ isvar = TRUE;
+ while (words[i])
+ {
+ ptr = words[i];
+ while (*ptr != '\0' && *ptr != '=')
+ ptr++;
+ if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0]))
+ {
+ reg = FALSE;
+ if (i == 0)
+ isvar = FALSE;
+ break ;
+ }
+ i++;
+ }
+ if (isvar == TRUE)
+ return (p_add_to_variables_and_delete(words, reg, i, msh));
+ return (words);
+}
diff --git a/src/ft_p_lcom.h b/src/p_lcom_next.h
index 256fe75..2d0ae98 100644
--- a/src/ft_p_lcom.h
+++ b/src/p_lcom_next.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_p_lcom.h :+: :+: :+: */
+/* p_lcom_next.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,17 +10,15 @@
/* */
/* ************************************************************************** */
-#ifndef FT_P_LCOM_H
-#define FT_P_LCOM_H
+#ifndef P_LCOM_NEXT_H
+#define P_LCOM_NEXT_H
#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-int8_t ft_get_redir(const char word[],
- t_lcom **link);
-int8_t ft_p_lcom(const char line[],
- const uint64_t count,
- t_msh *msh);
+char **p_subst_vars(char *words[], t_msh *msh);
+char **p_subst_args(const char word[], int8_t redir);
+char **p_check_args_equals(char *words[], t_msh *msh);
#endif
diff --git a/src/ft_p_line.c b/src/p_line.c
index 166b880..aafc900 100644
--- a/src/ft_p_line.c
+++ b/src/p_line.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_p_line.c :+: :+: :+: */
+/* p_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -13,15 +13,15 @@
#include <libft.h>
#include <stdlib.h>
-#include "ft_d_enum.h"
-#include "ft_f_fail.h"
-#include "ft_p_lcom.h"
-#include "ft_p_line.h"
-#include "ft_s_destroy.h"
-#include "ft_s_struct.h"
+#include "d_enum.h"
+#include "f_fail.h"
+#include "p_lcom.h"
+#include "p_line.h"
+#include "s_destroy.h"
+#include "s_struct.h"
void
- ft_p_line(char line[],
+ p_line(char line[],
t_msh *msh)
{
char *ptr;
@@ -42,9 +42,9 @@ void
{
count -= 1;
}
- if (ft_p_lcom(line, count, msh) < 0)
+ if (p_lcom(line, count, msh) < 0)
{
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
}
diff --git a/src/p_line.h b/src/p_line.h
new file mode 100644
index 0000000..b3a35c5
--- /dev/null
+++ b/src/p_line.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_line.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 P_LINE_H
+#define P_LINE_H
+
+#include "s_struct.h"
+
+void p_line(char *line, t_msh *msh);
+
+#endif
diff --git a/src/ft_s_destroy.c b/src/s_destroy.c
index 22009c8..f9d56eb 100644
--- a/src/ft_s_destroy.c
+++ b/src/s_destroy.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_destroy.c :+: :+: :+: */
+/* s_destroy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -12,17 +12,17 @@
#include <libft.h>
-#include "ft_s_destroy.h"
-#include "ft_s_lvars.h"
+#include "s_destroy.h"
+#include "s_lvars.h"
void
- ft_s_destroy(t_msh *msh)
+ s_destroy(t_msh *msh)
{
ft_memdel((void*)&msh->ps_one);
ft_memdel((void*)&msh->cwd);
ft_memdel((void*)&msh->shname);
ft_delwords(msh->bu_ref);
ft_delwords(msh->envp);
- ft_lvars_clear(&msh->vars);
+ lvars_clear(&msh->vars);
ft_memdel((void*)&msh);
}
diff --git a/src/s_destroy.h b/src/s_destroy.h
new file mode 100644
index 0000000..66aea91
--- /dev/null
+++ b/src/s_destroy.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* s_destroy.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 S_DESTROY_H
+#define S_DESTROY_H
+
+#include "s_struct.h"
+
+void s_destroy(t_msh *msh);
+
+#endif
diff --git a/src/ft_s_init.c b/src/s_init.c
index f3ebaf6..a0ea9a3 100644
--- a/src/ft_s_init.c
+++ b/src/s_init.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_init.c :+: :+: :+: */
+/* s_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,13 +15,14 @@
#include <stdlib.h>
#include <unistd.h>
-#include "ft_d_define.h"
-#include "ft_m_funptr.h"
-#include "ft_s_init.h"
-#include "ft_u_vars.h"
+#include "d_define.h"
+#include "m_funptr.h"
+#include "s_init.h"
+#include "u_vars.h"
+#include "u_vars_next.h"
static char
- **ft_dupenv_del(char **nenvp,
+ **dupenv_del(char **nenvp,
uint64_t i)
{
while (i > 0)
@@ -34,7 +35,7 @@ static char
}
static char
- **ft_dupenv(char *const envp[])
+ **dupenv(char *const envp[])
{
uint64_t i;
char **nenvp;
@@ -52,15 +53,28 @@ static char
while (envp[i])
{
if (!(nenvp[i] = ft_strdup(envp[i])))
- return (ft_dupenv_del(nenvp, i));
+ return (dupenv_del(nenvp, i));
i++;
}
nenvp[i] = NULL;
return (nenvp);
}
+static void
+ inc_shlvl(t_msh *msh)
+{
+ char *str_one;
+ char *str_two;
+
+ u_subst_var_value("$SHLVL",
+ str_one = ft_itoa(
+ ft_atoi(str_two = u_get_var_value("$SHLVL", msh)) + 1), msh);
+ ft_memdel((void*)&str_one);
+ ft_memdel((void*)&str_two);
+}
+
t_msh
- *ft_init_msh(char *const argv[],
+ *init_msh(char *const argv[],
char *const envp[])
{
t_msh *msh;
@@ -73,13 +87,14 @@ t_msh
return (NULL);
/* TODO: shname: care about "./", try with symlinks */
msh->envp = NULL;
- if (!(msh->envp = ft_dupenv(envp)))
+ if (!(msh->envp = dupenv(envp)))
return (NULL);
msh->cwd = NULL;
- msh->cwd = ft_subst_var_value("$PWD", msh);
+ msh->cwd = u_get_var_value("$PWD", msh);
msh->ret = 0;
- ft_init_buptr(msh);
+ init_buptr(msh);
msh->curr = NULL;
msh->vars = NULL;
+ inc_shlvl(msh);
return (msh);
}
diff --git a/src/ft_s_init.h b/src/s_init.h
index bd8edc7..3539086 100644
--- a/src/ft_s_init.h
+++ b/src/s_init.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_init.h :+: :+: :+: */
+/* s_init.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_S_INIT_H
-#define FT_S_INIT_H
+#ifndef S_INIT_H
+#define S_INIT_H
#include <stdlib.h>
-#include "ft_s_struct.h"
-t_msh *ft_init_msh(char *const argv[],
- char *const envp[]);
+#include "s_struct.h"
+
+t_msh *init_msh(char *const argv[], char *const envp[]);
#endif
diff --git a/src/ft_s_lcom.c b/src/s_lcom.c
index d56ba7f..f1ef2a4 100644
--- a/src/ft_s_lcom.c
+++ b/src/s_lcom.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_lcom.c :+: :+: :+: */
+/* s_lcom.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,12 +14,12 @@
#include <stdlib.h>
#include <stdint.h>
-#include "ft_p_lcom.h"
-#include "ft_p_lcom_next.h"
-#include "ft_s_struct.h"
+#include "p_lcom.h"
+#include "p_lcom_next.h"
+#include "s_struct.h"
static int8_t
- ft_fill_lcom(char *words[],
+ fill_lcom(char *words[],
t_lcom **lcom)
{
/* TODO: norme */
@@ -49,11 +49,8 @@ static int8_t
j = 0;
while (i > 0 && j < i)
{
- if (!((*lcom)->argv[j] =
- (char*)malloc((ft_strlen(words[j]) + 1) * sizeof(char))))
+ if (!((*lcom)->argv[j] = ft_strdup(words[j])))
return (-1);
- ft_strlcpy((*lcom)->argv[j], words[j],
- ft_strlen(words[j]) + 1);
j++;
}
(*lcom)->argv[j] = 0;
@@ -61,7 +58,7 @@ static int8_t
}
t_lcom
- *ft_lcom_last(t_lcom *lcom)
+ *lcom_last(t_lcom *lcom)
{
while (lcom->next != NULL)
lcom = lcom->next;
@@ -69,7 +66,7 @@ t_lcom
}
void
- ft_lcom_add_back(t_lcom **alcom,
+ lcom_add_back(t_lcom **alcom,
t_lcom *new)
{
t_lcom *tmp;
@@ -78,13 +75,13 @@ void
*alcom = new;
else
{
- tmp = ft_lcom_last(*alcom);
+ tmp = lcom_last(*alcom);
tmp->next = new;
}
}
void
- ft_lcom_clear(t_lcom **lcom)
+ lcom_clear(t_lcom **lcom)
{
t_lcom *tmp;
t_lcom *renext;
@@ -107,7 +104,7 @@ void
}
t_lcom
- *ft_lcom_new(const char word[],
+ *lcom_new(const char word[],
t_msh *msh)
{
/* TODO: norme */
@@ -128,13 +125,14 @@ t_lcom
return (link);
}
link->pipes = NULL;
- if (ft_get_redir(word, &link) != 0)
+ if (get_redir(word, &link) != 0)
return (NULL);
- if (!(words = ft_subst_args(word, link->redir)))
+ if (!(words = p_subst_args(word, link->redir)))
return (NULL);
- if (!(words = ft_subst_vars(words, msh)))
+ if (!(words = p_subst_vars(words, msh)))
return (NULL);
- if (ft_fill_lcom(words, &link) < 0)
+ words = p_check_args_equals(words, msh);
+ if (fill_lcom(words, &link) < 0)
{
ft_delwords(words);
return (NULL);
diff --git a/src/s_lcom.h b/src/s_lcom.h
new file mode 100644
index 0000000..10fcf7c
--- /dev/null
+++ b/src/s_lcom.h
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* s_lcom.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 S_LCOM_H
+#define S_LCOM_H
+
+#include "s_struct.h"
+
+void lcom_add_back(t_lcom **alcom, t_lcom *new);
+void lcom_clear(t_lcom **lcom);
+t_lcom *lcom_new(const char word[], t_msh *msh);
+t_lcom *lcom_last(t_lcom *lcom);
+
+#endif
diff --git a/src/ft_s_lpipes.c b/src/s_lpipes.c
index 8bd34de..cb78df3 100644
--- a/src/ft_s_lpipes.c
+++ b/src/s_lpipes.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_lpipes.c :+: :+: :+: */
+/* s_lpipes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,12 +14,12 @@
#include <stdlib.h>
#include <stdint.h>
-#include "ft_s_lcom.h"
-#include "ft_s_lpipes.h"
-#include "ft_s_struct.h"
+#include "s_lcom.h"
+#include "s_lpipes.h"
+#include "s_struct.h"
struct s_lpipes
- *ft_lpipes_last(struct s_lpipes *lpipes)
+ *lpipes_last(struct s_lpipes *lpipes)
{
while (lpipes->next != NULL)
lpipes = lpipes->next;
@@ -27,7 +27,7 @@ struct s_lpipes
}
void
- ft_lpipes_add_back(struct s_lpipes **alpipes,
+ lpipes_add_back(struct s_lpipes **alpipes,
struct s_lpipes *new)
{
struct s_lpipes *tmp;
@@ -36,13 +36,13 @@ void
*alpipes = new;
else
{
- tmp = ft_lpipes_last(*alpipes);
+ tmp = lpipes_last(*alpipes);
tmp->next = new;
}
}
void
- ft_lpipes_clear(struct s_lpipes **lpipes)
+ lpipes_clear(struct s_lpipes **lpipes)
{
struct s_lpipes *tmp;
struct s_lpipes *renext;
@@ -53,7 +53,7 @@ void
while (tmp)
{
renext = tmp->next;
- ft_lcom_clear(&tmp->one);
+ lcom_clear(&tmp->one);
ft_memdel((void*)&tmp);
tmp = renext;
}
@@ -61,7 +61,7 @@ void
}
struct s_lpipes
- *ft_lpipes_new(const char pipedword[],
+ *lpipes_new(const char pipedword[],
t_msh *msh)
{
struct s_lpipes *link;
@@ -69,7 +69,7 @@ struct s_lpipes
if (!(link = (struct s_lpipes*)malloc(sizeof(struct s_lpipes))))
return (NULL);
link->one = NULL;
- if (!(link->one = ft_lcom_new(pipedword, msh)))
+ if (!(link->one = lcom_new(pipedword, msh)))
{
return (NULL);
}
@@ -78,7 +78,7 @@ struct s_lpipes
}
struct s_lpipes
- *ft_split_pipes(const char word[],
+ *split_pipes(const char word[],
t_lcom *lcom,
t_msh *msh)
{
@@ -93,11 +93,11 @@ struct s_lpipes
return (NULL);
while (words[i])
{
- if (!(lpipes = ft_lpipes_new(words[i], msh)))
+ if (!(lpipes = lpipes_new(words[i], msh)))
{
return (NULL);
}
- ft_lpipes_add_back(&lcom->pipes, lpipes);
+ lpipes_add_back(&lcom->pipes, lpipes);
i++;
}
ft_delwords(words);
diff --git a/src/ft_s_lpipes.h b/src/s_lpipes.h
index 50fd693..1fc6eec 100644
--- a/src/ft_s_lpipes.h
+++ b/src/s_lpipes.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_lpipes.h :+: :+: :+: */
+/* s_lpipes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,16 +10,16 @@
/* */
/* ************************************************************************** */
-#ifndef FT_S_LPIPES_H
-#define FT_S_LPIPES_H
+#ifndef S_LPIPES_H
+#define S_LPIPES_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-struct s_lpipes *ft_lpipes_last(struct s_lpipes *lpipes);
-void ft_lpipes_add_back(struct s_lpipes **alpipes,
+struct s_lpipes *lpipes_last(struct s_lpipes *lpipes);
+void lpipes_add_back(struct s_lpipes **alpipes,
struct s_lpipes *new);
-void ft_lpipes_clear(struct s_lpipes **lpipes);
-struct s_lpipes *ft_lpipes_new(const char pipedword[], t_msh *msh);
-struct s_lpipes *ft_split_pipes(const char word[], t_lcom *lcom, t_msh *msh);
+void lpipes_clear(struct s_lpipes **lpipes);
+struct s_lpipes *lpipes_new(const char pipedword[], t_msh *msh);
+struct s_lpipes *split_pipes(const char word[], t_lcom *lcom, t_msh *msh);
#endif
diff --git a/src/ft_s_lvars.c b/src/s_lvars.c
index fb3a0f4..d9b7159 100644
--- a/src/ft_s_lvars.c
+++ b/src/s_lvars.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_lvars.c :+: :+: :+: */
+/* s_lvars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,17 +16,17 @@
#include <errno.h>
#include <unistd.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
void
- ft_lvars_rebind(t_lvars **lvars,
+ lvars_rebind(t_lvars **lvars,
const char name[],
const char newval[])
{
t_lvars *tmp;
tmp = *lvars;
- while (tmp && ft_strncmp(tmp->name, name, ft_strlen(name)))
+ while (tmp && ft_strncmp(tmp->name, name, ft_strlen(name) + 1))
{
tmp = tmp->next;
}
@@ -40,17 +40,23 @@ void
ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno));
exit(FT_RET_ALLOC);
}
+ /* TODO: delete this */
+ tmp = *lvars;
+ while (tmp) {
+ ft_printf("[%s]: [%s]\n", tmp->name, tmp->val);
+ tmp = tmp->next;
+ }
}
void
- ft_lvars_delone(t_lvars **lvars,
+ lvars_delone(t_lvars **lvars,
const char name[])
{
t_lvars *tmp;
t_lvars *prev;
tmp = *lvars;
- if (tmp != NULL && !ft_strncmp(tmp->name, name, ft_strlen(name)))
+ if (tmp != NULL && !ft_strncmp(tmp->name, name, ft_strlen(name) + 1))
{
*lvars = tmp->next;
ft_memdel((void*)&tmp->name);
@@ -58,7 +64,7 @@ void
ft_memdel((void*)&tmp);
return ;
}
- while (tmp && ft_strncmp(tmp->name, name, ft_strlen(name)))
+ while (tmp && ft_strncmp(tmp->name, name, ft_strlen(name) + 1))
{
prev = tmp;
tmp = tmp->next;
@@ -72,7 +78,7 @@ void
}
void
- ft_lvars_add_front(t_lvars **alvars,
+ lvars_add_front(t_lvars **alvars,
t_lvars *new)
{
if (!alvars || !new)
@@ -84,7 +90,7 @@ void
}
void
- ft_lvars_clear(t_lvars **lvars)
+ lvars_clear(t_lvars **lvars)
{
t_lvars *tmp;
t_lvars *renext;
@@ -104,7 +110,7 @@ void
}
t_lvars
- *ft_lvars_new(const char name[],
+ *lvars_new(const char name[],
const char val[])
{
t_lvars *link;
diff --git a/src/s_lvars.h b/src/s_lvars.h
new file mode 100644
index 0000000..163f6cc
--- /dev/null
+++ b/src/s_lvars.h
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* s_lvars.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 S_LVARS_H
+#define S_LVARS_H
+
+#include "s_struct.h"
+
+void lvars_rebind(t_lvars **lvars, const char name[], const char newval[]);
+void lvars_delone(t_lvars **lvars, const char name[]);
+void lvars_add_front(t_lvars **alvars, t_lvars *new);
+void lvars_clear(t_lvars **lvars);
+t_lvars *lvars_new(const char name[], const char val[]);
+
+#endif
diff --git a/src/ft_s_struct.h b/src/s_struct.h
index 3a8df0a..8c72012 100644
--- a/src/ft_s_struct.h
+++ b/src/s_struct.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_s_struct.h :+: :+: :+: */
+/* s_struct.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,12 +10,12 @@
/* */
/* ************************************************************************** */
-#ifndef FT_S_STRUCT_H
-#define FT_S_STRUCT_H
+#ifndef S_STRUCT_H
+#define S_STRUCT_H
#include <stdint.h>
-#include "ft_d_define.h"
+#include "d_define.h"
/*
** redir(int8_t) index
diff --git a/src/ft_u_utils.c b/src/u_utils.c
index b7ab7d8..20c5cfc 100644
--- a/src/ft_u_utils.c
+++ b/src/u_utils.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_u_utils.c :+: :+: :+: */
+/* u_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,7 +15,7 @@
#include <stdint.h>
uint64_t
- ft_get_argc(const char *args[])
+ u_builtins_get_argc(const char *args[])
{
uint64_t argc;
diff --git a/src/ft_e_lcom.h b/src/u_utils.h
index 5244001..d822343 100644
--- a/src/ft_e_lcom.h
+++ b/src/u_utils.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_e_lcom.h :+: :+: :+: */
+/* u_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,12 +10,11 @@
/* */
/* ************************************************************************** */
-#ifndef FT_E_LCOM_H
-#define FT_E_LCOM_H
+#ifndef U_UTILS_H
+#define U_UTILS_H
#include <stdint.h>
-#include "ft_s_struct.h"
-void ft_e_lcom(t_msh *msh);
+uint64_t u_builtins_get_argc(const char *args[]);
#endif
diff --git a/src/ft_u_vars.c b/src/u_vars.c
index cb020e3..2a78f3d 100644
--- a/src/ft_u_vars.c
+++ b/src/u_vars.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_u_vars.c :+: :+: :+: */
+/* u_vars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -14,26 +14,25 @@
#include <stdlib.h>
#include <stdint.h>
-#include "ft_d_define.h"
-#include "ft_f_fail.h"
-#include "ft_s_destroy.h"
-#include "ft_s_lcom.h"
-#include "ft_s_struct.h"
-
+#include "d_define.h"
+#include "f_fail.h"
+#include "s_destroy.h"
+#include "s_lcom.h"
+#include "s_struct.h"
static char
- *ft_set_rva(const char varname[],
- t_msh *msh)
+ *u_set_rva(const char varname[],
+ t_msh *msh)
{
char *rvarname;
if (!(rvarname = (char*)malloc((ft_strlen(varname) + 1) * sizeof(char))))
{
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
- ft_memcpy((char*)rvarname, (const char*)varname + 1,
+ (void)ft_memcpy((char*)rvarname, (const char*)varname + 1,
ft_strlen(varname + 1));
*(rvarname + ft_strlen(varname + 1)) = '=';
*(rvarname + ft_strlen(varname + 1) + 1) = '\0';
@@ -41,25 +40,25 @@ static char
}
static char
- *ft_dup_env(char *p_env,
- char *rvarname,
- t_msh *msh)
+ *u_dup_env(char *p_env,
+ char *rvarname,
+ t_msh *msh)
{
char *varval;
if (!(varval = ft_strdup(p_env)))
{
ft_memdel((void*)&rvarname);
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
ft_memdel((void*)&rvarname);
return (varval);
}
static char
- *ft_get_frm_env(char rvarname[],
+ *u_get_frm_env(char rvarname[],
t_msh *msh)
{
char **p_env;
@@ -69,65 +68,86 @@ static char
p_env = msh->envp;
while (*p_env)
{
- if (!ft_strncmp(rvarname, *p_env, ft_strlen(rvarname)))
+ if (!ft_strncmp(rvarname, *p_env, ft_strclen(*p_env, '=')))
{
pp_env = *p_env;
while (*pp_env != '\0' && *pp_env != '=')
pp_env += 1;
if (*pp_env == '=')
pp_env += 1;
- varval = ft_dup_env(pp_env, rvarname, msh);
+ varval = u_dup_env(pp_env, rvarname, msh);
return (varval);
}
p_env += 1;
}
+ ft_memdel((void*)&rvarname);
return (NULL);
}
static char
- *ft_get_special_var(const char varname[],
- t_msh *msh)
+ *u_get_special_var(const char varname[],
+ t_msh *msh)
{
char *varval;
- if (!ft_strncmp(varname, FT_RET_VAR, 3))
+ if (ft_strncmp(varname, FT_RET_VAR, 3) == 0)
{
- if (!(varval = ft_uitoa(msh->ret)))
+ if ((varval = ft_uitoa(msh->ret)) == NULL)
{
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
return (varval);
}
- else if (!ft_strncmp(varname, FT_ZER_VAR, 3))
+ else if (ft_strncmp(varname, FT_ZER_VAR, 3) == 0)
{
- if (!(varval = ft_strdup(msh->shname)))
+ if ((varval = ft_strdup(msh->shname)) == NULL)
{
- ft_lcom_clear(&msh->curr);
- ft_s_destroy(msh);
- ft_fail_alloc(msh);
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
}
return (varval);
}
return (NULL);
}
-static char
- *ft_get_cstm_vr(const char varname[],
- t_msh *msh)
+char
+ *u_get_cstm_vr(const char varname[],
+ t_msh *msh)
{
- (void)varname;
- (void)msh;
- return (NULL);
+ t_lvars *ptr;
+ char *varval;
+
+ ptr = msh->vars;
+ while (ptr != NULL &&
+ ft_strncmp(varname + 1, ptr->name, ft_strlen(varname + 1) + 1) != 0)
+ {
+ ptr = ptr->next;
+ }
+ if (ptr != NULL)
+ {
+ if (!(varval = ft_strdup(ptr->val)))
+ {
+ lcom_clear(&msh->curr);
+ s_destroy(msh);
+ f_fail_alloc(msh);
+ }
+ return (varval);
+ }
+ else
+ {
+ return (NULL);
+ }
}
/*
-** char *
-** ft_subst_var_value(const char varname[], const t_msh *msh);
+** char*
+** u_get_var_value(const char varname[], t_msh *msh);
**
** DESCRIPTION
-** The ft_subst_var_value() function returns
+** The u_get_var_value() function returns
** a heap-allocated, null-terminated string
** that may later be free'd containing the
** value of the variable varname[] including
@@ -136,8 +156,8 @@ static char
*/
char
- *ft_subst_var_value(const char varname[],
- t_msh *msh)
+ *u_get_var_value(const char varname[],
+ t_msh *msh)
{
/* TODO: check behaviour on empty vars -> "QWE=" */
/* TODO: add support for global variables -> "$hey $nigga..." */
@@ -145,18 +165,18 @@ char
char *rvarname;
varval = NULL;
- if ((varval = ft_get_special_var(varname, msh)) != NULL)
+ if ((varval = u_get_special_var(varname, msh)) != NULL)
{
return (varval);
}
- else if ((varval = ft_get_cstm_vr(varname, msh)) != NULL)
+ else if ((varval = u_get_cstm_vr(varname, msh)) != NULL)
{
return (varval);
}
else
{
- rvarname = ft_set_rva(varname, msh);
- varval = ft_get_frm_env(rvarname, msh);
+ rvarname = u_set_rva(varname, msh);
+ varval = u_get_frm_env(rvarname, msh);
return (varval);
}
return (NULL);
diff --git a/src/ft_b_echo.h b/src/u_vars.h
index 7fd7463..0d83b4b 100644
--- a/src/ft_b_echo.h
+++ b/src/u_vars.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_b_echo.h :+: :+: :+: */
+/* u_vars.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,13 +10,12 @@
/* */
/* ************************************************************************** */
-#ifndef FT_B_ECHO_H
-#define FT_B_ECHO_H
+#ifndef U_VARS_H
+#define U_VARS_H
-#include <stdint.h>
-#include "ft_s_struct.h"
+#include "s_struct.h"
-uint8_t ft_b_echo(char *args[],
- t_msh *msh);
+char *u_get_cstm_vr(const char varname[], t_msh *msh);
+char *u_get_var_value(const char varname[], t_msh *msh);
#endif
diff --git a/src/u_vars_next.c b/src/u_vars_next.c
new file mode 100644
index 0000000..820bbe1
--- /dev/null
+++ b/src/u_vars_next.c
@@ -0,0 +1,102 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* u_vars_next.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 <inttypes.h>
+#include <stdlib.h>
+
+#include "d_enum.h"
+#include "s_lvars.h"
+#include "s_struct.h"
+
+static int64_t
+ u_get_env_var_line(const char varname[],
+ t_msh *msh)
+{
+ char **env_ptr;
+ int64_t i;
+
+ env_ptr = msh->envp;
+ i = 0;
+ while (*env_ptr &&
+ ft_strncmp(varname, *env_ptr, ft_strclen(*env_ptr, '=')) != 0)
+ {
+ env_ptr++;
+ i++;
+ }
+ if (*env_ptr)
+ return (i);
+ else
+ return (-1);
+}
+
+static t_bool
+ u_get_custom_var_existance(const char varname[],
+ t_msh *msh)
+{
+ t_lvars *ptr;
+
+ ptr = msh->vars;
+ while (ptr &&
+ ft_strncmp(varname, ptr->name, ft_strlen(varname) + 1) != 0)
+ {
+ ptr = ptr->next;
+ }
+ if (ptr != NULL)
+ {
+ return (TRUE);
+ }
+ else
+ {
+ return (FALSE);
+ }
+}
+
+/*
+** void
+** u_subst_var_value(const char varname[], const char newval[], t_msh *msh);
+**
+** DESCRIPTION
+** The subst_var_value() changes the value of msh->envp
+** variable varname[] with newval[]. If varname[] wasn't found
+** in msh->envp, varname[] is searched in msh->vars.
+*/
+
+void
+ u_subst_var_value(const char varname[],
+ const char newval[],
+ t_msh *msh)
+{
+ char new_line_fmt[2048];
+ int64_t env_line;
+
+ if ((env_line = u_get_env_var_line(varname + 1, msh)) > -1)
+ {
+ ft_memdel((void*)&msh->envp[env_line]);
+ ft_sprintf(new_line_fmt, "%s=%s", varname + 1, newval);
+ if (!(msh->envp[env_line] =
+ (char*)malloc((ft_strlen(new_line_fmt) + 1) * sizeof(char))))
+ {
+ /* TODO: Handle this fail */
+ }
+ (void)ft_strlcpy(msh->envp[env_line],
+ new_line_fmt, ft_strlen(new_line_fmt) + 1);
+ }
+ else if ((env_line = u_get_custom_var_existance(varname + 1, msh)) == TRUE)
+ {
+ lvars_rebind(&msh->vars, varname + 1, newval);
+ }
+ else
+ {
+ lvars_add_front(&msh->vars, lvars_new(varname + 1, newval));
+ }
+}
diff --git a/src/ft_f_errno.h b/src/u_vars_next.h
index 86fce83..118451f 100644
--- a/src/ft_f_errno.h
+++ b/src/u_vars_next.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_f_errno.h :+: :+: :+: */
+/* u_vars_next.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -10,12 +10,13 @@
/* */
/* ************************************************************************** */
-#ifndef FT_F_ERRNO_H
-#define FT_F_ERRNO_H
+#ifndef U_VARS_NEXT_H
+#define U_VARS_NEXT_H
-#include "ft_s_struct.h"
+#include "s_struct.h"
-void ft_f_dump_errno(const char concern[],
+void u_subst_var_value(const char varname[],
+ const char newval[],
t_msh *msh);
#endif