rectif free on expand_var
This commit is contained in:
parent
ec945bb5a5
commit
6ce2a1ec14
8 changed files with 105 additions and 42 deletions
|
|
@ -59,7 +59,6 @@ completion/c_sizing.c\
|
|||
completion/c_terminal.c\
|
||||
completion/completion.c\
|
||||
exec/ast_free.c\
|
||||
exec/redir_free.c\
|
||||
exec/bad_fd.c\
|
||||
exec/exec_ampersand.c\
|
||||
exec/exec_and_if.c\
|
||||
|
|
@ -88,6 +87,7 @@ exec/process_reset.c\
|
|||
exec/process_setexec.c\
|
||||
exec/process_setgroup.c\
|
||||
exec/process_setsig.c\
|
||||
exec/redir_free.c\
|
||||
exec/redirect_dgreat.c\
|
||||
exec/redirect_dless.c\
|
||||
exec/redirect_great.c\
|
||||
|
|
@ -101,6 +101,7 @@ glob/esc_print.c\
|
|||
glob/expand_bquote.c\
|
||||
glob/expand_brace.c\
|
||||
glob/expand_esc.c\
|
||||
glob/expand_home.c\
|
||||
glob/expand_var.c\
|
||||
glob/ft_strsplit_esc.c\
|
||||
glob/ft_strsplit_spe.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 20:07:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:28:08 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ void set_exitstatus(int status, int override);
|
|||
void ast_free(void *data, size_t content_size);
|
||||
void redir_free(void *data, size_t content_size);
|
||||
|
||||
char **token_to_argv(t_ld *ld);
|
||||
char **token_to_argv(t_ld *ld, int do_match);
|
||||
|
||||
int add_new_job(t_job *job);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/20 19:03:45 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:39:05 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);
|
||||
|
||||
/*
|
||||
|
|
@ -96,6 +96,7 @@ void modify_esc_split(unsigned char *esc_dest,
|
|||
void expand_brace(t_glob *tglob);
|
||||
void expand_bquote(t_glob *gl);
|
||||
void expand_var(t_glob *tglob);
|
||||
void expand_home(t_glob *gl, char *str);
|
||||
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||
int dir_research(t_glob *tglob, char *p, char *pat, int rec);
|
||||
char **gen_tab(const char *pat, const unsigned char *esc,
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 19:46:11 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:28:21 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
char **token_to_argv(t_ld *ld)
|
||||
char **token_to_argv(t_ld *ld, int do_match)
|
||||
{
|
||||
char **my_tab;
|
||||
int index;
|
||||
|
|
@ -23,7 +23,7 @@ char **token_to_argv(t_ld *ld)
|
|||
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], do_match)))
|
||||
{
|
||||
index = -1;
|
||||
while (expand[++index])
|
||||
|
|
@ -65,7 +65,7 @@ int exec_cmd(t_btree **ast)
|
|||
job->first_process = NULL;
|
||||
job->attrs = EXEC_IS_FG(exec->attrs) ? 0 : JOB_BG;
|
||||
}
|
||||
if (!(p.av = token_to_argv(cmd->token)))
|
||||
if (!(p.av = token_to_argv(cmd->token, 1)))
|
||||
return (1);
|
||||
process_setexec(&p);
|
||||
if (!(launch_process(&p)))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 16:28:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:32:27 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int exec_var(t_btree **ast)
|
|||
char **av;
|
||||
|
||||
node = (*ast)->item;
|
||||
/* av = token_to_argv(node); */
|
||||
av = token_to_argv(node->data.cmd.token, 0);
|
||||
builtin_setenv("setenv", av, data_singleton()->local_var);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
51
42sh/src/glob/expand_home.c
Normal file
51
42sh/src/glob/expand_home.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_home.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 14:11:46 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/03 20:23:49 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void do_expand_home(t_bquote *me, char *home)
|
||||
{
|
||||
char **old_tab;
|
||||
char **new_tab;
|
||||
|
||||
old_tab = CH(*me->wk);
|
||||
new_tab = gen_tab(ft_strjoin(home, me->str + 1),
|
||||
calc_expand_esc(me->esc, 0,
|
||||
(int[2]){ft_strlen(home), 1},
|
||||
(int[2]){1, ft_strlen(me->str) - 1}),
|
||||
calc_expand_esc(me->esc2, 0,
|
||||
(int[2]){ft_strlen(home), 1},
|
||||
(int[2]){1, ft_strlen(me->str) - 1}), 0);
|
||||
(*me->wk)->content = new_tab;
|
||||
ft_tabdel(&old_tab);
|
||||
}
|
||||
|
||||
void expand_home(t_glob *gl, char *home)
|
||||
{
|
||||
t_bquote me;
|
||||
|
||||
me = (t_bquote){NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
gl->m_pat = ft_ld_front(gl->m_pat);
|
||||
while (gl->m_pat)
|
||||
{
|
||||
me.wk = &gl->m_pat;
|
||||
me.esc = UCH(gl->m_pat)[1];
|
||||
me.esc2 = UCH(gl->m_pat)[2];
|
||||
me.str = CH(gl->m_pat)[0];
|
||||
if (!is_char_esc(me.esc, me.str, me.str) && me.str[0] == '~')
|
||||
do_expand_home(&me, home);
|
||||
if (!gl->m_pat->next)
|
||||
break ;
|
||||
gl->m_pat = gl->m_pat->next;
|
||||
}
|
||||
gl->m_pat = ft_ld_front(gl->m_pat);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 16:09:27 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/24 22:05:34 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:38:36 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,7 +42,6 @@ static void insert_var(t_glob *gl, char *pos, char *name, char *content)
|
|||
gl->esc2 = new_esc;
|
||||
ft_strdel(&s1);
|
||||
ft_strdel(&s2);
|
||||
ft_strdel(&content);
|
||||
}
|
||||
|
||||
static char *get_name(t_glob *gl, const char *pat)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/24 22:05:48 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:38:53 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,8 +34,20 @@ static char **treat_glob(t_glob *gl)
|
|||
return (ret);
|
||||
}
|
||||
|
||||
static void normal_expand_before_match(t_glob *gl, int do_match)
|
||||
{
|
||||
char *home;
|
||||
|
||||
expand_var(gl);
|
||||
expand_bquote(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;
|
||||
|
|
@ -43,9 +55,8 @@ 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};
|
||||
expand_var(&gl);
|
||||
expand_bquote(&gl);
|
||||
expand_brace(&gl);
|
||||
normal_expand_before_match(&gl, do_match);
|
||||
if (do_match)
|
||||
while (gl.m_pat && !(gl.found = 0))
|
||||
{
|
||||
gl.cur_dir = 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue