summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSalad <water_appreciator@protonmail.com>2020-10-02 16:55:52 +0200
committerSalad <water_appreciator@protonmail.com>2020-10-02 16:55:52 +0200
commitb6b09fc1fa8e4f70f042cfe48f26b28d798498d3 (patch)
tree22ec864530fc4a0a9e642bdf35c42b2dacc93e95
parentlessgo (diff)
download42-minishell-b6b09fc1fa8e4f70f042cfe48f26b28d798498d3.tar.gz
42-minishell-b6b09fc1fa8e4f70f042cfe48f26b28d798498d3.tar.bz2
42-minishell-b6b09fc1fa8e4f70f042cfe48f26b28d798498d3.tar.xz
42-minishell-b6b09fc1fa8e4f70f042cfe48f26b28d798498d3.tar.zst
42-minishell-b6b09fc1fa8e4f70f042cfe48f26b28d798498d3.zip
almost there : norme + miltiligne
-rw-r--r--src/c_init.c17
-rw-r--r--src/c_init.h3
-rw-r--r--src/c_input.c3
-rw-r--r--src/c_input.h2
-rw-r--r--src/c_utils.c17
-rw-r--r--src/m_loop.c2
-rw-r--r--src/m_loop_next.c11
-rw-r--r--src/psbin0 -> 6854 bytes
8 files changed, 29 insertions, 26 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 7296a2b..66e0541 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -66,9 +66,9 @@ c_read_cap(char *buf,
t_msh *msh)
{
if ((*((unsigned int *)buf)) == LEFT_K)
- return (c_key_left(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
+ return (c_key_left(ft_strlen(line), ft_strlen(msh->ps[tcaps->psx]), tcaps));
else if ((*((unsigned int *)buf)) == RIGHT_K)
- return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
+ return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[tcaps->psx]), tcaps));
else if ((*((unsigned int *)buf)) == HOME_K)
return (c_home_key(tcaps));
else if ((*((unsigned int *)buf)) == END_K)
@@ -81,7 +81,7 @@ c_read_cap(char *buf,
return (0);
}
-char
+static char
*c_process_key(char *buf,
t_caps *tcaps,
t_msh *msh)
@@ -102,17 +102,18 @@ char
tcaps->cpos++;
}
else if ((*((unsigned int *)buf)) == DEL_K)
- c_back_slash(&line, ft_strlen(msh->ps[0]), tcaps);
- else if (buf[0] == '\n')
- return (c_new_line(line, tcaps, msh));
+ c_back_slash(&line, ft_strlen(msh->ps[tcaps->psx]), tcaps);
else
c_read_cap(buf, line, tcaps, msh);
+ if (buf[0] == '\n')
+ return (c_new_line(line, tcaps, msh));
return (NULL);
}
int16_t
c_init_tcaps(int32_t fd,
char **line,
+ uint8_t psx,
t_msh *msh)
{
t_caps tcaps;
@@ -123,9 +124,9 @@ c_init_tcaps(int32_t fd,
if (!tgetent(NULL, term))
return (-1);
c_get_struct(1, &tcaps);
- c_init_line(&tcaps);
+ c_init_line(psx, &tcaps);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
- m_prompt_psx(1, msh);
+ m_prompt_psx(psx, msh);
ft_bzero(nread, 5);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
diff --git a/src/c_init.h b/src/c_init.h
index db448cf..5dd4a13 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -36,9 +36,10 @@ typedef struct s_caps
uint32_t cpos; /*cursor position (column)*/
uint32_t lpos; /*cursor position (line)*/
uint32_t nlines; /*cursor position (line)*/
+ uint8_t psx; /*cursor position (line)*/
} t_caps;
-int16_t c_init_tcaps(int32_t fd, char **line, t_msh *msh);
+int16_t c_init_tcaps(int32_t fd, char **line, uint8_t psx, t_msh *msh);
int16_t c_set_term_raw(uint8_t mode);
#endif
diff --git a/src/c_input.c b/src/c_input.c
index d3360cd..1cc8814 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -22,7 +22,7 @@
#include "m_loop.h"
int16_t
- c_init_line(t_caps *tcaps)
+ c_init_line(uint8_t psx, t_caps *tcaps)
{
if (tcaps)
{
@@ -30,6 +30,7 @@ int16_t
signal(SIGINT, SIG_IGN);
tcaps->cpos = 0;
tcaps->lpos = 0;
+ tcaps->psx = psx - 1;
return (1);
}
else
diff --git a/src/c_input.h b/src/c_input.h
index cc2e969..a586e2f 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -16,7 +16,7 @@
int16_t c_back_slash(char **line, uint32_t plen, t_caps *tcaps);
int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
uint32_t c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps);
-int16_t c_init_line(t_caps *tcaps);
+int16_t c_init_line(uint8_t psx, t_caps *tcaps);
uint16_t c_get_win_size(struct winsize *ws);
#endif
diff --git a/src/c_utils.c b/src/c_utils.c
index 78b923a..8a142cf 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -24,9 +24,7 @@
/*
** TODO:
** delchar MOVE
-** plen opti
** NORME
-** FLECHES UP DOWN
** C-c globul pid
*/
@@ -142,14 +140,13 @@ int16_t
{
uint32_t i;
uint32_t j;
- uint32_t len;
- len = ft_strlen(line);
- tcaps->nlines = c_get_line_num(line, tcaps->cpos, ft_strlen(msh->ps[0]), tcaps);
+ tcaps->nlines = c_get_line_num(line, tcaps->cpos,
+ ft_strlen(msh->ps[tcaps->psx]), tcaps);
j = tcaps->lpos;
i = 0;
tputs(tgetstr("cr", NULL), 1, ft_putchar);
- if (((tcaps->cpos + ft_strlen(msh->ps[0])) % tcaps->ws.ws_col) == 0)
+ if (((tcaps->cpos + ft_strlen(msh->ps[tcaps->psx])) % tcaps->ws.ws_col) == 0)
{
tputs(tgetstr("sf", NULL), 1, ft_putchar);
return (1);
@@ -160,10 +157,10 @@ int16_t
tputs(tgetstr("up", NULL), 1, ft_putchar);
tputs(tgetstr("up", NULL), 1, ft_putchar);
}
- while (i++ < ft_strlen(msh->ps[0]))
+ while (i++ < ft_strlen(msh->ps[tcaps->psx]))
tputs(tgetstr("nd", NULL), 1, ft_putchar);
ft_printf("%s", line);
- if (tcaps->cpos != len)
- return (c_redraw_next(ft_strlen(msh->ps[0]), len, tcaps));
- return (len);
+ return ((tcaps->cpos != ft_strlen(line)) ?
+ c_redraw_next(ft_strlen(msh->ps[tcaps->psx]), ft_strlen(line), tcaps) :
+ ft_strlen(line));
}
diff --git a/src/m_loop.c b/src/m_loop.c
index f1fc80d..3269fe4 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -44,7 +44,7 @@ uint8_t
/* if (fd == STDIN_FILENO) */
/* m_prompt_psx(1, msh); */
/* gnl = get_next_line(fd, &line); */
- gnl = c_init_tcaps(fd, &line, msh);
+ gnl = c_init_tcaps(fd, &line, 1, msh);
if (line[0] != '\0')
{
line = m_check_multi_backslash(fd, line, msh);
diff --git a/src/m_loop_next.c b/src/m_loop_next.c
index 9aa7129..d7d3377 100644
--- a/src/m_loop_next.c
+++ b/src/m_loop_next.c
@@ -16,15 +16,17 @@
#include "m_prompt.h"
#include "s_struct.h"
+#include "c_init.h"
static char
*m_counter_line_backslash(int32_t fd, uint8_t psx, char *line, t_msh *msh)
{
char *counter_line;
- if (fd == STDIN_FILENO)
- m_prompt_psx(psx, msh);
- get_next_line(fd, &counter_line);
+ /* if (fd == STDIN_FILENO) */
+ /* m_prompt_psx(psx, msh); */
+ /* get_next_line(fd, &counter_line); */
+ c_init_tcaps(fd, &counter_line, psx, msh);
if (counter_line[0] != 0)
{
line = ft_nrealloc(line,
@@ -45,7 +47,8 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
- get_next_line(fd, &counter_line);
+ /* get_next_line(fd, &counter_line); */
+ c_init_tcaps(fd, &counter_line, psx, msh);
if (counter_line[0] != 0)
{
line = ft_nrealloc(line,
diff --git a/src/ps b/src/ps
new file mode 100644
index 0000000..d7fb6e3
--- /dev/null
+++ b/src/ps
Binary files differ