diff options
author | Salad <water_appreciator@protonmail.com> | 2020-09-29 23:09:43 +0200 |
---|---|---|
committer | Salad <water_appreciator@protonmail.com> | 2020-09-29 23:09:43 +0200 |
commit | 894e9e2177c3fcf12010b0c0a8ee9e27c684dc00 (patch) | |
tree | 25d02c41f83c8b271f7411c225801544d76d7440 | |
parent | pouche yeah yeay yeah (diff) | |
download | 42-minishell-894e9e2177c3fcf12010b0c0a8ee9e27c684dc00.tar.gz 42-minishell-894e9e2177c3fcf12010b0c0a8ee9e27c684dc00.tar.bz2 42-minishell-894e9e2177c3fcf12010b0c0a8ee9e27c684dc00.tar.xz 42-minishell-894e9e2177c3fcf12010b0c0a8ee9e27c684dc00.tar.zst 42-minishell-894e9e2177c3fcf12010b0c0a8ee9e27c684dc00.zip |
gnl grand remplacment
-rw-r--r-- | src/c_init.c | 33 | ||||
-rw-r--r-- | src/c_init.h | 2 | ||||
-rw-r--r-- | src/m_loop.c | 8 |
3 files changed, 23 insertions, 20 deletions
diff --git a/src/c_init.c b/src/c_init.c index 50c974b..d78a8f2 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -82,8 +82,8 @@ c_read_cap(char *buf, return (0); } -int16_t - c_process_key(char *buf, +char + *c_process_key(char *buf, t_caps *tcaps, t_msh *msh) { @@ -93,7 +93,7 @@ int16_t i = -1; if (line == NULL) if (!(line = ft_calloc(1, sizeof(char)))) - return (-1); + return (NULL); if (ft_isprint(buf[0])) { line = c_insert_char(line, buf[0], tcaps); @@ -103,26 +103,21 @@ int16_t else if ((*((unsigned int *)buf)) == DEL_K) { c_back_slash(&line, ft_strlen(msh->ps[0]), tcaps); - return (1); } - else if (buf[0] == '\n') + else { - c_new_line(ft_strdup(line), msh, tcaps); - ft_memdel((void**)&line); - return (1); + c_read_cap(buf, line, tcaps, msh); } - else - return (c_read_cap(buf, line, tcaps, msh)); - return (0); + return (ft_strdup(line)); } int16_t - c_init_tcaps(t_msh *msh) + c_init_tcaps(char **line, + t_msh *msh) { t_caps tcaps; char *term; char nread[5]; - int ret; term = getenv("TERM"); if (!tgetent(NULL, term)) @@ -130,16 +125,24 @@ int16_t c_set_term_raw(1); c_get_struct(1, &tcaps); c_init_line(&tcaps); + tputs(tgetstr("cr", NULL), 1, ft_putchar); m_prompt_psx(1, msh); signal(SIGINT, SIG_IGN); + ft_bzero(nread, 5); if (!(c_get_win_size(&tcaps.ws))) return (-1); - while (1) + while (!(ft_strchr(nread, '\n'))) { ft_bzero(nread, 5); if (!(read(STDIN_FILENO, nread, 4))) return (0); - ret = c_process_key(nread, &tcaps, msh); + else + *line = c_process_key(nread, &tcaps, msh); + if (*line == NULL) + { + ft_printf("FUCK"); + return (0); + } tputs(tgetstr("ve", NULL), 1, ft_putchar); } return (1); diff --git a/src/c_init.h b/src/c_init.h index d5f2c89..1614b5e 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -38,7 +38,7 @@ typedef struct s_caps uint32_t nlines; /*cursor position (line)*/ } t_caps; -int16_t c_init_tcaps(t_msh *msh); +int16_t c_init_tcaps(char **line, t_msh *msh); int16_t c_set_term_raw(uint8_t mode); #endif diff --git a/src/m_loop.c b/src/m_loop.c index 600758d..d4bc665 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -39,12 +39,12 @@ uint8_t int8_t gnl; gnl = 1; - c_init_tcaps(msh); while (gnl > 0) { - if (fd == STDIN_FILENO) - m_prompt_psx(1, msh); - gnl = get_next_line(fd, &line); + /* if (fd == STDIN_FILENO) */ + /* m_prompt_psx(1, msh); */ + /* gnl = get_next_line(fd, &line); */ + gnl = c_init_tcaps(&line, msh); if (line[0] != '\0') { line = m_check_multi_backslash(fd, line, msh); |