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))