From df7ed59b032bad39ac6ec93c491c89050475e491 Mon Sep 17 00:00:00 2001 From: wescande Date: Fri, 3 Mar 2017 16:30:06 +0100 Subject: [PATCH] ajout du bool dans l'appel a glob pour demander un matching complet ou juste une expnsion de var +bquote (cas de l'assignation de variables) --- 42sh/includes/glob.h | 4 ++-- 42sh/libft | 2 +- 42sh/src/exec/exec_command.c | 4 ++-- 42sh/src/glob/glob.c | 42 +++++++++++++++++++----------------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/42sh/includes/glob.h b/42sh/includes/glob.h index 80287b48..008e9eb4 100644 --- a/42sh/includes/glob.h +++ b/42sh/includes/glob.h @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:31:18 by wescande #+# #+# */ -/* Updated: 2017/03/03 12:10:17 by wescande ### ########.fr */ +/* Updated: 2017/03/03 16:15:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ typedef struct s_bquote ** interface of glob. */ char **glob(char *str, unsigned char *esc, - unsigned char *dbl_esc); + unsigned char *dbl_esc, int do_match); void esc_print(char *str, unsigned char *esc); /* diff --git a/42sh/libft b/42sh/libft index bfc8ca20..8f6e64fa 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit bfc8ca207ab4d39f0140322c0f1d368137304a3c +Subproject commit 8f6e64fa9b4ac1dd3e3d5200fb93471ddfeedd40 diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index a2988704..7790ccaa 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/02/07 18:06:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 16:19:31 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ static char **token_to_argv(t_astnode *node) while (ld) { content = ld->content; - if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2]))) + if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2], 1))) { index = -1; while (expand[++index]) diff --git a/42sh/src/glob/glob.c b/42sh/src/glob/glob.c index ee862418..522c0122 100644 --- a/42sh/src/glob/glob.c +++ b/42sh/src/glob/glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/03/03 12:11:17 by wescande ### ########.fr */ +/* Updated: 2017/03/03 16:18:11 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,19 +34,20 @@ static char **treat_glob(t_glob *gl) return (ret); } -static void normal_expand_before_match(t_glob *gl) +static void normal_expand_before_match(t_glob *gl, int do_match) { char *home; expand_var(gl); expand_bquote(gl); - expand_brace(gl); + if (do_match) + expand_brace(gl); if ((home = ft_getenv(data_singleton()->env, "HOME"))) expand_home(gl, home); } char **glob(char *pat, unsigned char *esc, - unsigned char *esc2) + unsigned char *esc2, int do_match) { t_glob gl; int len; @@ -54,21 +55,22 @@ char **glob(char *pat, unsigned char *esc, len = ft_strlen(pat); gl = (t_glob){0, 0, ft_strdup(pat), dup_char_esc(esc, (len >> 3) + 1), dup_char_esc(esc2, (len >> 3) + 1), NULL, NULL}; - normal_expand_before_match(&gl); - while (gl.m_pat && !(gl.found = 0)) - { - gl.cur_dir = 1; - gl.pat = CH(gl.m_pat)[0]; - if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/') - dir_research(&gl, ".", gl.pat, 0); - else - dir_research(&gl, "/", gl.pat + 1, 0); - if (!gl.found) - ft_ld_pushfront(&gl.match, - ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0])); - if (!gl.m_pat->next) - break ; - gl.m_pat = gl.m_pat->next; - } + normal_expand_before_match(&gl, do_match); + if (do_match) + while (gl.m_pat && !(gl.found = 0)) + { + gl.cur_dir = 1; + gl.pat = CH(gl.m_pat)[0]; + if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/') + dir_research(&gl, ".", gl.pat, 0); + else + dir_research(&gl, "/", gl.pat + 1, 0); + if (!gl.found) + ft_ld_pushfront(&gl.match, + ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0])); + if (!gl.m_pat->next) + break ; + gl.m_pat = gl.m_pat->next; + } return (treat_glob(&gl)); }