ajout du ** en mode tmp. Besoin de votre avis dessus. segfault sur la ligne de commande mais doi etre rebase pour savoir d'ou ca vient
This commit is contained in:
parent
c556b0eea5
commit
c3c47e9a5a
3 changed files with 37 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/24 19:27:53 by wescande ### ########.fr */
|
/* Updated: 2017/01/24 21:22:58 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,8 +25,10 @@ typedef struct s_ld
|
||||||
char **glob(const char *str, char **env);
|
char **glob(const char *str, char **env);
|
||||||
t_ld *expand_brace(const char *pat);
|
t_ld *expand_brace(const char *pat);
|
||||||
void glob_print(t_list *token, t_data *data);
|
void glob_print(t_list *token, t_data *data);
|
||||||
int match_pattern(const char *pat, char *str, char *full_word, t_ld **match);
|
int match_pattern(const char *pat, char *str,
|
||||||
|
char *full_word, t_ld **match);
|
||||||
void dir_research(const char *pat, char *path, t_ld **match);
|
void dir_research(const char *pat, char *path, t_ld **match);
|
||||||
|
void dir_research_recursive(const char *pat, char *p, t_ld **match);
|
||||||
bool is_directory(const char *path);
|
bool is_directory(const char *path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/24 19:10:52 by wescande ### ########.fr */
|
/* Updated: 2017/01/24 21:16:42 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -46,3 +46,32 @@ void dir_research(const char *pat, char *p, t_ld **match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dir_research_recursive(const char *pat, char *p, t_ld **match)
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *in;
|
||||||
|
char *path_tmp;
|
||||||
|
|
||||||
|
if (ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.')
|
||||||
|
{
|
||||||
|
if (!(dir = opendir(p)))
|
||||||
|
return ;
|
||||||
|
while ((in = readdir(dir)))
|
||||||
|
{
|
||||||
|
if (ft_strcmp(in->d_name, ".") && ft_strcmp(in->d_name, ".."))
|
||||||
|
{
|
||||||
|
if (*p == '/' && !*(p + 1))
|
||||||
|
path_tmp = ft_strjoin(p, in->d_name);
|
||||||
|
else
|
||||||
|
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
||||||
|
if (is_directory(path_tmp))
|
||||||
|
dir_research_recursive(pat, path_tmp, match);
|
||||||
|
if (match_pattern(pat, in->d_name, path_tmp, match))
|
||||||
|
ft_ld_pushfront(match, ft_strdup(path_tmp + 2 *
|
||||||
|
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
||||||
|
ft_strdel(&path_tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
|
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/24 20:42:30 by wescande ### ########.fr */
|
/* Updated: 2017/01/24 20:58:47 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -72,6 +72,8 @@ static int match_star(const char *pat, char *str,
|
||||||
{
|
{
|
||||||
char *fix;
|
char *fix;
|
||||||
|
|
||||||
|
if (pat[1] == '*')
|
||||||
|
dir_research_recursive(pat, full_word, match);
|
||||||
if (!pat[1])
|
if (!pat[1])
|
||||||
return (1);
|
return (1);
|
||||||
fix = str + ft_strlen(str);
|
fix = str + ft_strlen(str);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue