diff options
Diffstat (limited to 'src/c_utils.c')
-rw-r--r-- | src/c_utils.c | 128 |
1 files changed, 74 insertions, 54 deletions
diff --git a/src/c_utils.c b/src/c_utils.c index a7769bb..10013d7 100644 --- a/src/c_utils.c +++ b/src/c_utils.c @@ -21,58 +21,6 @@ #include "m_loop.h" #include "s_struct.h" -char - *c_new_line(t_caps *tcaps) -{ - char *ret; - size_t i; - - i = tcaps->lpos; - ret = NULL; - write(1, "\n", 1); - tputs(tgetstr("cr", NULL), 1, ft_putchar); - c_set_term_raw(0); - tcaps->cpos = 0; - tputs(tgetstr("cr", NULL), 1, ft_putchar); - if (i < tcaps->nlines && tcaps->nlines != 1) - while (i++ < tcaps->nlines) - { - write(1, "\n", 1); - } - return (ret); -} - -/* char */ -/* *c_insert_char(char *str, char c, t_caps *tcaps) */ -/* { */ - -/* } */ - -char - *c_delchar(char *str, unsigned short cpos) -{ - unsigned short i; - unsigned short j; - char *dst; - - j = 0; - i = 0; - if (!(dst = malloc((ft_strlen(str)) * sizeof(char)))) - return (NULL); - cpos -= 1; - while (j < (ft_strlen(str) - 1)) - { - if (i == cpos) - i++; - dst[j] = str[i]; - i++; - j++; - } - ft_memdel((void**)&str); - dst[j] = '\0'; - return (dst); -} - static unsigned int c_redraw_next(size_t plen, unsigned int len, t_caps *tcaps) { @@ -104,12 +52,11 @@ static unsigned int } unsigned int - c_redraw_line(char *line, t_caps *tcaps, t_msh *msh) + c_redraw_line(char *line, t_caps *tcaps) { unsigned int i; unsigned int j; - (void)msh; tcaps->nlines = c_get_line_num(line, tcaps->cpos, tcaps->plen, tcaps); i = 0; @@ -128,3 +75,76 @@ unsigned int c_redraw_next(tcaps->plen, ft_strlen(line), tcaps) : ft_strlen(line)); } + +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*)ft_calloc(sizeof(char), len))) + return ; + while (++i < (int)len) + if (i == (int)tcaps->cpos) + dst[i] = buf[0]; + else + dst[i] = line[0][j++]; + 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); +} + +char + *c_delchar(char *str, unsigned short cpos) +{ + unsigned short i; + unsigned short j; + char *dst; + + j = 0; + i = 0; + if (!(dst = malloc((ft_strlen(str)) * sizeof(char)))) + return (NULL); + cpos -= 1; + while (j < (ft_strlen(str) - 1)) + { + if (i == cpos) + i++; + dst[j] = str[i]; + i++; + j++; + } + ft_memdel((void**)&str); + dst[j] = '\0'; + return (dst); +} + +void + c_new_line(t_caps *tcaps) +{ + size_t i; + + i = tcaps->lpos; + write(1, "\n", 1); + tputs(tgetstr("cr", NULL), 1, ft_putchar); + c_set_term_raw(0); + tcaps->cpos = 0; + tputs(tgetstr("cr", NULL), 1, ft_putchar); + if (i < tcaps->nlines && tcaps->nlines != 1) + while (i++ < tcaps->nlines) + { + write(1, "\n", 1); + } +} |