summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO.org2
-rw-r--r--src/m_loop.c31
-rw-r--r--src/p_args.c5
-rw-r--r--src/p_args_next.c5
-rw-r--r--src/p_line.c8
-rw-r--r--src/s_init.c1
-rw-r--r--src/s_struct.h1
7 files changed, 28 insertions, 25 deletions
diff --git a/TODO.org b/TODO.org
index c19ad6c..4746863 100644
--- a/TODO.org
+++ b/TODO.org
@@ -21,7 +21,7 @@
** TODO [#C] Handle memory
** TODO [#C] Go full stack to ken dash in the ass
** TODO [#C] Handle comments better #
-** TODO [#C] msh ~> ./qwe.sh <---- without shebang (maybe works find already)
+** TODO [#C] msh ~> ./qwe.sh <---- without shebang (maybe works fine already)
* Stuff to add
** DONE [#A] builtins to pipes
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);
}
diff --git a/src/p_args.c b/src/p_args.c
index 383700f..78cfc06 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -116,9 +116,10 @@ static uint16_t
if (ft_iswhitespace(*ptr) &&
p_meet_whitespace((char*)word, ptr, mode) == TRUE)
{
- count += 1;
ptr = p_skip_whitespace(ptr);
- start[count - 1] = (ptr - word);
+ start[count] = (ptr - word);
+ if (*ptr != C_NUL)
+ count += 1;
ptr -= 1;
}
ptr++;
diff --git a/src/p_args_next.c b/src/p_args_next.c
index 77f8ced..6fd6b08 100644
--- a/src/p_args_next.c
+++ b/src/p_args_next.c
@@ -25,8 +25,8 @@ static char
{
tmp[0] = '\0';
ft_strlcpy(tmp,
- word + start[i],
- (p_arg_len(word, start[i]) - start[i]) + 1);
+ word + start[i],
+ (p_arg_len(word, start[i]) - start[i]) + 1);
return (tmp);
}
@@ -63,4 +63,3 @@ uint16_t
}
return (i);
}
-
diff --git a/src/p_line.c b/src/p_line.c
index 9c96610..170d8a8 100644
--- a/src/p_line.c
+++ b/src/p_line.c
@@ -19,6 +19,7 @@
#include "p_lcom.h"
#include "s_destroy.h"
#include "s_struct.h"
+#include "u_utils.h"
static void
p_delete_comments(char line[])
@@ -30,8 +31,11 @@ static void
{
if (*ptr == '#')
{
- *ptr = '\0';
- return ;
+ if ((ptr - line) == 0 || ft_iswhitespace(*(ptr - 1)) == TRUE)
+ {
+ *ptr = '\0';
+ return ;
+ }
}
ptr++;
}
diff --git a/src/s_init.c b/src/s_init.c
index 55f9cf0..9ef856f 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -175,7 +175,6 @@ t_msh
init_buptr(msh);
msh->curr = NULL;
msh->vars = NULL;
- msh->hist[0] = '\0';
set_cwd(cwd, msh);
if ((msh->cwd = ft_strdup(cwd)) == NULL)
return (NULL);
diff --git a/src/s_struct.h b/src/s_struct.h
index a1d1828..1089dc6 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -74,7 +74,6 @@ typedef struct s_msh
char ps[4][1024];
char env_fork_tmp[128][1024];
char sqb_ref[FT_ID_SQB_COUNT][4];
- char hist[1037595];
char *shname;
char *cwd;
int32_t fd;