summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_ctrls.c3
-rw-r--r--src/c_init.c41
-rw-r--r--src/c_utils.c128
-rw-r--r--src/c_utils.h2
4 files changed, 77 insertions, 97 deletions
diff --git a/src/c_ctrls.c b/src/c_ctrls.c
index dcb51de..9431f72 100644
--- a/src/c_ctrls.c
+++ b/src/c_ctrls.c
@@ -44,7 +44,8 @@ char *c_ctrl_c(char **line, char *buf, t_msh *msh)
buf[0] = '\n';
write(1, "\n", 1);
ft_memdel((void**)line);
- return (ft_strdup("\0"));
+ *line = ft_strdup("\0");
+ return (NULL);
}
void c_signal_int(int signo)
diff --git a/src/c_init.c b/src/c_init.c
index 434f456..93f6bb3 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -145,53 +145,14 @@ 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 **line, char *buf, t_caps *tcaps, t_msh *msh)
{
char *ptr;
if (*line == NULL)
- {
if (!(*line = calloc(1, sizeof(char))))
return (NULL);
- }
if (ft_isprint(buf[0]))
c_add_char(line, buf, tcaps);
else if (((*((unsigned int *)buf)) == UP_K) ||
@@ -213,9 +174,7 @@ static char
c_back_slash(line, tcaps->plen, tcaps);
if ((((tcaps->cpos) + tcaps->plen) %
tcaps->ws.ws_col) == 0)
- {
return (NULL);
- }
c_redraw_line(*line, tcaps);
}
else if ((*((unsigned int *)buf)) == CTRL_C)
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);
+ }
+}
diff --git a/src/c_utils.h b/src/c_utils.h
index 4cafa3b..549c536 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -15,8 +15,8 @@
# include "s_struct.h"
+void c_add_char(char **line, char *buf, t_caps *tcaps);
char *c_new_line(t_caps *tcaps);
-char *c_insert_char(char *str, char c, t_caps *tcaps);
char *c_delchar(char *str, unsigned short cpos);
short c_redraw_line(char *line, t_caps *tcaps);