summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-17 19:49:35 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-17 19:49:35 +0200
commit990143a3f21f5500abc329c7df4ef30d20cb71eb (patch)
tree4039744d012594f1923508bcb8f8c57c270e4172
parentIn progress (diff)
download42-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
-rw-r--r--TODO.org2
-rw-r--r--src/b_cd.c2
-rw-r--r--src/d_define.h8
-rw-r--r--src/m_argv.c2
-rw-r--r--src/m_minishell.c1
-rw-r--r--src/m_mshrc.c20
-rw-r--r--src/m_mshrc.h4
7 files changed, 34 insertions, 5 deletions
diff --git a/TODO.org b/TODO.org
index 0e9a590..18a07f8 100644
--- a/TODO.org
+++ b/TODO.org
@@ -4,6 +4,7 @@
** DONE cd qweqwe <=== stderr
** DONE [#A] lpipes leaks <=== this is a big one (split lpipes | lcom | com)
** DONE [#B] forked write(2) stuff on cd
+** TODO [#B] /true/path/to/non-existant/bin/fail-plus-bad-fork
** TODO [#C] fix that goddamn exit(2) 25 leak
** TODO [#C] lpipes leaks on builtins (same as above man)
** TODO [#C] leaks on builtins (same as above man)
@@ -21,4 +22,5 @@
** TODO [#B] .minishell_history
** TODO [#C] Norm
** TODO [#C] [ builtin <=== pretty cool yet simple stuff ( [ $a -eq 1 ] )
+** TODO [#C] alias
** DONE [#C] Read scripts
diff --git a/src/b_cd.c b/src/b_cd.c
index d2b1042..d82ab9c 100644
--- a/src/b_cd.c
+++ b/src/b_cd.c
@@ -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