summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-12-18 16:00:22 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-12-18 16:00:22 +0100
commit62a1c19e2095a8dd0fb66f4e29dce37eae0c5d69 (patch)
treef2e879822c0043495152b4c597d7234e29bfe063
parentspammingnormcommits (diff)
download42-minishell-gnu-compat.tar.gz
42-minishell-gnu-compat.tar.bz2
42-minishell-gnu-compat.tar.xz
42-minishell-gnu-compat.tar.zst
42-minishell-gnu-compat.zip
-rw-r--r--src/b_exit.c1
-rw-r--r--src/c_init.c28
-rw-r--r--src/m_argv.c4
-rw-r--r--src/m_loop.c2
4 files changed, 22 insertions, 13 deletions
diff --git a/src/b_exit.c b/src/b_exit.c
index 4f395cf..b9b17ea 100644
--- a/src/b_exit.c
+++ b/src/b_exit.c
@@ -25,6 +25,7 @@ unsigned char b_exit(char *args[], t_msh *msh)
unsigned char ret;
const unsigned long argc = u_builtins_get_argc((const char**)args);
+ write(STDERR_FILENO, "exit\n", 5 * sizeof(char));
if (argc > 1)
{
f_fail_too_many_args("exit", msh);
diff --git a/src/c_init.c b/src/c_init.c
index 84098ec..b2fd3d3 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -76,6 +76,22 @@ static short
return (0);
}
+static void
+ c_set_ptr_norme(char key, t_bool *sw, char **p, char **context)
+{
+ if ((key == -1 && *p - *context != 0) || key == 1)
+ {
+ *p += (key == -1) ? (2 * key) : (0);
+ while (*sw == FALSE && ((key == -1 && *p - *context != 0) || key == 1)
+ && **p != C_LF && **p != C_NUL)
+ *p += key;
+ if (*sw == TRUE)
+ *sw = FALSE;
+ if (*p - *context != 0 && **p != C_NUL)
+ *p += 1;
+ }
+}
+
char
*c_set_ptr(t_bool reset, char key, t_msh *msh)
{
@@ -102,17 +118,7 @@ char
context = msh->curr_hist_ptr;
sw = TRUE;
}
- if ((key == -1 && p - context != 0) || key == 1)
- {
- p += (key == -1) ? (2 * key) : (0);
- while (sw == FALSE && ((key == -1 && p - context != 0) || key == 1)
- && *p != C_LF && *p != C_NUL)
- p += key;
- if (sw == TRUE)
- sw = FALSE;
- if (p - context != 0 && *p != C_NUL)
- p += 1;
- }
+ c_set_ptr_norme(key, &sw, &p, &context);
return (p);
}
diff --git a/src/m_argv.c b/src/m_argv.c
index 525439b..859fa72 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -16,6 +16,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include "c_init.h"
+#include "c_utils_next.h"
#include "f_fail.h"
#include "d_define.h"
#include "m_comm.h"
@@ -69,6 +71,8 @@ unsigned char m_argv(int argc, char *const argv[], t_msh *msh)
msh->prev_hist = m_get_prev_hist(msh);
msh->ret = m_source_mshrc(msh);
msh->fd = STDIN_FILENO;
+ c_get_msh(1, msh);
+ c_set_ptr(TRUE, 0, msh);
msh->ret = m_loop(STDIN_FILENO, msh);
}
else if (argc > 1 && ft_strncmp(*(argv + 1), M_OPT_COMMAND, 3) == 0)
diff --git a/src/m_loop.c b/src/m_loop.c
index e493c7d..6ec2a3b 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -142,8 +142,6 @@ unsigned char m_loop(int fd, t_msh *msh)
gnl = 1;
msh->curr_hist_ptr = hist;
- c_get_msh(1, msh);
- c_set_ptr(TRUE, 0, msh);
while (gnl > 0)
{
gnl = (fd == STDIN_FILENO) ? c_gnl(fd, &line, 1, msh) :