From c654e524f4cc3418c20c648396466e0c0a8ad77d Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 12:14:06 +0100 Subject: [PATCH] fix somes bugs #100 --- 42sh/Makefile | 1 + 42sh/includes/completion.h | 4 ++-- 42sh/includes/ft_readline.h | 3 ++- 42sh/src/completion/c_files.c | 9 +++++---- 42sh/src/completion/c_matching.c | 5 +++-- 42sh/src/completion/c_parser.c | 5 +++-- 42sh/src/completion/c_terminal.c | 8 ++++---- 42sh/src/completion/completion.c | 4 ++-- 42sh/src/history/add_str_in_history.c | 2 +- 42sh/src/job-control/sigttou_handler.c | 4 ++-- 42sh/src/main/shell_init.c | 5 +++-- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 75cb24da..ce133a74 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -263,6 +263,7 @@ line-editing/move_up_and_down.c\ line-editing/print_and_del.c\ line-editing/queue.c\ line-editing/readline.c\ +line-editing/resize.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 54ae20b1..1f341a15 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 17:38:50 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 12:09:55 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -120,7 +120,7 @@ int completion(long int key); void c_init(t_data *s, long int input); int c_matching(t_data *s, t_comp *c); int c_seek_binary(t_data *s, t_comp *c); -int c_seek_files(t_data *s, t_comp *c); +int c_seek_files(t_data *s, t_comp *c, char *current_word); int c_parser(t_comp *c, char *path, char *name); int c_sizing(t_comp *c); diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index cbd312d1..9ff205fc 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/03/10 17:40:40 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 11:09:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -131,6 +131,7 @@ void ft_clear_window(void); void free_history_list(t_list_history *head); int ft_nb_of_line(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos); +void sigwinch_resize(int sig); char *ft_read_stdin(void); void ft_end(void); diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index 30006e18..7144b386 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/10 17:38:37 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 12:09:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,10 +70,10 @@ 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 (c_chevron(c)) +/* if (c_chevron(c)) c->match = ft_strdup(""); else - c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i); + c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);*/ tmp ? ft_memdel((void *)&tmp) : (0); return (rt); } @@ -82,7 +82,7 @@ static char *c_slicer(t_comp *c) ** Files searching */ -int c_seek_files(t_data *s, t_comp *c) +int c_seek_files(t_data *s, t_comp *c, char *current_word) { char *path; @@ -95,6 +95,7 @@ int c_seek_files(t_data *s, t_comp *c) if (c->cpath == NULL) { path = c_slicer(c); + c->match = ft_strdup(current_word); c->cpath = path_solver(c, path, NULL); path ? ft_memdel((void *)&path) : (0); } diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index 68dc4d8f..4794c531 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/10 17:20:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 12:12:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,7 @@ static char *c_current_words(t_comp *c) --pos; if (c->rcmd[pos] == ' ') ++pos; + DG("rcmd = \"%s\"", c->rcmd); return (c->rcmd + pos); } @@ -69,7 +70,7 @@ int c_matching(t_data *s, t_comp *c) else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c)) c_seek_binary(s, c); else - c_seek_files(s, c); + c_seek_files(s, c, current_word); if (s->comp && s->comp->lst) { c_sizing(c); diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index d29fc547..67c6dc84 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/09 16:47:31 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 11:37:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,8 @@ static int c_storing(t_comp *c, char *value, unsigned char type) { t_clst *tmp; - if (ft_strncmp(".", value, 1) == 0 || ft_strncmp("..", value, 2) == 0) + if (!(c->match && ft_strncmp(".", c->match, 1) == 0) && + (ft_strncmp(".", value, 1) == 0 || ft_strncmp("..", value, 2) == 0)) return (0); if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1) return (0); diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 185c35bc..ebef1cee 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 16:07:36 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 10:51:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,7 +46,7 @@ void c_term_mv_back(t_comp *c) int value; i = 0; - if (c->c_sy > c->win_y) + if (c->c_line > c->win_y) value = c->m_size; else value = c->c_line; @@ -77,7 +77,7 @@ void c_term_mv_down(t_comp *c) int value; i = 0; - if (c->c_sy > c->win_y) + if (c->c_line > c->win_y) value = c->m_size; else value = c->c_line; @@ -88,7 +88,7 @@ void c_term_mv_down(t_comp *c) i++; } i = 0; - if (c->c_sy > c->win_y) + if (c->c_line > c->win_y) value = c->m_size - 1; else value = c->c_line - 1; diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index e9c82539..498261a9 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 17:20:04 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 11:22:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ static void c_next_item(t_comp *c) ** of the cursor is restored. */ -static int c_dispatcher(t_data *s) +int c_dispatcher(t_data *s) { if (s->comp && s->comp->lst == NULL) { diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 0a8c95ee..0da0f1ee 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/13 14:30:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 09:50:57 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigttou_handler.c b/42sh/src/job-control/sigttou_handler.c index e89a5641..a710c83e 100644 --- a/42sh/src/job-control/sigttou_handler.c +++ b/42sh/src/job-control/sigttou_handler.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* sigttou_handler.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/01/08 13:24:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 10:55:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index a4e6f9d2..1844fe2e 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* shell_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/11 14:08:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 11:09:31 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,7 @@ void shell_init(int ac, char **av) signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGCHLD, SIG_DFL); + signal(SIGWINCH, sigwinch_resize); *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) {