summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-29 14:15:27 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-29 14:15:27 +0200
commit8625b18bc68a149014edd059cdeb831716fc3d86 (patch)
treeb30eb584e3cb888caa1f17f3bfa9583233617d8d /src/c_init.c
parentTHI S IS THE END (diff)
download42-minishell-8625b18bc68a149014edd059cdeb831716fc3d86.tar.gz
42-minishell-8625b18bc68a149014edd059cdeb831716fc3d86.tar.bz2
42-minishell-8625b18bc68a149014edd059cdeb831716fc3d86.tar.xz
42-minishell-8625b18bc68a149014edd059cdeb831716fc3d86.tar.zst
42-minishell-8625b18bc68a149014edd059cdeb831716fc3d86.zip
pouche yeah yeay yeah
Diffstat (limited to '')
-rw-r--r--src/c_init.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 16f6cba..50c974b 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -61,6 +61,28 @@ int16_t
}
int16_t
+c_read_cap(char *buf,
+ char *line,
+ t_caps *tcaps,
+ t_msh *msh)
+{
+ if ((*((unsigned int *)buf)) == LEFT_K)
+ return (c_key_left(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
+ else if ((*((unsigned int *)buf)) == RIGHT_K)
+ return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
+ else if ((*((unsigned int *)buf)) == HOME_K)
+ return (c_home_key(tcaps));
+ else if ((*((unsigned int *)buf)) == END_K)
+ return (c_end_key(ft_strlen(line), 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
+ return (0);
+}
+
+int16_t
c_process_key(char *buf,
t_caps *tcaps,
t_msh *msh)
@@ -70,44 +92,27 @@ int16_t
i = -1;
if (line == NULL)
- {
if (!(line = ft_calloc(1, sizeof(char))))
return (-1);
- }
if (ft_isprint(buf[0]))
{
line = c_insert_char(line, buf[0], tcaps);
c_redraw_line(line, tcaps, msh);
tcaps->cpos++;
}
- else
+ else if ((*((unsigned int *)buf)) == DEL_K)
{
- if (ft_strncmp(buf, tcaps->KL, 4) == 0)
- return (c_key_left(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
- else if (ft_strncmp(buf, tcaps->KR, 4) == 0)
- return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
- else if (ft_strncmp(buf, tcaps->HM, 4) == 0)
- return (c_home_key(tcaps));
- else if (ft_strncmp(buf, tcaps->ND, 4) == 0)
- return (c_end_key(ft_strlen(line), tcaps));
- 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 (ft_strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
- {
- c_back_slash(&line, ft_strlen(msh->ps[0]), tcaps);
- return (1);
- }
- else if (buf[0] == '\n')
- {
- c_new_line(ft_strdup(line), msh, tcaps);
- ft_memdel((void**)&line);
- return (1);
- }
- else
- return (0);
+ c_back_slash(&line, ft_strlen(msh->ps[0]), tcaps);
+ return (1);
}
+ else if (buf[0] == '\n')
+ {
+ c_new_line(ft_strdup(line), msh, tcaps);
+ ft_memdel((void**)&line);
+ return (1);
+ }
+ else
+ return (c_read_cap(buf, line, tcaps, msh));
return (0);
}
@@ -122,11 +127,9 @@ int16_t
term = getenv("TERM");
if (!tgetent(NULL, term))
return (-1);
- tcaps.cpos = 0;
- tcaps.lpos = 0;
c_set_term_raw(1);
c_get_struct(1, &tcaps);
- c_init_keys(&tcaps);
+ c_init_line(&tcaps);
m_prompt_psx(1, msh);
signal(SIGINT, SIG_IGN);
if (!(c_get_win_size(&tcaps.ws)))