diff options
Diffstat (limited to 'src/c_init.c')
-rw-r--r-- | src/c_init.c | 74 |
1 files changed, 21 insertions, 53 deletions
diff --git a/src/c_init.c b/src/c_init.c index 1d2f588..4e74d87 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -11,12 +11,12 @@ /* ************************************************************************** */ #include <unistd.h> -#include <stdlib.h> #include <libft.h> #include <signal.h> #include <string.h> #include <term.h> +#include "b_exit.h" #include "c_ctrls.h" #include "c_init.h" #include "c_keys.h" @@ -24,14 +24,10 @@ #include "c_input.h" #include "c_utils.h" #include "d_define.h" -#include "b_exit.h" +#include "m_prompt.h" #include "s_struct.h" #include "s_com.h" #include "s_line.h" -#include "s_destroy.h" -#include "m_prompt.h" -#include "m_loop.h" -#include "u_utils.h" short c_set_term_raw(char mode) @@ -57,25 +53,9 @@ short return (1); } -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) + tcaps->plen) % - tcaps->ws.ws_col) == 0) - { - write(STDOUT_FILENO, "\n\r", 2); - return ; - } - c_redraw_line(*line, tcaps, msh); -} - static short c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh) { - int tmp; - if (((*((unsigned int *)buf)) == LEFT_K) || ((*((unsigned int *)buf)) == CTRL_B)) return (c_key_left(tcaps->plen, tcaps)); @@ -92,18 +72,8 @@ static short return (c_ctrl_l(line, tcaps, msh)); else if ((*((unsigned int *)buf)) == CTRL_D && line[0] == '\0') - { - c_set_term_raw(0); - write(STDERR_FILENO, "exit\n", 5); - u_eof_fd(msh->fd); - m_dump_hist(msh->curr_hist_ptr, msh); - tmp = msh->ret; - s_destroy(msh); - exit(tmp); - return (0); - } - else - return (0); + return (c_ctrl_d(msh)); + return (0); } char *ft_strrbavchr(const char *s, int c, size_t start) @@ -159,48 +129,45 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh) return (p); } +/* TODO : key_up_down should manage and set the correct key */ + static char - *c_process_key(char *buf, t_caps *tcaps, t_msh *msh) + *c_process_key(char **line, char *buf, t_caps *tcaps, t_msh *msh) { - static char *line = NULL; - int i; char *ptr; - i = -1; - if (line == NULL) - if (!(line = ft_calloc(1, sizeof(char)))) + if (*line == NULL) + if (!(*line = ft_calloc(1, sizeof(char)))) return (NULL); if (ft_isprint(buf[0])) - c_add_char(&line, buf, tcaps, msh); + c_add_char(line, buf, tcaps); else if (((*((unsigned int *)buf)) == UP_K) || ((*((unsigned int *)buf)) == CTRL_P)) { ptr = c_set_ptr(FALSE, -1, msh); - c_key_up_down(&line, tcaps, ptr); - c_redraw_line(line, tcaps, msh); + c_key_up_down(line, tcaps, ptr); + c_redraw_line(*line, tcaps); } else if (((*((unsigned int *)buf)) == DOWN_K) || ((*((unsigned int *)buf)) == CTRL_N)) { ptr = c_set_ptr(FALSE, 1, msh); - c_key_up_down(&line, tcaps, ptr); - c_redraw_line(line, tcaps, msh); + c_key_up_down(line, tcaps, ptr); + c_redraw_line(*line, tcaps); } else if ((*((unsigned int *)buf)) == DEL_K) { - c_back_slash(&line, tcaps->plen, tcaps); + c_back_slash(line, tcaps->plen, tcaps); if ((((tcaps->cpos) + tcaps->plen) % tcaps->ws.ws_col) == 0) - { return (NULL); - } - c_redraw_line(line, tcaps, msh); + c_redraw_line(*line, tcaps); } else if ((*((unsigned int *)buf)) == CTRL_C) - return (c_ctrl_c(&line, buf, msh)); + return (c_ctrl_c(line, buf, msh)); else - c_read_cap(buf, line, tcaps, msh); - return ((buf[0] == '\n') ? c_new_line(line, tcaps) : NULL); + c_read_cap(buf, *line, tcaps, msh); + return ((buf[0] == '\n') ? c_new_line(tcaps) : NULL); } short @@ -215,6 +182,7 @@ short ft_bzero(nread, 4); msh->sig = 0; tcaps.plen = (unsigned int)m_plen(msh->ps[psx - 1]); + *line = NULL; if (!(c_get_win_size(&tcaps.ws))) return (-1); while (!(ft_strchr(nread, '\n'))) @@ -223,7 +191,7 @@ short if (!(read(fd, nread, 3))) return (0); else - *line = c_process_key(nread, &tcaps, msh); + c_process_key(line, nread, &tcaps, msh); tputs(tgetstr("ve", NULL), 1, ft_putchar); } return (1); |