debut mise a la norme/nettoyage
This commit is contained in:
parent
485f1bb619
commit
3dd298b9c4
17 changed files with 343 additions and 364 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/25 14:37:32 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 20:04:33 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -68,6 +68,12 @@ typedef struct s_line
|
||||||
t_list_history *list_beg;
|
t_list_history *list_beg;
|
||||||
} t_line;
|
} t_line;
|
||||||
|
|
||||||
|
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||||
|
void ft_move_right(size_t *pos, char *str);
|
||||||
|
void ft_move_left(size_t *pos, char *str);
|
||||||
|
int ft_put(int nb);
|
||||||
|
void ft_end(char *str, size_t *pos);
|
||||||
|
void ft_home(char *str, size_t *pos);
|
||||||
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||||
void ft_realloc_str_history(char **str, size_t pos
|
void ft_realloc_str_history(char **str, size_t pos
|
||||||
, int nb_his, int len);
|
, int nb_his, int len);
|
||||||
|
|
@ -123,7 +129,6 @@ void ft_move_suppr(char *str, size_t pos);
|
||||||
void ft_move_dell(char *str, size_t pos);
|
void ft_move_dell(char *str, size_t pos);
|
||||||
void ft_move_to_word(int ret, size_t *pos, char *str);
|
void ft_move_to_word(int ret, size_t *pos, char *str);
|
||||||
void ft_move_term(int ret, size_t *pos, char *str);
|
void ft_move_term(int ret, size_t *pos, char *str);
|
||||||
void ft_move_left(size_t pos, char *str);
|
|
||||||
void ft_home_end(char *str, int ret, size_t *pos);
|
void ft_home_end(char *str, int ret, size_t *pos);
|
||||||
int ft_put(int nb);
|
int ft_put(int nb);
|
||||||
char **ft_split_whitespaces(char const *s);
|
char **ft_split_whitespaces(char const *s);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */
|
/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 16:44:13 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 15:48:52 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,7 +25,8 @@ void ft_history_builtin(void)
|
||||||
head = head->next;
|
head = head->next;
|
||||||
while (head && head->str)
|
while (head && head->str)
|
||||||
{
|
{
|
||||||
ft_putnc(' ', ft_nbr_len(data_singleton()->line.list_size) - ft_nbr_len(len));
|
ft_putnc(' ', ft_nbr_len(data_singleton()->line.list_size)
|
||||||
|
- ft_nbr_len(len));
|
||||||
ft_printf("%zu %s\n", len, head->str);
|
ft_printf("%zu %s\n", len, head->str);
|
||||||
++len;
|
++len;
|
||||||
head = head->next;
|
head = head->next;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 14:28:57 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 17:58:33 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -81,7 +81,6 @@ static void ft_x(char **tmp, size_t *pos, char **str)
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ft_cxv(int ret, size_t *pos, char **str)
|
void ft_cxv(int ret, size_t *pos, char **str)
|
||||||
{
|
{
|
||||||
static char *tmp = NULL;
|
static char *tmp = NULL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/02 17:52:52 by gwojda #+# #+# */
|
/* Created: 2016/11/02 17:52:52 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/25 14:10:37 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 15:49:21 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/25 14:39:59 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:26:30 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,6 +18,10 @@ static int ft_lecture_3(int ret, char **str, size_t *i)
|
||||||
ft_suppr(str, i);
|
ft_suppr(str, i);
|
||||||
else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str)))
|
else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str)))
|
||||||
ft_del(str, i);
|
ft_del(str, i);
|
||||||
|
else if (ret == TOUCHE_HOME)
|
||||||
|
ft_home(*str, i);
|
||||||
|
else if (ret == TOUCHE_END)
|
||||||
|
ft_end(*str, i);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -32,8 +36,10 @@ static int ft_lecture_2(int ret, char **str, size_t *i)
|
||||||
else if (ret == TOUCHE_OPT_X || ret == TOUCHE_OPT_C
|
else if (ret == TOUCHE_OPT_X || ret == TOUCHE_OPT_C
|
||||||
|| ret == TOUCHE_OPT_V)
|
|| ret == TOUCHE_OPT_V)
|
||||||
ft_cxv(ret, i, str);
|
ft_cxv(ret, i, str);
|
||||||
else if (ret == FLECHE_DROITE || ret == FLECHE_GAUCHE)
|
else if (ret == FLECHE_DROITE)
|
||||||
ft_move_term(ret, i, *str);
|
ft_move_right(i, *str);
|
||||||
|
else if (ret == FLECHE_GAUCHE)
|
||||||
|
ft_move_left(i, *str);
|
||||||
else if (ret == TOUCHE_OPT_UP || ret == TOUCHE_OPT_DOWN)
|
else if (ret == TOUCHE_OPT_UP || ret == TOUCHE_OPT_DOWN)
|
||||||
ft_move_to_line(ret, i, *str);
|
ft_move_to_line(ret, i, *str);
|
||||||
else if (ft_isprint(ret))
|
else if (ft_isprint(ret))
|
||||||
|
|
@ -67,8 +73,10 @@ char *ft_lecture(t_list_history *head)
|
||||||
read(0, &ret, sizeof(int));
|
read(0, &ret, sizeof(int));
|
||||||
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0)
|
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0)
|
||||||
continue ;
|
continue ;
|
||||||
// if (ret == TOUCHE_TAB)
|
/*
|
||||||
// ret = ft_completion(&str, &i);
|
** if (ret == TOUCHE_TAB)
|
||||||
|
** ret = ft_completion(&str, &i);
|
||||||
|
*/
|
||||||
if (ret == TOUCHE_CTRL_C || ret == TOUCHE_CTRL_D)
|
if (ret == TOUCHE_CTRL_C || ret == TOUCHE_CTRL_D)
|
||||||
exit(1);
|
exit(1);
|
||||||
if (ft_lecture_2(ret, &str, &i))
|
if (ft_lecture_2(ret, &str, &i))
|
||||||
|
|
@ -81,8 +89,6 @@ char *ft_lecture(t_list_history *head)
|
||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
else if (ret == TOUCHE_HOME || ret == TOUCHE_END)
|
|
||||||
ft_home_end(str, ret, &i);
|
|
||||||
else if (ft_lecture_3(ret, &str, &i))
|
else if (ft_lecture_3(ret, &str, &i))
|
||||||
continue ;
|
continue ;
|
||||||
else if (ret == 10)
|
else if (ret == 10)
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 10:21:48 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 15:49:11 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_history_2(char **str, int ret, t_list_history **head, size_t *pos)
|
void ft_history_2(char **str, int ret, t_list_history **head
|
||||||
|
, size_t *pos)
|
||||||
{
|
{
|
||||||
if (*str)
|
if (*str)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 11:22:42 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:26:42 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,9 +18,7 @@ int ft_put(int nb)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_home_end(char *str, int ret, size_t *pos)
|
void ft_end(char *str, size_t *pos)
|
||||||
{
|
|
||||||
if (ret == TOUCHE_END && str)
|
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +32,8 @@ void ft_home_end(char *str, int ret, size_t *pos)
|
||||||
ft_current_str(str, *pos);
|
ft_current_str(str, *pos);
|
||||||
ft_get_next_str(str, pos);
|
ft_get_next_str(str, pos);
|
||||||
}
|
}
|
||||||
else if (ret == TOUCHE_HOME)
|
|
||||||
|
void ft_home(char *str, size_t *pos)
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
|
|
@ -52,14 +51,13 @@ void ft_home_end(char *str, int ret, size_t *pos)
|
||||||
--(*pos);
|
--(*pos);
|
||||||
ft_get_beggin_with_curs(str, pos);
|
ft_get_beggin_with_curs(str, pos);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_term(int ret, size_t *pos, char *str)
|
void ft_move_right(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
|
|
||||||
if (ret == FLECHE_DROITE && str && ft_strlen(str) > *pos)
|
if (ft_strlen(str) <= *pos)
|
||||||
{
|
return ;
|
||||||
if (str[*pos] == '\n')
|
if (str[*pos] == '\n')
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
|
|
@ -67,7 +65,6 @@ void ft_move_term(int ret, size_t *pos, char *str)
|
||||||
tmp = *pos - 1;
|
tmp = *pos - 1;
|
||||||
ft_get_beggin_with_curs(str, &tmp);
|
ft_get_beggin_with_curs(str, &tmp);
|
||||||
}
|
}
|
||||||
//si premiere ligne ne contient que \n, puis fleche droite -> decalage//
|
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
++(*pos);
|
++(*pos);
|
||||||
ft_current_str(str, *pos);
|
ft_current_str(str, *pos);
|
||||||
|
|
@ -82,8 +79,11 @@ void ft_move_term(int ret, size_t *pos, char *str)
|
||||||
++(*pos);
|
++(*pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ret == FLECHE_GAUCHE && *pos > 0)
|
|
||||||
|
void ft_move_left(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
|
if (!*pos)
|
||||||
|
return ;
|
||||||
if (str[*pos - 1] == '\n')
|
if (str[*pos - 1] == '\n')
|
||||||
{
|
{
|
||||||
if (*pos - 1 == 0)
|
if (*pos - 1 == 0)
|
||||||
|
|
@ -105,4 +105,3 @@ void ft_move_term(int ret, size_t *pos, char *str)
|
||||||
--(*pos);
|
--(*pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/24 15:52:34 by gwojda #+# #+# */
|
/* Created: 2017/01/24 15:52:34 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 17:07:21 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:03:11 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,32 +26,13 @@ char *ft_get_next_word(char *str)
|
||||||
return (ft_strndup(str + j, k));
|
return (ft_strndup(str + j, k));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_check_heredoc(char **str)
|
static void ft_check_heredoc_2(char **str, char *end)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char boolean;
|
char boolean;
|
||||||
char *end;
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
i = 0;
|
|
||||||
end = NULL;
|
|
||||||
boolean = 0;
|
boolean = 0;
|
||||||
if (!*str)
|
|
||||||
return ;
|
|
||||||
while ((*str)[i])
|
|
||||||
{
|
|
||||||
if ((*str)[i] == '<' && !ft_strncmp(*str + i, "<<", 2))
|
|
||||||
{
|
|
||||||
if ((*str)[i + 1] == '<' && (*str)[i + 2])
|
|
||||||
end = ft_get_next_word(*str + i + 2);
|
|
||||||
else
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
if (!end)
|
|
||||||
return ;
|
|
||||||
while (!boolean)
|
while (!boolean)
|
||||||
{
|
{
|
||||||
ft_putstr("heredoc> ");
|
ft_putstr("heredoc> ");
|
||||||
|
|
@ -69,3 +50,28 @@ void ft_check_heredoc(char **str)
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_check_heredoc(char **str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *end;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
end = NULL;
|
||||||
|
if (!*str)
|
||||||
|
return ;
|
||||||
|
while ((*str)[i])
|
||||||
|
{
|
||||||
|
if ((*str)[i] == '<' && !ft_strncmp(*str + i, "<<", 2))
|
||||||
|
{
|
||||||
|
if ((*str)[i + 1] == '<' && (*str)[i + 2])
|
||||||
|
end = ft_get_next_word(*str + i + 2);
|
||||||
|
else
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (!end)
|
||||||
|
return ;
|
||||||
|
ft_check_heredoc_2(str, end);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,64 +6,67 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/25 15:05:04 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 20:05:40 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static char *ft_strget_history(char *str)
|
static int ft_history_parsing_4(char *str, int *i)
|
||||||
{
|
{
|
||||||
t_list_history *list;
|
if (!ft_strncmp("!!", str + *i, 2))
|
||||||
size_t i;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
list = data_singleton()->line.list_beg;
|
|
||||||
if (!list)
|
|
||||||
return (NULL);
|
|
||||||
if (!list->str)
|
|
||||||
list = list->prev;
|
|
||||||
while (list->str)
|
|
||||||
{
|
{
|
||||||
tmp = list->str;
|
ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2);
|
||||||
i = 0;
|
++(*i);
|
||||||
while (tmp[i])
|
return (1);
|
||||||
{
|
|
||||||
if (ft_strlen(tmp + i) >= ft_strlen(str)
|
|
||||||
&& !ft_strncmp(tmp + i, str, ft_strlen(str)))
|
|
||||||
return (tmp);
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
list = list->prev;
|
else if (ft_isdigit(str[(*i) + 1]))
|
||||||
|
{
|
||||||
|
ft_realloc_str_history(&(data_singleton()->line.input), *i,
|
||||||
|
ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1);
|
||||||
|
(*i) += ft_nbr_len(ft_atoi(str + *i + 1));
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
return (list->str);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s)
|
static int ft_history_parsing_3(char *str, int *i)
|
||||||
{
|
{
|
||||||
char *new_str;
|
if (ft_history_parsing_4(str, i))
|
||||||
char *new_str2;
|
return (1);
|
||||||
char *new_str3;
|
else if (str[*i + 1] == '-')
|
||||||
|
|
||||||
if (!*str)
|
|
||||||
return ;
|
|
||||||
new_str = ft_strndup(*str, pos);
|
|
||||||
new_str3 = ft_strget_history(s);
|
|
||||||
if (new_str3)
|
|
||||||
{
|
{
|
||||||
new_str2 = ft_strjoin(new_str, new_str3);
|
ft_realloc_str_history(&(data_singleton()->line.input), *i,
|
||||||
free(new_str);
|
data_singleton()->line.list_size - ft_atoi(str + *i + 2),
|
||||||
new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2);
|
ft_nbr_len(ft_atoi(str + *i + 2)) + 2);
|
||||||
free(new_str2);
|
(*i) += ft_nbr_len(ft_atoi(str + *i + 2) + 1);
|
||||||
}
|
}
|
||||||
|
else if (str[*i + 1] == '?')
|
||||||
|
ft_realloc_str_history_3(&(data_singleton()->line.input), *i,
|
||||||
|
ft_strdupi_w(str + *i + 2));
|
||||||
|
else if (str[*i + 1] != ' ')
|
||||||
|
ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
|
||||||
|
ft_strdupi_w(str + *i + 1));
|
||||||
else
|
else
|
||||||
new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2);
|
return (0);
|
||||||
free(s);
|
return (1);
|
||||||
free(*str);
|
|
||||||
*str = new_str3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_history_parsing()
|
static void ft_history_parsing_2(void)
|
||||||
|
{
|
||||||
|
data_singleton()->line.opt = data_singleton()->line.opt | HIST;
|
||||||
|
ft_prompt();
|
||||||
|
data_singleton()->line.input = ft_lecture(
|
||||||
|
data_singleton()->line.list_beg);
|
||||||
|
ft_putchar('\n');
|
||||||
|
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
||||||
|
ft_check_quotes(&data_singleton()->line.input,
|
||||||
|
data_singleton()->line.list_beg);
|
||||||
|
ft_check_heredoc(&data_singleton()->line.input);
|
||||||
|
ft_history_parsing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_history_parsing(void)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -79,44 +82,11 @@ void ft_history_parsing()
|
||||||
if (str[i] == '!')
|
if (str[i] == '!')
|
||||||
{
|
{
|
||||||
boolean = 1;
|
boolean = 1;
|
||||||
if (!ft_strncmp("!!", str + i, 2))
|
if (!ft_history_parsing_3(str, &i))
|
||||||
{
|
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), i, 0, 2);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else if (ft_isdigit(str[i + 1]))
|
|
||||||
{
|
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), i,
|
|
||||||
ft_atoi(str + i + 1), ft_nbr_len(ft_atoi(str + i + 1)) + 1);
|
|
||||||
i += ft_nbr_len(ft_atoi(str + i + 1));
|
|
||||||
}
|
|
||||||
else if (str[i + 1] == '-')
|
|
||||||
{
|
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), i,
|
|
||||||
data_singleton()->line.list_size - ft_atoi(str + i + 2),
|
|
||||||
ft_nbr_len(ft_atoi(str + i + 2)) + 2);
|
|
||||||
i += ft_nbr_len(ft_atoi(str + i + 2) + 1);
|
|
||||||
}
|
|
||||||
else if (str[i + 1] == '?')
|
|
||||||
ft_realloc_str_history_3(&(data_singleton()->line.input), i,
|
|
||||||
ft_strdupi_w(str + i + 2));
|
|
||||||
else if (str[i + 1] != ' ')
|
|
||||||
ft_realloc_str_history_2(&(data_singleton()->line.input), i,
|
|
||||||
ft_strdupi_w(str + i + 1));
|
|
||||||
else
|
|
||||||
boolean = 0;
|
boolean = 0;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (boolean)
|
if (boolean)
|
||||||
{
|
ft_history_parsing_2();
|
||||||
data_singleton()->line.opt = data_singleton()->line.opt | HIST;
|
|
||||||
ft_prompt();
|
|
||||||
data_singleton()->line.input = ft_lecture(data_singleton()->line.list_beg);
|
|
||||||
ft_putchar('\n');
|
|
||||||
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
|
||||||
ft_check_quotes(&data_singleton()->line.input, data_singleton()->line.list_beg);
|
|
||||||
ft_check_heredoc(&data_singleton()->line.input);
|
|
||||||
ft_history_parsing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
42sh/src/line-editing/history_parsing_toolz_2.c
Normal file
64
42sh/src/line-editing/history_parsing_toolz_2.c
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* history_parsing_toolz_2.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/25 20:04:16 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/01/25 20:06:09 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static char *ft_strget_history(char *str)
|
||||||
|
{
|
||||||
|
t_list_history *list;
|
||||||
|
size_t i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
list = data_singleton()->line.list_beg;
|
||||||
|
if (!list)
|
||||||
|
return (NULL);
|
||||||
|
if (!list->str)
|
||||||
|
list = list->prev;
|
||||||
|
while (list->str)
|
||||||
|
{
|
||||||
|
tmp = list->str;
|
||||||
|
i = 0;
|
||||||
|
while (tmp[i])
|
||||||
|
{
|
||||||
|
if (ft_strlen(tmp + i) >= ft_strlen(str)
|
||||||
|
&& !ft_strncmp(tmp + i, str, ft_strlen(str)))
|
||||||
|
return (tmp);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
list = list->prev;
|
||||||
|
}
|
||||||
|
return (list->str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_realloc_str_history_3(char **str, size_t pos, char *s)
|
||||||
|
{
|
||||||
|
char *new_str;
|
||||||
|
char *new_str2;
|
||||||
|
char *new_str3;
|
||||||
|
|
||||||
|
if (!*str)
|
||||||
|
return ;
|
||||||
|
new_str = ft_strndup(*str, pos);
|
||||||
|
new_str3 = ft_strget_history(s);
|
||||||
|
if (new_str3)
|
||||||
|
{
|
||||||
|
new_str2 = ft_strjoin(new_str, new_str3);
|
||||||
|
free(new_str);
|
||||||
|
new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2);
|
||||||
|
free(new_str2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2);
|
||||||
|
free(s);
|
||||||
|
free(*str);
|
||||||
|
*str = new_str3;
|
||||||
|
}
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* line_return_toolz.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/01/06 14:32:12 by gwojda #+# #+# */
|
|
||||||
/* Updated: 2017/01/23 10:57:17 by gwojda ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
static int ft_found_prev_char(char *str, size_t i)
|
|
||||||
{
|
|
||||||
while (i)
|
|
||||||
{
|
|
||||||
if (str[i] == '\n')
|
|
||||||
return (1);
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_dell(char *str, size_t pos)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
count = 1;
|
|
||||||
i = 0;
|
|
||||||
while (str[i + pos + 1])
|
|
||||||
{
|
|
||||||
if (str[i + pos] == '\n')
|
|
||||||
++count;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (i && str[i + pos + 1] != '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
if (i)
|
|
||||||
{
|
|
||||||
while (i && count)
|
|
||||||
{
|
|
||||||
if (str[i + pos + 1] == '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("up");
|
|
||||||
--count;
|
|
||||||
}
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
while (pos && str[pos] != '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("nd");
|
|
||||||
--pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_suppr(char *str, size_t pos)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int count;
|
|
||||||
int prompt_size;
|
|
||||||
|
|
||||||
prompt_size = data_singleton()->line.prompt_size;
|
|
||||||
count = 0;
|
|
||||||
i = 0;
|
|
||||||
while (str[i + pos])
|
|
||||||
{
|
|
||||||
if (str[i + pos] == '\n')
|
|
||||||
++count;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (i && str[i + pos] != '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
if (i)
|
|
||||||
{
|
|
||||||
while (i && count)
|
|
||||||
{
|
|
||||||
if (str[i + pos] == '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("up");
|
|
||||||
--count;
|
|
||||||
}
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
if (pos > 2)
|
|
||||||
pos -= 2;
|
|
||||||
if (!ft_found_prev_char(str, pos))
|
|
||||||
{
|
|
||||||
while (--prompt_size + 3)
|
|
||||||
ft_puttermcaps("nd");
|
|
||||||
}
|
|
||||||
while (pos && str[pos] != '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("nd");
|
|
||||||
--pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,29 +6,18 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/21 17:29:08 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:40:09 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static void ft_up(size_t *pos, char *str)
|
static void ft_up_2(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int len;
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (str[*pos - 1] == '\n')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
(*pos) -= 2;
|
|
||||||
ft_get_beggin(str, pos);
|
|
||||||
ft_current_str(str, *pos);
|
|
||||||
ft_get_next_str(str, pos);
|
|
||||||
++(*pos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
len = ft_size_term();
|
len = ft_size_term();
|
||||||
if (str[*pos - i] == '\n')
|
if (str[*pos - i] == '\n')
|
||||||
{
|
{
|
||||||
|
|
@ -48,15 +37,26 @@ static void ft_up(size_t *pos, char *str)
|
||||||
}
|
}
|
||||||
(*pos) -= i;
|
(*pos) -= i;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_down(size_t *pos, char *str)
|
static void ft_up(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (str[*pos] == '\n')
|
if (str[*pos - 1] == '\n')
|
||||||
|
{
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
(*pos) -= 2;
|
||||||
|
ft_get_beggin(str, pos);
|
||||||
|
ft_current_str(str, *pos);
|
||||||
|
ft_get_next_str(str, pos);
|
||||||
|
++(*pos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_up_2(pos, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_down_2(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
|
|
@ -72,6 +72,15 @@ static void ft_down(size_t *pos, char *str)
|
||||||
--(*pos);
|
--(*pos);
|
||||||
ft_get_beggin_with_curs(str, pos);
|
ft_get_beggin_with_curs(str, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ft_down(size_t *pos, char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (str[*pos] == '\n')
|
||||||
|
ft_down_2(pos, str);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = ft_size_term();
|
len = ft_size_term();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 14:40:21 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:37:45 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,6 +38,19 @@ void ft_print(char **str, int ret, size_t *i)
|
||||||
++(*i);
|
++(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_suppr_2(char **str, size_t *i, size_t tmp)
|
||||||
|
{
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
ft_current_str(*str, *i);
|
||||||
|
ft_get_next_str(*str, i);
|
||||||
|
if (*i && (*str)[*i] && ft_found_next_char(*str, *i))
|
||||||
|
++(*i);
|
||||||
|
ft_putnc('\b', *i - tmp);
|
||||||
|
(*i) = tmp;
|
||||||
|
if (ft_strlen(*str) == 0)
|
||||||
|
*str = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void ft_suppr(char **str, size_t *i)
|
void ft_suppr(char **str, size_t *i)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
|
|
@ -58,15 +71,7 @@ void ft_suppr(char **str, size_t *i)
|
||||||
*str = ft_remove_imput((*str), tmp);
|
*str = ft_remove_imput((*str), tmp);
|
||||||
ft_get_beggin(*str, i);
|
ft_get_beggin(*str, i);
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_suppr_2(str, i, tmp);
|
||||||
ft_current_str(*str, *i);
|
|
||||||
ft_get_next_str(*str, i);
|
|
||||||
if (*i && (*str)[*i] && ft_found_next_char(*str, *i))
|
|
||||||
++(*i);
|
|
||||||
ft_putnc('\b', *i - tmp);
|
|
||||||
(*i) = tmp;
|
|
||||||
if (ft_strlen(*str) == 0)
|
|
||||||
*str = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_del(char **str, size_t *i)
|
void ft_del(char **str, size_t *i)
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,15 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/20 11:30:17 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:31:24 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
/* ft_printf de la lib bug avec unicode */
|
/*
|
||||||
|
**ft_printf de la lib bug avec unicode
|
||||||
|
*/
|
||||||
|
|
||||||
static void ft_get_date(void)
|
static void ft_get_date(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */
|
/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/19 16:43:10 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 16:50:14 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,22 +23,22 @@ int ft_check_quotes_num(char *s)
|
||||||
doub = 0;
|
doub = 0;
|
||||||
while (s[i])
|
while (s[i])
|
||||||
{
|
{
|
||||||
if (s[i] == '\'')
|
if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))
|
||||||
{
|
{
|
||||||
simp = 1;
|
simp = 1;
|
||||||
++i;
|
++i;
|
||||||
while (s[i] && s[i] != '\'')
|
while (s[i] && !(s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)))
|
||||||
++i;
|
++i;
|
||||||
if (s[i] == '\'')
|
if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))
|
||||||
simp = 0;
|
simp = 0;
|
||||||
}
|
}
|
||||||
else if (s[i] == '"')
|
else if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i))
|
||||||
{
|
{
|
||||||
doub = 1;
|
doub = 1;
|
||||||
++i;
|
++i;
|
||||||
while (s[i] && s[i] != '"')
|
while (s[i] && !(s[i] == '"' && ((i && s[i - 1] != '\\') || !i)))
|
||||||
++i;
|
++i;
|
||||||
if (s[i] == '"')
|
if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i))
|
||||||
doub = 0;
|
doub = 0;
|
||||||
}
|
}
|
||||||
if (s[i])
|
if (s[i])
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,31 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/20 18:15:12 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 19:07:39 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < 4 && t[i] == '\0')
|
||||||
|
++i;
|
||||||
|
while (i < 4)
|
||||||
|
{
|
||||||
|
if (t[i] && ft_isprint(t[i]))
|
||||||
|
{
|
||||||
|
*str = ft_realloc_imput(*str, t[i], *pos);
|
||||||
|
++(*pos);
|
||||||
|
++(*j);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ft_read_it_2(int input, char t[5])
|
static void ft_read_it_2(int input, char t[5])
|
||||||
{
|
{
|
||||||
t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0';
|
t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0';
|
||||||
|
|
@ -31,31 +50,17 @@ static void ft_read_it_2(int input, char t[5])
|
||||||
|
|
||||||
void ft_read_it(int input, size_t *pos, char **str)
|
void ft_read_it(int input, size_t *pos, char **str)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int j;
|
int j;
|
||||||
char t[5];
|
char t[5];
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
i = 0;
|
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
|
||||||
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || input == 126 ||
|
input == 126 || input == 993090331 || input == 925981467 ||
|
||||||
input == 993090331 || input == 925981467 || input == 21298 ||
|
input == 21298 || input == 892427035 || input == 8270395 ||
|
||||||
input == 892427035 || input == 8270395 || input == 942758683 ||
|
input == 942758683 || input == 993090331 || input == 18489 || input == 17977)
|
||||||
input == 993090331 || input == 18489 || input == 17977)
|
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
ft_read_it_2(input, t);
|
ft_read_it_2(input, t);
|
||||||
while (i < 4 && t[i] == '\0')
|
ft_read_it_3(str, t, pos, &j);
|
||||||
++i;
|
|
||||||
while (i < 4)
|
|
||||||
{
|
|
||||||
if (t[i] && ft_isprint(t[i]))
|
|
||||||
{
|
|
||||||
*str = ft_realloc_imput(*str, t[i], *pos);
|
|
||||||
++(*pos);
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
ft_putstr((*str) + (*pos) - j);
|
ft_putstr((*str) + (*pos) - j);
|
||||||
ft_putnc('\b', ft_strlen((*str)) - ((*pos)));
|
ft_putnc('\b', ft_strlen((*str)) - ((*pos)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/25 14:37:16 by gwojda ### ########.fr */
|
/* Updated: 2017/01/25 17:06:53 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -50,8 +50,22 @@ struct termios *ft_stats_term_termcaps(void)
|
||||||
return (term);
|
return (term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_reset_stats_term(int signal)
|
||||||
|
{
|
||||||
|
char *name_term;
|
||||||
|
|
||||||
|
if (signal == SIGWINCH)
|
||||||
|
{
|
||||||
|
if ((name_term = getenv("TERM")) == NULL)
|
||||||
|
return ;
|
||||||
|
if (tgetent(NULL, name_term) == -1)
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ft_readline(void)
|
int ft_readline(void)
|
||||||
{
|
{
|
||||||
|
signal(SIGWINCH, ft_reset_stats_term);
|
||||||
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (data_singleton()->line.input)
|
if (data_singleton()->line.input)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue