Commit 43b02983 authored by Seblu's avatar Seblu

ajout des fichiers d'execution dans le makefile.am

correction de ses fichiers
correction d'un problem leger dans le parser
nettoyage
parent cf1158bc
......@@ -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
......
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= *~ '\#*'
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** 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 <assert.h>
# include <stdio.h>
# 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); */
......
/*
** exec_and.c for 42sh in /home/seblu
** exec_and.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_node.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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); */
/* } */
/*
** exec_bang.c for 42sh in /home/seblu
** exec_bang.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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;
}
/*
** exec_cmd.c for 42sh in /home/seblu/devel/c/42sh/src/execution
** exec_cmd.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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)
......
/*
** exec_if.c for 42sh in /home/seblu
** exec_if.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_line.c for 42sh in /home/seblu
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_and.c for 42sh in /home/seblu
** exec_and.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_sep.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_sepand.c for 42sh in /home/seblu
** exec_sepand.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_semicolon.c for 42sh in /home/seblu
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_start.c for 42sh in /home/seblu
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_subshell.c for 42sh in /home/seblu/devel/c/42sh/src/execution
** exec_subshell.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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 <string.h>
......
/*
** exec_until.c for 42sh in /home/seblu
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
/*
** exec_while.c for 42sh in /home/seblu
** exec_while.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** 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);
}
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** 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 <stdio.h>
......@@ -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) {
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** 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;
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** 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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment