diff --git a/42sh/Makefile b/42sh/Makefile index 23e13026..3f641915 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -102,7 +102,6 @@ exec/plaunch_until.c\ exec/plaunch_while.c\ exec/process_launch.c\ exec/process_redirect.c\ -exec/process_resetfds.c\ exec/process_set.c\ exec/process_setgroup.c\ exec/process_setsig.c\ @@ -274,6 +273,7 @@ main/data_singleton.c\ main/ft_putast.c\ main/main.c\ main/shell_init.c\ +main/shell_reset.c\ parser/add_bang.c\ parser/add_case.c\ parser/add_cmd.c\ diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index 8526ef14..3e7e356e 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,29 +6,30 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:34:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:25:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef BUILTIN_READ_H # define BUILTIN_READ_H -# define READ_OPT_LA (1 << 0) -# define READ_OPT_LD (1 << 1) -# define READ_OPT_LE (1 << 2) -# define READ_OPT_LI (1 << 3) -# define READ_OPT_LN (1 << 4) -# define READ_OPT_UN (1 << 5) -# define READ_OPT_LP (1 << 6) -# define READ_OPT_LR (1 << 7) -# define READ_OPT_LS (1 << 8) -# define READ_OPT_LT (1 << 9) -# define READ_OPT_LU (1 << 10) +# define BT_READ_LA (1 << 0) +# define BT_READ_LD (1 << 1) +# define BT_READ_LE (1 << 2) +# define BT_READ_LI (1 << 3) +# define BT_READ_LN (1 << 4) +# define BT_READ_UN (1 << 5) +# define BT_READ_LP (1 << 6) +# define BT_READ_LR (1 << 7) +# define BT_READ_LS (1 << 8) +# define BT_READ_LT (1 << 9) +# define BT_READ_LU (1 << 10) +# define BT_READ_INTER (1 << 11) typedef struct s_read t_read; typedef struct s_readopt t_readopt; -struct s_read +struct s_read { t_flag opts; char **names; diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index d0ee6e3c..7313f13b 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/21 20:17:27 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:35:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -144,7 +144,6 @@ int process_fork(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); -void process_resetfds(t_process *p); int fd_is_valid(int fd, int flag); int bad_fd(int fd); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 13e3c824..8840d4b0 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/21 14:40:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:24:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ # define JOBS_OPT_L (1 << 0) -struct s_jobc +struct s_jobc { t_list *first_job; pid_t shell_pgid; @@ -75,9 +75,11 @@ void sigttou_handler(int signo); int process_cmp_pid(t_process *p, pid_t *pid); void process_format(t_list **p, int firstp, int opts); + /* ** Mapping pour afficher les process */ + void pprint(t_process *p); int pprint_subshell(t_process *p);; int pprint_brace(t_process *p); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index f156068a..122b8365 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:25:58 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:29:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 2be1b684..27fa02d0 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:26:34 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:29:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,17 +32,10 @@ # include "glob.h" # include "completion.h" # include "hash.h" -/* # define malloc(x) NULL */ # define SH_MSG(s, ...) "{red}%s: " s "{eoc}\n", g_argv[0], ##__VA_ARGS__ # define SH_ERR(s, ...) ft_dprintf(STDERR, SH_MSG(s, ##__VA_ARGS__)) -#ifndef DEBUG -# define DEBUG_MODE 0 -#else -# define DEBUG_MODE 1 -#endif - struct s_data { t_flag opts; @@ -62,13 +55,15 @@ struct s_data t_list *lst_func; }; +t_data *data_singleton(); int shell_init(int ac, char **av); void shell_exit(void); int data_init(int ac, char **av); void data_exit(void); int get_c_arg(char ***av, t_data *data); -/* void content_free(void *data, size_t content_size); */ +void shell_resetfds(void); +void shell_resetsig(void); char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 5ca2429f..4ee154f1 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/22 16:53:22 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:30:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ # define SH_IS_INTERACTIVE(b) (b & SH_INTERACTIVE) # define SH_NO_INTERACTIVE(b) !(b & SH_INTERACTIVE) -# define SH_MSG_NOJOBC "no job-control" +# define SH_MSG_NOJOBC "no job-control" typedef long long t_type; typedef long long t_flag; @@ -88,8 +88,6 @@ typedef struct s_errormatch t_errormatch; typedef struct s_treematch t_treematch; typedef struct s_distrostree t_distrostree; -t_data *data_singleton(); - enum e_sym { LINEBREAK = 1, diff --git a/42sh/libft/src/ft_printf/ft_vprintf.c b/42sh/libft/src/ft_printf/ft_vprintf.c index 718897e9..09ba322c 100644 --- a/42sh/libft/src/ft_printf/ft_vprintf.c +++ b/42sh/libft/src/ft_printf/ft_vprintf.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_vprintf.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:34:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:22:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,7 +57,7 @@ int ft_vasprintf(char **ret, const char *format, va_list ap) return (-1); } else if (!(final = ft_strjoin(final, (char[]){*str++, 0}))) - return (-1); + return (-1); ft_strdel(&tmp); } *ret = final; diff --git a/42sh/libft/src/sys/fd_replace.c b/42sh/libft/src/sys/fd_replace.c index f8a753dd..2e22e75e 100644 --- a/42sh/libft/src/sys/fd_replace.c +++ b/42sh/libft/src/sys/fd_replace.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* fd_replace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:42:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:22:55 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,6 @@ int fd_replace(int fd1, int fd2) { if (fd1 != fd2) - return(dup2_close(fd1, fd2)); + return (dup2_close(fd1, fd2)); return (0); } diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index 2fb1d5f1..1df15cbc 100644 --- a/42sh/src/builtin/bt_read_term.c +++ b/42sh/src/builtin/bt_read_term.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:23:46 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:48:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,17 +25,23 @@ int bt_read_terminit(t_read *data) { struct termios term; - (void)data; term = bt_read_term(1); + if (!(data->opts & BT_READ_INTER)) + return (0); term.c_lflag = ECHO | ECHOE | ECHOK | ICANON; - term.c_lflag &= data->timeout ? ~ICANON : ~0; - if (data->opts & READ_OPT_LS) + { + term.c_lflag &= data->timeout ? ~ICANON : ~0; + term.c_cc[VTIME] = data->timeout * 10; + term.c_cc[VMIN] = !data->timeout; + } + if (data->opts & BT_READ_LS) term.c_lflag &= ~ECHO; - term.c_cc[VTIME] = data->timeout * 10; - term.c_cc[VMIN] = !data->timeout; term.c_cc[VEOL] = data->delim; if (tcsetattr(0, TCSANOW, &term) < 0) + { + SH_ERR("tcsetattr(): %s", strerror(errno)); return (-1); + } return (0); } diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index bf22360f..08c29937 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_env.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */ +/* Updated: 2017/03/22 17:17:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" #define ENV_USAGE "env [-i] [name=value]... [utility [argument...]]" @@ -51,10 +63,10 @@ int builtin_env(const char *path, if (!(path = ft_strchr(data.av_data[0], '/') ? ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0])) || access(path, F_OK) != 0) - exit (SH_ERR(ENV_NOFILE, data.av_data[0])); + exit(SH_ERR(ENV_NOFILE, data.av_data[0])); stat(path, &buf); if (S_ISDIR(buf.st_mode) || access(path, X_OK) != 0) - exit (SH_ERR(ENV_NOPERM, data.av_data[0])); + exit(SH_ERR(ENV_NOPERM, data.av_data[0])); execve(path, data.av_data, data.custom_env); } waitpid(pid, &status, 0); diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 7410da42..3f23df8d 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/21 15:16:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:50:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,13 +17,13 @@ t_cliopts g_read_opts[] = { - {'d', NULL, READ_OPT_LD, 0, bt_read_getdelim}, - {'n', NULL, READ_OPT_LN, 0, bt_read_getnchars}, - {'p', NULL, READ_OPT_LP, 0, bt_read_getprompt}, - {'r', NULL, READ_OPT_LR, 0, NULL}, - {'s', NULL, READ_OPT_LS, 0, NULL}, - {'t', NULL, READ_OPT_LT, 0, bt_read_gettimeout}, - {'u', NULL, READ_OPT_LU, 0, bt_read_getfd}, + {'d', NULL, BT_READ_LD, 0, bt_read_getdelim}, + {'n', NULL, BT_READ_LN, 0, bt_read_getnchars}, + {'p', NULL, BT_READ_LP, 0, bt_read_getprompt}, + {'r', NULL, BT_READ_LR, 0, NULL}, + {'s', NULL, BT_READ_LS, 0, NULL}, + {'t', NULL, BT_READ_LT, 0, bt_read_gettimeout}, + {'u', NULL, BT_READ_LU, 0, bt_read_getfd}, {0, 0, 0, 0, 0}, }; @@ -38,6 +38,8 @@ int bt_read_init(t_read *data, char **av) data->input = NULL; if ((cliopts_get(av, g_read_opts, data))) return (ft_perror() ? 2 : 2); + if (isatty(STDIN)) + data->opts |= BT_READ_INTER; if (bt_read_terminit(data) < 0) return (-1); return (0); @@ -52,7 +54,7 @@ int bt_read_loop(t_read *data) esc = 0; i = 0; - if (data->prompt) + if (data->prompt && data->opts & BT_READ_INTER) ft_printf(data->prompt); while (42) { @@ -61,11 +63,12 @@ int bt_read_loop(t_read *data) buf[ret] = 0; if (!esc && *buf == data->delim) break ; - esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\'); + esc = esc ? 0 : !(data->opts & BT_READ_LR) && (*buf == '\\'); ft_strappend(&data->input, buf); - if (*buf == '\n' && !(data->opts & (READ_OPT_LR | READ_OPT_LS))) + if (*buf == '\n' && !(data->opts & + (BT_READ_LR | BT_READ_LS | BT_READ_INTER))) ft_putstr("> "); - if ((data->opts & READ_OPT_LN) && ++i >= data->nchars) + if ((data->opts & BT_READ_LN) && ++i >= data->nchars) break ; } return (0); diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index 9a70a184..a00dd611 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/21 18:11:31 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:21:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define SETERR_0 "%s: %s: invalid variable name" +#define SETERR_0 "%s: %s: invalid variable name" static int assign_var(char *const av[], char ***env) { diff --git a/42sh/src/completion/c_match.c b/42sh/src/completion/c_match.c index 3c9b3a0f..fa560399 100644 --- a/42sh/src/completion/c_match.c +++ b/42sh/src/completion/c_match.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/22 16:02:25 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:20:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,6 @@ static char *c_strdupi(char *s, int (*f)(char)) return (str); } - /* ** Seek the current word. */ diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 8fe4a385..9b64ae05 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/20 20:40:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:09:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 30b1e401..6a41a54a 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/21 20:59:57 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n" +#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n" int plaunch_function(t_process *p) { @@ -26,7 +26,7 @@ int plaunch_function(t_process *p) func_lvl += ft_strlenchr(func_lvl, '=') + 1; if ((value = ft_atoi(func_lvl)) >= 199) { - ft_strdel(&temp); + ft_strdel(&temp); return (SH_ERR(FUNCERR_0)); } value += 1; diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 0d4d86dd..697d9194 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/21 18:11:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:34:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,8 @@ int process_launch(t_process *p) set_exitstatus(1, 1); else set_exitstatus(p->map.launch(p), 1); - process_resetfds(p); + shell_resetfds(); + shell_resetsig(); process_free(p, 0); return (0); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 29c64f87..b4df8be9 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 20:41:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:24:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,9 +67,8 @@ int process_set(t_process *p, t_btree *ast) p->fdout = fds[PIPE_WRITE]; p->pid = 0; exec->fdin = fds[PIPE_READ]; - if (!ast) - return (0); - p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, + if (ast) + p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); - return (process_set_spec(p, ast)); + return ((!ast) ? 0 : process_set_spec(p, ast)); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 1632df9c..ed66829a 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:58:33 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:45:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,7 @@ int process_setgroup(t_process *p, pid_t pid) if (!SH_IS_INTERACTIVE(data_singleton()->opts)) return (0); if (setpgid(pid, j->pgid) == -1) - ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", - SHELL_NAME, errno); + SH_ERR("setpgid(): %s", strerror(errno)); if (pid == 0 && JOB_IS_FG(j->attrs)) tcsetpgrp(STDIN, j->pgid); return (0); diff --git a/42sh/src/exec/process_setsig.c b/42sh/src/exec/process_setsig.c index 21f96de6..126c0267 100644 --- a/42sh/src/exec/process_setsig.c +++ b/42sh/src/exec/process_setsig.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 14:08:35 by jhalford #+# #+# */ -/* Updated: 2017/03/18 00:16:37 by wescande ### ########.fr */ +/* Updated: 2017/03/22 16:05:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/builtin_fg.c b/42sh/src/job_control/builtin_fg.c index 74258367..eef63ca6 100644 --- a/42sh/src/job_control/builtin_fg.c +++ b/42sh/src/job_control/builtin_fg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:42:22 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:30:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) (void)envp; if (!SH_HAS_JOBC(data_singleton()->opts)) { - ft_dprintf(2, "{red}fg: %s{eoc}\n", SH_MSG_NOJOBC); + SH_ERR("fg: %s", SH_MSG_NOJOBC); return (-1); } jobc = &data_singleton()->jobc; @@ -33,7 +33,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) job_run(jlist->content, 1); else - ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id); + SH_ERR("{red}fg: job not found: [%i]", id); } else { @@ -42,7 +42,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id))) job_run(jlist->content, 1); else - ft_dprintf(2, "{red}fg: no current job{eoc}\n"); + SH_ERR("fg: no current job"); } return (0); } diff --git a/42sh/src/job_control/process_format.c b/42sh/src/job_control/process_format.c index 4fba94b2..19e9e66a 100644 --- a/42sh/src/job_control/process_format.c +++ b/42sh/src/job_control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/21 14:11:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:40:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,7 +98,7 @@ void process_format(t_list **plist, int firstp, int opts) p = (*plist)->content; if (!firstp) - ft_printf(" "); + ft_putstr(" "); if (opts & JOBS_OPT_L) ft_printf("%i ", p->pid); process_format_state(p); diff --git a/42sh/src/job_control/put_job_in_foreground.c b/42sh/src/job_control/put_job_in_foreground.c index 74bafa70..7714628a 100644 --- a/42sh/src/job_control/put_job_in_foreground.c +++ b/42sh/src/job_control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/16 16:51:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:32:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/do_lexer_routine.c b/42sh/src/lexer/do_lexer_routine.c index d442c402..a02f5887 100644 --- a/42sh/src/lexer/do_lexer_routine.c +++ b/42sh/src/lexer/do_lexer_routine.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/19 14:24:38 by wescande #+# #+# */ -/* Updated: 2017/03/20 16:44:31 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:37:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,11 @@ int do_lexer_routine(t_list **token, char *stream) data = data_singleton(); if (data->lexer.state == HEREDOC) ft_strappend(&data->lexer.str, (char[]){'\n', 0}); - if (data->parser.state == UNDEFINED && !isrw_delim(last)) + if (data->parser.state == UNDEFINED && !isrw_delim(last)) ft_strappend(&data->lexer.str, (char[]){';', 0}); else if (data->parser.state == UNDEFINED && last != 0) ft_strappend(&data->lexer.str, (char[]){' ', 0}); - if (data->lexer.state == HEREDOC || (data->parser.state == UNDEFINED + if (data->lexer.state == HEREDOC || (data->parser.state == UNDEFINED && last != 0)) data->lexer.pos++; ft_strappend(&data->lexer.str, stream); @@ -34,9 +34,7 @@ int do_lexer_routine(t_list **token, char *stream) ltoken = ft_lstlast(*token); if (lexer_lex(*token ? <oken : token, &data->lexer) < 0) exit(1); - if (get_lexer_stack(data->lexer) > 2) - return (1); - if (get_reserved_words(*token)) + if ((get_lexer_stack(data->lexer) > 2) || (get_reserved_words(*token))) return (1); keep_last_type(&last, *token); data->lexer.state = DEFAULT; diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 39b4d333..3426c33d 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/20 16:01:29 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:38:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,7 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk) || pv_tk->type == TK_FI || pv_tk->type == TK_THEN || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE || pv_tk->type == TK_DSEMI || pv_tk->type == TK_PAREN_OPEN - || pv_tk->type == TK_LBRACE || pv_tk->type == TK_UNTIL) + || pv_tk->type == TK_LBRACE || pv_tk->type == TK_UNTIL) || (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN)); } diff --git a/42sh/src/lexer/isrw_delim.c b/42sh/src/lexer/isrw_delim.c index a7903f29..bb9e9af3 100644 --- a/42sh/src/lexer/isrw_delim.c +++ b/42sh/src/lexer/isrw_delim.c @@ -6,17 +6,17 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 19:12:50 by ariard #+# #+# */ -/* Updated: 2017/03/20 19:12:51 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:38:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int isrw_delim(t_type type) +int isrw_delim(t_type type) { return (type == TK_NEWLINE || type == TK_AMP || type == TK_SEMI || type == TK_PIPE - || type == TK_WHILE || type == TK_UNTIL + || type == TK_WHILE || type == TK_UNTIL || type == TK_DONE || type == TK_RBRACE || type == TK_DO || type == TK_IF || type == TK_FI || type == TK_THEN diff --git a/42sh/src/lexer/keep_last_type.c b/42sh/src/lexer/keep_last_type.c index f92829a7..9e881e97 100644 --- a/42sh/src/lexer/keep_last_type.c +++ b/42sh/src/lexer/keep_last_type.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 16:15:34 by ariard #+# #+# */ -/* Updated: 2017/03/20 16:25:06 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:38:19 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,4 +19,4 @@ int keep_last_type(t_type *last, t_list *token) if (!(tmp = ft_lstlast(token))) return ((*last = 0)); return (*last = ((t_token *)tmp->content)->type); -} +} diff --git a/42sh/src/lexer/lexer_paren.c b/42sh/src/lexer/lexer_paren.c index 5abf4b69..03efd44e 100644 --- a/42sh/src/lexer/lexer_paren.c +++ b/42sh/src/lexer/lexer_paren.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:14:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:16:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,11 @@ int lexer_paren(t_list **alst, t_lexer *lexer) token->type = TK_PAREN_OPEN; push(&lexer->stack, PAREN); } - else if (get_lexer_stack(*lexer)) + else { token->type = TK_PAREN_CLOSE; - pop(&lexer->stack); + if (get_lexer_stack(*lexer) == PAREN) + pop(&lexer->stack); } lexer->pos++; lexer->state = DEFAULT; diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index be837ca1..2f0df7e5 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/03/21 20:37:47 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:13:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ void token_print(t_list *lst) while (lst) { - DG("in token print"); if (lst->content) token = lst->content; if (token->type) diff --git a/42sh/src/line_editing/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste.c index 3127478d..95cfc94a 100644 --- a/42sh/src/line_editing/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/21 18:11:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:49:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,17 +43,16 @@ int ft_v(char **str, size_t *pos) int i; char *tmp; - tmp = data_singleton()->line.copy_tmp; i = -1; tmp_pos = *pos; + tmp = data_singleton()->line.copy_tmp; if (!*str || !tmp) return (0); while (tmp[++i]) { if (ft_strlen(*str) > SIZE_LINE) break ; - if (!(*str = ft_realloc_imput(*str, tmp[i], *pos + i))) - return (-1); + *str = ft_realloc_imput(*str, tmp[i], *pos + i); } if (*pos) { diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 04cbdc62..1fc2ab2b 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/20 21:19:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:49:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,7 @@ int readline(int has_prompt, char **input) if (!SH_IS_INTERACTIVE(data_singleton()->opts)) { if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) - { - DG("returning %i", !ret); return (!ret); - } return (ret); } readline_init(has_prompt); diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 9fcce223..0abc6637 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/21 01:50:24 by wescande ### ########.fr */ +/* Updated: 2017/03/22 15:55:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,8 +68,8 @@ int data_init(int ac, char **av) parser_init(&data->parser); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) { - /* ft_dprintf(2, "{red}TERM not set\n{eoc}"); */ term_name = "dumb"; + /* ft_dprintf(2, "{red}TERM not set\n{eoc}"); */ /* return (-1); */ } if (tgetent(NULL, term_name) != 1) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index ad444135..b407d5e3 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/22 17:00:12 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:29:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 0def2805..b734b6c5 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/20 18:12:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 16:08:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,13 +71,8 @@ static int interactive_settings(void) shell_pgid = &data->jobc.shell_pgid; while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) kill(-*shell_pgid, SIGTTIN); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGTSTP, SIG_IGN); - signal(SIGTTIN, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGCHLD, SIG_DFL); *shell_pgid = getpid(); + shell_resetsig(); if (setpgid(*shell_pgid, *shell_pgid)) { ft_dprintf(2, diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/main/shell_reset.c similarity index 68% rename from 42sh/src/exec/process_resetfds.c rename to 42sh/src/main/shell_reset.c index 4eb0da6c..fd0d3546 100644 --- a/42sh/src/exec/process_resetfds.c +++ b/42sh/src/main/shell_reset.c @@ -1,23 +1,32 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_resetfds.c :+: :+: :+: */ +/* shell_reset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */ -/* Updated: 2017/03/21 20:54:20 by ariard ### ########.fr */ +/* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */ +/* Updated: 2017/03/22 16:25:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void process_resetfds(t_process *p) +void shell_resetsig(void) +{ + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTIN, SIG_IGN); + signal(SIGTTOU, SIG_IGN); + signal(SIGCHLD, SIG_DFL); +} + +void shell_resetfds(void) { t_exec *exec; int i; - (void)p; exec = &data_singleton()->exec; i = -1; while (++i < 10) diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 3729d800..f6b1c456 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/21 20:01:37 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:52:57 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,10 +94,10 @@ t_list *is_already_func(t_btree **new) while (tmp && ret) { if ((ast = tmp->content) && !*ast) - break; + break ; old_name = token_to_argv(((t_astnode *) (*ast)->item)->data.cmd.token, 1); - ret = (new_name && new_name[0] && old_name && old_name[0] + ret = (new_name && new_name[0] && old_name && old_name[0] && !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1; ft_tabdel(&old_name); tmp = tmp->next; @@ -117,7 +117,7 @@ int add_one_func(t_btree **ast, t_list **lst) func_ast = btree_map(*ast, &node_copy); if ((old_func = is_already_func(&func_ast))) ft_lst_delif(&data_singleton()->lst_func, - old_func->content, &ft_addrcmp, &tree_func_free); + old_func->content, &ft_addrcmp, &tree_func_free); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); }