summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-11 16:01:55 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-11 16:01:55 +0200
commit5c8ded7ac978cde22cba31d1d03086f9a60a101b (patch)
tree0f75f3f47c2c43fed7b1fd24b1d78a435310ec85
parenthome works, not END. lets go for a bit of norming (diff)
download42-minishell-5c8ded7ac978cde22cba31d1d03086f9a60a101b.tar.gz
42-minishell-5c8ded7ac978cde22cba31d1d03086f9a60a101b.tar.bz2
42-minishell-5c8ded7ac978cde22cba31d1d03086f9a60a101b.tar.xz
42-minishell-5c8ded7ac978cde22cba31d1d03086f9a60a101b.tar.zst
42-minishell-5c8ded7ac978cde22cba31d1d03086f9a60a101b.zip
grep TODO c_utils.c
-rw-r--r--src/c_init.c38
-rw-r--r--src/c_init.h1
-rw-r--r--src/c_input.c30
-rw-r--r--src/c_input.h2
-rw-r--r--src/c_utils.c33
-rw-r--r--src/c_utils.h1
6 files changed, 50 insertions, 55 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 3829a78..ee6782d 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -24,31 +24,6 @@
#include "s_struct.h"
#include "m_prompt.h"
-static char
- *ft_strjoin_m(char *s1,
- char *s2)
-{
- size_t i;
- size_t j;
- char *dst;
- size_t size1;
- size_t size2;
-
- i = -1;
- j = -1;
- size1 = ft_strlen(s1);
- size2 = ft_strlen(s2);
- if (!(dst = (char*)malloc((size1 + size2 + 1) * sizeof(char))))
- return (NULL);
- while (++i < size1)
- dst[i] = s1[i];
- while (++j < size2)
- dst[i + j] = s2[j];
- dst[i + j] = '\0';
- ft_memdel((void*)&s1);
- return (dst);
-}
-
static t_caps
*c_get_struct(int mode,
t_caps *src)
@@ -86,8 +61,6 @@ int16_t
return (1);
}
-/* c_insert_char */
-
int16_t
c_process_key(char *buf,
t_caps *tcaps,
@@ -103,7 +76,7 @@ int16_t
if (ft_isprint(buf[0]))
{
if (tcaps->cpos == ft_strlen(line))
- line = ft_strjoin_m(line, buf);
+ line = ft_strjoin(line, buf);
else
line = c_insert_char(line, buf[0], tcaps);
c_redraw_line(line, tcaps->cpos, msh);
@@ -123,6 +96,10 @@ int16_t
{
return (c_ctrl_l(line, tcaps, msh));
}
+ else if (strncmp(buf, tcaps->CC, 4) == 0)
+ {
+ return (c_new_line(buf, NULL, msh, tcaps));
+ }
else if (strncmp(buf, tcaps->HM, 4) == 0)
{
return (c_home_key(tcaps));
@@ -147,14 +124,12 @@ int16_t
c_init_tcaps(t_msh *msh)
{
t_caps tcaps;
- char *bp;
char *term;
char nread[5];
int ret;
- bp = NULL;
term = getenv("TERM");
- if (!tgetent(bp, term))
+ if (!tgetent(NULL, term))
return (-1);
tcaps.cpos = 0;
c_set_term_raw(1);
@@ -168,7 +143,6 @@ int16_t
ft_bzero(nread, 5);
if (!(read(STDIN_FILENO, nread, 4)))
return (0);
- tputs(tgetstr("vi", NULL), 1, ft_putchar);
ret = c_process_key(nread, &tcaps, msh);
tputs(tgetstr("ve", NULL), 1, ft_putchar);
}
diff --git a/src/c_init.h b/src/c_init.h
index af3756c..64603a5 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -23,6 +23,7 @@ typedef struct s_caps
char KL[4];
char KR[4];
char CL[4];
+ char CC[4];
char HM[4];
char ND[4];
struct termios tios;
diff --git a/src/c_input.c b/src/c_input.c
index 2435e4a..ed60ae4 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -22,24 +22,6 @@
int16_t
- c_new_line(char *buf,
- char **line,
- t_msh *msh,
- t_caps *tcaps)
-{
- write(1, buf, ft_strlen(buf));
- tputs(tgetstr("cr", NULL), 1, ft_putchar);
- c_set_term_raw(0);
- m_parse_and_run_line(*line, msh);
- *line = NULL;
- tcaps->cpos = 0;
- tputs(tgetstr("cr", NULL), 1, ft_putchar);
- c_set_term_raw(1);
- m_prompt_psx(1, msh);
- return (1);
-}
-
-int16_t
c_back_slash(char **line,
t_caps *tcaps)
{
@@ -65,6 +47,17 @@ int16_t
}
int16_t
+ c_ctrl_c(char *line,
+ t_caps *tcaps,
+ t_msh *msh)
+{
+ tputs(tgetstr("cl", NULL), 1, ft_putchar);
+ m_prompt_psx(1, msh);
+ c_redraw_line(line, tcaps->cpos, msh);
+ return (1);
+}
+
+int16_t
c_home_key(t_caps *tcaps)
{
uint16_t i;
@@ -94,7 +87,6 @@ int16_t
return (1);
}
-
int16_t
c_key_right(uint32_t len,
t_caps *tcaps)
diff --git a/src/c_input.h b/src/c_input.h
index be26a79..ec833d7 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -15,9 +15,9 @@
int16_t c_key_right(uint32_t len, t_caps *tcaps);
int16_t c_key_left(uint32_t len, t_caps *tcaps);
-int16_t c_new_line(char *buf, char **line, t_msh *msh, t_caps *tcaps);
int16_t c_back_slash(char **line, t_caps *tcaps);
int16_t c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
+int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
int16_t c_home_key(t_caps *tcaps);
int16_t c_end_key(uint16_t size, t_caps *tcaps);
diff --git a/src/c_utils.c b/src/c_utils.c
index 2b2f8e4..d5a45e0 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -24,10 +24,12 @@
/*
** TODO:
-** term(0) on exit
-** cursor on char insert DONE
** quotes
** leaks
+** C-c
+** tests varies
+** term(0) on exit DONE
+** cursor on char insert DONE
*/
int16_t
@@ -47,13 +49,17 @@ int16_t
tcaps->CL[1] = 0;
tcaps->CL[2] = 0;
tcaps->CL[3] = 0;
+ tcaps->CC[0] = 3;
+ tcaps->CC[1] = 0;
+ tcaps->CC[2] = 0;
+ tcaps->CC[3] = 0;
tcaps->HM[0] = 27;
tcaps->HM[1] = 91;
tcaps->HM[2] = 72;
tcaps->HM[3] = 0;
tcaps->ND[0] = 27;
tcaps->ND[1] = 91;
- tcaps->ND[2] = 70;
+ tcaps->ND[2] = -103;
tcaps->ND[3] = 0;
return (1);
}
@@ -74,6 +80,27 @@ uint16_t
return (1);
}
+int16_t
+ c_new_line(char *buf,
+ char **line,
+ t_msh *msh,
+ t_caps *tcaps)
+{
+ write(1, buf, ft_strlen(buf));
+ tputs(tgetstr("cr", NULL), 1, ft_putchar);
+ c_set_term_raw(0);
+ if (line != NULL)
+ {
+ m_parse_and_run_line(*line, msh);
+ *line = NULL;
+ }
+ tcaps->cpos = 0;
+ tputs(tgetstr("cr", NULL), 1, ft_putchar);
+ c_set_term_raw(1);
+ m_prompt_psx(1, msh);
+ return (1);
+}
+
char
*c_insert_char(char *str,
char c,
diff --git a/src/c_utils.h b/src/c_utils.h
index fc9a700..e915365 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -21,5 +21,6 @@ uint16_t c_get_win_size(struct winsize *ws);
int32_t c_catch_tcaps(char *buf, char **line, t_caps *tcaps, t_msh *msh);
char *c_insert_char(char *str, char c, t_caps *tcaps);
int16_t c_init_keys(t_caps *tcaps);
+int16_t c_new_line(char *buf, char **line, t_msh *msh, t_caps *tcaps);
#endif