Merge branch 'master' of https://github.com/jzck/minishell
This commit is contained in:
commit
5cac33e7cf
5 changed files with 75 additions and 28 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/02/04 12:47:31 by gwojda ### ########.fr #
|
# Updated: 2017/02/06 15:47:04 by wescande ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ NB = $(words $(SRC_BASE))
|
||||||
INDEX = 0
|
INDEX = 0
|
||||||
|
|
||||||
all :
|
all :
|
||||||
@make $(NAME)
|
@make -j $(NAME)
|
||||||
|
|
||||||
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
||||||
@$(CC) $(FLAGS) $(D_FLAGS) \
|
@$(CC) $(FLAGS) $(D_FLAGS) \
|
||||||
|
|
|
||||||
|
|
@ -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/02/01 19:50:07 by wescande ### ########.fr */
|
/* Updated: 2017/02/06 15:12:39 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -53,11 +53,19 @@ char **glob(const char *str, const unsigned char *esc);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int is_directory(const char *path);
|
int is_directory(const char *path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** return TRUE if char at str_pos in ini_str is escape.
|
** return TRUE if char at str_pos in ini_str is escape.
|
||||||
|
** five the possibility to set if the char is esc or not.
|
||||||
*/
|
*/
|
||||||
int is_char_esc(const unsigned char *esc,
|
int is_char_esc(const unsigned char *esc,
|
||||||
const char *ini_str, const char *str_pos);
|
const char *ini_str, const char *str_pos);
|
||||||
|
void set_char_esc_mode(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos, int mode);
|
||||||
|
void set_char_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos);
|
||||||
|
void set_char_no_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Internal function.
|
** Internal function.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/03 17:30:08 by jhalford ### ########.fr */
|
/* Updated: 2017/02/06 15:31:42 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,11 +27,13 @@ static char **token_to_argv(t_astnode *node)
|
||||||
while (ld)
|
while (ld)
|
||||||
{
|
{
|
||||||
content = ld->content;
|
content = ld->content;
|
||||||
expand = glob(content[0], (unsigned char *)content[1]);
|
if ((expand = glob(content[0], (unsigned char *)content[1])))
|
||||||
index = -1;
|
{
|
||||||
while (expand[++index])
|
index = -1;
|
||||||
my_tab = ft_sstradd(my_tab, expand[index]);
|
while (expand[++index])
|
||||||
ft_tabdel(&expand);
|
my_tab = ft_sstradd(my_tab, expand[index]);
|
||||||
|
ft_tabdel(&expand);
|
||||||
|
}
|
||||||
ld = ld->next;
|
ld = ld->next;
|
||||||
}
|
}
|
||||||
return (my_tab);
|
return (my_tab);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 19:00:29 by wescande #+# #+# */
|
/* Created: 2017/01/12 19:00:29 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/31 23:20:38 by wescande ### ########.fr */
|
/* Updated: 2017/02/06 15:51:32 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
** pattern searched are {ab, cd}.
|
** pattern searched are {ab, cd}.
|
||||||
** return is t_ld which first param is ab and second is cd
|
** return is t_ld which first param is ab and second is cd
|
||||||
** input parameters are :
|
** input parameters are :
|
||||||
** -char *pat -> pattern string to be looking for expand
|
** -t_glob *gl -> struct of expanding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char **gen_tab(const char *pat,
|
static char **gen_tab(const char *pat,
|
||||||
|
|
@ -49,9 +49,9 @@ static void iter_on_each(t_expand *me)
|
||||||
unsigned char *second;
|
unsigned char *second;
|
||||||
t_ld *wk_tmp;
|
t_ld *wk_tmp;
|
||||||
|
|
||||||
i = -1;
|
i = ft_tablen(me->split);
|
||||||
wk_tmp = *me->wk;
|
wk_tmp = *me->wk;
|
||||||
while (me->split[++i])
|
while (i--)
|
||||||
{
|
{
|
||||||
first = ft_strjoinf(ft_strjoin(me->s1, me->split[i]), me->str + 1, 1);
|
first = ft_strjoinf(ft_strjoin(me->s1, me->split[i]), me->str + 1, 1);
|
||||||
second = calc_expand_esc(me->esc,
|
second = calc_expand_esc(me->esc,
|
||||||
|
|
@ -66,7 +66,7 @@ static void iter_on_each(t_expand *me)
|
||||||
me->wk = &wk_tmp;
|
me->wk = &wk_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_expand(t_expand *me, char *start)
|
static int init_expand(t_expand *me, char *start)
|
||||||
{
|
{
|
||||||
unsigned char *esc;
|
unsigned char *esc;
|
||||||
|
|
||||||
|
|
@ -81,28 +81,32 @@ static void init_expand(t_expand *me, char *start)
|
||||||
ft_strdel(&me->s1);
|
ft_strdel(&me->s1);
|
||||||
ft_tabdel(&me->split);
|
ft_tabdel(&me->split);
|
||||||
ft_tabdel((char ***)&me->m_esc);
|
ft_tabdel((char ***)&me->m_esc);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int search_brace(t_expand *me)
|
static int search_brace(t_expand *me)
|
||||||
{
|
{
|
||||||
char *start;
|
char *start;
|
||||||
|
int comma;
|
||||||
int nb;
|
int nb;
|
||||||
|
|
||||||
start = NULL;
|
start = NULL;
|
||||||
nb = 0;
|
nb = 0;
|
||||||
|
comma = 0;
|
||||||
while (*me->str)
|
while (*me->str)
|
||||||
{
|
{
|
||||||
start = *me->str == '{'
|
start = *me->str == '{' && !is_char_esc(me->esc, CH(*me->wk)[0],
|
||||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str)
|
me->str) && nb == 0 ? me->str : start;
|
||||||
&& nb == 0 ? me->str : start;
|
nb += *me->str == '{' && !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
||||||
nb += *me->str == '{'
|
nb -= *me->str == '}' && !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
||||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
comma += *me->str == ',' && nb == 1;
|
||||||
nb -= *me->str == '}'
|
|
||||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
|
||||||
if (!nb && start)
|
if (!nb && start)
|
||||||
{
|
{
|
||||||
init_expand(me, start);
|
if (comma)
|
||||||
return (1);
|
return (init_expand(me, start));
|
||||||
|
set_char_esc(me->esc, CH(*me->wk)[0], start);
|
||||||
|
set_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
||||||
|
return (2);
|
||||||
}
|
}
|
||||||
++me->str;
|
++me->str;
|
||||||
}
|
}
|
||||||
|
|
@ -127,11 +131,9 @@ void expand_brace(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.str = CH(gl->m_pat)[0];
|
me.str = CH(gl->m_pat)[0];
|
||||||
if ((tmp = gl->m_pat) && search_brace(&me))
|
if ((tmp = gl->m_pat) &&
|
||||||
{
|
(do_it = search_brace(&me)) == 1)
|
||||||
ft_ld_del(&tmp, &ft_tabdel);
|
ft_ld_del(&tmp, &ft_tabdel);
|
||||||
do_it = 1;
|
|
||||||
}
|
|
||||||
gl->m_pat = gl->m_pat->next;
|
gl->m_pat = gl->m_pat->next;
|
||||||
}
|
}
|
||||||
gl->m_pat = ft_ld_front(gl->m_pat);
|
gl->m_pat = ft_ld_front(gl->m_pat);
|
||||||
|
|
|
||||||
|
|
@ -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/01/27 23:45:51 by wescande ### ########.fr */
|
/* Updated: 2017/02/06 15:11:14 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,8 +17,43 @@ int is_char_esc(const unsigned char *esc,
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
|
if (!esc || !ini_str || !str_pos)
|
||||||
|
return (0);
|
||||||
pos = str_pos - ini_str;
|
pos = str_pos - ini_str;
|
||||||
if ((esc[pos / 8] >> (7 - pos % 8)) & 1)
|
if ((esc[pos / 8] >> (7 - pos % 8)) & 1)
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_char_esc_mode(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos, int mode)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (!esc || !ini_str || !str_pos || mode < 0 || mode > 1)
|
||||||
|
return ;
|
||||||
|
pos = str_pos - ini_str;
|
||||||
|
esc[pos / 8] |= mode << (7 - pos % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_char_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (!esc || !ini_str || !str_pos)
|
||||||
|
return ;
|
||||||
|
pos = str_pos - ini_str;
|
||||||
|
esc[pos / 8] |= 1 << (7 - pos % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_char_no_esc(unsigned char *esc,
|
||||||
|
const char *ini_str, const char *str_pos)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (!esc || !ini_str || !str_pos)
|
||||||
|
return ;
|
||||||
|
pos = str_pos - ini_str;
|
||||||
|
esc[pos / 8] |= 0 << (7 - pos % 8);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue