diff options
Diffstat (limited to 'src/c_init.c')
-rw-r--r-- | src/c_init.c | 57 |
1 files changed, 39 insertions, 18 deletions
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); } |