summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--src/c_init.c34
-rw-r--r--src/c_init.h14
-rw-r--r--src/c_input.c109
-rw-r--r--src/c_input.h5
-rw-r--r--src/c_keys.c84
-rw-r--r--src/c_keys.h22
-rw-r--r--src/c_utils.c35
8 files changed, 156 insertions, 148 deletions
diff --git a/Makefile b/Makefile
index b715579..0627f02 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ SRCS_NAME += b_type
SRCS_NAME += b_unset
SRCS_NAME += c_init
SRCS_NAME += c_input
+SRCS_NAME += c_keys
SRCS_NAME += c_utils
SRCS_NAME += e_builtins
SRCS_NAME += e_externs
diff --git a/src/c_init.c b/src/c_init.c
index ac0c579..8870b27 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -11,15 +11,13 @@
/* ************************************************************************** */
#include <unistd.h>
-#include <termios.h>
#include <stdlib.h>
-#include <string.h>
#include <term.h>
-#include <signal.h>
#include <libft.h>
#include "c_init.h"
#include "c_input.h"
+#include "c_keys.h"
#include "c_utils.h"
#include "s_struct.h"
#include "m_prompt.h"
@@ -83,34 +81,20 @@ int16_t
}
else
{
- if (strncmp(buf, tcaps->KL, 4) == 0)
- {
+ if (ft_strncmp(buf, tcaps->KL, 4) == 0)
return (c_key_left(ft_strlen(line), tcaps));
- }
- else if (strncmp(buf, tcaps->KR, 4) == 0)
- {
+ else if (ft_strncmp(buf, tcaps->KR, 4) == 0)
return (c_key_right(ft_strlen(line), tcaps));
- }
- else if (strncmp(buf, tcaps->HM, 4) == 0)
- {
+ else if (ft_strncmp(buf, tcaps->HM, 4) == 0)
return (c_home_key(tcaps));
- }
- else if (strncmp(buf, tcaps->ND, 4) == 0)
- {
+ else if (ft_strncmp(buf, tcaps->ND, 4) == 0)
return (c_end_key(ft_strlen(line), tcaps));
- }
- else if (strncmp(buf, tcaps->CC, 4) == 0)
- {
- return (c_new_line(NULL, msh, tcaps));
- }
- else if (strncmp(buf, tcaps->CL, 4) == 0)
- {
+ else if (ft_strncmp(buf, tcaps->CC, 4) == 0)
+ return (c_ctrl_c(NULL, tcaps, msh));
+ else if (ft_strncmp(buf, tcaps->CL, 4) == 0)
return (c_ctrl_l(line, tcaps, msh));
- }
- else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
- {
+ else if (ft_strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
return (c_back_slash(&line, tcaps));
- }
else if (buf[0] == '\n')
{
c_new_line(ft_strdup(line), msh, tcaps);
diff --git a/src/c_init.h b/src/c_init.h
index 64603a5..2f93a00 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* u_init.h :+: :+: :+: */
+/* c_init.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -47,15 +47,3 @@ int16_t c_init_tcaps(t_msh *msh);
int16_t c_set_term_raw(uint8_t mode);
#endif
-
- /* tcaps.cl = tgetstr("cl", &term); */
- /* tcaps.ks = tgetstr("ks", &term); */
- /* tcaps.kl = tgetstr("kl", &term); */
- /* tcaps.ke = tgetstr("ke", &term); */
- /* tcaps.kr = tgetstr("kr", &term); */
- /* tcaps.pc = tgetstr("pc", &term); */
- /* tcaps.bc = tgetstr("bc", &term); */
- /* tcaps.up = tgetstr("up", &term); */
- /* tcaps.nd = tgetstr("nd", &term); */
- /* tcaps.le = tgetstr("le", &term); */
- /* tcaps.DO = tgetstr("do", &term); */
diff --git a/src/c_input.c b/src/c_input.c
index 478c29e..5e9db72 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <libft.h>
-#include <unistd.h>
#include <term.h>
#include "c_init.h"
@@ -21,6 +20,41 @@
#include "m_loop.h"
int16_t
+ c_init_keys(t_caps *tcaps)
+{
+ if (tcaps)
+ {
+ tcaps->KL[0] = 27;
+ tcaps->KL[1] = 91;
+ tcaps->KL[2] = 68;
+ tcaps->KL[3] = 0;
+ tcaps->KR[0] = 27;
+ tcaps->KR[1] = 91;
+ tcaps->KR[2] = 67;
+ tcaps->KR[3] = 0;
+ tcaps->CL[0] = 12;
+ 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] = -103;
+ tcaps->ND[3] = 0;
+ return (1);
+ }
+ else
+ return (-1);
+}
+
+int16_t
c_back_slash(char **line,
t_caps *tcaps)
{
@@ -35,78 +69,13 @@ int16_t
}
int16_t
- c_ctrl_l(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, msh);
- return (1);
-}
-
-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, msh);
- return (1);
-}
-
-int16_t
- c_home_key(t_caps *tcaps)
-{
- uint16_t i;
-
- i = tcaps->cpos;
- while (i > 0)
- {
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- i--;
- }
- tcaps->cpos = 0;
- return (1);
-}
-
-int16_t
- c_end_key(uint16_t size, t_caps *tcaps)
-{
- uint16_t i;
-
- i = tcaps->cpos;
- while (i < size)
- {
- tputs(tgetstr("nd", NULL), 1, ft_putchar);
- i++;
- }
- tcaps->cpos = size;
- return (1);
-}
-
-int16_t
- c_key_right(uint32_t len,
- t_caps *tcaps)
-{
- if (tcaps->cpos < len)
- {
- tputs(tgetstr("nd", NULL), 1, ft_putchar);
- tcaps->cpos++;
- }
- return (1);
-}
-
-int16_t
- c_key_left(uint32_t len,
- t_caps *tcaps)
-{
- (void)len;
- if (tcaps->cpos >= 1)
- {
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- tcaps->cpos--;
- }
+ (void)tcaps;
+ (void)line;
+ msh->ret = 130;
+ c_new_line(NULL, msh, tcaps);
return (1);
}
diff --git a/src/c_input.h b/src/c_input.h
index ec833d7..e621061 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -13,12 +13,7 @@
#ifndef C_INPUT_H
#define C_INPUT_H
-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_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);
#endif
diff --git a/src/c_keys.c b/src/c_keys.c
new file mode 100644
index 0000000..d388d60
--- /dev/null
+++ b/src/c_keys.c
@@ -0,0 +1,84 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* c_keys.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <term.h>
+#include <libft.h>
+
+#include "c_init.h"
+#include "c_utils.h"
+#include "m_prompt.h"
+
+int16_t
+ c_ctrl_l(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, msh);
+ return (1);
+}
+
+int16_t
+ c_home_key(t_caps *tcaps)
+{
+ uint16_t i;
+
+ i = tcaps->cpos;
+ while (i > 0)
+ {
+ tputs(tgetstr("le", NULL), 1, ft_putchar);
+ i--;
+ }
+ tcaps->cpos = 0;
+ return (1);
+}
+
+int16_t
+ c_end_key(uint16_t size, t_caps *tcaps)
+{
+ uint16_t i;
+
+ i = tcaps->cpos;
+ while (i < size)
+ {
+ tputs(tgetstr("nd", NULL), 1, ft_putchar);
+ i++;
+ }
+ tcaps->cpos = size;
+ return (1);
+}
+
+int16_t
+ c_key_right(uint32_t len,
+ t_caps *tcaps)
+{
+ if (tcaps->cpos < len)
+ {
+ tputs(tgetstr("nd", NULL), 1, ft_putchar);
+ tcaps->cpos++;
+ }
+ return (1);
+}
+
+int16_t
+ c_key_left(uint32_t len,
+ t_caps *tcaps)
+{
+ (void)len;
+ if (tcaps->cpos >= 1)
+ {
+ tputs(tgetstr("le", NULL), 1, ft_putchar);
+ tcaps->cpos--;
+ }
+ return (1);
+}
diff --git a/src/c_keys.h b/src/c_keys.h
new file mode 100644
index 0000000..e492499
--- /dev/null
+++ b/src/c_keys.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* c_keys.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef C_KEYS_H
+#define C_KEYS_H
+
+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_home_key(t_caps *tcaps);
+int16_t c_end_key(uint16_t size, t_caps *tcaps);
+int16_t c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
+
+#endif
diff --git a/src/c_utils.c b/src/c_utils.c
index 35c95ef..1890192 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -31,41 +31,6 @@
** leaks on line ??? GONE ?
*/
-int16_t
- c_init_keys(t_caps *tcaps)
-{
- if (tcaps)
- {
- tcaps->KL[0] = 27;
- tcaps->KL[1] = 91;
- tcaps->KL[2] = 68;
- tcaps->KL[3] = 0;
- tcaps->KR[0] = 27;
- tcaps->KR[1] = 91;
- tcaps->KR[2] = 67;
- tcaps->KR[3] = 0;
- tcaps->CL[0] = 12;
- 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] = -103;
- tcaps->ND[3] = 0;
- return (1);
- }
- else
- return (-1);
-}
-
uint16_t
c_get_win_size(struct winsize *ws)
{