diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index f47ca6be..24e96a51 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* 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_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(char **str, size_t pos , 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_to_word(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); int ft_put(int nb); char **ft_split_whitespaces(char const *s); diff --git a/42sh/src/line-editing/builtin_history.c b/42sh/src/line-editing/builtin_history.c index d3e95a78..76b99fa1 100644 --- a/42sh/src/line-editing/builtin_history.c +++ b/42sh/src/line-editing/builtin_history.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_history_builtin(void) { - size_t len; + size_t len; t_list_history *head; head = data_singleton()->line.list_end; @@ -25,7 +25,8 @@ void ft_history_builtin(void) head = head->next; 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); ++len; head = head->next; diff --git a/42sh/src/line-editing/copy_cut_paste.c b/42sh/src/line-editing/copy_cut_paste.c index 4aa21239..0282e916 100644 --- a/42sh/src/line-editing/copy_cut_paste.c +++ b/42sh/src/line-editing/copy_cut_paste.c @@ -6,7 +6,7 @@ /* 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"); } - void ft_cxv(int ret, size_t *pos, char **str) { static char *tmp = NULL; diff --git a/42sh/src/line-editing/ft_split_whitespaces.c b/42sh/src/line-editing/ft_split_whitespaces.c index 86cb9aaf..05506cfb 100644 --- a/42sh/src/line-editing/ft_split_whitespaces.c +++ b/42sh/src/line-editing/ft_split_whitespaces.c @@ -6,13 +6,13 @@ /* 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 */ /* */ /* ************************************************************************** */ #include "minishell.h" -char *ft_strdupi_w(char const *s) +char *ft_strdupi_w(char const *s) { int i; char *str; diff --git a/42sh/src/line-editing/get_touch.c b/42sh/src/line-editing/get_touch.c index 14104d63..375303a1 100644 --- a/42sh/src/line-editing/get_touch.c +++ b/42sh/src/line-editing/get_touch.c @@ -6,7 +6,7 @@ /* 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); else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str))) ft_del(str, i); + else if (ret == TOUCHE_HOME) + ft_home(*str, i); + else if (ret == TOUCHE_END) + ft_end(*str, i); else return (0); 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 || ret == TOUCHE_OPT_V) ft_cxv(ret, i, str); - else if (ret == FLECHE_DROITE || ret == FLECHE_GAUCHE) - ft_move_term(ret, i, *str); + else if (ret == FLECHE_DROITE) + 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) ft_move_to_line(ret, i, *str); else if (ft_isprint(ret)) @@ -67,8 +73,10 @@ char *ft_lecture(t_list_history *head) read(0, &ret, sizeof(int)); if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0) 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) exit(1); if (ft_lecture_2(ret, &str, &i)) @@ -81,8 +89,6 @@ char *ft_lecture(t_list_history *head) else i = 0; } - else if (ret == TOUCHE_HOME || ret == TOUCHE_END) - ft_home_end(str, ret, &i); else if (ft_lecture_3(ret, &str, &i)) continue ; else if (ret == 10) diff --git a/42sh/src/line-editing/get_touch_toolz.c b/42sh/src/line-editing/get_touch_toolz.c index 1f45a11c..06cba8b4 100644 --- a/42sh/src/line-editing/get_touch_toolz.c +++ b/42sh/src/line-editing/get_touch_toolz.c @@ -6,13 +6,14 @@ /* 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" -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) { diff --git a/42sh/src/line-editing/get_touch_toolz_2.c b/42sh/src/line-editing/get_touch_toolz_2.c index 768a1606..c38664e4 100644 --- a/42sh/src/line-editing/get_touch_toolz_2.c +++ b/42sh/src/line-editing/get_touch_toolz_2.c @@ -6,7 +6,7 @@ /* 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,91 +18,90 @@ int ft_put(int nb) 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) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - ft_puttermcaps("cd"); - while (str[*pos]) - ++(*pos); - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); + --(*pos); + ft_get_beggin_with_curs(str, pos); } - else if (ret == TOUCHE_HOME) + ft_puttermcaps("cd"); + while (str[*pos]) + ++(*pos); + ft_get_beggin(str, pos); + ft_current_str(str, *pos); + ft_get_next_str(str, pos); +} + +void ft_home(char *str, size_t *pos) +{ + if (*pos) + { + --(*pos); + ft_get_beggin_with_curs(str, pos); + if (str[*pos + 1] == '\n') + ft_puttermcaps("nd"); + } + ft_puttermcaps("cd"); + *pos = 0; + ft_current_str(str, *pos); + ft_get_next_str(str, pos); + ft_check_end_of_line(str, *pos); + if (!str[*pos]) + --(*pos); + ft_get_beggin_with_curs(str, pos); +} + +void ft_move_right(size_t *pos, char *str) +{ + size_t tmp; + + if (ft_strlen(str) <= *pos) + return ; + if (str[*pos] == '\n') { if (*pos) { - --(*pos); - ft_get_beggin_with_curs(str, pos); - if (str[*pos + 1] == '\n') - ft_puttermcaps("nd"); + tmp = *pos - 1; + ft_get_beggin_with_curs(str, &tmp); } ft_puttermcaps("cd"); - *pos = 0; + ++(*pos); ft_current_str(str, *pos); ft_get_next_str(str, pos); - ft_check_end_of_line(str, *pos); if (!str[*pos]) --(*pos); ft_get_beggin_with_curs(str, pos); } + else + { + ft_putchar(str[*pos]); + ++(*pos); + } } -void ft_move_term(int ret, size_t *pos, char *str) +void ft_move_left(size_t *pos, char *str) { - size_t tmp; - - if (ret == FLECHE_DROITE && str && ft_strlen(str) > *pos) + if (!*pos) + return ; + if (str[*pos - 1] == '\n') { - if (str[*pos] == '\n') + if (*pos - 1 == 0) { - if (*pos) - { - tmp = *pos - 1; - ft_get_beggin_with_curs(str, &tmp); - } - //si premiere ligne ne contient que \n, puis fleche droite -> decalage// ft_puttermcaps("cd"); - ++(*pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (!str[*pos]) - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - else - { - ft_putchar(str[*pos]); - ++(*pos); - } - } - else if (ret == FLECHE_GAUCHE && *pos > 0) - { - if (str[*pos - 1] == '\n') - { - if (*pos - 1 == 0) - { - ft_puttermcaps("cd"); - --(*pos); - return ; - } - ft_puttermcaps("cd"); - (*pos) -= 2; - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - ++(*pos); - } - else - { - ft_puttermcaps("le"); --(*pos); + return ; } + ft_puttermcaps("cd"); + (*pos) -= 2; + ft_get_beggin(str, pos); + ft_current_str(str, *pos); + ft_get_next_str(str, pos); + ++(*pos); + } + else + { + ft_puttermcaps("le"); + --(*pos); } } diff --git a/42sh/src/line-editing/heredoc.c b/42sh/src/line-editing/heredoc.c index b2411c88..649524d0 100644 --- a/42sh/src/line-editing/heredoc.c +++ b/42sh/src/line-editing/heredoc.c @@ -6,13 +6,13 @@ /* 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 */ /* */ /* ************************************************************************** */ #include "minishell.h" -char *ft_get_next_word(char *str) +char *ft_get_next_word(char *str) { int j; int k; @@ -26,32 +26,13 @@ char *ft_get_next_word(char *str) 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 *end; char *tmp; char *tmp2; - i = 0; - end = NULL; 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) { ft_putstr("heredoc> "); @@ -69,3 +50,28 @@ void ft_check_heredoc(char **str) 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); +} diff --git a/42sh/src/line-editing/history_parsing.c b/42sh/src/line-editing/history_parsing.c index 7e5fdecd..ec518952 100644 --- a/42sh/src/line-editing/history_parsing.c +++ b/42sh/src/line-editing/history_parsing.c @@ -6,64 +6,67 @@ /* 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" -static char *ft_strget_history(char *str) +static int ft_history_parsing_4(char *str, int *i) { - 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) + if (!ft_strncmp("!!", str + *i, 2)) { - 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; + ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2); + ++(*i); + return (1); } - return (list->str); + 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 (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; - char *new_str2; - char *new_str3; - - if (!*str) - return ; - new_str = ft_strndup(*str, pos); - new_str3 = ft_strget_history(s); - if (new_str3) + if (ft_history_parsing_4(str, i)) + return (1); + else if (str[*i + 1] == '-') { - 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); + 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 - new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2); - free(s); - free(*str); - *str = new_str3; + return (0); + return (1); } -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; int i; @@ -79,44 +82,11 @@ void ft_history_parsing() if (str[i] == '!') { boolean = 1; - if (!ft_strncmp("!!", str + i, 2)) - { - 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 + if (!ft_history_parsing_3(str, &i)) boolean = 0; } ++i; } if (boolean) - { - 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(); - } + ft_history_parsing_2(); } diff --git a/42sh/src/line-editing/history_parsing_toolz_2.c b/42sh/src/line-editing/history_parsing_toolz_2.c new file mode 100644 index 00000000..eda2bcf0 --- /dev/null +++ b/42sh/src/line-editing/history_parsing_toolz_2.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* history_parsing_toolz_2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/42sh/src/line-editing/line_return_toolz.c b/42sh/src/line-editing/line_return_toolz.c deleted file mode 100644 index 454fe978..00000000 --- a/42sh/src/line-editing/line_return_toolz.c +++ /dev/null @@ -1,107 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* line_return_toolz.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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; - } - } -} diff --git a/42sh/src/line-editing/move_to_line.c b/42sh/src/line-editing/move_to_line.c index 17f154ca..87b3a5d1 100644 --- a/42sh/src/line-editing/move_to_line.c +++ b/42sh/src/line-editing/move_to_line.c @@ -6,16 +6,41 @@ /* 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" +static void ft_up_2(size_t *pos, char *str) +{ + int len; + int i; + + i = 0; + len = ft_size_term(); + if (str[*pos - i] == '\n') + { + --len; + ft_puttermcaps("le"); + ++i; + } + while (*pos - i && str[*pos - i] != '\n' && --len + 1) + { + ft_puttermcaps("le"); + ++i; + } + if (str[*pos - i] == '\n') + { + ft_puttermcaps("nd"); + ++(*pos); + } + (*pos) -= i; +} + static void ft_up(size_t *pos, char *str) { int i; - int len; i = 0; if (str[*pos - 1] == '\n') @@ -28,26 +53,24 @@ static void ft_up(size_t *pos, char *str) ++(*pos); } else + ft_up_2(pos, str); +} + +static void ft_down_2(size_t *pos, char *str) +{ + if (*pos) { - len = ft_size_term(); - if (str[*pos - i] == '\n') - { - --len; - ft_puttermcaps("le"); - ++i; - } - while (*pos - i && str[*pos - i] != '\n' && --len + 1) - { - ft_puttermcaps("le"); - ++i; - } - if (str[*pos - i] == '\n') - { - ft_puttermcaps("nd"); - ++(*pos); - } - (*pos) -= i; + --(*pos); + ft_get_beggin_with_curs(str, pos); } + ft_puttermcaps("cd"); + ft_get_next_str(str, pos); + (*pos) += 2; + ft_current_str(str, *pos); + ft_get_next_str(str, pos); + if (!(str[*pos])) + --(*pos); + ft_get_beggin_with_curs(str, pos); } static void ft_down(size_t *pos, char *str) @@ -57,21 +80,7 @@ static void ft_down(size_t *pos, char *str) i = 0; if (str[*pos] == '\n') - { - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - ft_puttermcaps("cd"); - ft_get_next_str(str, pos); - (*pos) += 2; - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (!(str[*pos])) - --(*pos); - ft_get_beggin_with_curs(str, pos); - } + ft_down_2(pos, str); else { len = ft_size_term(); diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c index 900e0dfa..2dfe8996 100644 --- a/42sh/src/line-editing/print_and_del.c +++ b/42sh/src/line-editing/print_and_del.c @@ -6,7 +6,7 @@ /* 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); } +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) { size_t tmp; @@ -58,15 +71,7 @@ void ft_suppr(char **str, size_t *i) *str = ft_remove_imput((*str), tmp); ft_get_beggin(*str, i); } - 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; + ft_suppr_2(str, i, tmp); } void ft_del(char **str, size_t *i) diff --git a/42sh/src/line-editing/prompt.c b/42sh/src/line-editing/prompt.c index ec630120..94482a27 100644 --- a/42sh/src/line-editing/prompt.c +++ b/42sh/src/line-editing/prompt.c @@ -6,13 +6,15 @@ /* 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" -/* ft_printf de la lib bug avec unicode */ +/* +**ft_printf de la lib bug avec unicode +*/ static void ft_get_date(void) { diff --git a/42sh/src/line-editing/quotes_gest.c b/42sh/src/line-editing/quotes_gest.c index f5ca96e9..caf7ba9d 100644 --- a/42sh/src/line-editing/quotes_gest.c +++ b/42sh/src/line-editing/quotes_gest.c @@ -6,7 +6,7 @@ /* 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; while (s[i]) { - if (s[i] == '\'') + if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)) { simp = 1; ++i; - while (s[i] && s[i] != '\'') + while (s[i] && !(s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))) ++i; - if (s[i] == '\'') + if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)) simp = 0; } - else if (s[i] == '"') + else if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i)) { doub = 1; ++i; - while (s[i] && s[i] != '"') + while (s[i] && !(s[i] == '"' && ((i && s[i - 1] != '\\') || !i))) ++i; - if (s[i] == '"') + if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i)) doub = 0; } if (s[i]) diff --git a/42sh/src/line-editing/reader.c b/42sh/src/line-editing/reader.c index 7c647b55..4a3e17d3 100644 --- a/42sh/src/line-editing/reader.c +++ b/42sh/src/line-editing/reader.c @@ -6,12 +6,31 @@ /* 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" +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]) { 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) { - int i; int j; char t[5]; j = 0; - i = 0; - if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || input == 126 || - input == 993090331 || input == 925981467 || input == 21298 || - input == 892427035 || input == 8270395 || input == 942758683 || - input == 993090331 || input == 18489 || input == 17977) - + if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || + input == 126 || input == 993090331 || input == 925981467 || + input == 21298 || input == 892427035 || input == 8270395 || + input == 942758683 || input == 993090331 || input == 18489 || input == 17977) return ; ft_read_it_2(input, t); - 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; - } + ft_read_it_3(str, t, pos, &j); ft_putstr((*str) + (*pos) - j); ft_putnc('\b', ft_strlen((*str)) - ((*pos))); } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 6903af81..af9225b3 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* 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); } +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) { + signal(SIGWINCH, ft_reset_stats_term); if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1) return (-1); if (data_singleton()->line.input)