From 3d74e17ac9964df3c69324110cbc10080ae57a96 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 10 Mar 2017 13:17:39 +0100 Subject: [PATCH] rectif de glob sur les dossier pour matcher uniquement avec le bon nombre d'inclusion de / --- 42sh/src/glob/dir_glob.c | 23 ++++++++++++----------- 42sh/src/glob/match_pattern.c | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 67f87cbc..98d3eb47 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -21,27 +21,27 @@ int is_directory(const char *path) } static void dir_list_content(t_glob *gl, char **str, char *pat, - int recursive) + int recursive) { - char *path_tmp; + char *path; if (str[1][0] != '.') { if (*str[0] == '/' && !*(str[0] + 1)) - path_tmp = ft_strjoin(str[0], str[1]); + path = ft_strjoin(str[0], str[1]); else - path_tmp = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1); + path = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1); if (recursive) - dir_research(gl, path_tmp, pat, recursive); + dir_research(gl, path, pat, recursive); gl->pat = pat; - if (match_pattern(gl, str[1], path_tmp)) + if (match_pattern(gl, str[1], path)) { gl->found = 1; - ft_ld_pushfront(&gl->match_tmp, ft_strdup(path_tmp + gl->cur_dir * 2 * - (path_tmp[0] == '.' && path_tmp[1] == '/'))); + ft_ld_pushfront(&gl->match_tmp, ft_strdup(path + gl->cur_dir * 2 * + (path[0] == '.' && path[1] == '/'))); } gl->pat = pat; - ft_strdel(&path_tmp); + ft_strdel(&path); } } @@ -51,10 +51,11 @@ int dir_research(t_glob *gl, char *p, DIR *dir; struct dirent *in; - if (!pat) + if (!*pat) { gl->found = 1; - ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p, "/")); + ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 * + (p[0] == '.' && p[1] == '/'), "/")); return (0); } if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index 59dbe552..29c23ae6 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -119,7 +119,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word) else if (*gl->pat == '*') return (match_star(gl, str, full_word)); else if (*gl->pat == '/' && !*str && is_directory(full_word)) - dir_research(gl, full_word, gl->pat + 1, 0); + return (dir_research(gl, full_word, gl->pat + 1, 0)); else if (*gl->pat != *str) return (0); ++str;