end pull
This commit is contained in:
commit
6fa5153df2
69 changed files with 377 additions and 400 deletions
|
|
@ -65,38 +65,37 @@ exec/exec_ampersand.c\
|
|||
exec/exec_and_if.c\
|
||||
exec/exec_case_branch.c\
|
||||
exec/exec_command.c\
|
||||
exec/exec_default.c\
|
||||
exec/exec_elif.c\
|
||||
exec/exec_else.c\
|
||||
exec/exec_func.c\
|
||||
exec/exec_leaf.c\
|
||||
exec/exec_math.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
exec/exec_reset.c\
|
||||
exec/exec_semi.c\
|
||||
exec/exec_until.c\
|
||||
exec/exec_var.c\
|
||||
exec/fd_is_valid.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
exec/is_function.c\
|
||||
exec/launch_builtin.c\
|
||||
exec/launch_case.c\
|
||||
exec/launch_file.c\
|
||||
exec/launch_for.c\
|
||||
exec/launch_function.c\
|
||||
exec/launch_if.c\
|
||||
exec/launch_process.c\
|
||||
exec/launch_subshell.c\
|
||||
exec/launch_until.c\
|
||||
exec/launch_while.c\
|
||||
exec/mark_process_status.c\
|
||||
exec/node_copy.c\
|
||||
exec/process_redirect.c\
|
||||
exec/process_reset.c\
|
||||
exec/process_setexec.c\
|
||||
exec/process_setgroup.c\
|
||||
exec/process_setsig.c\
|
||||
exec/redir_free.c\
|
||||
exec/redir_copy.c\
|
||||
exec/node_copy.c\
|
||||
exec/redir_free.c\
|
||||
exec/redirect_dgreat.c\
|
||||
exec/redirect_dless.c\
|
||||
exec/redirect_great.c\
|
||||
|
|
@ -207,11 +206,11 @@ lexer/lexer_bquote.c\
|
|||
lexer/lexer_curly_braces.c\
|
||||
lexer/lexer_default.c\
|
||||
lexer/lexer_delim.c\
|
||||
lexer/lexer_dless.c\
|
||||
lexer/lexer_dquote.c\
|
||||
lexer/lexer_end.c\
|
||||
lexer/lexer_great.c\
|
||||
lexer/lexer_greatand.c\
|
||||
lexer/lexer_heredoc.c\
|
||||
lexer/lexer_init.c\
|
||||
lexer/lexer_less.c\
|
||||
lexer/lexer_lessand.c\
|
||||
|
|
@ -251,7 +250,6 @@ main/data_singleton.c\
|
|||
main/ft_putast.c\
|
||||
main/instruction_free.c\
|
||||
main/main.c\
|
||||
main/shell_exit.c\
|
||||
main/shell_get_avdata.c\
|
||||
main/shell_get_opts.c\
|
||||
main/shell_init.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 15:49:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,6 +31,4 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]);
|
|||
int builtin_history(const char *path, char *const av[], char *const envp[]);
|
||||
int builtin_hash(const char *path, char *const av[], char *const envp[]);
|
||||
|
||||
extern t_stof g_builtins[];
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 03:05:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ struct s_data_cmd
|
|||
char **av;
|
||||
char *path;
|
||||
t_execf *execf;
|
||||
struct stat stat;
|
||||
struct stat *stat;
|
||||
};
|
||||
|
||||
struct s_data_cond
|
||||
|
|
@ -74,6 +74,7 @@ union u_process_data
|
|||
{
|
||||
struct s_data_cmd cmd;
|
||||
struct s_data_subshell subshell;
|
||||
struct s_data_subshell function;
|
||||
struct s_data_cond d_while;
|
||||
struct s_data_cond d_until;
|
||||
struct s_data_cond d_if;
|
||||
|
|
@ -130,32 +131,8 @@ extern t_itof g_execmap[];
|
|||
extern t_itof g_redirmap[];
|
||||
extern t_itof g_launchmap[];
|
||||
|
||||
int ft_exec(t_btree **ast);
|
||||
|
||||
int exec_default(t_btree **ast);
|
||||
|
||||
int exec_semi(t_btree **ast);
|
||||
int exec_ampersand(t_btree **ast);
|
||||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
/* int exec_redir(t_btree **ast); */
|
||||
//int exec_cmd(t_btree **ast);
|
||||
int exec_leaf(t_btree **ast);
|
||||
|
||||
//int exec_while(t_btree **ast);
|
||||
//int exec_if(t_btree **ast);
|
||||
int exec_elif(t_btree **ast);
|
||||
int exec_else(t_btree **ast);
|
||||
//int exec_until(t_btree **ast);
|
||||
//int exec_default(t_btree **ast);
|
||||
int exec_var(t_btree **ast);
|
||||
//int exec_for(t_btree **ast);
|
||||
//int exec_case(t_btree **ast);
|
||||
int exec_case_branch(t_btree **ast);
|
||||
int exec_math(t_btree **ast);
|
||||
|
||||
int process_setexec(t_process *p);
|
||||
int exec_reset(void);
|
||||
int process_setgroup(t_process *p, pid_t pid);
|
||||
void process_setsig(void);
|
||||
void process_reset(t_process *p);
|
||||
|
|
@ -186,6 +163,7 @@ char **token_to_argv(t_ld *ld, int do_match);
|
|||
int add_new_job(t_job *job);
|
||||
|
||||
int error_badidentifier(char *name);
|
||||
t_btree *is_function(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour free les process
|
||||
|
|
@ -208,18 +186,36 @@ int launch_case(t_process *p);
|
|||
int launch_file(t_process *p);
|
||||
int launch_builtin(t_process *p);
|
||||
int launch_subshell(t_process *p);
|
||||
int launch_function(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour set les process
|
||||
*/
|
||||
|
||||
int set_process(t_process *p, t_btree *ast);
|
||||
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd);
|
||||
int set_process_map(t_process *p, t_btree *ast);
|
||||
int set_process_cmd(t_process *p, t_btree *ast);
|
||||
int set_process_while(t_process *p, t_btree *ast);
|
||||
int set_process_until(t_process *p, t_btree *ast);
|
||||
int set_process_if(t_process *p, t_btree *ast);
|
||||
int set_process_for(t_process *p, t_btree *ast);
|
||||
int set_process_case(t_process *p, t_btree *ast);
|
||||
int set_process_subshell(t_process *p, t_btree *ast);
|
||||
|
||||
/*
|
||||
** Mapping pour exec les process
|
||||
*/
|
||||
int ft_exec(t_btree **ast);
|
||||
int exec_leaf(t_btree **ast);
|
||||
int exec_semi(t_btree **ast);
|
||||
int exec_ampersand(t_btree **ast);
|
||||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
int exec_elif(t_btree **ast);
|
||||
int exec_else(t_btree **ast);
|
||||
int exec_var(t_btree **ast);
|
||||
int exec_case_branch(t_btree **ast);
|
||||
int exec_math(t_btree **ast);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 18:36:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:00:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -54,12 +54,12 @@
|
|||
# define TOUCHE_F5 892427035
|
||||
# define TOUCHE_F6 925981467
|
||||
|
||||
# define IS_QUOTES (1 << 0)
|
||||
# define IS_BQUOTES (1 << 1)
|
||||
# define IS_DQUOTES (1 << 2)
|
||||
# define IS_BSLASH (1 << 3)
|
||||
# define IS_ACCOLADE (1 << 4)
|
||||
# define IS_BRACKET (1 << 5)
|
||||
/* # define IS_QUOTES (1 << 0) */
|
||||
/* # define IS_BQUOTES (1 << 1) */
|
||||
/* # define IS_DQUOTES (1 << 2) */
|
||||
/* # define IS_BSLASH (1 << 3) */
|
||||
/* # define IS_ACCOLADE (1 << 4) */
|
||||
/* # define IS_BRACKET (1 << 5) */
|
||||
|
||||
# define STR data_singleton()->line.input
|
||||
# define POS data_singleton()->line.pos
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 15:49:00 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 16:11:21 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ enum e_lexstate
|
|||
{
|
||||
DEFAULT,
|
||||
PAREN,
|
||||
DLESS,
|
||||
HEREDOC,
|
||||
NEWLINE,
|
||||
DELIM,
|
||||
SEP,
|
||||
|
|
@ -99,10 +99,13 @@ t_lexstate get_state_redir(t_lexer *lexer);
|
|||
int get_lexer_stack(t_lexer lexer);
|
||||
int get_reserved_words(t_list **alst);
|
||||
int insert_newline(t_list **alst);
|
||||
|
||||
void lexer_init(t_lexer *lexer);
|
||||
|
||||
int lexer_lex(t_list **alst, t_lexer *lexer);
|
||||
int lexer_default(t_list **alst, t_lexer *lexer);
|
||||
int lexer_newline(t_list **alst, t_lexer *lexer);
|
||||
int lexer_heredoc(t_list **alst, t_lexer *lexer);
|
||||
int lexer_delim(t_list **alst, t_lexer *lexer);
|
||||
int lexer_sep(t_list **alst, t_lexer *lexer);
|
||||
int lexer_word(t_list **alst, t_lexer *lexer);
|
||||
|
|
@ -111,7 +114,6 @@ int lexer_less(t_list **alst, t_lexer *lexer);
|
|||
int lexer_great(t_list **alst, t_lexer *lexer);
|
||||
int lexer_greatand(t_list **alst, t_lexer *lexer);
|
||||
int lexer_lessand(t_list **alst, t_lexer *lexer);
|
||||
int lexer_dless(t_list **alst, t_lexer *lexer);
|
||||
int lexer_quote(t_list **alst, t_lexer *lexer);
|
||||
int lexer_dquote(t_list **alst, t_lexer *lexer);
|
||||
int lexer_bquote(t_list **alst, t_lexer *lexer);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 21:13:31 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:05:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 15:52:51 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 16:08:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
|
@ -192,6 +192,7 @@ enum e_sym
|
|||
MATH_SUP,
|
||||
REDIR,
|
||||
CMD,
|
||||
HEREDOCDATA,
|
||||
ALL = 200,
|
||||
TERMINUS = 300,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 73c28532404e437d670607c909fbe56d717e9683
|
||||
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/18 16:48:42 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:04:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,15 +29,15 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
|
|||
ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME);
|
||||
return (0);
|
||||
}
|
||||
if (av[1])
|
||||
if (av && av[1])
|
||||
status = ft_atoi(av[1]);
|
||||
else
|
||||
{
|
||||
/* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */
|
||||
status = 0;
|
||||
}
|
||||
status = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
||||
ft_save_termios(-1);
|
||||
ft_free_hash_table();
|
||||
data_exit();
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
|
||||
exit(status);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_default.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/31 19:29:59 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/05 22:18:50 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_default(t_btree **ast)
|
||||
{
|
||||
|
||||
(void)ast;
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_while.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 21:30:29 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:47:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,11 +17,9 @@ int exec_leaf(t_btree **ast)
|
|||
t_process p;
|
||||
t_job *job;
|
||||
|
||||
DG("in exec leaf");
|
||||
job = &data_singleton()->exec.job;
|
||||
if (set_process(&p, *ast))
|
||||
return (1);
|
||||
DG("set_process done");
|
||||
if (!(launch_process(&p)))
|
||||
{
|
||||
job_addprocess(&p);
|
||||
|
|
|
|||
|
|
@ -1,26 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* shell_exit.c :+: :+: :+: */
|
||||
/* exec_reset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 20:14:43 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 14:45:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void shell_exit(void)
|
||||
int exec_reset(void)
|
||||
{
|
||||
t_data *data;
|
||||
t_exec *exec;
|
||||
|
||||
/* DG("shell_exit()"); */
|
||||
data = data_singleton();
|
||||
data_exit();
|
||||
if (SH_HAS_JOBC(data->opts))
|
||||
job_kill_all();
|
||||
if (SH_IS_INTERACTIVE(data->opts))
|
||||
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
|
||||
exec = &data_singleton()->exec;
|
||||
exec->fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC);
|
||||
exec->fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
||||
exec->fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
||||
exec->op_stack = NULL;
|
||||
exec->fdin = STDIN;
|
||||
exec->attrs = 0;
|
||||
exec->job.id = 0;
|
||||
exec->job.pgid = 0;
|
||||
exec->job.attrs = 0;
|
||||
exec->job.first_process = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 01:48:55 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 11:57:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -44,7 +44,6 @@ int ft_exec(t_btree **ast)
|
|||
if (!*ast)
|
||||
return (0);
|
||||
item = (*ast)->item;
|
||||
DG("COMPARE : %d vs %d (SUBSHEELLL)", item->type, SUBSHELL);
|
||||
while (g_execmap[i].id)
|
||||
{
|
||||
if (item->type == g_execmap[i].id)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_until.c :+: :+: :+: */
|
||||
/* is_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/08 02:09:21 by ariard ### ########.fr */
|
||||
/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_until(t_btree **ast)
|
||||
t_btree *is_function(t_process *p)
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "1") == 0)
|
||||
t_list *tmp;
|
||||
|
||||
tmp = data_singleton()->lst_func;
|
||||
while (tmp)
|
||||
{
|
||||
DG("before right");
|
||||
ft_exec(&(*ast)->right);
|
||||
DG("before left");
|
||||
ft_exec(&(*ast)->left);
|
||||
if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0]))
|
||||
return (btree_map(p->data.subshell.content, node_copy));
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (0);
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 16:51:58 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:10:49 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,7 @@ int launch_builtin(t_process *p)
|
|||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
|
||||
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 21:02:46 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:11:02 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -57,6 +57,11 @@ int launch_case(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_case(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 21:33:56 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:46:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,7 +25,12 @@ int launch_file(t_process *p)
|
|||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(127);
|
||||
}
|
||||
else if (S_ISDIR(p->data.cmd.stat.st_mode))
|
||||
else if (!p->data.cmd.stat)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(127);
|
||||
}
|
||||
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: %s: Is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(126);
|
||||
|
|
@ -35,10 +40,13 @@ int launch_file(t_process *p)
|
|||
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(126);
|
||||
}
|
||||
// for all leaves
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
//
|
||||
(*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env);
|
||||
ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(42);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 21:02:18 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:07:55 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,6 +51,11 @@ int launch_for(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_for(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
45
42sh/src/exec/launch_function.c
Normal file
45
42sh/src/exec/launch_function.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* launch_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 15:08:20 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int do_function(t_process *p)
|
||||
{
|
||||
ft_exec(&p->data.function.content);
|
||||
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
|
||||
}
|
||||
|
||||
int launch_function(t_process *p)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
{
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_function(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
return (pid);
|
||||
}
|
||||
else
|
||||
do_function(p);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 21:03:04 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,6 +38,11 @@ int launch_if(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_if(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 00:11:15 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:45:54 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
t_itof g_launchmap[] =
|
||||
{
|
||||
{PROCESS_FUNCTION, NULL},
|
||||
{PROCESS_FUNCTION, launch_function},
|
||||
{PROCESS_BUILTIN, launch_builtin},
|
||||
{PROCESS_FILE, launch_file},
|
||||
{PROCESS_SUBSHELL, launch_subshell},
|
||||
|
|
@ -28,7 +28,6 @@ t_itof g_launchmap[] =
|
|||
|
||||
int launch_process(t_process *p)
|
||||
{
|
||||
// int i;
|
||||
int pid;
|
||||
|
||||
if (p->type >= PROCESS_MAX)
|
||||
|
|
@ -42,25 +41,4 @@ int launch_process(t_process *p)
|
|||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
return (0);
|
||||
/*
|
||||
i = 0;
|
||||
while (g_launchmap[i].id)
|
||||
{
|
||||
if (p->type == g_launchmap[i].id)
|
||||
{
|
||||
if (!g_launchmap[i].f)
|
||||
return (-1);
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
p->attrs |= PROCESS_RUNNING;
|
||||
if ((pid = (*g_launchmap[i].f)(p)))
|
||||
{
|
||||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (-1);
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 00:32:13 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:08:04 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,6 +29,11 @@ int launch_subshell(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_subshell(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 02:35:09 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:08:13 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,6 +38,11 @@ int launch_until(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_until(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 20:59:40 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -55,6 +55,11 @@ int launch_while(t_process *p)
|
|||
{
|
||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
exec_reset();
|
||||
exit(do_while(p));
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ast_copy.c :+: :+: :+: */
|
||||
/* node_copy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:00:05 by ariard ### ########.fr */
|
||||
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 12:01:07 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,17 +20,17 @@ void *node_copy(void *data)
|
|||
if (!data)
|
||||
return (NULL);
|
||||
old = data;
|
||||
ft_bzero((void *)&new, sizeof(t_astdata));
|
||||
new = (t_astnode *)ft_memalloc(sizeof(t_astnode));
|
||||
new->nest = old->nest;
|
||||
new->full = old->full;
|
||||
new->type = old->type;
|
||||
new->pattern = old->pattern;
|
||||
if (old->type == CMD || old->type == TK_ASSIGNEMENT_WORD)
|
||||
{
|
||||
new->data.cmd.redir = ft_lstdup(&old->data.cmd.redir, &redir_copy);
|
||||
{
|
||||
new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy);
|
||||
new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
|
||||
}
|
||||
if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE)
|
||||
new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
|
||||
new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
|
||||
return (new);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:36:21 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:51:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,12 +18,10 @@ void process_reset(t_process *p)
|
|||
// p->path = NULL;
|
||||
// p->execf = NULL;
|
||||
p->pid = 0;
|
||||
/* p->fdin = STDIN; */
|
||||
/* p->fdout = STDOUT; */
|
||||
p->fdin = STDIN;
|
||||
p->fdout = STDOUT;
|
||||
p->to_close = 0;
|
||||
p->redirs = NULL;
|
||||
p->status = -1;
|
||||
p->attrs = 0;
|
||||
// p->condition = NULL;
|
||||
// p->content = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* process_setexec.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 21:44:37 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int process_setexec(t_process *p)
|
||||
{
|
||||
p->data.cmd.path = NULL;
|
||||
p->data.cmd.execf = NULL;
|
||||
/* if ((p->execf = is_function(p))) */
|
||||
/* p->type = PROCESS_FUNCTION; */
|
||||
if ((p->data.cmd.execf = is_builtin(p)))
|
||||
p->type = PROCESS_BUILTIN;
|
||||
else if (ft_strchr(p->data.cmd.av[0], '/'))
|
||||
{
|
||||
p->type = PROCESS_FILE;
|
||||
p->data.cmd.execf = &execve;
|
||||
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
||||
stat(p->data.cmd.path, &p->data.cmd.stat);
|
||||
}
|
||||
else
|
||||
{
|
||||
p->type = PROCESS_FILE;
|
||||
if (ft_hash(p))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
stat(p->data.cmd.path, &p->data.cmd.stat);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 00:02:58 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/08 00:41:57 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 11:53:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,14 +15,14 @@
|
|||
void *redir_copy(void *data)
|
||||
{
|
||||
t_redir *old;
|
||||
t_redir *new;
|
||||
t_redir *new;
|
||||
|
||||
if (!data)
|
||||
return (NULL);
|
||||
old = data;
|
||||
ft_bzero((void *)&new, sizeof(t_astdata));
|
||||
new = (t_redir *)ft_memalloc(sizeof(t_redir));
|
||||
new->type = old->type;
|
||||
new->n = old->n;
|
||||
new->word = ft_strdup(old->word);
|
||||
return (0);
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 18:06:24 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:40:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,9 +22,5 @@ void redir_free(void *data, size_t content_size)
|
|||
{
|
||||
ft_strdel(&redir->word);
|
||||
}
|
||||
/* else */
|
||||
/* redir->type = 0; */
|
||||
/* redir->n = 0; */
|
||||
/* redir->close = 1; */
|
||||
free(redir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 21:12:02 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:55:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,12 +15,12 @@
|
|||
int set_process(t_process *p, t_btree *ast)
|
||||
{
|
||||
t_exec *exec;
|
||||
t_cmd *cmd;
|
||||
// t_cmd *cmd;
|
||||
int op;
|
||||
int fds[2];
|
||||
|
||||
cmd = &((t_astnode *)ast->item)->data.cmd;
|
||||
process_reset(p);
|
||||
// cmd = &((t_astnode *)ast->item)->data.cmd;
|
||||
/* process_reset(p); */
|
||||
exec = &data_singleton()->exec;
|
||||
op = pop(&exec->op_stack);
|
||||
if ((EXEC_IS_AND_IF(exec->attrs)
|
||||
|
|
@ -38,10 +38,6 @@ int set_process(t_process *p, t_btree *ast)
|
|||
p->to_close = fds[PIPE_READ];
|
||||
p->fdout = fds[PIPE_WRITE];
|
||||
exec->fdin = fds[PIPE_READ];
|
||||
p->redirs = ft_lstmap(cmd->redir, ft_id);
|
||||
if (set_process_map(p, ast, cmd))
|
||||
return (1);
|
||||
// if (exec->control_count)
|
||||
// p->attrs |= PROCESS_CONTROL;
|
||||
return (0);
|
||||
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
|
||||
return (set_process_map(p, ast));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 20:36:04 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:49:48 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:59:25 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_case(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy);
|
||||
p->data.d_case.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_CASE;
|
||||
|
|
|
|||
|
|
@ -6,17 +6,46 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 21:44:40 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:55:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_cmd(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)ast;
|
||||
if (!(p->data.cmd.av = token_to_argv(cmd->token, 1)))
|
||||
t_btree *func;
|
||||
|
||||
if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1)))
|
||||
return (1);
|
||||
process_setexec(p);
|
||||
p->data.cmd.path = NULL;
|
||||
p->data.cmd.execf = NULL;
|
||||
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
|
||||
DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]);
|
||||
p->type = PROCESS_FILE;
|
||||
if ((func = is_function(p)))
|
||||
{
|
||||
p->data.subshell.content = func;
|
||||
p->type = PROCESS_FUNCTION;
|
||||
}
|
||||
else if ((p->data.cmd.execf = is_builtin(p)))
|
||||
p->type = PROCESS_BUILTIN;
|
||||
else if (ft_strchr(p->data.cmd.av[0], '/'))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
||||
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
|
||||
ft_memdel((void**)&p->data.cmd.stat);
|
||||
}
|
||||
else if (ft_hash(p))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
DG("found hash at [%s]", p->data.cmd.path);
|
||||
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
|
||||
{
|
||||
ft_memdel((void**)&p->data.cmd.stat);
|
||||
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:50:33 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:59:08 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_for(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy);
|
||||
p->data.d_for.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_FOR;
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 19:19:50 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:51:09 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_if(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.d_if.condition = btree_map(ast->left, &node_copy);
|
||||
p->data.d_if.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_IF;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:08:12 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 00:23:22 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:58:36 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ t_itof g_setprocessmap[] =
|
|||
{0, NULL}
|
||||
};
|
||||
|
||||
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_map(t_process *p, t_btree *ast)
|
||||
{
|
||||
int i;
|
||||
t_astnode *item;
|
||||
|
|
@ -48,8 +48,8 @@ int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
|
|||
if (item->type == g_setprocessmap[i].id)
|
||||
{
|
||||
if (!g_setprocessmap[i].f)
|
||||
return (0);
|
||||
return ((*g_setprocessmap[i].f)(p, ast, cmd));
|
||||
return (1);
|
||||
return ((*g_setprocessmap[i].f)(p, ast));
|
||||
}
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:52:45 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:59:55 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_subshell(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.subshell.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_SUBSHELL;
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 03:06:03 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:59:36 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_until(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.d_while.condition = btree_map(ast->left, &node_copy);
|
||||
p->data.d_while.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_UNTIL;
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 01:51:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd)
|
||||
int set_process_while(t_process *p, t_btree *ast)
|
||||
{
|
||||
(void)cmd;
|
||||
p->data.d_while.condition = btree_map(ast->left, &node_copy);
|
||||
p->data.d_while.content = btree_map(ast->right, &node_copy);
|
||||
p->type = PROCESS_WHILE;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/24 22:04:49 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:50:58 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -49,9 +49,13 @@ int dir_research(t_glob *gl, char *p,
|
|||
{
|
||||
DIR *dir;
|
||||
struct dirent *in;
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if (!pat)
|
||||
{
|
||||
gl->found = 1;
|
||||
ft_ld_pushfront(&gl->match, ft_strjoin(p, "/"));
|
||||
return (0);
|
||||
}
|
||||
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
||||
{
|
||||
dir = opendir(p);
|
||||
|
|
@ -60,5 +64,5 @@ int dir_research(t_glob *gl, char *p,
|
|||
(char *[2]){p, in->d_name}, pat, recursive);
|
||||
closedir(dir);
|
||||
}
|
||||
return (ret);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/03 20:38:53 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:50:56 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -66,8 +66,7 @@ char **glob(char *pat, unsigned char *esc,
|
|||
else
|
||||
dir_research(&gl, "/", gl.pat + 1, 0);
|
||||
if (!gl.found)
|
||||
ft_ld_pushfront(&gl.match,
|
||||
ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0]));
|
||||
ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
|
||||
if (!gl.m_pat->next)
|
||||
break ;
|
||||
gl.m_pat = gl.m_pat->next;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/24 22:06:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:35:43 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -90,6 +90,7 @@ static char *manage_pat(t_glob *gl, char *pat, char *str)
|
|||
if (pat[0] == '.' && pat[1] == '/'
|
||||
&& ((str[0] == '.' && str[1] != '/') || str[0] != '.'))
|
||||
{
|
||||
DG("%s vs %s", pat, str);
|
||||
gl->cur_dir = 0;
|
||||
return (pat + 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 02:03:58 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,7 +22,6 @@ void job_remove(int id)
|
|||
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||
if (job_is_completed(id))
|
||||
{
|
||||
DG();
|
||||
p = ft_lstlast(j->first_process)->content;
|
||||
set_exitstatus(p->status, 0);
|
||||
if (id < data_singleton()->jobc.current_id)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 03:07:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:40:22 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
t_itof g_freemap[] =
|
||||
{
|
||||
{PROCESS_FUNCTION, NULL},
|
||||
{PROCESS_BUILTIN, NULL},
|
||||
{PROCESS_FUNCTION, process_free_subshell},
|
||||
{PROCESS_BUILTIN, process_free_cmd},
|
||||
{PROCESS_FILE, process_free_cmd},
|
||||
{PROCESS_SUBSHELL, process_free_subshell},
|
||||
{PROCESS_WHILE, process_free_cond},
|
||||
|
|
@ -36,6 +36,6 @@ void process_free(void *content, size_t content_size)
|
|||
return ;
|
||||
if (g_freemap[p->type].f)
|
||||
(g_freemap[p->type].f)(p);
|
||||
ft_lstdel(&p->redirs, ft_lst_cfree);
|
||||
ft_lstdel(&p->redirs, redir_free);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 02:31:01 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:04:45 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,5 +16,7 @@ int process_free_cmd(t_process *p)
|
|||
{
|
||||
ft_strdel(&p->data.cmd.path);
|
||||
ft_sstrfree(p->data.cmd.av);
|
||||
p->data.cmd.execf = NULL;
|
||||
ft_memdel((void**)&p->data.cmd.stat);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 02:38:12 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 02:38:27 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:16:22 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,6 @@
|
|||
|
||||
int process_free_subshell(t_process *p)
|
||||
{
|
||||
btree_del(&p->data.d_while.content, &ast_free);
|
||||
btree_del(&p->data.subshell.content, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 00:35:38 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,24 +26,16 @@ int put_job_in_foreground(t_job *j, int cont)
|
|||
if (kill(-j->pgid, SIGCONT) < 0)
|
||||
DG("kill(SIGCONT) failed");
|
||||
}
|
||||
DG();
|
||||
job_wait(j->id);
|
||||
DG();
|
||||
job_remove(j->id);
|
||||
DG();
|
||||
|
||||
tcsetpgrp(STDIN, jobc->shell_pgid);
|
||||
|
||||
tcgetattr(STDIN, &j->tmodes);
|
||||
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
DG();
|
||||
job_wait(j->id);
|
||||
DG();
|
||||
job_remove(j->id);
|
||||
DG();
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:08:23 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:09:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int lexer_dless(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_list *heredoc_lst;
|
||||
t_token *eof_tok;
|
||||
t_token *heredoc_tok;
|
||||
|
||||
(void)alst;
|
||||
(void)lexer;
|
||||
heredoc_lst = *(t_list**)lexer->heredoc_stack->content;
|
||||
heredoc_tok = heredoc_lst->content;
|
||||
if (!(heredoc_lst->next))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME);
|
||||
return (1);
|
||||
}
|
||||
eof_tok = heredoc_lst->next->content;
|
||||
if (!(eof_tok->type == TK_WORD))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME);
|
||||
return (1);
|
||||
}
|
||||
DG("heredoc contains [%s]", heredoc_tok->data);
|
||||
DG("heredoc ends at [%s]", eof_tok->data);
|
||||
DG("input is [%s]", lexer->str + lexer->pos);
|
||||
if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0)
|
||||
{
|
||||
pop(&lexer->stack);
|
||||
pop(&lexer->heredoc_stack);
|
||||
while (lexer->str[++lexer->pos])
|
||||
;
|
||||
ft_strappend(&lexer->str, (char[]){'\n', 0});
|
||||
lexer->pos++;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
while (lexer->str[lexer->pos])
|
||||
token_append_char(heredoc_tok, lexer->str[lexer->pos++], 0, 0);
|
||||
return (lexer_end(alst, lexer));
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:29:17 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:52:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,21 +16,14 @@ int lexer_end(t_list **alst, t_lexer *lexer)
|
|||
{
|
||||
t_token *token;
|
||||
|
||||
if ((*alst && (lexer->state == QUOTE || lexer->state == DQUOTE
|
||||
|| lexer->state == BQUOTE)) || get_lexer_stack(*lexer) == DLESS)
|
||||
if (*alst && (lexer->state == QUOTE
|
||||
|| lexer->state == DQUOTE
|
||||
|| lexer->state == BQUOTE))
|
||||
{
|
||||
token = (*alst)->content;
|
||||
ft_strappend(&lexer->str, (char[]){'\n', 0});
|
||||
token_append_char(token, '\n', 1, 0);
|
||||
lexer->pos++;
|
||||
if (get_lexer_stack(*lexer) == DLESS)
|
||||
{
|
||||
token = (*(t_list**)lexer->heredoc_stack->content)->content;
|
||||
token_append_char(token, '\n', 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
token = (*alst)->content;
|
||||
token_append_char(token, '\n', 1, 0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 18:20:02 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:10:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
53
42sh/src/lexer/lexer_heredoc.c
Normal file
53
42sh/src/lexer/lexer_heredoc.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lexer_heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 15:53:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int lexer_heredoc(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
token->type = HEREDOCDATA;
|
||||
token_append_str(token, lexer->str, 0, 0);
|
||||
return (0);
|
||||
/* heredoc_lst = *(t_list**)lexer->heredoc_stack->content; */
|
||||
/* heredoc_tok = heredoc_lst->content; */
|
||||
/* if (!(heredoc_lst->next)) */
|
||||
/* { */
|
||||
/* ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); */
|
||||
/* return (1); */
|
||||
/* } */
|
||||
/* eof_tok = heredoc_lst->next->content; */
|
||||
/* if (!(eof_tok->type == TK_WORD)) */
|
||||
/* { */
|
||||
/* ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); */
|
||||
/* return (1); */
|
||||
/* } */
|
||||
/* DG("heredoc contains [%s]", heredoc_tok->data); */
|
||||
/* DG("heredoc ends at [%s]", eof_tok->data); */
|
||||
/* DG("input is [%s]", lexer->str + lexer->pos); */
|
||||
/* if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0) */
|
||||
/* { */
|
||||
/* /1* pop(&lexer->stack); *1/ */
|
||||
/* pop(&lexer->heredoc_stack); */
|
||||
/* while (lexer->str[++lexer->pos]) */
|
||||
/* ; */
|
||||
/* ft_strappend(&lexer->str, (char[]){'\n', 0}); */
|
||||
/* lexer->pos++; */
|
||||
/* return (0); */
|
||||
/* } */
|
||||
/* else */
|
||||
/* while (lexer->str[lexer->pos]) */
|
||||
/* token_append_char(heredoc_tok, lexer->str[lexer->pos++], 0, 0); */
|
||||
/* return (lexer_end(alst, lexer)); */
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 18:19:48 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:35:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,24 +17,18 @@ int lexer_less(t_list **alst, t_lexer *lexer)
|
|||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
token_append(token, lexer, 0, 0);
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == '&')
|
||||
{
|
||||
token->type = TK_LESSAND;
|
||||
token_append(token, lexer, 0, 0);
|
||||
lexer->pos++;
|
||||
return (lexer_lessand(alst, lexer));
|
||||
}
|
||||
if (lexer->str[lexer->pos] == '<')
|
||||
{
|
||||
token_free(token, 0);
|
||||
(*alst)->content = token_init();
|
||||
token->type = TK_DLESS;
|
||||
lexer->pos++;
|
||||
push(&lexer->stack, DLESS);
|
||||
lexer->state = DEFAULT;
|
||||
ft_lsteadd(&lexer->heredoc_stack, ft_lstnew(alst, sizeof(alst)));
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
}
|
||||
token->type = TK_LESS;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 18:05:39 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/06 14:55:25 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 15:51:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
|||
{
|
||||
&lexer_default,
|
||||
&lexer_paren,
|
||||
&lexer_heredoc,
|
||||
&lexer_newline,
|
||||
&lexer_delim,
|
||||
&lexer_sep,
|
||||
|
|
@ -25,7 +26,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
|||
&lexer_great,
|
||||
&lexer_lessand,
|
||||
&lexer_greatand,
|
||||
&lexer_dless,
|
||||
&lexer_quote,
|
||||
&lexer_dquote,
|
||||
&lexer_bquote,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 16:48:06 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:14:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int lexer_paren(t_list **alst, t_lexer *lexer)
|
|||
|
||||
token = (*alst)->content;
|
||||
if (token->type)
|
||||
lexer_lex(&(*alst)->next, lexer);
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
if (lexer->str[lexer->pos] == '(')
|
||||
{
|
||||
token->type = TK_PAREN_OPEN;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 20:26:36 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:20:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,26 +19,20 @@ int lexer_sep(t_list **alst, t_lexer *lexer)
|
|||
char cn;
|
||||
|
||||
lexer->state = DEFAULT;
|
||||
if (*alst)
|
||||
{
|
||||
token = (*alst)->content;
|
||||
if (*token->data)
|
||||
return (lexer_sep(&(*alst)->next, lexer));
|
||||
}
|
||||
else
|
||||
{
|
||||
token = token_init();
|
||||
*alst = ft_lstnew(token, sizeof(*token));
|
||||
}
|
||||
token = (*alst)->content;
|
||||
if (token->type)
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
c = lexer->str[lexer->pos];
|
||||
cn = lexer->str[lexer->pos + 1];
|
||||
lexer->pos++;
|
||||
cn = lexer->str[lexer->pos];
|
||||
if (c == '&')
|
||||
token->type = cn == '&' ? TK_AND_IF : TK_AMP;
|
||||
else if (c == '|')
|
||||
token->type = cn == '|' ? TK_OR_IF : TK_PIPE;
|
||||
token->type = (c == ';') ? TK_SEMI : token->type;
|
||||
token->type = (c == ';') && (cn == ';') ? TK_DSEMI : token->type;
|
||||
lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF | TK_DSEMI) ? 1 : 0);
|
||||
else if (c == ';')
|
||||
token->type = cn == ';' ? TK_DSEMI : TK_SEMI;
|
||||
if (token->type == TK_AND_IF || token->type == TK_OR_IF
|
||||
|| token->type == TK_DSEMI)
|
||||
lexer->pos++;
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 21:00:18 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:10:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 18:57:46 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:22:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 20:55:35 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:21:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 16:27:58 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:14:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ void token_print(t_list *lst)
|
|||
if (lst->content)
|
||||
token = lst->content;
|
||||
if (token->type)
|
||||
DG("token : %s data [%s]\n", read_state(token->type), token->data);
|
||||
DG("token : %s data [%s]", read_state(token->type), token->data);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/14 14:08:21 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/08 12:56:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 11:20:27 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:00:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 16:38:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 14:39:07 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,19 +21,10 @@ int data_init(void)
|
|||
|
||||
data = data_singleton();
|
||||
data->env = ft_sstrdup(environ);
|
||||
set_exitstatus(0, 1);
|
||||
data->comp = NULL;
|
||||
data->opts = 0;
|
||||
data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
||||
data->exec.op_stack = NULL;
|
||||
data->exec.fdin = STDIN;
|
||||
data->exec.attrs = 0;
|
||||
|
||||
data->exec.job.id = 0;
|
||||
data->exec.job.pgid = 0;
|
||||
data->exec.job.attrs = 0;
|
||||
data->exec.job.first_process = NULL;
|
||||
exec_reset();
|
||||
|
||||
data->jobc.first_job = NULL;
|
||||
data->jobc.current_id = 1;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 15:48:41 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 16:06:44 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -39,8 +39,8 @@ int handle_instruction(int fd)
|
|||
ft_strappend(&lexer.str, str);
|
||||
if (get_lexer_stack(lexer) == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
else if (get_lexer_stack(lexer) == DLESS)
|
||||
lexer.state = DLESS;
|
||||
/* else if (get_lexer_stack(lexer) == DLESS) */
|
||||
/* lexer.state = DLESS; */
|
||||
ltoken = ft_lstlast(token);
|
||||
if (lexer_lex(token ? <oken : &token, &lexer))
|
||||
return (1);
|
||||
|
|
@ -124,6 +124,6 @@ int main(int ac, char **av)
|
|||
// parser_clean;
|
||||
;
|
||||
}
|
||||
shell_exit();
|
||||
builtin_exit(NULL, NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 16:38:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 13:04:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,7 +21,6 @@ void shell_init(int ac, char **av)
|
|||
data = data_singleton();
|
||||
data->argc = ac;
|
||||
data->argv = ft_sstrdup(av);
|
||||
/* atexit(&shell_exit); */
|
||||
shell_get_opts(ac, av);
|
||||
if (SH_IS_INTERACTIVE(data->opts))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 10:49:15 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/08 03:21:13 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ int isfunc_name(t_btree **ast, t_list **lst)
|
|||
{
|
||||
DG("add func name");
|
||||
node->type = FNAME;
|
||||
node->data.str = ft_strdup(token->data);
|
||||
return (1);
|
||||
}
|
||||
if (node->type == FNAME && token->type == TK_PAREN_CLOSE && node->nest == 0)
|
||||
|
|
@ -88,7 +89,7 @@ int add_one_func(t_btree **ast, t_list **lst)
|
|||
t_btree *func_ast;
|
||||
|
||||
(void)lst;
|
||||
// func_ast = btree_map(*ast, &id);
|
||||
func_ast = btree_map(*ast, node_copy);
|
||||
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
|
||||
DG("arbre ajoute");
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue