summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-14 15:59:30 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-14 15:59:30 +0200
commitb6806c73f4ae94dd76ad7a51ad25255b3493e9c9 (patch)
tree6d5d530cdd8b282caff2436651697d273e0f315e
parentgrep TODO c_utils.c (diff)
download42-minishell-b6806c73f4ae94dd76ad7a51ad25255b3493e9c9.tar.gz
42-minishell-b6806c73f4ae94dd76ad7a51ad25255b3493e9c9.tar.bz2
42-minishell-b6806c73f4ae94dd76ad7a51ad25255b3493e9c9.tar.xz
42-minishell-b6806c73f4ae94dd76ad7a51ad25255b3493e9c9.tar.zst
42-minishell-b6806c73f4ae94dd76ad7a51ad25255b3493e9c9.zip
quelques additions
Diffstat (limited to '')
-rw-r--r--src/c_init.c12
-rw-r--r--src/c_input.c5
-rw-r--r--src/c_utils.c21
-rw-r--r--src/c_utils.h2
4 files changed, 24 insertions, 16 deletions
diff --git a/src/c_init.c b/src/c_init.c
index ee6782d..2bc0be3 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -10,12 +10,12 @@
/* */
/* ************************************************************************** */
-
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
#include <term.h>
+#include <signal.h>
#include <libft.h>
#include "c_init.h"
@@ -71,15 +71,17 @@ int16_t
i = -1;
if (line == NULL)
- if (!(line = ft_calloc(2, sizeof(char))))
- return (0);
+ {
+ if (!(line = ft_calloc(1, sizeof(char))))
+ return (-1);
+ }
if (ft_isprint(buf[0]))
{
if (tcaps->cpos == ft_strlen(line))
line = ft_strjoin(line, buf);
else
line = c_insert_char(line, buf[0], tcaps);
- c_redraw_line(line, tcaps->cpos, msh);
+ c_redraw_line(line, tcaps, msh);
tcaps->cpos++;
}
else
@@ -116,6 +118,8 @@ int16_t
{
return (c_new_line(buf, &line, msh, tcaps));
}
+ else
+ return (0);
}
return (0);
}
diff --git a/src/c_input.c b/src/c_input.c
index ed60ae4..478c29e 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -20,7 +20,6 @@
#include "m_prompt.h"
#include "m_loop.h"
-
int16_t
c_back_slash(char **line,
t_caps *tcaps)
@@ -42,7 +41,7 @@ int16_t
{
tputs(tgetstr("cl", NULL), 1, ft_putchar);
m_prompt_psx(1, msh);
- c_redraw_line(line, tcaps->cpos, msh);
+ c_redraw_line(line, tcaps, msh);
return (1);
}
@@ -53,7 +52,7 @@ int16_t
{
tputs(tgetstr("cl", NULL), 1, ft_putchar);
m_prompt_psx(1, msh);
- c_redraw_line(line, tcaps->cpos, msh);
+ c_redraw_line(line, tcaps, msh);
return (1);
}
diff --git a/src/c_utils.c b/src/c_utils.c
index d5a45e0..43d6452 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -25,9 +25,11 @@
/*
** TODO:
** quotes
-** leaks
+** leaks on line
** C-c
** tests varies
+** NORME
+** MULTILIGHNE
** term(0) on exit DONE
** cursor on char insert DONE
*/
@@ -93,6 +95,7 @@ int16_t
{
m_parse_and_run_line(*line, msh);
*line = NULL;
+ free(*line);
}
tcaps->cpos = 0;
tputs(tgetstr("cr", NULL), 1, ft_putchar);
@@ -119,7 +122,10 @@ char
while (i < len)
{
if (i == tcaps->cpos)
- dst[i++] = c;
+ {
+ dst[i] = c;
+ i++;
+ }
else
{
dst[i] = str[j];
@@ -127,8 +133,8 @@ char
j++;
}
}
+ free(str);
dst[i] = '\0';
- ft_memdel((void*)&str);
return (dst);
}
@@ -153,14 +159,14 @@ char
i++;
j++;
}
- free(str);
+ ft_memdel((void**)&str);
dst[j] = '\0';
return (dst);
}
int16_t
c_redraw_line(char *line,
- uint16_t cpos,
+ t_caps *tcaps,
t_msh *msh)
{
uint32_t i;
@@ -168,7 +174,6 @@ int16_t
int16_t ret;
i = 0;
- (void)cpos;
tputs(tgetstr("cr", NULL), 1, ft_putchar);
while (i < ft_strlen(msh->ps[0]))
{
@@ -177,8 +182,8 @@ int16_t
}
ret = ft_printf("%s", line) + ft_strlen(msh->ps[0]);
len = ft_strlen(line);
- if (cpos != len)
- while (--len > cpos)
+ if (tcaps->cpos != len)
+ while (--len > tcaps->cpos)
tputs(tgetstr("le", NULL), 1, ft_putchar);
return (ret);
}
diff --git a/src/c_utils.h b/src/c_utils.h
index e915365..62179b7 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -15,7 +15,7 @@
#include "s_struct.h"
-int16_t c_redraw_line(char *line, uint16_t cpos, t_msh *msh);
+int16_t c_redraw_line(char *line, t_caps *tcaps, t_msh *msh);
char *c_delchar(char *str, uint16_t cpos);
uint16_t c_get_win_size(struct winsize *ws);
int32_t c_catch_tcaps(char *buf, char **line, t_caps *tcaps, t_msh *msh);