first batch of fixes on lexer and bquote expansion
This commit is contained in:
parent
665c593f5d
commit
75c11ff4a6
5 changed files with 24 additions and 12 deletions
|
|
@ -49,12 +49,15 @@ int bquotes_substitute(t_list *cur_word, char *bq_start, char *bq_end)
|
|||
|
||||
*bq_start = 0;
|
||||
*bq_end = 0;
|
||||
output = command_getoutput(bq_start + 1);
|
||||
if ((output = command_getoutput(bq_start + 1)))
|
||||
{
|
||||
last_char = output + ft_strlen(output) - 1;
|
||||
while (*last_char == '\n')
|
||||
*last_char++ = 0;
|
||||
}
|
||||
DG("output = [%s]", output);
|
||||
after_bq = ft_strdup(bq_end + 1);
|
||||
last_char = output + ft_strlen(output) - 1;
|
||||
while (*last_char == '\n')
|
||||
*last_char++ = 0;
|
||||
bquotes_insert_words(cur_word, output, after_bq);
|
||||
bquotes_insert_words(cur_word, output ? output : "", after_bq);
|
||||
ft_strdel(&output);
|
||||
ft_strdel(&after_bq);
|
||||
return (0);
|
||||
|
|
@ -85,6 +88,8 @@ int bquotes_expand(t_list **alst)
|
|||
}
|
||||
if (bquotes_substitute(cur_word, bq_start, bq_end))
|
||||
return (-1);
|
||||
if (!(*((t_token*)cur_word->content)->data))
|
||||
ft_lst_delif(alst, cur_word->content, ft_addrcmp, token_free);
|
||||
cur_word = lst;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -19,8 +19,13 @@ int lexer_backslash(t_list **alst, t_lexer *lexer)
|
|||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
lexer->pos++;
|
||||
lexer->state = WORD;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
{
|
||||
push(&lexer->stack, BACKSLASH);
|
||||
return (0);
|
||||
}
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
lexer->state = WORD;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
|
|||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
{
|
||||
push(&lexer->stack, BACKSLASH);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ int lexer_number(t_list **alst, t_lexer *lexer)
|
|||
|
||||
token = (*alst)->content;
|
||||
if ((state = get_state_global(lexer)))
|
||||
{
|
||||
lexer->state = state;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
else if ((state = get_state_redir(lexer)))
|
||||
{
|
||||
lexer->state = state;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ int non_interactive_shell(char *command)
|
|||
do {
|
||||
lexer_lex(&token, &lexer);
|
||||
} while (lexer.str[lexer.pos] == '\n');
|
||||
if (!token)
|
||||
return (0);
|
||||
if (bquotes_expand(&token))
|
||||
return (1);
|
||||
token_print(token);
|
||||
|
|
@ -55,18 +57,18 @@ int interactive_shell()
|
|||
lexer.stack = NULL;
|
||||
ast = NULL;
|
||||
do {
|
||||
ft_strappend(&lexer.str, readline(stack_to_prompt(lexer.stack)));
|
||||
if (lexer.stack && *(int*)lexer.stack->content == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
ft_strappend(&lexer.str, readline(stack_to_prompt(lexer.stack)));
|
||||
ltoken = ft_lstlast(token);
|
||||
lexer_lex((token ? <oken : &token), &lexer);
|
||||
DG("[{mag}%s{eoc}] stack=[%i] state=[%i]", lexer.str, lexer.stack ? *(int*)lexer.stack->content : 0, lexer.state);
|
||||
token_print(token);
|
||||
} while (lexer.stack);
|
||||
if (!token)
|
||||
return (0);
|
||||
if (bquotes_expand(&token))
|
||||
return (1);
|
||||
if (!token)
|
||||
return (0);
|
||||
token_print(token);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue