summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-10-23 17:40:46 +0200
committersalad <fmoenne-@student.le-101.fr>2020-10-23 17:40:46 +0200
commitabd3bd0b2d2c3869d81706d0266cfc561e4bc925 (patch)
treede58eb28ccb5c7679e2cb38d0d94eee8a2100479 /src
parentmakeshift (diff)
download42-minishell-abd3bd0b2d2c3869d81706d0266cfc561e4bc925.tar.gz
42-minishell-abd3bd0b2d2c3869d81706d0266cfc561e4bc925.tar.bz2
42-minishell-abd3bd0b2d2c3869d81706d0266cfc561e4bc925.tar.xz
42-minishell-abd3bd0b2d2c3869d81706d0266cfc561e4bc925.tar.zst
42-minishell-abd3bd0b2d2c3869d81706d0266cfc561e4bc925.zip
loadsamoney
Diffstat (limited to 'src')
-rw-r--r--src/c_init.c51
-rw-r--r--src/c_init.h5
-rw-r--r--src/c_input.c12
-rw-r--r--src/m_loop.c3
-rw-r--r--src/m_loop_next.c17
5 files changed, 36 insertions, 52 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 844e4a6..7ea11ac 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <term.h>
#include <libft.h>
+#include <signal.h>
#include "c_init.h"
#include "c_input.h"
@@ -22,18 +23,6 @@
#include "s_struct.h"
#include "m_prompt.h"
-static t_caps
- *c_get_struct(int mode, t_caps *src)
-{
- static t_caps *caps;
-
- if (mode == 1)
- {
- caps = src;
- }
- return (caps);
-}
-
int16_t
c_set_term_raw(uint8_t mode)
{
@@ -58,7 +47,21 @@ int16_t
return (1);
}
-int16_t
+static void
+ c_add_char(char **line, char *buf, t_caps *tcaps, t_msh *msh)
+{
+ *line = c_insert_char(*line, buf[0], tcaps);
+ tcaps->cpos++;
+ if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
+ tcaps->ws.ws_col) == 0)
+ {
+ write(1, "\n\r", 2);
+ return ;
+ }
+ c_redraw_line(*line, tcaps, msh);
+}
+
+static int16_t
c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
{
uint32_t plen;
@@ -70,12 +73,12 @@ int16_t
else if (((*((unsigned int *)buf)) == RIGHT_K) ||
((*((unsigned int *)buf)) == CTRL_F))
return (c_key_right(ft_strlen(line), plen, tcaps));
- else if ((*((unsigned int *)buf)) == HOME_K)
+ else if (((*((unsigned int *)buf)) == HOME_K) ||
+ ((*((unsigned int *)buf)) == CTRL_A))
return (c_home_key(plen, tcaps));
- else if ((*((unsigned int *)buf)) == END_K)
+ else if (((*((unsigned int *)buf)) == END_K) ||
+ ((*((unsigned int *)buf)) == CTRL_E))
return (c_end_key(ft_strlen(line), plen, tcaps));
- else if ((*((unsigned int *)buf)) == CTRL_C)
- return (c_ctrl_c(NULL, tcaps, msh));
else if ((*((unsigned int *)buf)) == CTRL_L)
return (c_ctrl_l(line, tcaps, msh));
else
@@ -93,17 +96,7 @@ static char
if (!(line = ft_calloc(1, sizeof(char))))
return (NULL);
if (ft_isprint(buf[0]))
- {
- line = c_insert_char(line, buf[0], tcaps);
- tcaps->cpos++;
- if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
- tcaps->ws.ws_col) == 0)
- {
- write(1, "\n\r", 2);
- return (NULL);
- }
- c_redraw_line(line, tcaps, msh);
- }
+ c_add_char(&line, buf, tcaps, msh);
else if ((*((unsigned int *)buf)) == DEL_K)
{
c_back_slash(&line, ft_strlen(msh->ps[tcaps->psx]), tcaps);
@@ -129,9 +122,9 @@ int16_t
char nread[5];
term = getenv("TERM");
+ signal(SIGINT, SIG_DFL);
if (!tgetent(NULL, term))
return (-1);
- c_get_struct(1, &tcaps);
c_init_line(psx, &tcaps);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
m_prompt_psx(psx, msh);
diff --git a/src/c_init.h b/src/c_init.h
index 9ffd1eb..e723563 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -25,9 +25,12 @@
# define DEL_K 0x7f
# define RET_K 0x0d
-# define CTRL_F 0x06
+# define CTRL_A 0x01
# define CTRL_B 0x02
# define CTRL_C 0x03
+# define CTRL_D 0x04
+# define CTRL_E 0x05
+# define CTRL_F 0x06
# define CTRL_L 0x0c
typedef struct s_caps
diff --git a/src/c_input.c b/src/c_input.c
index e1dce63..d680552 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -66,7 +66,7 @@ uint32_t
while (it < len)
{
it += (it == 0) ? (tcaps->ws.ws_col - plen) : tcaps->ws.ws_col;
- tcaps->lpos += (it < (cpos)) ? 1 : 0;
+ tcaps->lpos += (it < cpos) ? 1 : 0;
line_num++;
}
return (line_num);
@@ -83,13 +83,3 @@ int16_t
}
return (1);
}
-
-int16_t
- c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh)
-{
- (void)tcaps;
- (void)line;
- msh->ret = 130;
- c_new_line(NULL, tcaps);
- return (1);
-}
diff --git a/src/m_loop.c b/src/m_loop.c
index 6bba915..89b06b9 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -41,9 +41,6 @@ uint8_t
gnl = 1;
while (gnl > 0)
{
- /* if (fd == STDIN_FILENO) */
- /* m_prompt_psx(1, msh); */
- /* gnl = get_next_line(fd, &line); */
gnl = c_gnl(fd, &line, 1, msh);
if (line[0] != '\0')
{
diff --git a/src/m_loop_next.c b/src/m_loop_next.c
index 90ffc01..6c0888f 100644
--- a/src/m_loop_next.c
+++ b/src/m_loop_next.c
@@ -24,12 +24,15 @@ static char
char *counter_line;
c_gnl(fd, &counter_line, psx, msh);
- line = ft_nrealloc(line,
- ft_strlen(line) + 1,
- ft_strlen(line) + ft_strlen(counter_line));
- ft_memcpy(line + ft_strlen(line) - 1,
- counter_line,
- ft_strlen(counter_line) + 1);
+ if (counter_line[0] != 0)
+ {
+ line = ft_nrealloc(line,
+ ft_strlen(line) + 1,
+ ft_strlen(line) + ft_strlen(counter_line));
+ ft_memcpy(line + ft_strlen(line) - 1,
+ counter_line,
+ ft_strlen(counter_line) + 1);
+ }
ft_memdel((void*)&counter_line);
return (line);
}
@@ -39,8 +42,6 @@ static char
{
char *counter_line;
- if (fd == STDIN_FILENO)
- m_prompt_psx(psx, msh);
c_gnl(fd, &counter_line, psx, msh);
if (counter_line[0] != 0)
{