From f8753ccae1fa1ae644cf075d9e0bbfe35aa241b1 Mon Sep 17 00:00:00 2001 From: Emeline Saley Date: Mon, 27 Feb 2017 13:09:53 +0100 Subject: [PATCH 01/17] 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 From 2265938254d9b4297ae07ca0a6a8dfffe5329aca Mon Sep 17 00:00:00 2001 From: M600 Date: Mon, 27 Feb 2017 13:17:42 +0100 Subject: [PATCH 02/17] Rebase --- 42sh/src/completion/c_binary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/42sh/src/completion/c_binary.c b/42sh/src/completion/c_binary.c index 226de97c..01de0087 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/17 14:56:04 by alao ### ########.fr */ +/* Updated: 2017/02/27 13:17:27 by alao ### ########.fr */ /* */ /* ************************************************************************** */ From c1b3704cab134b96c3890487a0e5f7e105250a72 Mon Sep 17 00:00:00 2001 From: M600 Date: Mon, 27 Feb 2017 13:25:15 +0100 Subject: [PATCH 03/17] Include rebase --- 42sh/includes/completion.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 76b10e06..7d043215 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/02/17 11:10:48 by gwojda ### ########.fr */ +/* Updated: 2017/02/18 14:35:10 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define COMPLETION_H # include "minishell.h" +#define RETARDED_BEHAVIOR 0 /* ** Autocompletion list for the valid candidates from the parser. @@ -55,6 +56,7 @@ typedef struct s_clst ** c_pline : Number of item per line when printing. ** c_line : Number of line required to move to terminal up. ** win_x : Size of the window in length. +** win_y : Size of the window in height. ** key : The keypressed lastly. ** isfolder : If the match is a folder. boolean. ** lst : List of the item corresponding to the completion. @@ -90,8 +92,10 @@ typedef struct s_comp int c_pline; int c_line; int win_x; + int win_y; int key; int isfolder; + int isrematch; t_clst *lst; } t_comp; @@ -132,12 +136,14 @@ int c_rematch(t_comp *c, long int keypress); ** c_term_mv_down : Make space for the list. ** c_term_mv_back : Reset the cursor position. ** c_term_clear : Delete the list from the terminal. +** c_term_resize : Refresh win_x and win_y. ** c_printer : Printer of the list. */ void c_term_mv_down(t_comp *c); void c_term_mv_back(t_comp *c); void c_term_clear(t_comp *c); +int c_term_resize(t_comp *c); void c_printer(t_comp *c); /* @@ -151,12 +157,9 @@ void c_printer(t_comp *c); int c_clear(t_data *s); int c_clear_lst(t_comp *c); char *path_solver(t_comp *c, char *cmd, char *cwd); - -/* -** ajout rapide gwojda pour compiler : -*/ - -int ft_sstrlen(char **s); -char *ft_sstrtostr(char **s, char *sep); +int c_spacing_escape(t_clst *node, int x, int o); +int c_spacing_clear(t_comp *c); +int ft_sstrlen(char **s); +char *ft_sstrtostr(char **s, char *sep); #endif From 4d805a1c7431e3401b9b0493e4c7e947a73a44f3 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 8 Mar 2017 13:39:41 +0100 Subject: [PATCH 04/17] completion a partir de la racine ok (sauf si jai fait des betises) --- 42sh/includes/completion.h | 8 +++++++- 42sh/src/completion/c_files.c | 4 ++-- 42sh/src/completion/c_init.c | 2 +- 42sh/src/completion/c_matching.c | 7 ++++--- 42sh/src/completion/c_parser.c | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 7d043215..630f5b7b 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/02/18 14:35:10 by alao ### ########.fr */ +/* Updated: 2017/03/08 13:34:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -162,4 +162,10 @@ int c_spacing_clear(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); +/* +** yolo je mets ca au pif - gwojda +*/ + +int c_exclusion_folder(t_comp *c); + #endif diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index bfbee103..4586095f 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/17 15:34:30 by alao ### ########.fr */ +/* Updated: 2017/03/08 13:33:13 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ ** Returning 1 if success (trigger an update) or 0. */ -static int c_exclusion_folder(t_comp *c) +int c_exclusion_folder(t_comp *c) { DIR *rep; char *tmp; diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index 7c327de1..d1529e0b 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/17 13:44:39 by alao ### ########.fr */ +/* Updated: 2017/03/08 12:18:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index cce8fad7..bc639b2d 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/17 12:29:20 by alao ### ########.fr */ +/* Updated: 2017/03/08 13:33:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,9 +29,10 @@ int c_matching(t_data *s, t_comp *c) { if (c->rcmd[0] == '.' || c->rcmd[0] == '/') { - c->rcmd[0] == '.' ? c->cpath = path_solver(c, "./", NULL) : 0; - c->rcmd[0] == '/' ? c->cpath = path_solver(c, "/", NULL) : 0; + c->cpath = ft_strndup(c->rcmd, ft_strrchr(c->rcmd, '/') - c->rcmd + 1); + !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; c_parser(c, c->cpath, c->match); + c_exclusion_folder(c); } else if (!(ft_strchr(c->rcmd, ' '))) c_seek_binary(s, c); diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index 304c6611..d8cb5f2b 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/17 15:34:57 by alao ### ########.fr */ +/* Updated: 2017/03/08 12:56:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ From 301ec53259d77677183f1d7fd0603e14a033d37f Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 8 Mar 2017 13:48:37 +0100 Subject: [PATCH 05/17] j'avais fait des betises --- 42sh/includes/completion.h | 8 +------- 42sh/src/completion/c_files.c | 4 ++-- 42sh/src/completion/c_matching.c | 26 +++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 630f5b7b..dc826172 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/08 13:34:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:46:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -162,10 +162,4 @@ int c_spacing_clear(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); -/* -** yolo je mets ca au pif - gwojda -*/ - -int c_exclusion_folder(t_comp *c); - #endif diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index 4586095f..3196a90d 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/03/08 13:33:13 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:46:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ ** Returning 1 if success (trigger an update) or 0. */ -int c_exclusion_folder(t_comp *c) +static int c_exclusion_folder(t_comp *c) { DIR *rep; char *tmp; diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index bc639b2d..bbbd8fa3 100644 --- a/42sh/src/completion/c_matching.c +++ b/42sh/src/completion/c_matching.c @@ -6,12 +6,36 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/08 13:33:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:47:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +static int c_exclusion_folder(t_comp *c) +{ + DIR *rep; + char *tmp; + char *tmp2; + + tmp = ft_strjoin(c->cpath, c->match); + tmp2 = NULL; + if (tmp[ft_strlen(tmp) - 1] == '/') + return (0); + if ((rep = opendir(tmp)) && (!closedir(rep))) + { + tmp ? ft_memdel((void *)&tmp) : (0); + tmp2 = ft_strjoin(c->match, "/"); + c_updater(c, tmp2); + tmp2 ? ft_memdel((void *)&tmp2) : (0); + ft_strdel(&c->match); + c->match = ft_strdup("/"); + return (1); + } + tmp ? ft_memdel((void *)&tmp) : (0); + tmp ? ft_memdel((void *)&tmp) : (0); + return (0); +} /* ** Start the parsing for the autocompletion. ** Check the first char of the c->rcmd for a . or /. to see if it's a local From 8cad57fc8e2d930983235a5ea810c9596792a8e5 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 8 Mar 2017 16:07:12 +0100 Subject: [PATCH 06/17] fixe #49 --- 42sh/src/completion/c_files.c | 12 +++++++++-- 42sh/src/completion/c_matching.c | 34 +++++++++++++++++++++++++++++--- 42sh/src/completion/c_parser.c | 2 +- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index 3196a90d..096ade88 100644 --- a/42sh/src/completion/c_files.c +++ b/42sh/src/completion/c_files.c @@ -6,11 +6,12 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */ -/* Updated: 2017/03/08 13:46:46 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 16:06:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +int c_chevron(t_comp *c); /* ** If the parsing for local file fail. The function is called to check if the @@ -70,7 +71,9 @@ 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 (c_chevron(c)) + c->match = ft_strdup(""); + else c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i); tmp ? ft_memdel((void *)&tmp) : (0); return (rt); @@ -85,6 +88,11 @@ int c_seek_files(t_data *s, t_comp *c) char *path; (void)s; + if (c->rcmd[0] == '.') + { + c->cpath = ft_strdup("./"); + c->match = ft_strdup("."); + } if (c->cpath == NULL) { path = c_slicer(c); diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index bbbd8fa3..f47db9d5 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/03/08 13:47:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 16:06:13 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,26 @@ static int c_exclusion_folder(t_comp *c) tmp ? ft_memdel((void *)&tmp) : (0); return (0); } +/* +** chevron y es-tu ??? +*/ + +int c_chevron(t_comp *c) +{ + size_t pos; + + pos = c->ircmd; + while (pos) + { + if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') + return (1); + --pos; + } + if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') + return (1); + return (0); +} + /* ** Start the parsing for the autocompletion. ** Check the first char of the c->rcmd for a . or /. to see if it's a local @@ -51,14 +71,22 @@ static int c_exclusion_folder(t_comp *c) int c_matching(t_data *s, t_comp *c) { - if (c->rcmd[0] == '.' || c->rcmd[0] == '/') + char *tmp; + + if (ft_strchr(c->rcmd, '/')) { c->cpath = ft_strndup(c->rcmd, ft_strrchr(c->rcmd, '/') - c->rcmd + 1); + if (c->rcmd[0] == '~') + { + tmp = c->cpath; + c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); + free(tmp); + } !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; c_parser(c, c->cpath, c->match); c_exclusion_folder(c); } - else if (!(ft_strchr(c->rcmd, ' '))) + else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c)) c_seek_binary(s, c); else c_seek_files(s, c); diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index d8cb5f2b..b5d60ac9 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/03/08 12:56:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 15:47:58 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ From 0872af38f0ab78d676ee2b37dfe87452df341c46 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 9 Mar 2017 17:29:55 +0100 Subject: [PATCH 07/17] ajout module de glob + match sur les vars d'environnement --- 42sh/Makefile | 3 + 42sh/includes/completion.h | 10 ++- 42sh/includes/ft_readline.h | 4 +- 42sh/src/c_seek_env.c | 55 +++++++++++++ 42sh/src/completion/c_abs_path.c | 27 +++++++ 42sh/src/completion/c_glob_matching.c | 72 +++++++++++++++++ 42sh/src/completion/c_init.c | 4 +- 42sh/src/completion/c_matching.c | 24 ++++-- 42sh/src/completion/c_parser.c | 4 +- 42sh/src/completion/completion.c | 4 +- 42sh/src/line-editing/completion.c | 37 ++++++--- .../lib_line_editing/ft_nb_line.c | 25 ++++++ .../lib_line_editing/toolz_termcaps.c | 4 +- 42sh/test | 77 +++++++++++++++++++ 42sh/testmake | 1 + 42sh/tost | 0 16 files changed, 328 insertions(+), 23 deletions(-) create mode 100644 42sh/src/c_seek_env.c create mode 100644 42sh/src/completion/c_abs_path.c create mode 100644 42sh/src/completion/c_glob_matching.c create mode 100644 42sh/src/line-editing/lib_line_editing/ft_nb_line.c create mode 100644 42sh/test create mode 100644 42sh/testmake create mode 100644 42sh/tost diff --git a/42sh/Makefile b/42sh/Makefile index 4fd57af5..dc8ffbfd 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -44,9 +44,11 @@ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ +c_seek_env.c\ completion/c_binary.c\ completion/c_clear.c\ completion/c_files.c\ +completion/c_glob_matching.c\ completion/c_init.c\ completion/c_matching.c\ completion/c_misc.c\ @@ -194,6 +196,7 @@ line-editing/copy_cut_paste.c\ line-editing/ft_prompt.c\ line-editing/get_key.c\ line-editing/home_end.c\ +line-editing/lib_line_editing/ft_nb_line.c\ line-editing/lib_line_editing/tool_line.c\ line-editing/lib_line_editing/tool_line_2.c\ line-editing/lib_line_editing/toolz.c\ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index dc826172..06d71d79 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/08 13:46:51 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 15:58:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -162,4 +162,12 @@ int c_spacing_clear(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); +/* +** j'ajoute a la va vite^^ +*/ + +int c_glob_matching(void); +int c_seek_env(t_comp *c, char *current_word); +void c_add_to_lst(t_comp *c, t_clst *node); + #endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 06b7f449..3a434f35 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/02/16 12:44:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 17:43:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -152,6 +152,8 @@ char *ft_strget_history(char *str); int ft_nb_last_line(char *str, size_t pos); int ft_put(int nb); void ft_check_line(void); +int ft_nb_of_line(char *str, size_t pos); +int ft_get_size_prev(char *str, size_t pos); char *ft_read_stdin(void); void ft_end(void); diff --git a/42sh/src/c_seek_env.c b/42sh/src/c_seek_env.c new file mode 100644 index 00000000..9c3680c0 --- /dev/null +++ b/42sh/src/c_seek_env.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_seek_env.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ +/* Updated: 2017/03/09 16:52:57 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int c_storing(t_comp *c, char *value) +{ + t_clst *tmp; + + if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) + return (-1); + tmp->name = value; + tmp->len = ft_strlen(tmp->name); + tmp->type = 10; + tmp->cursor = 0; + c_add_to_lst(c, tmp); + return (0); +} + +static void c_maj_rcmd(t_comp *c, char *current_word) +{ + char *tmp; + + tmp = c->rcmd; + c->rcmd = ft_strndup(c->rcmd, current_word - c->rcmd + 1); + free(tmp); +} + +int c_seek_env(t_comp *c, char *current_word) +{ + char *match; + char **env; + int i; + + i = 0; + env = data_singleton()->env; + match = ft_strdupi_w(current_word + 1); + c_maj_rcmd(c, current_word); + while (env[i]) + { + if (!ft_strncmp(match, env[i], ft_strlen(match))) + c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); + ++i; + } + return (0); +} diff --git a/42sh/src/completion/c_abs_path.c b/42sh/src/completion/c_abs_path.c new file mode 100644 index 00000000..a7519125 --- /dev/null +++ b/42sh/src/completion/c_abs_path.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_abs_path.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ +/* Updated: 2017/03/09 16:55:45 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "completion.h" + +void c_seek_abs_path(t_comp *c) +{ + c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1); + if (current_word[0] == '~') + { + tmp = c->cpath; + c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); + free(tmp); + } + !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; + c_parser(c, c->cpath, c->match); + c_exclusion_folder(c); +} diff --git a/42sh/src/completion/c_glob_matching.c b/42sh/src/completion/c_glob_matching.c new file mode 100644 index 00000000..2efdddc0 --- /dev/null +++ b/42sh/src/completion/c_glob_matching.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_glob_matching.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ +/* Updated: 2017/03/09 17:29:01 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void c_replace_globbing(char **glob, size_t start) +{ + char *ref_next; + char *ref_mid; + char *ref_prev; + char *str; + size_t pos; + + str = data_singleton()->line.input; + pos = data_singleton()->line.pos; + while (str[pos] && str[pos] != ' ') + ++pos; + while (str[pos] && str[pos] == ' ') + ++pos; + ref_prev = ft_strndup(str, start); + ref_mid = ft_sstrtostr(glob, " "); + ref_next = ft_strdup(str + pos); + data_singleton()->line.input = ft_str3join(ref_prev, ref_mid, ref_next); + free(ref_prev); + free(ref_mid); + free(ref_next); + free(str); +} + +int c_glob_matching(void) +{ + char *current_word; + char **ss_glob; + unsigned char *glob_echap; + char *str; + size_t pos; + + str = data_singleton()->line.input; + pos = data_singleton()->line.pos; + if (!str) + return (0); + if (pos && str[pos] == ' ') + --pos; + while (pos && str[pos] != ' ') + --pos; + if (str[pos] == ' ') + ++pos; + current_word = ft_strdupi_w(str + pos); + if (current_word[0] == '$') + { + free(current_word); + return (0); + } + glob_echap = (unsigned char *)ft_strnew(ft_strlen(str) >> 3); + ft_bzero(glob_echap, ft_strlen(str) >> 3); +// glob = glob(current_word, glob_echap, glob_echap, 1); + ss_glob = glob(current_word, glob_echap, glob_echap); + free(current_word); + if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) + return (0); + c_replace_globbing(ss_glob, pos); + return (1); +} diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index d1529e0b..f7df54b5 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/03/08 12:18:07 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 14:45:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ static void c_init_base(t_comp *c) ** structure data and call for the c_matching() function. */ -void c_init(t_data *s, long int input) +void c_init(t_data *s, long int input) { int len_trail; diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index f47db9d5..50b1932e 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/03/08 16:06:13 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 17:25:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,6 @@ static int c_exclusion_folder(t_comp *c) tmp2 = ft_strjoin(c->match, "/"); c_updater(c, tmp2); tmp2 ? ft_memdel((void *)&tmp2) : (0); - ft_strdel(&c->match); - c->match = ft_strdup("/"); return (1); } tmp ? ft_memdel((void *)&tmp) : (0); @@ -69,14 +67,28 @@ int c_chevron(t_comp *c) ** Else 0 is returned. */ +static char *c_current_words(t_comp *c) +{ + int pos; + + pos = c->ircmd; + while (pos && c->rcmd[pos] != ' ') + --pos; + if (c->rcmd[pos] == ' ') + ++pos; + return (c->rcmd + pos); +} + int c_matching(t_data *s, t_comp *c) { + char *current_word; char *tmp; + current_word = c_current_words(c); if (ft_strchr(c->rcmd, '/')) { - c->cpath = ft_strndup(c->rcmd, ft_strrchr(c->rcmd, '/') - c->rcmd + 1); - if (c->rcmd[0] == '~') + c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1); + if (current_word[0] == '~') { tmp = c->cpath; c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); @@ -86,6 +98,8 @@ int c_matching(t_data *s, t_comp *c) c_parser(c, c->cpath, c->match); c_exclusion_folder(c); } + else if (ft_strchr(c->rcmd, '$')) + c_seek_env(c, current_word); else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c)) c_seek_binary(s, c); else diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index b5d60ac9..38a45cfd 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/03/08 15:47:58 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 16:47:31 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ ** Add the matching element to the list */ -static void c_add_to_lst(t_comp *c, t_clst *node) +void c_add_to_lst(t_comp *c, t_clst *node) { if (c->lst == NULL) { diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index d84c9a9e..d92dea80 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/17 18:36:14 by alao ### ########.fr */ +/* Updated: 2017/03/09 14:44:52 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,8 @@ int completion(long int keypress) t_data *s; s = data_singleton(); + if (c_glob_matching()) + return (1); if (s->comp == NULL) { if (s->line.pos == 0) diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index 0e09cc3f..10caf891 100644 --- a/42sh/src/line-editing/completion.c +++ b/42sh/src/line-editing/completion.c @@ -6,36 +6,55 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ -/* Updated: 2017/02/16 14:22:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 15:20:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_completion(int ret) +static size_t ft_strleni_w(char *str, size_t pos, char c) +{ + size_t len; + + len = 0; + if (!STR) + return (0); + while (str[pos] && str[pos] != c) + { + ++len; + ++pos; + } + return (len); +} + +int ft_completion(int ret) { size_t tmp; size_t pos_tmp; - int beg_len; + size_t right; char boolean; boolean = 0; - beg_len = ft_strlen(data_singleton()->line.input); + pos_tmp = POS; + right = ft_strleni_w(STR, POS, '\n'); if (((ret != TOUCHE_TAB && ret != 10) || (ret == 10)) && !(data_singleton()->comp)) return (0); - tmp = POS; - pos_tmp = POS; if (data_singleton()->comp || ret == TOUCHE_TAB) boolean = completion(ret); if (boolean || ret == 10) { + if (pos_tmp) + --pos_tmp; + else + ft_puttermcaps("nd"); + ft_get_beggin_with_curs(STR, &pos_tmp); + tmp = pos_tmp; ft_puttermcaps("cd"); ft_current_str(STR, tmp); ft_get_next_str(STR, &tmp); - ft_putnc('\b', tmp - - (pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len)); - POS = pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len; + ft_putnc('\b', right); + POS = ft_strleni_w(STR, pos_tmp, '\n') - right; } return (1); } diff --git a/42sh/src/line-editing/lib_line_editing/ft_nb_line.c b/42sh/src/line-editing/lib_line_editing/ft_nb_line.c new file mode 100644 index 00000000..c8fef299 --- /dev/null +++ b/42sh/src/line-editing/lib_line_editing/ft_nb_line.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_nb_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 17:11:57 by gwojda #+# #+# */ +/* Updated: 2017/03/08 17:43:14 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int ft_nb_of_line(char *str, size_t pos) +{ + int len; + + len = 1; + if (pos && str[pos] == '\n') + --pos; + len += data_singleton()->line.prompt_size; + len += ft_get_size_prev(str, pos); + return (len / ft_size_term()); +} diff --git a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c index 637b5aef..6de15a4d 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c +++ b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ -/* Updated: 2017/02/14 11:13:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 17:10:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ int ft_nb_last_line(char *str, size_t pos) --pos; len += data_singleton()->line.prompt_size; len += ft_get_size_prev(str, pos); - return ((len) ? len % ft_size_term() : -1); + return (len % ft_size_term()); } void ft_check_end_of_line(char *str, size_t pos) diff --git a/42sh/test b/42sh/test new file mode 100644 index 00000000..7572deac --- /dev/null +++ b/42sh/test @@ -0,0 +1,77 @@ + shell_init.c 28 interactive shell settings + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = / + c_glob_matching.c 66 current str = /Applications + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib + c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib diff --git a/42sh/testmake b/42sh/testmake new file mode 100644 index 00000000..5ceb6d13 --- /dev/null +++ b/42sh/testmake @@ -0,0 +1 @@ + shell_init.c 28 interactive shell settings diff --git a/42sh/tost b/42sh/tost new file mode 100644 index 00000000..e69de29b From 34ea7ec36a035ac89b15da082e4a789126ee61e9 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 9 Mar 2017 17:30:11 +0100 Subject: [PATCH 08/17] ajout module de glob + match sur les vars d'environnement --- 42sh/test | 77 --------------------------------------------------- 42sh/testmake | 1 - 42sh/tost | 0 3 files changed, 78 deletions(-) delete mode 100644 42sh/test delete mode 100644 42sh/testmake delete mode 100644 42sh/tost diff --git a/42sh/test b/42sh/test deleted file mode 100644 index 7572deac..00000000 --- a/42sh/test +++ /dev/null @@ -1,77 +0,0 @@ - shell_init.c 28 interactive shell settings - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = / - c_glob_matching.c 66 current str = /Applications - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/ - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib - c_glob_matching.c 66 current str = /Applications/CocoaDialog.app/Contents/Resources/Inputbox.nib/keyedobjects.nib diff --git a/42sh/testmake b/42sh/testmake deleted file mode 100644 index 5ceb6d13..00000000 --- a/42sh/testmake +++ /dev/null @@ -1 +0,0 @@ - shell_init.c 28 interactive shell settings diff --git a/42sh/tost b/42sh/tost deleted file mode 100644 index e69de29b..00000000 From 7508a136b2ef3f7e36bcf75ec032b926cb8c3413 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 9 Mar 2017 17:35:42 +0100 Subject: [PATCH 09/17] on compile mnt --- 42sh/Makefile | 1 + 42sh/includes/completion.h | 5 +++-- 42sh/src/completion/c_abs_path.c | 29 ++++++++++++++++++++++-- 42sh/src/completion/c_matching.c | 38 ++------------------------------ 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index dc8ffbfd..f410aef1 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -45,6 +45,7 @@ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ c_seek_env.c\ +completion/c_abs_path.c\ completion/c_binary.c\ completion/c_clear.c\ completion/c_files.c\ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 06d71d79..61943c44 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/09 15:58:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 17:34:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -167,7 +167,8 @@ char *ft_sstrtostr(char **s, char *sep); */ int c_glob_matching(void); -int c_seek_env(t_comp *c, char *current_word); void c_add_to_lst(t_comp *c, t_clst *node); +int c_seek_env(t_comp *c, char *current_word); +void c_seek_abs_path(t_comp *c, char *current_word); #endif diff --git a/42sh/src/completion/c_abs_path.c b/42sh/src/completion/c_abs_path.c index a7519125..cd2537c8 100644 --- a/42sh/src/completion/c_abs_path.c +++ b/42sh/src/completion/c_abs_path.c @@ -6,14 +6,39 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/09 16:55:45 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 17:34:43 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -void c_seek_abs_path(t_comp *c) +static int c_exclusion_folder(t_comp *c) { + DIR *rep; + char *tmp; + char *tmp2; + + tmp = ft_strjoin(c->cpath, c->match); + tmp2 = NULL; + if (tmp[ft_strlen(tmp) - 1] == '/') + return (0); + if ((rep = opendir(tmp)) && (!closedir(rep))) + { + tmp ? ft_memdel((void *)&tmp) : (0); + tmp2 = ft_strjoin(c->match, "/"); + c_updater(c, tmp2); + tmp2 ? ft_memdel((void *)&tmp2) : (0); + return (1); + } + tmp ? ft_memdel((void *)&tmp) : (0); + tmp ? ft_memdel((void *)&tmp) : (0); + return (0); +} + +void c_seek_abs_path(t_comp *c, char *current_word) +{ + char *tmp; + c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1); if (current_word[0] == '~') { diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index 50b1932e..d85cd257 100644 --- a/42sh/src/completion/c_matching.c +++ b/42sh/src/completion/c_matching.c @@ -6,34 +6,12 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/09 17:25:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 17:35:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -static int c_exclusion_folder(t_comp *c) -{ - DIR *rep; - char *tmp; - char *tmp2; - - tmp = ft_strjoin(c->cpath, c->match); - tmp2 = NULL; - if (tmp[ft_strlen(tmp) - 1] == '/') - return (0); - if ((rep = opendir(tmp)) && (!closedir(rep))) - { - tmp ? ft_memdel((void *)&tmp) : (0); - tmp2 = ft_strjoin(c->match, "/"); - c_updater(c, tmp2); - tmp2 ? ft_memdel((void *)&tmp2) : (0); - return (1); - } - tmp ? ft_memdel((void *)&tmp) : (0); - tmp ? ft_memdel((void *)&tmp) : (0); - return (0); -} /* ** chevron y es-tu ??? */ @@ -82,22 +60,10 @@ static char *c_current_words(t_comp *c) int c_matching(t_data *s, t_comp *c) { char *current_word; - char *tmp; current_word = c_current_words(c); if (ft_strchr(c->rcmd, '/')) - { - c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1); - if (current_word[0] == '~') - { - tmp = c->cpath; - c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); - free(tmp); - } - !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; - c_parser(c, c->cpath, c->match); - c_exclusion_folder(c); - } + c_seek_abs_path(c, current_word); else if (ft_strchr(c->rcmd, '$')) c_seek_env(c, current_word); else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c)) From 328db0b2605a57e72d511f2769000621b0a45cb8 Mon Sep 17 00:00:00 2001 From: M600 Date: Fri, 10 Mar 2017 08:48:21 +0100 Subject: [PATCH 10/17] Add rolling list --- 42sh/Makefile | 4 +-- 42sh/includes/completion.h | 14 ++++++--- 42sh/src/completion/c_init.c | 8 ++++- 42sh/src/completion/c_printer.c | 51 ++++++++++++++++++++++++++++++-- 42sh/src/completion/c_sizing.c | 4 +-- 42sh/src/completion/c_terminal.c | 10 +++---- 42sh/src/completion/completion.c | 2 +- 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index f410aef1..ab23380f 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/02/17 17:16:16 by wescande ### ########.fr # +# Updated: 2017/03/10 08:47:51 by alao ### ########.fr # # # # **************************************************************************** # @@ -242,7 +242,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make -j $(NAME) + @make -f $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(FLAGS) $(D_FLAGS) \ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 61943c44..13bac1cc 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/09 17:34:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:31:49 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,6 +57,9 @@ typedef struct s_clst ** c_line : Number of line required to move to terminal up. ** win_x : Size of the window in length. ** win_y : Size of the window in height. +** m_size : Max size of the list in pagination. +** pos_x : Position of the element relative to the terminal in list mode (X). +** pos_y : Position of the element relative to the terminal in list mode (Y). ** key : The keypressed lastly. ** isfolder : If the match is a folder. boolean. ** lst : List of the item corresponding to the completion. @@ -65,9 +68,9 @@ typedef struct s_clst ** ** Exemple: [ ls / ; cd (tab) ; pwd ] ** -** (int)cutpoint -** | -** | +** (int)cutpoint +** | +** | ** Become: [ls / ;] [ ] [cd ] [ ; pwd] ** | | | | ** | | | | @@ -93,6 +96,9 @@ typedef struct s_comp int c_line; int win_x; int win_y; + int m_size; + int pos_x; + int pos_y; int key; int isfolder; int isrematch; diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index f7df54b5..a661cf45 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/03/09 14:45:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:32:11 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,12 @@ 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->m_size = data_singleton()->line.prompt_size; + c->m_size += ft_strlen(data_singleton()->line.input); + c->m_size = (c->m_size / c->win_y); + c->m_size = c->win_y - c->m_size - 1; + c->pos_x = 1; + c->pos_y = 1; c->cutpoint = 0; c->between = NULL; c->isfolder = 0; diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index f43163de..0dc398b6 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/02/16 22:11:48 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:45:06 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,48 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i) return (0); } +/* +** Controlling the offset value for the rolling list if the space in the +** terminal is too small to display the whole list. +** +** Controlled value are: +** - x : the column of the element currently selected. +*/ + +static t_clst *c_rolling(t_comp *c) +{ + t_clst *ptr; + int x; + int y; + int id; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + + x = 1; + while ((x * c->c_line) < ptr->id) + x++; + id = ((x == 1) ? ptr->id : (ptr->id - ((x - 1) * c->c_line))); + y = 1; + while ((y * (c->m_size - 1)) < id) + y++; + if (y > 1) + { + c->pos_x = x; + c->pos_y = y; + x = (y - 1) * (c->m_size - 1); + ptr = c->lst; + while (x) + { + ptr = ptr->next; + x--; + } + return (ptr); + } + return (c->lst); +} + /* ** Control the number of time it cycle for LINE */ @@ -80,14 +122,17 @@ void c_printer(t_comp *c) { t_clst *ptr; int loop; + int max_line; - ptr = c->lst; loop = c->c_line; - while (loop) + max_line = c->m_size - 1; + ptr = c_rolling(c); + while (loop && max_line) { c_printer_line(c, ptr, c->c_pline, 1); loop > 1 ? ft_putstr(tgetstr("do", NULL)) : (0); ptr = ptr->next; loop--; + max_line--; } } diff --git a/42sh/src/completion/c_sizing.c b/42sh/src/completion/c_sizing.c index 78892cff..7a2697b0 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/17 13:45:33 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,5 @@ int c_sizing(t_comp *c) 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 4fdc60b1..83800ecf 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/17 18:36:56 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:46:13 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ void c_term_mv_back(t_comp *c) int lcmd; i = 0; - while (i != (c->c_line)) + while (i != (c->m_size)) { ft_putstr(tgetstr("up", NULL)); i++; @@ -71,14 +71,14 @@ void c_term_mv_down(t_comp *c) int i; i = 0; - while (i < c->c_line) + while (i < c->m_size) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL)); i++; } i = 0; - while (i != (c->c_line - 1)) + while (i != (c->m_size - 1)) { ft_putstr(tgetstr("up", NULL)); i++; @@ -86,7 +86,7 @@ void c_term_mv_down(t_comp *c) } /* -** If the terminal has chaged in size, the function will refresh these values +** If the terminal has changed in size, the function will refresh these values ** and clear the previous print list. */ diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index d92dea80..d85a41b6 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/03/09 14:44:52 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:46:26 by alao ### ########.fr */ /* */ /* ************************************************************************** */ From b8324bdc51f4c2b918453cf6583b6a5c6b40cae8 Mon Sep 17 00:00:00 2001 From: M600 Date: Fri, 10 Mar 2017 10:00:43 +0100 Subject: [PATCH 11/17] Add early arrow support --- 42sh/Makefile | 5 +- 42sh/includes/completion.h | 3 +- 42sh/src/completion/c_arrow.c | 87 ++++++++++++++++++++++++++++++++ 42sh/src/completion/c_output.c | 8 ++- 42sh/src/completion/c_terminal.c | 4 +- 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 42sh/src/completion/c_arrow.c diff --git a/42sh/Makefile b/42sh/Makefile index ab23380f..638cfa8c 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/10 08:47:51 by alao ### ########.fr # +# Updated: 2017/03/10 09:14:50 by alao ### ########.fr # # # # **************************************************************************** # @@ -46,6 +46,7 @@ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ c_seek_env.c\ completion/c_abs_path.c\ +completion/c_arrow.c\ completion/c_binary.c\ completion/c_clear.c\ completion/c_files.c\ @@ -242,7 +243,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make -f $(NAME) + @make $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(FLAGS) $(D_FLAGS) \ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 13bac1cc..88aad82c 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/10 08:31:49 by alao ### ########.fr */ +/* Updated: 2017/03/10 09:15:27 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -176,5 +176,6 @@ int c_glob_matching(void); void c_add_to_lst(t_comp *c, t_clst *node); int c_seek_env(t_comp *c, char *current_word); void c_seek_abs_path(t_comp *c, char *current_word); +void c_arrow(t_comp *c, long int keypress); #endif diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c new file mode 100644 index 00000000..10476742 --- /dev/null +++ b/42sh/src/completion/c_arrow.c @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_arrow.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: alao +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/10 09:04:42 by alao #+# #+# */ +/* Updated: 2017/03/10 09:57:44 by alao ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "completion.h" + +static void c_arrow_right(t_comp *c) +{ + t_clst *ptr; + int i; + + ptr = c->lst; + i = 0; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + while (i < c->c_line) + { + ptr = ptr->next; + if (ptr == c->lst) + i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + i++; + } + ptr->cursor = 1; +} + +static void c_arrow_left(t_comp *c) +{ + t_clst *ptr; + int i; + + ptr = c->lst; + i = 0; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + while (i < c->c_line) + { + ptr = ptr->prev; + if (ptr == c->lst) + i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + i++; + } + ptr->cursor = 1; +} + +static void c_arrow_down(t_comp *c) +{ + t_clst *ptr; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + ptr->next->cursor = 1; +} + +static void c_arrow_up(t_comp *c) +{ + t_clst *ptr; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + ptr->prev->cursor = 1; +} + +void c_arrow(t_comp *c, long int keypress) +{ + if (keypress == 4283163) + c_arrow_up(c); + if (keypress == 4348699) + c_arrow_down(c); + if (keypress == 4479771) + c_arrow_left(c); + if (keypress == 4414235) + c_arrow_right(c); +} diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index 3e37f799..72c91f8b 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/17 13:44:51 by alao ### ########.fr */ +/* Updated: 2017/03/10 09:05:23 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -114,5 +114,11 @@ int c_gtfo(t_comp *c, long int keypress) c_updater(c, ptr->name); return (1); } + if (keypress == 4283163 || keypress == 4348699 + || keypress == 4479771 || keypress == 4414235) + { + c_arrow(c, keypress); + return (0); + } return ((c_rematch(c, keypress)) ? (0) : (1)); } diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 83800ecf..aa0e65b1 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/03/10 08:46:13 by alao ### ########.fr */ +/* Updated: 2017/03/10 10:00:03 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ void c_term_mv_down(t_comp *c) int i; i = 0; - while (i < c->m_size) + while (i < c->m_size + 1) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL)); From 12c35ed904980b59187178657eba30bc21d2ca89 Mon Sep 17 00:00:00 2001 From: M600 Date: Fri, 10 Mar 2017 11:46:48 +0100 Subject: [PATCH 12/17] Fix padding multicolumn --- 42sh/src/completion/c_arrow.c | 22 +++++++++++++++++++++- 42sh/src/completion/c_init.c | 3 ++- 42sh/src/completion/c_printer.c | 4 +++- 42sh/src/completion/c_terminal.c | 22 ++++++++++++++++++---- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c index 10476742..c32f0745 100644 --- a/42sh/src/completion/c_arrow.c +++ b/42sh/src/completion/c_arrow.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 09:04:42 by alao #+# #+# */ -/* Updated: 2017/03/10 09:57:44 by alao ### ########.fr */ +/* Updated: 2017/03/10 10:21:01 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,17 @@ static void c_arrow_right(t_comp *c) i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); i++; } + DG("POSX [%d] C_PLINE [%d]", c->pos_x, c->c_line); + if (c->pos_x == (c->c_pline - 1)) + { + DG("X"); + i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + while (i < c->c_line) + { + ptr = ptr->next; + i++; + } + } ptr->cursor = 1; } @@ -49,6 +60,15 @@ static void c_arrow_left(t_comp *c) i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); i++; } +/* if (c->pos_x == 1) + { + i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + while (i < c->c_line) + { + ptr = ptr->prev; + i++; + } + }*/ ptr->cursor = 1; } diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index a661cf45..8e356bfc 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/03/10 08:32:11 by alao ### ########.fr */ +/* Updated: 2017/03/10 11:38:35 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ static void c_init_base(t_comp *c) c->m_size += ft_strlen(data_singleton()->line.input); c->m_size = (c->m_size / c->win_y); c->m_size = c->win_y - c->m_size - 1; + DG("MS [%d] WX %d WY %d", c->m_size, c->win_x, c->win_y); c->pos_x = 1; c->pos_y = 1; c->cutpoint = 0; diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index 0dc398b6..7f03451a 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/03/10 08:45:06 by alao ### ########.fr */ +/* Updated: 2017/03/10 10:18:16 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,6 +98,8 @@ static t_clst *c_rolling(t_comp *c) y = 1; while ((y * (c->m_size - 1)) < id) y++; + c->pos_x = x; + c->pos_y = y; if (y > 1) { c->pos_x = x; diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index aa0e65b1..b8e6c21c 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/03/10 10:00:03 by alao ### ########.fr */ +/* Updated: 2017/03/10 11:45:57 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,9 +43,14 @@ void c_term_mv_back(t_comp *c) { int i; int lcmd; + int value; i = 0; - while (i != (c->m_size)) + if (c->c_sy > c->win_y) + value = c->m_size; + else + value = c->c_line; + while (i != value) { ft_putstr(tgetstr("up", NULL)); i++; @@ -69,16 +74,25 @@ void c_term_mv_back(t_comp *c) void c_term_mv_down(t_comp *c) { int i; + int value; i = 0; - while (i < c->m_size + 1) + if (c->c_sy > c->win_y) + value = c->m_size + 1; + else + value = c->c_line; + while (i < value) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL)); i++; } i = 0; - while (i != (c->m_size - 1)) + if (c->c_sy > c->win_y) + value = c->m_size - 1; + else + value = c->c_line - 1; + while (i != value) { ft_putstr(tgetstr("up", NULL)); i++; From 7bf475540c87c5c969cdd198b5a305840d525130 Mon Sep 17 00:00:00 2001 From: M600 Date: Fri, 10 Mar 2017 12:44:54 +0100 Subject: [PATCH 13/17] Fix padding and arrows --- 42sh/src/completion/c_arrow.c | 4 +--- 42sh/src/completion/c_init.c | 3 +-- 42sh/src/completion/c_printer.c | 22 ++++++++++++++++------ 42sh/src/completion/c_terminal.c | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c index c32f0745..4890cec9 100644 --- a/42sh/src/completion/c_arrow.c +++ b/42sh/src/completion/c_arrow.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 09:04:42 by alao #+# #+# */ -/* Updated: 2017/03/10 10:21:01 by alao ### ########.fr */ +/* Updated: 2017/03/10 12:44:05 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,10 +29,8 @@ static void c_arrow_right(t_comp *c) i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); i++; } - DG("POSX [%d] C_PLINE [%d]", c->pos_x, c->c_line); if (c->pos_x == (c->c_pline - 1)) { - DG("X"); i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); while (i < c->c_line) { diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index 8e356bfc..96035644 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/03/10 11:38:35 by alao ### ########.fr */ +/* Updated: 2017/03/10 12:43:57 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,7 +60,6 @@ static void c_init_base(t_comp *c) c->m_size += ft_strlen(data_singleton()->line.input); c->m_size = (c->m_size / c->win_y); c->m_size = c->win_y - c->m_size - 1; - DG("MS [%d] WX %d WY %d", c->m_size, c->win_x, c->win_y); c->pos_x = 1; c->pos_y = 1; c->cutpoint = 0; diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index 7f03451a..f0297976 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/03/10 10:18:16 by alao ### ########.fr */ +/* Updated: 2017/03/10 12:43:16 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,12 +98,10 @@ static t_clst *c_rolling(t_comp *c) y = 1; while ((y * (c->m_size - 1)) < id) y++; - c->pos_x = x; - c->pos_y = y; + c->pos_x = id; + c->pos_y = y; if (y > 1) { - c->pos_x = x; - c->pos_y = y; x = (y - 1) * (c->m_size - 1); ptr = c->lst; while (x) @@ -125,10 +123,17 @@ void c_printer(t_comp *c) t_clst *ptr; int loop; int max_line; + int offset; loop = c->c_line; - max_line = c->m_size - 1; + + max_line = c->c_line - (c->m_size - 1); ptr = c_rolling(c); + if ((c->pos_y * (c->m_size - 1)) > c->c_line) + max_line = (c->c_line % (c->m_size - 1)); + else + max_line = c->m_size - 1; + offset = (c->m_size - 1) - max_line; while (loop && max_line) { c_printer_line(c, ptr, c->c_pline, 1); @@ -137,4 +142,9 @@ void c_printer(t_comp *c) loop--; max_line--; } + while (offset) + { + ft_putstr(tgetstr("do", NULL)); + offset--; + } } diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index b8e6c21c..e8dcb5ba 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/03/10 11:45:57 by alao ### ########.fr */ +/* Updated: 2017/03/10 12:06:22 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,7 +78,7 @@ void c_term_mv_down(t_comp *c) i = 0; if (c->c_sy > c->win_y) - value = c->m_size + 1; + value = c->m_size; else value = c->c_line; while (i < value) From f889e8288f5693477c174d401f05bbbdb58757a4 Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 10 Mar 2017 16:10:14 +0100 Subject: [PATCH 14/17] pu de decalage --- 42sh/src/completion/c_printer.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index f0297976..a4be48b3 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/03/10 12:43:16 by alao ### ########.fr */ +/* Updated: 2017/03/10 16:09:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -142,9 +142,4 @@ void c_printer(t_comp *c) loop--; max_line--; } - while (offset) - { - ft_putstr(tgetstr("do", NULL)); - offset--; - } } From 0a205229a85ba818208f2e5e1f41848817469201 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 10 Mar 2017 17:08:04 +0100 Subject: [PATCH 15/17] pgid stuff, still must fix (ls) --- 42sh/includes/job_control.h | 2 +- 42sh/src/exec/exec_leaf.c | 4 +--- 42sh/src/exec/exec_reset.c | 6 ++---- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/exec/launch_while.c | 2 +- 42sh/src/exec/mark_process_status.c | 2 +- 42sh/src/exec/process_setgroup.c | 5 ++--- 42sh/src/job-control/builtin_fg.c | 2 +- 42sh/src/job-control/job_addprocess.c | 7 ++----- 42sh/src/job-control/job_update_status.c | 2 +- 42sh/src/job-control/job_wait.c | 7 +++++-- 42sh/src/job-control/process_format.c | 2 +- 42sh/src/job-control/put_job_in_foreground.c | 2 +- 13 files changed, 20 insertions(+), 25 deletions(-) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 5013d09c..d67c687b 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:38:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:57:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 424cf51f..f750c5e7 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/10 15:36:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:58:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,8 +29,6 @@ int exec_leaf(t_btree **ast) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); - /* else */ - /* put_job_in_background(job, 0); */ job->pgid = 0; } } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 354b3cde..df434fd0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:48:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:49:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,15 +20,13 @@ int exec_reset(void) /* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */ /* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */ /* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */ - DG("check 0"); if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno); - DG("check 1"); if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno); if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno); - DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); + /* DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); */ exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index ce257525..0fff5117 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:21:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:50:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index 462edb8b..b2268d0d 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */ +/* Updated: 2017/03/10 17:01:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 57b21b34..f07a5784 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/10 12:51:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:28:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 37cf1b81..cc63b209 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/09 14:28:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:51:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,7 @@ int process_setgroup(t_process *p, pid_t pid) if (!SH_HAS_JOBC(data->opts)) return (0); j = &data->exec.job; - if (!j->pgid) - j->pgid = pid ? pid : getpid(); + /* DG("setpgid(%i, %i)", pid, j->pgid); */ setpgid(pid, j->pgid); if (pid == 0 && JOB_IS_FG(j->attrs)) tcsetpgrp(STDIN, j->pgid); diff --git a/42sh/src/job-control/builtin_fg.c b/42sh/src/job-control/builtin_fg.c index 9e7720f6..df1cf8c1 100644 --- a/42sh/src/job-control/builtin_fg.c +++ b/42sh/src/job-control/builtin_fg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/02/21 20:09:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index fb153c30..e8dd64ea 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:36:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:45:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,15 +27,12 @@ int job_addprocess(t_process *p) job->pgid = p->pid; ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } - DG("check 0"); job = jobc->first_job->content; ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); - DG("[BG:%i]", JOB_IS_BG(job->attrs)); + /* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */ if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) { - DG("check 2"); job_notify_new(job); } - DG("check 3"); return (0); } diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index a3088f15..33c3eb72 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:38:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:45:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index d655567f..8aa3be7f 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:40:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:48:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,14 @@ int job_wait(int id) t_jobc *jobc; int status; - DG("job wait [%i]", id); jobc = &data_singleton()->jobc; j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; + DG("job wait id=[%i], pgid=[%i]", id, j->pgid); do + { pid = waitpid(-j->pgid, &status, WUNTRACED); + DG("pid=[%d]", pid); + } while (pid > 1 && !mark_process_status(pid, status) && !job_is_stopped(id) && !job_is_completed(id)); diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index c8a36422..9fcd987f 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:08:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 97b9ba4a..b07f40be 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:16:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 0c8e9b930cf7b03a010709770f5bfa35d149ceae Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 10 Mar 2017 17:34:11 +0100 Subject: [PATCH 16/17] bug completion env solved --- 42sh/src/completion/c_seek_env.c | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 42sh/src/completion/c_seek_env.c diff --git a/42sh/src/completion/c_seek_env.c b/42sh/src/completion/c_seek_env.c new file mode 100644 index 00000000..d69eb6c4 --- /dev/null +++ b/42sh/src/completion/c_seek_env.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_seek_env.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ +/* Updated: 2017/03/10 17:33:37 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int c_storing(t_comp *c, char *value) +{ + t_clst *tmp; + + if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) + return (-1); + tmp->name = value; + tmp->len = ft_strlen(tmp->name); + tmp->type = 10; + tmp->cursor = 0; + c_add_to_lst(c, tmp); + return (0); +} + +static void c_maj_rcmd(t_comp *c, char *current_word) +{ + char *tmp; + + tmp = c->rcmd; + c->rcmd = ft_strdupi_w(current_word); + free(tmp); +} + +int c_seek_env(t_comp *c, char *current_word) +{ + char *match; + char **env; + int i; + + i = 0; + env = data_singleton()->env; + match = ft_strdupi_w(current_word + 1); + c_maj_rcmd(c, current_word); + while (env[i]) + { + if (!ft_strncmp(match, env[i], ft_strlen(match))) + c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); + ++i; + } + return (0); +} From b8e9a9e09432193d27ba918b47568669570af0f3 Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 10 Mar 2017 17:34:31 +0100 Subject: [PATCH 17/17] pr compiler --- 42sh/Makefile | 2 +- 42sh/src/c_seek_env.c | 55 -------------------------------- 42sh/src/completion/c_matching.c | 2 +- 42sh/src/completion/c_rematch.c | 2 +- 42sh/src/completion/c_terminal.c | 2 +- 42sh/src/completion/completion.c | 2 +- 6 files changed, 5 insertions(+), 60 deletions(-) delete mode 100644 42sh/src/c_seek_env.c diff --git a/42sh/Makefile b/42sh/Makefile index 638cfa8c..9728595f 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -44,7 +44,6 @@ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ -c_seek_env.c\ completion/c_abs_path.c\ completion/c_arrow.c\ completion/c_binary.c\ @@ -59,6 +58,7 @@ completion/c_parser.c\ completion/c_pathsolver.c\ completion/c_printer.c\ completion/c_rematch.c\ +completion/c_seek_env.c\ completion/c_sizing.c\ completion/c_terminal.c\ completion/completion.c\ diff --git a/42sh/src/c_seek_env.c b/42sh/src/c_seek_env.c deleted file mode 100644 index 9c3680c0..00000000 --- a/42sh/src/c_seek_env.c +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* c_seek_env.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/09 16:52:57 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static int c_storing(t_comp *c, char *value) -{ - t_clst *tmp; - - if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) - return (-1); - tmp->name = value; - tmp->len = ft_strlen(tmp->name); - tmp->type = 10; - tmp->cursor = 0; - c_add_to_lst(c, tmp); - return (0); -} - -static void c_maj_rcmd(t_comp *c, char *current_word) -{ - char *tmp; - - tmp = c->rcmd; - c->rcmd = ft_strndup(c->rcmd, current_word - c->rcmd + 1); - free(tmp); -} - -int c_seek_env(t_comp *c, char *current_word) -{ - char *match; - char **env; - int i; - - i = 0; - env = data_singleton()->env; - match = ft_strdupi_w(current_word + 1); - c_maj_rcmd(c, current_word); - while (env[i]) - { - if (!ft_strncmp(match, env[i], ft_strlen(match))) - c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); - ++i; - } - return (0); -} diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index d85cd257..1c62187a 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/03/09 17:35:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 17:20:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_rematch.c b/42sh/src/completion/c_rematch.c index f11e1cc3..4ffa9dfb 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/17 14:57:22 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:27:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index e8dcb5ba..d76b09bc 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/03/10 12:06:22 by alao ### ########.fr */ +/* Updated: 2017/03/10 16:07:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index d85a41b6..dca82f0f 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/03/10 08:46:26 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:20:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */