diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-08 18:31:51 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-08 18:31:51 +0200 |
commit | d0038f19a7cb23749588b72c9febcf114d9d31e9 (patch) | |
tree | e7daa5c0058d7d293d1d93fe9068d5ad59afcabe /src/m_loop.c | |
parent | In progress (diff) | |
download | 42-minishell-d0038f19a7cb23749588b72c9febcf114d9d31e9.tar.gz 42-minishell-d0038f19a7cb23749588b72c9febcf114d9d31e9.tar.bz2 42-minishell-d0038f19a7cb23749588b72c9febcf114d9d31e9.tar.xz 42-minishell-d0038f19a7cb23749588b72c9febcf114d9d31e9.tar.zst 42-minishell-d0038f19a7cb23749588b72c9febcf114d9d31e9.zip |
static hist, words fix
Diffstat (limited to 'src/m_loop.c')
-rw-r--r-- | src/m_loop.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/m_loop.c b/src/m_loop.c index 0a810a0..7dc19e0 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -35,12 +35,12 @@ static void } void - m_dump_hist(t_msh *msh) + m_dump_hist(char hist[], t_msh *msh) { - int32_t fd; char histfile[PATH_MAX]; + int32_t fd; - if (msh->hist[0] != C_NUL && ft_strlen(msh->hist) > 0) + if (hist[0] != C_NUL && ft_strlen(hist) > 0) { u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh); if (histfile[0] != C_NUL) @@ -48,7 +48,7 @@ void if ((fd = open(histfile, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) { - ft_dprintf(fd, "%s", msh->hist); + ft_dprintf(fd, "%s", hist); close(fd); } } @@ -56,19 +56,19 @@ void } static void - m_handle_hist(char line[], t_msh *msh) + m_handle_hist(char hist[], char line[], t_msh *msh) { static uint16_t hist_i = 0; if (hist_i == 0) - msh->hist[0] = '\0'; - ft_strlcpy(msh->hist + ft_strlen(msh->hist), line, 4096); - msh->hist[ft_strlen(msh->hist) + 1] = '\0'; - msh->hist[ft_strlen(msh->hist)] = '\n'; + hist[0] = '\0'; + ft_strlcpy(hist + ft_strlen(hist), line, 4096); + hist[ft_strlen(hist) + 1] = '\0'; + hist[ft_strlen(hist)] = '\n'; hist_i += 1; - if (hist_i == 255) + if (hist_i == 254) { - m_dump_hist(msh); + m_dump_hist(hist, msh); hist_i = 0; } } @@ -76,8 +76,9 @@ static void uint8_t m_loop(int32_t fd, t_msh *msh) { - char *line; - int8_t gnl; + static char hist[255 * 4096]; + char *line; + int8_t gnl; msh->fd = fd; gnl = 1; @@ -93,7 +94,7 @@ uint8_t line = m_check_multi_and(fd, line, msh); line = m_check_multi_quotes(fd, line, msh); if (fd == STDIN_FILENO) - m_handle_hist(line, msh); + m_handle_hist(hist, line, msh); m_parse_and_run_line(line, msh); /* TODO: (null): Bad address on "msh ~> echo a > asd; cat < asd" but not on "msh ~> echo a > asd; cat asd" */ } @@ -101,6 +102,6 @@ uint8_t ft_memdel((void*)&line); } if (fd == STDIN_FILENO) - m_dump_hist(msh); + m_dump_hist(hist, msh); return (msh->ret); } |