rectif du tri du glob
This commit is contained in:
parent
c15b48afa9
commit
460d51f451
5 changed files with 44 additions and 7 deletions
|
|
@ -33,6 +33,7 @@ typedef struct s_glob
|
||||||
unsigned char *esc;
|
unsigned char *esc;
|
||||||
unsigned char *esc2;
|
unsigned char *esc2;
|
||||||
t_ld *match;
|
t_ld *match;
|
||||||
|
t_ld *match_tmp;
|
||||||
t_ld *m_pat;
|
t_ld *m_pat;
|
||||||
} t_glob;
|
} t_glob;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ void ft_ld_reverse(t_ld **lst);
|
||||||
t_ld *ft_ld_back(t_ld *ld);
|
t_ld *ft_ld_back(t_ld *ld);
|
||||||
t_ld *ft_ld_swap(t_ld *l_cur);
|
t_ld *ft_ld_swap(t_ld *l_cur);
|
||||||
char **ft_ld_to_tab(t_ld *ld);
|
char **ft_ld_to_tab(t_ld *ld);
|
||||||
t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)());
|
t_ld *ft_ld_order(t_ld *ld, int (*f)());
|
||||||
t_ld *ft_ld_copy(t_ld *src, void *(*f)(void *elem));
|
t_ld *ft_ld_copy(t_ld *src, void *(*f)(void *elem));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat,
|
||||||
if (match_pattern(gl, str[1], path_tmp))
|
if (match_pattern(gl, str[1], path_tmp))
|
||||||
{
|
{
|
||||||
gl->found = 1;
|
gl->found = 1;
|
||||||
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + gl->cur_dir * 2 *
|
ft_ld_pushfront(&gl->match_tmp, ft_strdup(path_tmp + gl->cur_dir * 2 *
|
||||||
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
||||||
}
|
}
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
|
|
@ -54,7 +54,7 @@ int dir_research(t_glob *gl, char *p,
|
||||||
if (!pat)
|
if (!pat)
|
||||||
{
|
{
|
||||||
gl->found = 1;
|
gl->found = 1;
|
||||||
ft_ld_pushfront(&gl->match, ft_strjoin(p, "/"));
|
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p, "/"));
|
||||||
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))
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,40 @@
|
||||||
** to just expanse in local directory and not in path dir
|
** to just expanse in local directory and not in path dir
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int order_glob(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
char c1;
|
||||||
|
char c2;
|
||||||
|
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (1);
|
||||||
|
c1 = ft_tolower(*s1++);
|
||||||
|
c2 = ft_tolower(*s2++);
|
||||||
|
if (!c1)
|
||||||
|
return (-(c1 - c2));
|
||||||
|
while (c1 == c2)
|
||||||
|
{
|
||||||
|
c1 = ft_tolower(*s1++);
|
||||||
|
c2 = ft_tolower(*s2++);
|
||||||
|
if (!c1)
|
||||||
|
return (-(c1 - c2));
|
||||||
|
}
|
||||||
|
return (-(c1 - c2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void merge_ld_glob(t_ld **match, t_ld **tmp)
|
||||||
|
{
|
||||||
|
t_ld *ultimate;
|
||||||
|
|
||||||
|
*tmp = ft_ld_order(*tmp, &order_glob);
|
||||||
|
ultimate = ft_ld_back(*tmp);
|
||||||
|
ultimate->next = *match;
|
||||||
|
if (*match)
|
||||||
|
(*match)->prev = ultimate;
|
||||||
|
*match = *tmp;
|
||||||
|
*tmp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static char **treat_glob(t_glob *gl)
|
static char **treat_glob(t_glob *gl)
|
||||||
{
|
{
|
||||||
char **ret;
|
char **ret;
|
||||||
|
|
@ -54,7 +88,7 @@ char **glob(char *pat, unsigned char *esc,
|
||||||
|
|
||||||
len = ft_strlen(pat);
|
len = ft_strlen(pat);
|
||||||
gl = (t_glob){0, 0, ft_strdup(pat), dup_char_esc(esc, (len >> 3) + 1),
|
gl = (t_glob){0, 0, ft_strdup(pat), dup_char_esc(esc, (len >> 3) + 1),
|
||||||
dup_char_esc(esc2, (len >> 3) + 1), NULL, NULL};
|
dup_char_esc(esc2, (len >> 3) + 1), NULL, NULL, NULL};
|
||||||
normal_expand_before_match(&gl, do_match);
|
normal_expand_before_match(&gl, do_match);
|
||||||
if (do_match)
|
if (do_match)
|
||||||
while (gl.m_pat && !(gl.found = 0))
|
while (gl.m_pat && !(gl.found = 0))
|
||||||
|
|
@ -67,6 +101,8 @@ char **glob(char *pat, unsigned char *esc,
|
||||||
dir_research(&gl, "/", gl.pat + 1, 0);
|
dir_research(&gl, "/", gl.pat + 1, 0);
|
||||||
if (!gl.found)
|
if (!gl.found)
|
||||||
ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
|
ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
|
||||||
|
else
|
||||||
|
merge_ld_glob(&gl.match, &gl.match_tmp);
|
||||||
if (!gl.m_pat->next)
|
if (!gl.m_pat->next)
|
||||||
break ;
|
break ;
|
||||||
gl.m_pat = gl.m_pat->next;
|
gl.m_pat = gl.m_pat->next;
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)())
|
t_ld *ft_ld_order(t_ld *ld, int (*f)())
|
||||||
{
|
{
|
||||||
int swap;
|
int swap;
|
||||||
|
|
||||||
swap = 1;
|
swap = 1;
|
||||||
ld = ft_ld_front(ld);
|
ld = ft_ld_front(ld);
|
||||||
|
if (!f)
|
||||||
|
return (ld);
|
||||||
while (swap)
|
while (swap)
|
||||||
{
|
{
|
||||||
swap = 0;
|
swap = 0;
|
||||||
|
|
@ -25,8 +27,6 @@ t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)())
|
||||||
{
|
{
|
||||||
if (f(ld->content, ld->next->content) > 0 && (swap = 1))
|
if (f(ld->content, ld->next->content) > 0 && (swap = 1))
|
||||||
ld = ft_ld_swap(ld);
|
ld = ft_ld_swap(ld);
|
||||||
else if (!f(ld->content, ld->next->content))
|
|
||||||
ft_ld_del(&ld, del);
|
|
||||||
ld = ld->next;
|
ld = ld->next;
|
||||||
}
|
}
|
||||||
ld = ft_ld_front(ld);
|
ld = ft_ld_front(ld);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue