glob a la norme + close an issue
This commit is contained in:
parent
d8e76dba3d
commit
f2c3ae16e9
9 changed files with 41 additions and 43 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/03/08 23:24:38 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 23:14:14 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ void expand_home(t_glob *gl, char *str);
|
||||||
void expand_var(t_glob *tglob);
|
void expand_var(t_glob *tglob);
|
||||||
void expand_home(t_glob *gl, char *str);
|
void expand_home(t_glob *gl, char *str);
|
||||||
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||||
int dir_research(t_glob *tglob, char *p, char *pat, int rec, int first);
|
int dir_research(t_glob *tglob, char *p, char *pat, int *mode);
|
||||||
char **gen_tab(const char *pat, const unsigned char *esc,
|
char **gen_tab(const char *pat, const unsigned char *esc,
|
||||||
const unsigned char *esc2, int dup);
|
const unsigned char *esc2, int dup);
|
||||||
char **ft_strsplit_spe(const char *str,
|
char **ft_strsplit_spe(const char *str,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* plaunch_for.c :+: :+: :+: */
|
/* plaunch_for.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
|
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 01:46:48 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -33,7 +33,6 @@ static int do_for(t_process *p)
|
||||||
builtin_setenv("setenv", (char*[]){var, av[i], 0},
|
builtin_setenv("setenv", (char*[]){var, av[i], 0},
|
||||||
data_singleton()->local_var);
|
data_singleton()->local_var);
|
||||||
ft_exec(&p->data.d_for.content);
|
ft_exec(&p->data.d_for.content);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:11:39 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ char *command_getoutput(char *command)
|
||||||
{
|
{
|
||||||
close(fds[PIPE_READ]);
|
close(fds[PIPE_READ]);
|
||||||
dup2_close(fds[PIPE_WRITE], STDOUT);
|
dup2_close(fds[PIPE_WRITE], STDOUT);
|
||||||
execle(data_singleton()->argv[0],data_singleton()->argv[0],
|
execle(data_singleton()->argv[0], data_singleton()->argv[0],
|
||||||
"-c", command, NULL,
|
"-c", command, NULL,
|
||||||
data_singleton()->env);
|
data_singleton()->env);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/09 03:24:59 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:14:19 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat,
|
||||||
else
|
else
|
||||||
path = 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, pat, recursive, 0);
|
dir_research(gl, path, pat, (int[]){recursive, 0});
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
if (match_pattern(gl, str[1], path))
|
if (match_pattern(gl, str[1], path))
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +46,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat,
|
||||||
}
|
}
|
||||||
|
|
||||||
int dir_research(t_glob *gl, char *p,
|
int dir_research(t_glob *gl, char *p,
|
||||||
char *pat, int recursive, int first)
|
char *pat, int *mode)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
|
|
@ -54,7 +54,7 @@ int dir_research(t_glob *gl, char *p,
|
||||||
if (!*pat)
|
if (!*pat)
|
||||||
{
|
{
|
||||||
gl->found = 1;
|
gl->found = 1;
|
||||||
if (!first)
|
if (!mode[1])
|
||||||
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 *
|
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 *
|
||||||
(p[0] == '.' && p[1] == '/'), "/"));
|
(p[0] == '.' && p[1] == '/'), "/"));
|
||||||
else
|
else
|
||||||
|
|
@ -66,7 +66,7 @@ int dir_research(t_glob *gl, char *p,
|
||||||
dir = opendir(p);
|
dir = opendir(p);
|
||||||
while ((in = readdir(dir)))
|
while ((in = readdir(dir)))
|
||||||
dir_list_content(gl,
|
dir_list_content(gl,
|
||||||
(char *[2]){p, in->d_name}, pat, recursive);
|
(char *[2]){p, in->d_name}, pat, mode[0]);
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:53:12 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -49,11 +49,9 @@ static void init_expand(t_bquote *me, char *content, int esc)
|
||||||
{
|
{
|
||||||
ft_ld_pushfront(me->wk, gen_tab(ft_strjoinf(ft_strjoin(me->s1, content),
|
ft_ld_pushfront(me->wk, gen_tab(ft_strjoinf(ft_strjoin(me->s1, content),
|
||||||
me->s2, 1),
|
me->s2, 1),
|
||||||
calc_expand_esc(me->esc, ft_strlen(me->s1),
|
calc_expand_esc(me->esc, ft_strlen(me->s1), (int[2]){ft_strlen(content), 1},
|
||||||
(int[2]){ft_strlen(content), 1},
|
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid), ft_strlen(me->s2)}),
|
||||||
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
|
calc_expand_esc(me->esc2, ft_strlen(me->s1),
|
||||||
ft_strlen(me->s2)}),
|
|
||||||
calc_expand_esc(me->esc2, ft_strlen(me->s1),
|
|
||||||
(int[2]){ft_strlen(content), 1},
|
(int[2]){ft_strlen(content), 1},
|
||||||
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
|
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
|
||||||
ft_strlen(me->s2)}), 0));
|
ft_strlen(me->s2)}), 0));
|
||||||
|
|
@ -75,7 +73,7 @@ static char *get_output(char *command)
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!(output = command_getoutput(command)))
|
if (!(output = command_getoutput(command)))
|
||||||
return (NULL);//ft_strnew(0));
|
return (NULL);
|
||||||
len = ft_strlen(output);
|
len = ft_strlen(output);
|
||||||
while (output[--len] == '\n')
|
while (output[--len] == '\n')
|
||||||
output[len] = '\0';
|
output[len] = '\0';
|
||||||
|
|
@ -88,7 +86,7 @@ static int search_bquote(t_bquote *me)
|
||||||
char *content;
|
char *content;
|
||||||
|
|
||||||
sta = NULL;
|
sta = NULL;
|
||||||
while (*me->str)
|
while (*(++me->str))
|
||||||
{
|
{
|
||||||
sta = *me->str == '`' && !sta
|
sta = *me->str == '`' && !sta
|
||||||
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta;
|
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta;
|
||||||
|
|
@ -99,14 +97,14 @@ static int search_bquote(t_bquote *me)
|
||||||
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
||||||
me->s2 = ft_strdup(me->str + 1);
|
me->s2 = ft_strdup(me->str + 1);
|
||||||
if ((content = get_output(me->mid)))
|
if ((content = get_output(me->mid)))
|
||||||
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
init_expand(me, content,
|
||||||
|
is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
||||||
ft_strdel(&me->mid);
|
ft_strdel(&me->mid);
|
||||||
ft_strdel(&me->s1);
|
ft_strdel(&me->s1);
|
||||||
ft_strdel(&me->s2);
|
ft_strdel(&me->s2);
|
||||||
ft_strdel(&content);
|
ft_strdel(&content);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
++me->str;
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +116,7 @@ void delete(t_ld **tmp, t_ld **src)
|
||||||
else
|
else
|
||||||
ft_ld_del(tmp, &ft_tabdel);
|
ft_ld_del(tmp, &ft_tabdel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expand_bquote(t_glob *gl)
|
void expand_bquote(t_glob *gl)
|
||||||
{
|
{
|
||||||
t_ld *tmp;
|
t_ld *tmp;
|
||||||
|
|
@ -135,11 +134,10 @@ void expand_bquote(t_glob *gl)
|
||||||
me.wk = &gl->m_pat;
|
me.wk = &gl->m_pat;
|
||||||
me.esc = UCH(gl->m_pat)[1];
|
me.esc = UCH(gl->m_pat)[1];
|
||||||
me.esc2 = UCH(gl->m_pat)[2];
|
me.esc2 = UCH(gl->m_pat)[2];
|
||||||
me.str = CH(gl->m_pat)[0];
|
me.str = CH(gl->m_pat)[0] - 1;
|
||||||
if ((tmp = gl->m_pat) &&
|
if ((tmp = gl->m_pat) &&
|
||||||
(do_it = search_bquote(&me)) == 1)
|
(do_it = search_bquote(&me)) == 1)
|
||||||
delete(&tmp, &gl->m_pat);
|
delete(&tmp, &gl->m_pat);
|
||||||
// ft_ld_del(&tmp, &ft_tabdel);
|
|
||||||
if (!gl->m_pat || !gl->m_pat->next)
|
if (!gl->m_pat || !gl->m_pat->next)
|
||||||
break ;
|
break ;
|
||||||
gl->m_pat = gl->m_pat->next;
|
gl->m_pat = gl->m_pat->next;
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,21 @@
|
||||||
/* 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/03/09 03:24:24 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:30:59 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** glob return expansion of a string.
|
** glob return expansion of a string.
|
||||||
** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, **
|
** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, **
|
||||||
** input parameters are :
|
** input parameters are :
|
||||||
** -char *pat -> pattern string to be looking for match
|
** -char *pat -> pattern string to be looking for match
|
||||||
** -char *esc -> escape binary sequence of *pat
|
** -char *esc -> escape binary sequence of *pat
|
||||||
** -char **env -> env var. could be NULL
|
** -char **env -> env var. could be NULL
|
||||||
** 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)
|
static int order_glob(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
|
@ -96,9 +96,9 @@ char **glob(char *pat, unsigned char *esc,
|
||||||
gl.cur_dir = 1;
|
gl.cur_dir = 1;
|
||||||
gl.pat = CH(gl.m_pat)[0];
|
gl.pat = CH(gl.m_pat)[0];
|
||||||
if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/')
|
if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/')
|
||||||
dir_research(&gl, ".", gl.pat, 0, 1);
|
dir_research(&gl, ".", gl.pat, (int[]){0, 1});
|
||||||
else
|
else
|
||||||
dir_research(&gl, "/", gl.pat + 1, 0, 1);
|
dir_research(&gl, "/", gl.pat + 1, (int[]){0, 1});
|
||||||
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
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/27 18:19:55 by wescande #+# #+# */
|
/* Created: 2017/01/27 18:19:55 by wescande #+# #+# */
|
||||||
/* Updated: 2017/02/20 20:43:38 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 23:11:59 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -67,6 +67,5 @@ unsigned char *dup_char_esc(const unsigned char *esc, const int size)
|
||||||
if (!(new_esc = (unsigned char *)ft_strnew(size)))
|
if (!(new_esc = (unsigned char *)ft_strnew(size)))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
new_esc = ft_memcpy(new_esc, esc, size);
|
new_esc = ft_memcpy(new_esc, esc, size);
|
||||||
|
|
||||||
return (new_esc);
|
return (new_esc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/03/09 03:24:48 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:25:44 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ static int match_star(t_glob *gl, char *str, char *full_word)
|
||||||
|
|
||||||
if (gl->pat[1] == '*' &&
|
if (gl->pat[1] == '*' &&
|
||||||
!is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1))
|
!is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1))
|
||||||
dir_research(gl, full_word, gl->pat + 1, 1, 0);
|
dir_research(gl, full_word, gl->pat + 1, (int[]){1, 0});
|
||||||
if (!*gl->pat || (*gl->pat == '*' && !*++gl->pat))
|
if (!*gl->pat || (*gl->pat == '*' && !*++gl->pat))
|
||||||
return (1);
|
return (1);
|
||||||
pat = gl->pat;
|
pat = gl->pat;
|
||||||
|
|
@ -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))
|
||||||
return (dir_research(gl, full_word, gl->pat + 1, 0, 0));
|
return (dir_research(gl, full_word, gl->pat + 1, (int[]){0, 0}));
|
||||||
else if (*gl->pat != *str)
|
else if (*gl->pat != *str)
|
||||||
return (0);
|
return (0);
|
||||||
++str;
|
++str;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
|
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/07 20:40:30 by wescande ### ########.fr */
|
/* Updated: 2017/03/14 23:12:20 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,5 +17,7 @@ void *tab_esc_copy(void *content)
|
||||||
char **ch_cont;
|
char **ch_cont;
|
||||||
|
|
||||||
ch_cont = (char **)content;
|
ch_cont = (char **)content;
|
||||||
return (gen_tab(ch_cont[0], (unsigned char *)ch_cont[1], (unsigned char *)ch_cont[2], 1));
|
return (gen_tab(ch_cont[0],
|
||||||
|
(unsigned char *)ch_cont[1],
|
||||||
|
(unsigned char *)ch_cont[2], 1));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue