backquote expansion checks for splitting
This commit is contained in:
parent
2e0b6102ce
commit
4840051dbd
6 changed files with 31 additions and 21 deletions
|
|
@ -246,7 +246,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||||
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||||
@printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
@printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
||||||
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
@$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\
|
||||||
-I $(INC_DIR)\
|
-I $(INC_DIR)\
|
||||||
-I $(LIBFT_INC)
|
-I $(LIBFT_INC)
|
||||||
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_memrealloc.c :+: :+: :+: */
|
/* ft_memrealloc.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/05 13:44:36 by wescande #+# #+# */
|
/* Created: 2016/11/05 13:44:36 by wescande #+# #+# */
|
||||||
/* Updated: 2017/02/10 12:13:23 by gwojda ### ########.fr */
|
/* Updated: 2017/02/09 17:01:01 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,16 @@ int expand_bquotes(t_list **alst)
|
||||||
t_list *cur_word;
|
t_list *cur_word;
|
||||||
t_list *lst;
|
t_list *lst;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_token token_buf;
|
t_token *token_buf;
|
||||||
char *word;
|
char *word;
|
||||||
|
char *ifs;
|
||||||
char *output;
|
char *output;
|
||||||
|
char *last_char;
|
||||||
char *bq_start;
|
char *bq_start;
|
||||||
char *bq_end;
|
char *bq_end;
|
||||||
char *after_bq;
|
char *after_bq;
|
||||||
char **str;
|
char **str;
|
||||||
|
t_lexer lexer;
|
||||||
t_flag tk;
|
t_flag tk;
|
||||||
|
|
||||||
tk = TK_WORD;
|
tk = TK_WORD;
|
||||||
|
|
@ -36,7 +39,6 @@ int expand_bquotes(t_list **alst)
|
||||||
after_word = cur_word->next;
|
after_word = cur_word->next;
|
||||||
token = cur_word->content;
|
token = cur_word->content;
|
||||||
str = &token->data;
|
str = &token->data;
|
||||||
DG("found word=[%s]", *str);
|
|
||||||
if (!(bq_start = ft_strchr(*str, '`')))
|
if (!(bq_start = ft_strchr(*str, '`')))
|
||||||
{
|
{
|
||||||
cur_word = cur_word->next;
|
cur_word = cur_word->next;
|
||||||
|
|
@ -49,31 +51,37 @@ int expand_bquotes(t_list **alst)
|
||||||
}
|
}
|
||||||
*bq_end = 0;
|
*bq_end = 0;
|
||||||
after_bq = ft_strdup(bq_end + 1);
|
after_bq = ft_strdup(bq_end + 1);
|
||||||
output = command_getoutput(bq_start + 1);
|
word = command_getoutput(bq_start + 1);
|
||||||
word = ft_strtok(output, " \n\t");
|
output = word;
|
||||||
DG("strtok=[%s]", word);
|
last_char = word + ft_strlen(word) - 1;
|
||||||
DG("first_tok was [%s]", *str);
|
while (*last_char == '\n')
|
||||||
|
*last_char++ = 0;
|
||||||
|
ifs = ft_getenv(data_singleton()->env, "IFS");
|
||||||
|
if (ifs)
|
||||||
|
word = ft_strtok(word, ifs);
|
||||||
*bq_start = 0;
|
*bq_start = 0;
|
||||||
ft_strappend(str, word);
|
ft_strappend(str, word);
|
||||||
DG("first_tok=[%s]", *str);
|
while (ifs && (lexer.str = ft_strtok(NULL, ifs)))
|
||||||
while ((word = ft_strtok(NULL, " \n\t")))
|
|
||||||
{
|
{
|
||||||
DG("strtok=[%s]", word);
|
lexer.pos = 0;
|
||||||
token_buf.data = ft_strdup(word);
|
token_buf = token_init();
|
||||||
token_buf.type = TK_WORD;
|
token_buf->type = TK_WORD;
|
||||||
new_word = ft_lstnew(&token_buf, sizeof(token_buf));
|
while (lexer.str[lexer.pos])
|
||||||
|
{
|
||||||
|
token_append(token_buf, &lexer, 0, 0);
|
||||||
|
lexer.pos++;
|
||||||
|
}
|
||||||
|
new_word = ft_lstnew(token_buf, sizeof(*token_buf));
|
||||||
cur_word->next = new_word;
|
cur_word->next = new_word;
|
||||||
new_word->next = after_word;
|
new_word->next = after_word;
|
||||||
cur_word = new_word;
|
cur_word = new_word;
|
||||||
}
|
}
|
||||||
token = new_word->content;
|
token = cur_word->content;
|
||||||
ft_strappend(&token->data, after_bq);
|
ft_strappend(&token->data, after_bq);
|
||||||
ft_strdel(&after_bq);
|
ft_strdel(&after_bq);
|
||||||
ft_strdel(&output);
|
ft_strdel(&output);
|
||||||
cur_word = after_word;
|
cur_word = after_word;
|
||||||
}
|
}
|
||||||
token_print(*alst);
|
|
||||||
DG("check end");
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,10 @@ int lexer_bquote(t_list **alst, t_lexer *lexer)
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
token_append(token, lexer, 0, 0);
|
if (lexer->state == DQUOTE_BQUOTE)
|
||||||
|
token_append(token, lexer, 1, 1);
|
||||||
|
else
|
||||||
|
token_append(token, lexer, 0, 0);
|
||||||
if (lexer->str[lexer->pos] == '`')
|
if (lexer->str[lexer->pos] == '`')
|
||||||
{
|
{
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ int lexer_delim(t_list **alst, t_lexer *lexer)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
DG("DELIM");
|
|
||||||
while (ft_is_delim(lexer->str[lexer->pos]))
|
while (ft_is_delim(lexer->str[lexer->pos]))
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
lexer->state = DEFAULT;
|
lexer->state = DEFAULT;
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,9 @@ int interactive_shell()
|
||||||
return (1);
|
return (1);
|
||||||
DG("check main 0");
|
DG("check main 0");
|
||||||
token_print(token);
|
token_print(token);
|
||||||
DG("check main 1");
|
|
||||||
if (ft_parse(&ast, &token))
|
if (ft_parse(&ast, &token))
|
||||||
return (1);
|
return (1);
|
||||||
|
DG("check main 1");
|
||||||
btree_print(STDBUG, ast, &ft_putast);
|
btree_print(STDBUG, ast, &ft_putast);
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue