rectif de glob sur les dossier pour matcher uniquement avec le bon nombre d'inclusion de /
This commit is contained in:
parent
1119f98e20
commit
3d74e17ac9
2 changed files with 13 additions and 12 deletions
|
|
@ -21,27 +21,27 @@ int is_directory(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dir_list_content(t_glob *gl, char **str, char *pat,
|
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[1][0] != '.')
|
||||||
{
|
{
|
||||||
if (*str[0] == '/' && !*(str[0] + 1))
|
if (*str[0] == '/' && !*(str[0] + 1))
|
||||||
path_tmp = ft_strjoin(str[0], str[1]);
|
path = ft_strjoin(str[0], str[1]);
|
||||||
else
|
else
|
||||||
path_tmp = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
|
path = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
|
||||||
if (recursive)
|
if (recursive)
|
||||||
dir_research(gl, path_tmp, pat, recursive);
|
dir_research(gl, path, pat, recursive);
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
if (match_pattern(gl, str[1], path_tmp))
|
if (match_pattern(gl, str[1], path))
|
||||||
{
|
{
|
||||||
gl->found = 1;
|
gl->found = 1;
|
||||||
ft_ld_pushfront(&gl->match_tmp, ft_strdup(path_tmp + gl->cur_dir * 2 *
|
ft_ld_pushfront(&gl->match_tmp, ft_strdup(path + gl->cur_dir * 2 *
|
||||||
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
(path[0] == '.' && path[1] == '/')));
|
||||||
}
|
}
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
ft_strdel(&path_tmp);
|
ft_strdel(&path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,10 +51,11 @@ int dir_research(t_glob *gl, char *p,
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
|
|
||||||
if (!pat)
|
if (!*pat)
|
||||||
{
|
{
|
||||||
gl->found = 1;
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word)
|
||||||
else if (*gl->pat == '*')
|
else if (*gl->pat == '*')
|
||||||
return (match_star(gl, str, full_word));
|
return (match_star(gl, str, full_word));
|
||||||
else if (*gl->pat == '/' && !*str && is_directory(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)
|
else if (*gl->pat != *str)
|
||||||
return (0);
|
return (0);
|
||||||
++str;
|
++str;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue