diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-17 19:49:35 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-17 19:49:35 +0200 |
commit | 990143a3f21f5500abc329c7df4ef30d20cb71eb (patch) | |
tree | 4039744d012594f1923508bcb8f8c57c270e4172 /src | |
parent | In progress (diff) | |
download | 42-minishell-990143a3f21f5500abc329c7df4ef30d20cb71eb.tar.gz 42-minishell-990143a3f21f5500abc329c7df4ef30d20cb71eb.tar.bz2 42-minishell-990143a3f21f5500abc329c7df4ef30d20cb71eb.tar.xz 42-minishell-990143a3f21f5500abc329c7df4ef30d20cb71eb.tar.zst 42-minishell-990143a3f21f5500abc329c7df4ef30d20cb71eb.zip |
.minishellrc working
Diffstat (limited to 'src')
-rw-r--r-- | src/b_cd.c | 2 | ||||
-rw-r--r-- | src/d_define.h | 8 | ||||
-rw-r--r-- | src/m_argv.c | 2 | ||||
-rw-r--r-- | src/m_minishell.c | 1 | ||||
-rw-r--r-- | src/m_mshrc.c | 20 | ||||
-rw-r--r-- | src/m_mshrc.h | 4 |
6 files changed, 32 insertions, 5 deletions
@@ -136,7 +136,7 @@ uint8_t { if ((path = u_get_var_value("$HOME", msh)) == NULL) { - ft_dprintf(STDERR_FILENO, "minishell: cd: HOME not set\n"); + ft_dprintf(STDERR_FILENO, "minishell: cd: %s\n", FT_FAIL_HOME_NOT_SET); return (2); } } diff --git a/src/d_define.h b/src/d_define.h index 899a2e7..d38cb10 100644 --- a/src/d_define.h +++ b/src/d_define.h @@ -45,5 +45,13 @@ #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" +#define FT_FAIL_HOME_NOT_SET "HOME not set" + +/* +** ====== FILES ====== +*/ + +#define FT_MINISHELLRC ".minishellrc" +#define FT_MINISHELL_HISTORY ".minishell_history" #endif diff --git a/src/m_argv.c b/src/m_argv.c index 0c32e3b..25b386e 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -19,6 +19,7 @@ #include "d_define.h" #include "m_comm.h" #include "m_loop.h" +#include "m_mshrc.h" #include "s_struct.h" uint8_t @@ -30,6 +31,7 @@ uint8_t if (argc == 1) { + msh->ret = m_source_mshrc(msh); msh->ret = m_loop(STDIN_FILENO, msh); } else if (argc > 1 && ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3) == 0) diff --git a/src/m_minishell.c b/src/m_minishell.c index 7a381ee..a538041 100644 --- a/src/m_minishell.c +++ b/src/m_minishell.c @@ -35,7 +35,6 @@ int ft_dprintf(2, "%s\n", strerror(errno)); return (FT_RET_ALLOC); } - m_source_mshrc(msh); ret = m_argv(argc, argv, msh); s_destroy(msh); return (ret); diff --git a/src/m_mshrc.c b/src/m_mshrc.c index acd64ec..f730113 100644 --- a/src/m_mshrc.c +++ b/src/m_mshrc.c @@ -11,15 +11,31 @@ /* ************************************************************************** */ #include <libft.h> +#include <stdint.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> +#include "d_define.h" #include "s_struct.h" +#include "m_loop.h" #include "u_vars.h" -void +uint8_t m_source_mshrc(t_msh *msh) { - (void)msh; + int32_t fd; + char *home; + char file[2048]; + uint8_t ret; + + if ((home = u_get_var_value("$HOME", msh)) == NULL) + return (0); + ft_sprintf(file, "%s/%s", home, FT_MINISHELLRC); + ft_memdel((void*)&home); + if ((fd = open(file, O_RDONLY)) < 0) + return (0); + ret = m_loop(fd, msh); + close(fd); + return (ret); } diff --git a/src/m_mshrc.h b/src/m_mshrc.h index 325b742..75daf15 100644 --- a/src/m_mshrc.h +++ b/src/m_mshrc.h @@ -13,8 +13,10 @@ #ifndef M_MSHRC_H #define M_MSHRC_H +#include <stdint.h> + #include "s_struct.h" -void m_source_mshrc(t_msh *msh); +uint8_t m_source_mshrc(t_msh *msh); #endif |