diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-12-15 13:37:41 +0100 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-12-15 13:37:41 +0100 |
commit | cbde2aa474cc289cc6db127ebcedeb7e5502d7be (patch) | |
tree | 5c530500265c737f2db68913c65595a87784a280 | |
parent | qwe (diff) | |
download | 42-minishell-cbde2aa474cc289cc6db127ebcedeb7e5502d7be.tar.gz 42-minishell-cbde2aa474cc289cc6db127ebcedeb7e5502d7be.tar.bz2 42-minishell-cbde2aa474cc289cc6db127ebcedeb7e5502d7be.tar.xz 42-minishell-cbde2aa474cc289cc6db127ebcedeb7e5502d7be.tar.zst 42-minishell-cbde2aa474cc289cc6db127ebcedeb7e5502d7be.zip |
onto something
-rw-r--r-- | 2do | 2 | ||||
-rw-r--r-- | src/c_init.c | 57 | ||||
-rw-r--r-- | src/c_utils.c | 32 |
3 files changed, 44 insertions, 47 deletions
@@ -1,2 +0,0 @@ -ptr to line maybe ??? -fix this fucvking leak already diff --git a/src/c_init.c b/src/c_init.c index 358f145..b1e9fb2 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -57,20 +57,6 @@ short return (1); } -static void - c_add_char(char **line, char *buf, t_caps *tcaps) -{ - *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); -} - static short c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh) { @@ -159,15 +145,51 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh) return (p); } +static void + c_add_char(char **line, char *buf, t_caps *tcaps) +{ + int i; + size_t j; + size_t len; + char *dst; + + i = -1; + j = 0; + len = (ft_strlen(*line) + 2); + if (!(dst = (char*)malloc((len) * sizeof(char)))) + return ; + while (++i < (int)len) + { + if (i == (int)tcaps->cpos) + dst[i] = buf[0]; + else + { + dst[i] = line[0][j]; + j++; + } + } + dst[len - 1] = '\0'; + ft_memdel((void**)&line[0]); + *line = ft_strdup(dst); + ft_memdel((void**)&dst); + tcaps->cpos++; + if ((((tcaps->cpos) + tcaps->plen) % + tcaps->ws.ws_col) == 0) + { + write(STDOUT_FILENO, "\n\r", 2); + return ; + } + c_redraw_line(*line, tcaps); +} + 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; char *ptr; - if (line == NULL) + if (line == NULL || line == (void*)0x1) { - ft_printf("\r\nline is NULL\r\n"); if (!(line = calloc(1, sizeof(char)))) return (NULL); } @@ -227,6 +249,5 @@ short *line = c_process_key(nread, &tcaps, msh); tputs(tgetstr("ve", NULL), 1, ft_putchar); } - ft_printf("[%s]\n", *line); return (1); } diff --git a/src/c_utils.c b/src/c_utils.c index 2414638..048b845 100644 --- a/src/c_utils.c +++ b/src/c_utils.c @@ -35,7 +35,7 @@ char if (line != NULL) { ret = ft_strdup(line); - line[0] = '\0'; + *line = '\0'; } tcaps->cpos = 0; tputs(tgetstr("cr", NULL), 1, ft_putchar); @@ -44,36 +44,14 @@ char { write(1, "\n", 1); } - /* ft_printf("[%s][%s]\n", ret, line); */ return (ret); } -char - *c_insert_char(char *str, char c, t_caps *tcaps) -{ - int i; - size_t j; - size_t len; - char *dst; +/* char */ +/* *c_insert_char(char *str, char c, t_caps *tcaps) */ +/* { */ - i = -1; - j = 0; - len = (ft_strlen(str) + 2); - if (!(dst = (char*)malloc((len) * sizeof(char)))) - return (NULL); - while (++i < (int)len) - { - if (i == (int)tcaps->cpos) - dst[i] = c; - else - { - dst[i] = str[j]; - j++; - } - } - ft_memdel((void**)&str); - return (dst); -} +/* } */ char *c_delchar(char *str, unsigned short cpos) |