From f8753ccae1fa1ae644cf075d9e0bbfe35aa241b1 Mon Sep 17 00:00:00 2001 From: Emeline Saley Date: Mon, 27 Feb 2017 13:09:53 +0100 Subject: [PATCH] Rebase current --- 42sh/src/completion/c_binary.c | 5 +++-- 42sh/src/completion/c_clear.c | 6 +++++- 42sh/src/completion/c_files.c | 20 ++++++++++++++++---- 42sh/src/completion/c_init.c | 5 +++-- 42sh/src/completion/c_matching.c | 4 ++-- 42sh/src/completion/c_output.c | 2 +- 42sh/src/completion/c_parser.c | 4 +--- 42sh/src/completion/c_rematch.c | 13 ++++--------- 42sh/src/completion/c_sizing.c | 6 ++++-- 42sh/src/completion/c_terminal.c | 21 ++++++++++++++++++++- 42sh/src/completion/completion.c | 13 ++++++------- 11 files changed, 65 insertions(+), 34 deletions(-) diff --git a/42sh/src/completion/c_binary.c b/42sh/src/completion/c_binary.c index bccc73d8..226de97c 100644 --- a/42sh/src/completion/c_binary.c +++ b/42sh/src/completion/c_binary.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:30:57 by alao #+# #+# */ -/* Updated: 2017/02/16 21:03:18 by alao ### ########.fr */ +/* Updated: 2017/02/17 14:56:04 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,8 @@ int c_seek_binary(t_data *s, t_comp *c) if (!(tmp = ft_strdup(ft_getenv(s->env, "PATH")))) return (-1); paths = ft_strsplit(tmp, ':'); - c->match = ft_strdup(c->rcmd); + if (c->match == NULL) + c->match = ft_strdup(c->rcmd); while (paths[i]) c_parser(c, paths[i++], c->rcmd); tmp ? ft_memdel((void *)&tmp) : (0); diff --git a/42sh/src/completion/c_clear.c b/42sh/src/completion/c_clear.c index 815d12b5..f95749c0 100644 --- a/42sh/src/completion/c_clear.c +++ b/42sh/src/completion/c_clear.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:37:43 by alao #+# #+# */ -/* Updated: 2017/02/16 22:03:41 by alao ### ########.fr */ +/* Updated: 2017/02/17 14:57:09 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,8 @@ int c_clear_lst(t_comp *c) t_clst *c_lst; t_clst *p_lst; + if (c->lst == NULL) + return (0); c_lst = c->lst; c->lst->prev ? (c->lst = c->lst->prev) : (0); c_lst->prev->next = NULL; @@ -48,6 +50,8 @@ int c_clear(t_data *s) { t_comp *ptr; + if (s->comp == NULL) + return (0); ptr = s->comp; ptr->rcmd ? ft_memdel((void *)&ptr->rcmd) : (0); ptr->match ? ft_memdel((void *)&ptr->match) : (0); diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index dba7bc4f..bfbee103 100644 --- a/42sh/src/completion/c_files.c +++ b/42sh/src/completion/c_files.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */ -/* Updated: 2017/02/16 22:14:51 by alao ### ########.fr */ +/* Updated: 2017/02/17 15:34:30 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,15 +27,22 @@ static int c_exclusion_folder(t_comp *c) char *tmp2; tmp = ft_strjoin(c->cpath, c->match); + tmp2 = NULL; if ((rep = opendir(tmp)) && (!closedir(rep))) { + tmp ? ft_memdel((void *)&tmp) : (0); + if (c->rcmd[ft_strlen(c->rcmd) - 1] == '/') + { + c_clear(data_singleton()); + return (0); + } tmp2 = ft_strjoin(c->match, "/"); c_updater(c, tmp2); - tmp ? ft_memdel((void *)&tmp) : (0); tmp2 ? ft_memdel((void *)&tmp2) : (0); return (1); } tmp ? ft_memdel((void *)&tmp) : (0); + tmp ? ft_memdel((void *)&tmp) : (0); return (0); } /* @@ -63,7 +70,7 @@ static char *c_slicer(t_comp *c) i--; tmp[i] == '/' ? i++ : (0); rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i); - if (i <= (int)ft_strlen(tmp) - i + 1) +// if (i <= (int)ft_strlen(tmp) - i + 1) c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i); tmp ? ft_memdel((void *)&tmp) : (0); return (rt); @@ -85,7 +92,12 @@ int c_seek_files(t_data *s, t_comp *c) path ? ft_memdel((void *)&path) : (0); } c_parser(c, c->cpath, c->match); - if (c->lst == NULL) + if (c->lst == NULL && c->isrematch == 0) c_exclusion_folder(c); + else if ((c->lst && (c->lst == c->lst->next)) && c->isrematch == 0) + { + if (c->match && ft_strequ(c->match, c->lst->name)) + c_exclusion_folder(c); + } return (0); } diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index d9701694..7c327de1 100644 --- a/42sh/src/completion/c_init.c +++ b/42sh/src/completion/c_init.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 11:21:16 by alao #+# #+# */ -/* Updated: 2017/02/16 22:08:25 by alao ### ########.fr */ +/* Updated: 2017/02/17 13:44:39 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,9 +55,11 @@ static void c_init_base(t_comp *c) ioctl(0, TIOCGWINSZ, &win); c->win_x = win.ws_col; + c->win_y = win.ws_row; c->cutpoint = 0; c->between = NULL; c->isfolder = 0; + c->isrematch = 0; c->match = NULL; c->cpath = NULL; c->lst = NULL; @@ -72,7 +74,6 @@ static void c_init_base(t_comp *c) void c_init(t_data *s, long int input) { - int len_trail; if (!(s->comp = (t_comp *)malloc((sizeof(t_comp))))) diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index 761f6ef3..cce8fad7 100644 --- a/42sh/src/completion/c_matching.c +++ b/42sh/src/completion/c_matching.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/02/16 21:57:47 by alao ### ########.fr */ +/* Updated: 2017/02/17 12:29:20 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,7 @@ int c_matching(t_data *s, t_comp *c) c_seek_binary(s, c); else c_seek_files(s, c); - if (s->comp && c->lst) + if (s->comp && s->comp->lst) { c_sizing(c); return (1); diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index 6b9f280d..3e37f799 100644 --- a/42sh/src/completion/c_output.c +++ b/42sh/src/completion/c_output.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */ -/* Updated: 2017/02/16 22:00:38 by alao ### ########.fr */ +/* Updated: 2017/02/17 13:44:51 by alao ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index f611f4df..304c6611 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/02/16 22:00:49 by alao ### ########.fr */ +/* Updated: 2017/02/17 15:34:57 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,8 +49,6 @@ static int c_storing(t_comp *c, char *value, unsigned char type) return (0); if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1) return (0); - if (c->match && ft_strequ(c->match, value)) - return (0); if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) return (-1); tmp->name = ft_strdup(value); diff --git a/42sh/src/completion/c_rematch.c b/42sh/src/completion/c_rematch.c index 13421f70..f11e1cc3 100644 --- a/42sh/src/completion/c_rematch.c +++ b/42sh/src/completion/c_rematch.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/02/16 22:03:42 by alao ### ########.fr */ +/* Updated: 2017/02/17 14:57:22 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,22 +50,17 @@ int c_rematch(t_comp *c, long int keypress) { if (ft_isascii(keypress)) { + c->isrematch = 1; c_term_clear(c); c_refresh_match(c, keypress); c_clear_lst(c); c_matching(data_singleton(), c); if (c->lst == NULL) - { c_clear(data_singleton()); - return (1); - } else if (c->lst == c->lst->next) return (1); - else - { - ft_print(keypress); - return(1); - } + ft_print(keypress); + return(1); } else { diff --git a/42sh/src/completion/c_sizing.c b/42sh/src/completion/c_sizing.c index 2d7adda9..78892cff 100644 --- a/42sh/src/completion/c_sizing.c +++ b/42sh/src/completion/c_sizing.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 08:50:26 by alao #+# #+# */ -/* Updated: 2017/02/16 22:01:47 by alao ### ########.fr */ +/* Updated: 2017/02/17 13:45:33 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,10 +56,12 @@ int c_sizing(t_comp *c) c->c_line = 0; while ((c->c_line * c->c_pline) < c->c_sy) c->c_line++; - if (c->win_x < c->c_sx) + if ((c->win_x < c->c_sx)) { c->c_pline = 0; c->c_line = 0; } + if ((c->win_y < c->c_line)) + c_clear(data_singleton()); return (0); } diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 1b5d28a2..4fdc60b1 100644 --- a/42sh/src/completion/c_terminal.c +++ b/42sh/src/completion/c_terminal.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/11 10:44:40 by alao #+# #+# */ -/* Updated: 2017/02/16 22:01:37 by alao ### ########.fr */ +/* Updated: 2017/02/17 18:36:56 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,3 +84,22 @@ void c_term_mv_down(t_comp *c) i++; } } + +/* +** If the terminal has chaged in size, the function will refresh these values +** and clear the previous print list. +*/ + +int c_term_resize(t_comp *c) +{ + struct winsize win; + + ioctl(0, TIOCGWINSZ, &win); + if ((win.ws_col == c->win_x) && (win.ws_row == c->win_y)) + return (0); + c->win_x = win.ws_col; + c->win_y = win.ws_row; + c_sizing(c); + c_term_clear(c); + return (0); +} diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index 42705b56..d84c9a9e 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/02/16 22:01:18 by alao ### ########.fr */ +/* Updated: 2017/02/17 18:36:14 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,18 +38,16 @@ static void c_next_item(t_comp *c) static int c_dispatcher(t_data *s) { - if (s->comp && s->comp->lst == NULL && s->comp->isfolder) - { - c_clear(s); - return (1); - } if (s->comp && s->comp->lst == NULL) { c_clear(s); return (1); } else if (s->comp && s->comp->lst == s->comp->lst->next) - return (c_updater(s->comp, s->comp->lst->name)); + { + c_updater(s->comp, s->comp->lst->name); + return (1); + } else if (s->comp && s->comp->lst != s->comp->lst->next) { c_term_mv_down(s->comp); @@ -96,6 +94,7 @@ int completion(long int keypress) } else { + c_term_resize(s->comp); if (keypress == TOUCHE_TAB) c_next_item(s->comp); else