From 43b0298323ad36924d1a6e7cefb0e22526348882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Sun, 12 Nov 2006 03:09:51 +0000 Subject: [PATCH] ajout des fichiers d'execution dans le makefile.am correction de ses fichiers correction d'un problem leger dans le parser nettoyage --- Makefile.am | 9 +++++- src/Makefile.am | 50 -------------------------------- src/exec/exec.h | 6 ++-- src/exec/exec_and.c | 25 ++++++---------- src/exec/exec_ast.c | 55 ------------------------------------ src/exec/exec_bang.c | 22 +++++---------- src/exec/exec_cmd.c | 5 ++-- src/exec/exec_if.c | 26 ++++++----------- src/exec/exec_line.c | 27 ------------------ src/exec/exec_or.c | 25 ++++++---------- src/exec/exec_sep.c | 19 +++++++++++++ src/exec/exec_sepand.c | 24 ++++++---------- src/exec/exec_sepsemicolon.c | 27 ------------------ src/exec/exec_start.c | 24 ---------------- src/exec/exec_subshell.c | 4 +-- src/exec/exec_until.c | 26 ----------------- src/exec/exec_while.c | 22 +++++---------- src/parser/lexer.c | 14 ++++++--- src/parser/parser.c | 6 +--- src/parser/parser.h | 4 +-- 20 files changed, 96 insertions(+), 324 deletions(-) delete mode 100644 src/Makefile.am delete mode 100644 src/exec/exec_ast.c delete mode 100644 src/exec/exec_line.c create mode 100644 src/exec/exec_sep.c delete mode 100644 src/exec/exec_sepsemicolon.c delete mode 100644 src/exec/exec_start.c delete mode 100644 src/exec/exec_until.c diff --git a/Makefile.am b/Makefile.am index 5bc0092..91e0332 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,7 +27,14 @@ bin_PROGRAMS=42sh src/common/strvmerge.c \ src/common/strndup.c \ src/exec/exec.h \ + src/exec/exec_and.c \ + src/exec/exec_bang.c \ src/exec/exec_node.c \ + src/exec/exec_or.c \ + src/exec/exec_if.c \ + src/exec/exec_sep.c \ + src/exec/exec_sepand.c \ + src/exec/exec_while.c \ src/parser/alias.h \ src/parser/alias.c \ src/parser/getline.h \ @@ -44,7 +51,7 @@ bin_PROGRAMS=42sh src/shell/shell_destroy.c \ src/shell/prompt.c -CLEANFILES= *~ '\#*' +CLEANFILES= *~ \#*\# EXTRA_DIST = AUTHORS README TODO diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 5abfe8e..0000000 --- a/src/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -bin_PROGRAMS=42sh - -#42sh_LDADD = parser/libparse.a ../check/leaktrack/libmem.a evalexpr/libevalexpr.a - - -42sh_SOURCES= ast/ast.h \ - ast/ast_and.c \ - ast/ast_bang.c \ - ast/ast_case.c \ - ast/ast_cmd.c \ - ast/ast_destruct.c \ - ast/ast_for.c \ - ast/ast_funcdec.c \ - ast/ast_if.c \ - ast/ast_or.c \ - ast/ast_pipe.c \ - ast/ast_print.c \ - ast/ast_red.c \ - ast/ast_sep.c \ - ast/ast_sepand.c \ - ast/ast_subshell.c \ - ast/ast_while.c \ - common/basename.c \ - common/common.h \ - common/constant.h \ - common/isdigitstr.c \ - common/macro.h \ - common/strmerge.c \ - common/strvectoradd.c \ - common/strvmerge.c \ - common/strndup.c \ - exec/exec.h \ - exec/exec_node.c \ - parser/alias.h \ - parser/alias.c \ - parser/getline.h \ - parser/getline.c \ - parser/parser.h \ - parser/parser.c \ - parser/lexer.c \ - shell/getoptions.c \ - shell/option.h \ - shell/option.c \ - shell/shell.h \ - shell/shell_entry.c \ - shell/shell_init.c \ - shell/shell_destroy.c \ - shell/prompt.c - -CLEANFILES= *~ '\#*' diff --git a/src/exec/exec.h b/src/exec/exec.h index 12122a6..95d1d6a 100644 --- a/src/exec/exec.h +++ b/src/exec/exec.h @@ -5,7 +5,7 @@ ** Login ** ** Started on Sun Mar 30 16:02:07 2006 Seblu -** Last update Tue Aug 29 00:15:59 2006 Seblu +** Last update Sun Nov 12 03:43:20 2006 seblu */ #ifndef EXEC_H_ @@ -14,10 +14,10 @@ # include # include # include "../ast/ast.h" +# include "../shell/shell.h" void exec_node(s_ast_node *node); -/* void exec_node(struct s_ast *node, struct s_42sh *sh); */ /* void exec_list(struct s_list *node, struct s_42sh *sh); */ /* void exec_if(struct s_if *node, struct s_42sh *sh); */ /* void exec_while(struct s_while *node, struct s_42sh *sh); */ @@ -32,7 +32,7 @@ void exec_node(s_ast_node *node); /* void exec_line(struct s_op *node, struct s_42sh *sh); */ /* void exec_subshell(struct s_subshell *node, struct s_42sh *sh); */ -/* /\* FIXME *\/ */ +/* FIXME */ /* void exec_for(struct s_for *node, struct s_42sh *sh); */ /* void exec_case(struct s_case *node, struct s_42sh *sh); */ diff --git a/src/exec/exec_and.c b/src/exec/exec_and.c index 40da8fd..ae82302 100644 --- a/src/exec/exec_and.c +++ b/src/exec/exec_and.c @@ -1,27 +1,20 @@ /* -** exec_and.c for 42sh in /home/seblu +** exec_and.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:43:57 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execution an AND node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_and(struct s_op *node, struct s_42sh *sh) +void exec_and(s_bin_node *node) { - assert(node && sh); - exec_node(node->left, sh); - if (!sh->last_status) - exec_node(node->right, sh); + assert(node && node->lhs && node->rhs); + exec_node(node->lhs); + //FIXME: error with chained "or" and "and" + if (!shell->status) + exec_node(node->rhs); } diff --git a/src/exec/exec_ast.c b/src/exec/exec_ast.c deleted file mode 100644 index 6ea4db6..0000000 --- a/src/exec/exec_ast.c +++ /dev/null @@ -1,55 +0,0 @@ -/* -** exec_node.c for 42sh -** -** Made by Seblu -** Login -** -** Started on Sat Mar 25 14:51:09 2006 Seblu -** Last update Sat Apr 15 09:12:38 2006 Seblu -*/ - -#include "exec.h" - -/*! -** Execute a node of ast by calling the good function -** -** @param node node to execute -** @param sh shell struct -*/ -void exec_ast(ts_ast_node *node) -{ - node = node; -} - -/* { */ -/* if (node == NULL) */ -/* return; */ -/* else if (node->type == T_CMD) */ -/* exec_cmd(&node->data.node_cmd, sh); */ -/* else if (node->type == T_PIPE) */ -/* exec_pipe(&node->data.node_op, sh); */ -/* else if (node->type == T_LINE) */ -/* exec_line(&node->data.node_op, sh); */ -/* else if (node->type == T_SEP_AND) */ -/* exec_sepand(&node->data.node_op, sh); */ -/* else if (node->type == T_SEP_SEMICOMMA) */ -/* exec_sepsemicolon(&node->data.node_op, sh); */ -/* else if (node->type == T_IF) */ -/* exec_if(&node->data.node_if, sh); */ -/* else if (node->type == T_FOR) */ -/* exec_for(&node->data.node_for, sh); */ -/* else if (node->type == T_AND) */ -/* exec_and(&node->data.node_op, sh); */ -/* else if (node->type == T_OR) */ -/* exec_or(&node->data.node_op, sh); */ -/* else if (node->type == T_WHILE) */ -/* exec_while(&node->data.node_while, sh); */ -/* else if (node->type == T_UNTIL) */ -/* exec_until(&node->data.node_while, sh); */ -/* else if (node->type == T_BANG) */ -/* exec_bang(&node->data.node_op, sh); */ -/* else if (node->type == T_SUBSHELL) */ -/* exec_subshell(&node->data.node_subshell, sh); */ -/* else */ -/* assert(0); */ -/* } */ diff --git a/src/exec/exec_bang.c b/src/exec/exec_bang.c index 3cc4b22..c6120e1 100644 --- a/src/exec/exec_bang.c +++ b/src/exec/exec_bang.c @@ -1,26 +1,18 @@ /* -** exec_bang.c for 42sh in /home/seblu +** exec_bang.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:44:33 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execution a BANG node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_bang(struct s_op *node, struct s_42sh *sh) +void exec_bang(s_bin_node *node) { - assert(node && sh && !node->left); - exec_node(node->left, sh); - sh->last_status = !sh->last_status; + assert(node && node->lhs); + exec_node(node->lhs); + shell->status = !shell->status; } diff --git a/src/exec/exec_cmd.c b/src/exec/exec_cmd.c index 653b04b..a4cf213 100644 --- a/src/exec/exec_cmd.c +++ b/src/exec/exec_cmd.c @@ -1,11 +1,11 @@ /* -** exec_cmd.c for 42sh in /home/seblu/devel/c/42sh/src/execution +** exec_cmd.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Apr 8 07:38:48 2006 Seblu -** Last update Sun May 21 17:07:27 2006 Seblu +** Last update Sun Nov 12 04:04:09 2006 seblu */ #define DEBUG_EXEC 0 @@ -28,7 +28,6 @@ #include "../history/history.h" #include "../expand/expand.h" -#include "mem.h" #define rederror(prompt) do { perror(prompt); return 0; } while (0) diff --git a/src/exec/exec_if.c b/src/exec/exec_if.c index 9715317..cc871ec 100644 --- a/src/exec/exec_if.c +++ b/src/exec/exec_if.c @@ -1,29 +1,21 @@ /* -** exec_if.c for 42sh in /home/seblu +** exec_if.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:45:42 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execute if struct. -** -** @param node if struct -** @param sh sh data -*/ -void exec_if(struct s_if *node, struct s_42sh *sh) +void exec_if(s_if_node *node) { - assert(node && sh); - exec_node(node->cond, sh); - if (!sh->last_status) - exec_node(node->if_then, sh); + assert(node); + exec_node(node->cond); + if (!shell->status) + exec_node(node->cond_true); else - exec_node(node->if_else, sh); + exec_node(node->cond_false); } diff --git a/src/exec/exec_line.c b/src/exec/exec_line.c deleted file mode 100644 index f9dbfd4..0000000 --- a/src/exec/exec_line.c +++ /dev/null @@ -1,27 +0,0 @@ -/* -** exec_line.c for 42sh in /home/seblu -** -** Made by Seblu -** Login -** -** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit -*/ - -#include "execution.h" - -#include "mem.h" - -/*! -** Execution a line node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_line(struct s_op *node, struct s_42sh *sh) -{ - assert(node && sh); - exec_node(node->left, sh); - if (node->right) - exec_node(node->right, sh); -} diff --git a/src/exec/exec_or.c b/src/exec/exec_or.c index 7a131ad..ec689be 100644 --- a/src/exec/exec_or.c +++ b/src/exec/exec_or.c @@ -1,27 +1,20 @@ /* -** exec_and.c for 42sh in /home/seblu +** exec_and.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:45:03 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execution an OR node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_or(struct s_op *node, struct s_42sh *sh) +void exec_or(s_bin_node *node) { - assert(node && sh); - exec_node(node->left, sh); - if (sh->last_status) - exec_node(node->right, sh); + assert(node && node->lhs && node->rhs); + exec_node(node->lhs); + //FIXME: error with chained "or" and "and" + if (shell->status) + exec_node(node->rhs); } diff --git a/src/exec/exec_sep.c b/src/exec/exec_sep.c new file mode 100644 index 0000000..bd7a4c5 --- /dev/null +++ b/src/exec/exec_sep.c @@ -0,0 +1,19 @@ +/* +** exec_sep.c for 42sh +** +** Made by Seblu +** Login +** +** Started on Sat Mar 25 15:27:20 2006 Seblu +** Last update Sun Nov 12 03:46:19 2006 seblu +*/ + +#include "exec.h" + +void exec_sep(s_bin_node *node) +{ + assert(node); + exec_node(node->lhs); + if (node->rhs) + exec_node(node->rhs); +} diff --git a/src/exec/exec_sepand.c b/src/exec/exec_sepand.c index 7094a53..6c081c3 100644 --- a/src/exec/exec_sepand.c +++ b/src/exec/exec_sepand.c @@ -1,27 +1,19 @@ /* -** exec_sepand.c for 42sh in /home/seblu +** exec_sepand.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:46:01 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execution a sepand node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_sepand(struct s_op *node, struct s_42sh *sh) +void exec_sepand(s_bin_node *node) { - assert(node && sh); - exec_node(node->left, sh); - if (node->right) - exec_node(node->right, sh); + assert(node); + exec_node(node->lhs); + if (node->rhs) + exec_node(node->rhs); } diff --git a/src/exec/exec_sepsemicolon.c b/src/exec/exec_sepsemicolon.c deleted file mode 100644 index e8cb550..0000000 --- a/src/exec/exec_sepsemicolon.c +++ /dev/null @@ -1,27 +0,0 @@ -/* -** exec_semicolon.c for 42sh in /home/seblu -** -** Made by Seblu -** Login -** -** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit -*/ - -#include "execution.h" - -#include "mem.h" - -/*! -** Execution a semicolon node -** -** @param node node to treat -** @param sh sh data -*/ -void exec_sepsemicolon(struct s_op *node, struct s_42sh *sh) -{ - assert(node && sh); - exec_node(node->left, sh); - if (node->right) - exec_node(node->right, sh); -} diff --git a/src/exec/exec_start.c b/src/exec/exec_start.c deleted file mode 100644 index 94b26f1..0000000 --- a/src/exec/exec_start.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -** exec_start.c for 42sh in /home/seblu -** -** Made by Seblu -** Login -** -** Started on Sat Mar 25 14:40:36 2006 Seblu -** Last update Fri May 19 17:57:30 2006 alexandre gerlic -*/ - -#include "execution.h" -#include "mem.h" - -/*! -** Start AST execution -** -** @param sh sh struct to execute -*/ -void exec_start(struct s_42sh *sh) -{ - assert(sh && sh->ast); - exec_node(sh->ast, sh); - ast_destruct(sh->ast); -} diff --git a/src/exec/exec_subshell.c b/src/exec/exec_subshell.c index 6e1c70d..a6bea56 100644 --- a/src/exec/exec_subshell.c +++ b/src/exec/exec_subshell.c @@ -1,11 +1,11 @@ /* -** exec_subshell.c for 42sh in /home/seblu/devel/c/42sh/src/execution +** exec_subshell.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Apr 15 08:54:51 2006 Seblu -** Last update Tue May 16 20:18:49 2006 Seblu +** Last update Sun Nov 12 03:48:42 2006 seblu */ #include diff --git a/src/exec/exec_until.c b/src/exec/exec_until.c deleted file mode 100644 index adca527..0000000 --- a/src/exec/exec_until.c +++ /dev/null @@ -1,26 +0,0 @@ -/* -** exec_until.c for 42sh in /home/seblu -** -** Made by Seblu -** Login -** -** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:03 2006 SIGOURE Benoit -*/ - -#include "execution.h" - -#include "mem.h" - -/*! -** Execute a node while a condition is verified -** -** @param node fucking node -** @param sh fucking sh structure -*/ -void exec_until(struct s_while *node, struct s_42sh *sh) -{ - assert(node && sh); - for (exec_node(node->cond, sh); sh->last_status; exec_node(node->cond, sh)) - exec_node(node->exec, sh); -} diff --git a/src/exec/exec_while.c b/src/exec/exec_while.c index 9e8c0e3..b08381f 100644 --- a/src/exec/exec_while.c +++ b/src/exec/exec_while.c @@ -1,26 +1,18 @@ /* -** exec_while.c for 42sh in /home/seblu +** exec_while.c for 42sh ** ** Made by Seblu ** Login ** ** Started on Sat Mar 25 15:27:20 2006 Seblu -** Last update Sun Apr 9 12:04:04 2006 SIGOURE Benoit +** Last update Sun Nov 12 03:46:34 2006 seblu */ -#include "execution.h" +#include "exec.h" -#include "mem.h" - -/*! -** Execute a node while a condition is verified -** -** @param node fucking node -** @param sh fucking sh structure -*/ -void exec_while(struct s_while *node, struct s_42sh *sh) +void exec_while(s_while_node *node) { - assert(node && sh); - for (exec_node(node->cond, sh); !sh->last_status; exec_node(node->cond, sh)) - exec_node(node->exec, sh); + assert(node); + for (exec_node(node->cond); !shell->status; exec_node(node->cond)) + exec_node(node->exec); } diff --git a/src/parser/lexer.c b/src/parser/lexer.c index 06ea1a5..a8eb485 100644 --- a/src/parser/lexer.c +++ b/src/parser/lexer.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Sun Jul 30 04:36:53 2006 Seblu -** Last update Thu Oct 19 13:18:20 2006 seblu +** Last update Sun Nov 12 03:11:19 2006 seblu */ #include @@ -239,7 +239,10 @@ s_token lexer_getheredoc(s_lexer *lexer, const char *delim) char *line; if (lexer->eof) { - token_set(&token, TOK_EOF, "EOF"); + //don't use token_set because it's not for new token + token.id = TOK_EOF; + token.str = "EOF"; + token.len = 3; return token; } show_prompt(PROMPT_PS2); @@ -252,7 +255,10 @@ s_token lexer_getheredoc(s_lexer *lexer, const char *delim) buf = strmerge(2, buf, line); } while (strcmp(line, delim)); - token_set(&token, TOK_WORD, buf); + //don't use token set because token is unitialized! + token.id = TOK_WORD; + token.str = buf; + token.len = strlen(buf); return token; } @@ -274,7 +280,7 @@ static void token_move(s_token *src, s_token *dst) src->len = 0; } -static void lexer_eattoken(s_lexer *lexer) +static void lexer_eattoken(s_lexer *lexer) { //if last char was read free buffer if (lexer->buf && lexer->buf_pos == lexer->buf_size) { diff --git a/src/parser/parser.c b/src/parser/parser.c index eaaa493..f9cbc97 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Wed Aug 2 00:56:07 2006 Seblu -** Last update Wed Oct 18 19:21:32 2006 seblu +** Last update Sun Nov 12 02:58:03 2006 seblu */ @@ -327,10 +327,6 @@ static s_ast_node *parse_simplecommand(s_parser *parser) found += parse_element(parser, cmd, &red); if (!found) parse_error(parser, lexer_lookahead(parser->lexer)); - if (cmd->body.child_cmd.argv && cmd->body.child_cmd.argv[0]) - debugmsg(cmd->body.child_cmd.argv[0]); - else if (cmd->body.child_cmd.prefix && cmd->body.child_cmd.prefix[0]) - debugmsg(cmd->body.child_cmd.prefix[0]); if (red) { red->body.child_red.mhs = cmd; cmd = red; diff --git a/src/parser/parser.h b/src/parser/parser.h index d0d7477..1844310 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -5,7 +5,7 @@ ** Login ** ** Started on Wed Aug 2 00:49:50 2006 Seblu -** Last update Wed Oct 18 18:28:06 2006 seblu +** Last update Sun Nov 12 02:55:47 2006 seblu */ #ifndef PARSER_H_ @@ -16,7 +16,7 @@ # include "getline.h" // Define is parser or lexer is running for DEBBUGING -# define DEBUG_PARSER 1 +# define DEBUG_PARSER 0 # define DEBUG_LEXER 0 enum { -- GitLab