execution case without extension
This commit is contained in:
parent
4849c899e4
commit
2b5b23e981
13 changed files with 46 additions and 37 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
case $rental in
|
case van in
|
||||||
( "bus" ) echo Hello world ;;
|
( "bus" ) echo Hello world ;;
|
||||||
( "van" ) echo Comment va ? ;;
|
( "velo" ) echo Comment va ;;
|
||||||
|
( "van" ) ls ;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,17 @@
|
||||||
|
|
||||||
int exec_case(t_btree **ast)
|
int exec_case(t_btree **ast)
|
||||||
{
|
{
|
||||||
// t_astnode *node;
|
t_astnode *node;
|
||||||
/* char **av; */
|
char *av;
|
||||||
t_exec *exec;
|
t_exec *exec;
|
||||||
|
|
||||||
(void)ast;
|
(void)ast;
|
||||||
return (0);
|
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
/* data_singleton()->exec.process.case_branch = 0; */
|
exec->attrs &= ~EXEC_CASE_BRANCH;
|
||||||
exec->attrs |= EXEC_CASE_BRANCH;
|
|
||||||
|
|
||||||
// node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
/* av = token_to_argv(node); */
|
av = node->data.str;
|
||||||
/* data_singleton()->exec.process.case_pattern = av[0]; */
|
// av = token_to_argv(node);
|
||||||
/* exec->case_pattern = av[0]; */
|
exec->case_pattern = av;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,24 @@
|
||||||
|
|
||||||
int exec_case_branch(t_btree **ast)
|
int exec_case_branch(t_btree **ast)
|
||||||
{
|
{
|
||||||
// t_astnode *node;
|
t_astnode *node;
|
||||||
/* char **av; */
|
char *av;
|
||||||
t_exec *exec;
|
t_exec *exec;
|
||||||
|
|
||||||
(void)ast;
|
(void)ast;
|
||||||
return (0);
|
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
/* if (data_singleton()->exec.process.case_branch == 1) */
|
|
||||||
|
DG("case");
|
||||||
if (EXEC_IS_CASE_BRANCH(exec->attrs))
|
if (EXEC_IS_CASE_BRANCH(exec->attrs))
|
||||||
return (0);
|
return (0);
|
||||||
// node = (*ast)->item;
|
DG("case2");
|
||||||
/* av = token_to_argv(node); */
|
node = (*ast)->item;
|
||||||
/* if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1) */
|
av = node->data.str;
|
||||||
/* { */
|
// av = token_to_argv(node);
|
||||||
/* data_singleton()->exec.process.case_branch = 1; */
|
if (ft_strcmp(av, exec->case_pattern) == 0)
|
||||||
/* ft_exec(&(*ast)->right); */
|
{
|
||||||
/* } */
|
exec->attrs |= EXEC_CASE_BRANCH;
|
||||||
|
ft_exec(&(*ast)->right);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ t_execmap g_execmap[] =
|
||||||
{TK_ELSE, &exec_else},
|
{TK_ELSE, &exec_else},
|
||||||
{TK_UNTIL, &exec_until},
|
{TK_UNTIL, &exec_until},
|
||||||
{TK_FOR, &exec_for},
|
{TK_FOR, &exec_for},
|
||||||
|
{TK_CASE, &exec_case},
|
||||||
|
{TK_PAREN_OPEN, &exec_case_branch},
|
||||||
/* {TK_SUBSHELL, &exec_}, */
|
/* {TK_SUBSHELL, &exec_}, */
|
||||||
{CMD, &exec_cmd},
|
{CMD, &exec_cmd},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ char *ft_putast(void *nodein)
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
node = nodein;
|
node = nodein;
|
||||||
|
|
||||||
|
if (node->type == TK_DSEMI)
|
||||||
|
return ("TK_DSEMI");
|
||||||
if (node->type == WORDLIST)
|
if (node->type == WORDLIST)
|
||||||
return ("WORDLIST");
|
return ("WORDLIST");
|
||||||
if (node->type == CMD)
|
if (node->type == CMD)
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ int handle_instruction(int fd)
|
||||||
error_syntax(&token, &parser, &ast);
|
error_syntax(&token, &parser, &ast);
|
||||||
}
|
}
|
||||||
DG("Before execution:");
|
DG("Before execution:");
|
||||||
btree_print(STDBUG, ast, &ft_putast);
|
// btree_print(STDBUG, ast, &ft_putast);
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
instruction_free(&token, &parser, &ast);
|
instruction_free(&token, &parser, &ast);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ int iscase_pattern(t_btree **ast, t_list **lst)
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
|
DG(" add pattern");
|
||||||
node = NULL;
|
node = NULL;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ int superflous_token(t_btree **ast, t_list **lst)
|
||||||
if (*lst)
|
if (*lst)
|
||||||
{
|
{
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type == TK_IN || token->type == TK_PAREN_OPEN)
|
if (token->type == TK_IN || token->type == TK_PAREN_CLOSE
|
||||||
|
|| token->type == TK_DSEMI)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -54,7 +55,7 @@ static int no_del_token(t_btree **ast, t_list **lst)
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if (node->type != TK_DO && node->type != TK_THEN && node->type != TK_PAREN_CLOSE
|
if (node->type != TK_DO && node->type != TK_THEN
|
||||||
&& node->type != CMD && node->type != REDIR)
|
&& node->type != CMD && node->type != REDIR)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
@ -91,6 +92,7 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
node->type = CMD;
|
node->type = CMD;
|
||||||
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
|
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
|
||||||
{
|
{
|
||||||
|
DG("add cmd default");
|
||||||
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
|
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
|
||||||
{
|
{
|
||||||
my_tab[0] = ft_strdup(token->data);
|
my_tab[0] = ft_strdup(token->data);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ int iscondition(t_btree **ast, t_list **lst)
|
||||||
|
|
||||||
node = NULL;
|
node = NULL;
|
||||||
// token = (*lst)->content;
|
// token = (*lst)->content;
|
||||||
DG("iscondition");
|
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ t_aggrematch g_aggrematch[] =
|
||||||
{TK_WORD, TK_IN, FOR_WORDLIST, TK_IN},
|
{TK_WORD, TK_IN, FOR_WORDLIST, TK_IN},
|
||||||
{TK_WORD, FOR_WORDLIST, FOR_WORDLIST, FOR_WORDLIST},
|
{TK_WORD, FOR_WORDLIST, FOR_WORDLIST, FOR_WORDLIST},
|
||||||
{TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0},
|
{TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0},
|
||||||
|
{TK_DSEMI, CMD_SUPERIOR, PIPE_SEQUENCE, CMD_SUPERIOR},
|
||||||
{TK_DSEMI, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
{TK_DSEMI, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
||||||
{TK_PAREN_OPEN, TK_IN, PATTERN_CASE, 0},
|
{TK_PAREN_OPEN, TK_IN, PATTERN_CASE, 0},
|
||||||
{TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0},
|
{TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0},
|
||||||
|
|
@ -315,21 +316,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
DG("aggregate head %s && sym %s",
|
// DG("aggregate head %s && sym %s",
|
||||||
read_state(*head), read_state(*new_sym));
|
// read_state(*head), read_state(*new_sym));
|
||||||
while (g_aggrematch[i].top)
|
while (g_aggrematch[i].top)
|
||||||
{
|
{
|
||||||
if (*new_sym == g_aggrematch[i].top
|
if (*new_sym == g_aggrematch[i].top
|
||||||
&& MATCH_STACK(*head, g_aggrematch[i].under))
|
&& MATCH_STACK(*head, g_aggrematch[i].under))
|
||||||
|
|
||||||
{
|
{
|
||||||
DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
|
// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
|
||||||
*new_sym = g_aggrematch[i].new_sym;
|
*new_sym = g_aggrematch[i].new_sym;
|
||||||
if (g_aggrematch[i].erase_sym)
|
if (g_aggrematch[i].erase_sym)
|
||||||
{
|
{
|
||||||
pop_stack(stack, g_aggrematch[i].erase_sym);
|
pop_stack(stack, g_aggrematch[i].erase_sym);
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
DG("stack after pop: %s", read_state(*head));
|
// DG("stack after pop: %s", read_state(*head));
|
||||||
}
|
}
|
||||||
if (eval_sym(stack, *new_sym))
|
if (eval_sym(stack, *new_sym))
|
||||||
return ((*state = ERROR));
|
return ((*state = ERROR));
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ t_stackmatch g_stackmatch[] =
|
||||||
{TK_DSEMI, COMPLETE_COMMANDS},
|
{TK_DSEMI, COMPLETE_COMMANDS},
|
||||||
{TK_DSEMI, COMPOUND_LIST},
|
{TK_DSEMI, COMPOUND_LIST},
|
||||||
{TK_DSEMI, CASE_LIST_NS},
|
{TK_DSEMI, CASE_LIST_NS},
|
||||||
|
{TK_DSEMI, CMD_SUPERIOR},
|
||||||
{TK_DSEMI, PIPE_SEMI_SEQUENCE},
|
{TK_DSEMI, PIPE_SEMI_SEQUENCE},
|
||||||
{TK_DSEMI, SEQUENCE},
|
{TK_DSEMI, SEQUENCE},
|
||||||
// watch!
|
// watch!
|
||||||
|
|
@ -853,7 +854,7 @@ t_stackmatch g_stackmatch[] =
|
||||||
{COMPOUND_LIST, TK_ELSE},
|
{COMPOUND_LIST, TK_ELSE},
|
||||||
{COMPOUND_LIST, COMPOUND_LIST},
|
{COMPOUND_LIST, COMPOUND_LIST},
|
||||||
{COMPOUND_LIST, COMPLETE_CONDITION},
|
{COMPOUND_LIST, COMPLETE_CONDITION},
|
||||||
{CLOSE_LIST, PATTERN_CASE},
|
{CLOSE_LIST, PATTERN},
|
||||||
{CLOSE_LIST, FUNC_NAME},
|
{CLOSE_LIST, FUNC_NAME},
|
||||||
{SUBSHELL, LINEBREAK},
|
{SUBSHELL, LINEBREAK},
|
||||||
{SUBSHELL, COMPLETE_COMMANDS},
|
{SUBSHELL, COMPLETE_COMMANDS},
|
||||||
|
|
@ -1027,7 +1028,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||||
i = 0;
|
i = 0;
|
||||||
while (g_stackmatch[i].top)
|
while (g_stackmatch[i].top)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
else
|
else
|
||||||
parser->state = UNDEFINED;
|
parser->state = UNDEFINED;
|
||||||
build_tree(ast, token);
|
build_tree(ast, token);
|
||||||
btree_print(STDBUG, *ast, &ft_putast);
|
// btree_print(STDBUG, *ast, &ft_putast);
|
||||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||||
insert_linebreak(token);
|
insert_linebreak(token);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,8 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
|
||||||
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
DG("produce stack : %s && token : %s", read_state(*head),
|
// DG("produce stack : %s && token : %s", read_state(*head),
|
||||||
read_state(token->type));
|
// read_state(token->type));
|
||||||
i = 0;
|
i = 0;
|
||||||
*new_sym = 0;
|
*new_sym = 0;
|
||||||
while (g_prodmatch[i].new_sym)
|
while (g_prodmatch[i].new_sym)
|
||||||
|
|
@ -116,7 +116,7 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
|
||||||
if (token->type == g_prodmatch[i].token
|
if (token->type == g_prodmatch[i].token
|
||||||
&& *head == g_prodmatch[i].stack)
|
&& *head == g_prodmatch[i].stack)
|
||||||
{
|
{
|
||||||
DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
|
// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
|
||||||
*new_sym = g_prodmatch[i].new_sym;
|
*new_sym = g_prodmatch[i].new_sym;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue