From e2a254863c24cdb257e6553844ca22938e441fe9 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 14:53:11 +0100 Subject: [PATCH] rectif du glob sur l'affichage du pattern quand pas de match, et ajout du / quand match avec un dossier --- 42sh/src/glob/dir_glob.c | 12 ++++++++---- 42sh/src/glob/glob.c | 5 ++--- 42sh/src/glob/match_pattern.c | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 2e9f3281..e83d55b9 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 12:07:16 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:04:49 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:50:58 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,9 +49,13 @@ int dir_research(t_glob *gl, char *p, { DIR *dir; struct dirent *in; - int ret; - ret = 0; + if (!pat) + { + gl->found = 1; + ft_ld_pushfront(&gl->match, ft_strjoin(p, "/")); + return (0); + } if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) { dir = opendir(p); @@ -60,5 +64,5 @@ int dir_research(t_glob *gl, char *p, (char *[2]){p, in->d_name}, pat, recursive); closedir(dir); } - return (ret); + return (0); } diff --git a/42sh/src/glob/glob.c b/42sh/src/glob/glob.c index b44b5c89..f3bbc2cf 100644 --- a/42sh/src/glob/glob.c +++ b/42sh/src/glob/glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/03/03 20:38:53 by wescande ### ########.fr */ +/* Updated: 2017/03/08 14:50:56 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,8 +66,7 @@ char **glob(char *pat, unsigned char *esc, else dir_research(&gl, "/", gl.pat + 1, 0); if (!gl.found) - ft_ld_pushfront(&gl.match, - ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0])); + ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0])); if (!gl.m_pat->next) break ; gl.m_pat = gl.m_pat->next; diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index f3573fe5..57323c48 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/24 17:30:23 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:06:01 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:35:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,6 +90,7 @@ static char *manage_pat(t_glob *gl, char *pat, char *str) if (pat[0] == '.' && pat[1] == '/' && ((str[0] == '.' && str[1] != '/') || str[0] != '.')) { + DG("%s vs %s", pat, str); gl->cur_dir = 0; return (pat + 2); }