diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 094bc086..96fb1253 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ -/* Updated: 2017/03/20 23:22:19 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:28:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ # define BT_ENV_LI (1 << 0) # define BT_ENV_LU (1 << 1) -struct s_env_data +struct s_env_data { t_flag flag; char **av_data; diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index 3e7e356e..61d5aa02 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:25:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:36:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index b2b62c12..7ce7db9e 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/17 17:23:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:19:43 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -185,5 +185,6 @@ char *path_solver(t_comp *c, char *cmd, char *cwd); int c_exclusion_folder(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); +char *ft_add_escape(char *str, char to_escape); #endif diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h deleted file mode 100644 index 8a5ef926..00000000 --- a/42sh/includes/ft_input.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_input.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */ -/* Updated: 2017/03/16 15:58:25 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_INPUT_H -# define FT_INPUT_H - -/* - * Input code mapping (!!!!LINUX!!!!) - * TODO Same for MACOSX -*/ - -# ifdef __linux__ -# define RL_INSERT_CODE 0x7e325b1b -# define RL_CLEAR_CODE 0xc -# define RL_NL_CODE 0xa -# define RL_COMP_CODE 0x9 -# define RL_LEFT_CODE 0x445b1b -# define RL_RIGHT_CODE 0x435b1b -# define RL_WLEFT_CODE 0x44323b315b1b -# define RL_WRIGHT_CODE 0x43323b315b1b -# define RL_HOME_CODE 0x485b1b -# define RL_END_CODE 0x465b1b -# define RL_PAGEUP_CODE 0x7e355b1b -# define RL_PAGEDOWN_CODE 0x7e365b1b -# define RL_SELECT_RIGHT_CODE 0x43333b315b1b -# define RL_SELECT_LEFT_CODE 0x44333b315b1b -# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b -# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b -# define RL_SELECT_HOME_CODE 0x48333b315b1b -# define RL_SELECT_END_CODE 0x46333b315b1b -# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b -# define RL_SELECT_WLEFT_CODE 0x44343b315b1b -# define RL_RETARR_CODE 0x7f -# define RL_SUPPR_CODE 0x7e335b1b -# define RL_ESC_CODE 0x5c -# define RL_QUOTE_CODE 0x27 -# define RL_DQUOTE_CODE 0x22 -# define RL_COPY_CODE 0x631b -# define RL_CUT_CODE 0x781b -# define RL_PASTE_CODE 0x761b -# endif - -# ifdef __APPLE__ -# define RL_INSERT_CODE 0x53323b315b1b -# define RL_CLEAR_CODE 0xc -# define RL_NL_CODE 0xa -# define RL_COMP_CODE 0x9 -# define RL_LEFT_CODE 0x445b1b -# define RL_RIGHT_CODE 0x435b1b -# define RL_WLEFT_CODE 0x44323b315b1b -# define RL_WRIGHT_CODE 0x43323b315b1b -# define RL_HOME_CODE 0x485b1b -# define RL_END_CODE 0x465b1b -# define RL_PAGEUP_CODE 0x7e355b1b -# define RL_PAGEDOWN_CODE 0x7e365b1b -# define RL_SELECT_RIGHT_CODE 0x435b1b1b -# define RL_SELECT_LEFT_CODE 0x445b1b1b -# define RL_SELECT_PAGEUP_CODE 0x7e355b1b1b -# define RL_SELECT_PAGEDOWN_CODE 0x7e365b1b1b -# define RL_SELECT_HOME_CODE 0X48393b315b1b -# define RL_SELECT_END_CODE 0X46393b315b1b -# define RL_SELECT_WRIGHT_CODE 0x4330313b315b1b -# define RL_SELECT_WLEFT_CODE 0x4430313b315b1b -# define RL_RETARR_CODE 0x7f -# define RL_SUPPR_CODE 0x7e335b1b -# define RL_ESC_CODE 0x5c -# define RL_QUOTE_CODE 0x27 -# define RL_DQUOTE_CODE 0x22 -# define RL_COPY_CODE 0xa7c3 -# define RL_CUT_CODE 0x8889e2 -# define RL_PASTE_CODE 0x9a88e2 -# endif - -#endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 47c887d6..cbef9516 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/22 20:57:29 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 20:59:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,6 @@ # include # include -# include "ft_input.h" - # define FLECHE_HAUT 4283163 # define FLECHE_BAS 4348699 # define FLECHE_GAUCHE 4479771 diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 5f60cc83..3a5ee122 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:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:13:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 2dd823c0..27fa02d0 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,12 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:23:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:29:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H + # define SHELL_NAME "minishell" # include diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 1a25f778..d3a0cbb7 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -1,11 +1,12 @@ /* ************************************************************************** */ /* */ +/* ::: :::::::: */ /* parser.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */ +/* Created: 2017/03/22 17:22:51 by ariard #+# #+# */ +/* Updated: 2017/03/22 17:25:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,10 +36,10 @@ struct s_parser struct s_aggrematch { - t_sym top; - t_sym under; - t_sym new_sym; - int erase_sym; + t_sym top; + t_sym under; + t_sym new_sym; + int erase_sym; }; struct s_prodmatch @@ -64,7 +65,7 @@ int do_parser_routine(t_list **token, t_btree **ast); void parser_init(t_parser *parser); void parser_destroy(t_parser *parser); int stack_init(t_parser *parser); -int redir_init(t_type type, t_redir *redir); +int redir_init(t_type type, t_redir *redir); int ft_parse(t_btree **ast, t_list **token, t_parser *parser); int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst); @@ -82,15 +83,10 @@ int error_eof(void); int ft_read_stack(t_sym *stack); char *read_state(t_sym current); -/* - * Build AST - rewriting - * -*/ - struct s_treematch { t_type type; - int (*add)(t_btree **ast, t_list **lst); + int (*add)(t_btree **ast, t_list **lst); }; int build_tree(t_btree **ast, t_list **lst); @@ -145,7 +141,7 @@ int superflous_token(t_btree **ast, t_list **list); void sym_free(void *data, size_t size); void tree_func_free(void *data, size_t content_size); -struct s_distrostree +struct s_distrostree { int (*test)(t_btree **ast, t_list **lst); int (*add)(t_btree **ast, t_list **lst); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 6540196b..fc142314 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 17:22:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:36:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index 1df15cbc..e3cf5bec 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/22 16:48:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:21:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 3f23df8d..ce94d408 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/22 16:50:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:21:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,7 @@ int bt_read_loop(t_read *data) esc = 0; i = 0; - if (data->prompt && data->opts & BT_READ_INTER) + if (data->prompt && (data->opts & BT_READ_INTER)) ft_printf(data->prompt); while (42) { diff --git a/42sh/src/completion/c_find_abspath.c b/42sh/src/completion/c_find_abspath.c index b60a71e7..9d2da32d 100644 --- a/42sh/src/completion/c_find_abspath.c +++ b/42sh/src/completion/c_find_abspath.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/22 15:14:41 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 20:25:19 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ void c_seek_abs_path(t_comp *c, char *current_word) if (current_word[0] == '~') { tmp = c->cpath; - c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); + c->cpath = ft_str3join(getenv("HOME"), "/", c->cpath + 2); free(tmp); } !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; diff --git a/42sh/src/completion/c_misc.c b/42sh/src/completion/c_misc.c index 92dd2101..1a979b1d 100644 --- a/42sh/src/completion/c_misc.c +++ b/42sh/src/completion/c_misc.c @@ -6,12 +6,61 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */ -/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:23:04 by alao ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +/* +** Count the number of time char c is in str. +*/ + +static size_t ft_strxchr(char *str, char c) +{ + size_t rt; + + rt = 0; + while(*str) + { + if (*str == c) + rt++; + str++; + } + return (rt); +} + +/* +** Add escape char \ for char to_escape. +*/ + +char *ft_add_escape(char *str, char to_escape) +{ + char *rt; + int i; + int j; + + if (!str) + return (NULL); + if (!ft_strxchr(str, ' ')) + return (ft_strdup(str)); + rt = ft_strnew(ft_strlen(str) + ft_strxchr(str, to_escape)); + i = 0; + j = 0; + while (str[i]) + { + if (str[i] == to_escape) + { + i++; + rt[j++] = '\\'; + rt[j++] = ' '; + } + else + rt[j++] = str[i++]; + } + return (rt); +} + /* ** Support: Return the size of a char**. */ diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index c4aead28..ed2a512d 100644 --- a/42sh/src/completion/c_output.c +++ b/42sh/src/completion/c_output.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */ -/* Updated: 2017/03/21 14:37:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:20:29 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,19 +53,22 @@ int c_updater(t_comp *c, char *select) { char *tmp; char *rt; + char *alter; tmp = NULL; rt = NULL; + alter = ft_add_escape(select, ' '); if (c->match) tmp = ft_strsub(c->rcmd, 0, ft_strlen(c->rcmd) - ft_strlen(c->match)); else tmp = ft_strdup(c->rcmd); - rt = ft_strjoin(tmp, select); + rt = ft_strjoin(tmp, alter); tmp ? ft_memdel((void *)&tmp) : (0); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd = ft_strdup(rt); c_updater_rcmd(c); rt ? ft_memdel((void *)&rt) : (0); + alter ? ft_memdel((void *)&alter) : (0); c_clear(data_singleton()); return (1); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 2f2bd313..a95f54c2 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/21 20:15:59 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:27:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 9b64ae05..c4ba1f07 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/22 16:09:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:26:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_func.c b/42sh/src/exec/pfree_func.c index 98e5fe2f..b8a467b7 100644 --- a/42sh/src/exec/pfree_func.c +++ b/42sh/src/exec/pfree_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 20:18:34 by ariard #+# #+# */ -/* Updated: 2017/03/21 20:53:45 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:25:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int pfree_func(t_process *p) { - ft_putstr("hello"); btree_del(&p->data.function.content, &ast_free); return (0); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 6a41a54a..c1b7ca60 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/22 16:22:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:37:08 by jhalford ### ########.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" int plaunch_function(t_process *p) { @@ -36,6 +36,6 @@ int plaunch_function(t_process *p) builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", ft_itoa(value), 0}, NULL); ft_exec(&p->data.function.content); - DG(); + builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "0", 0}, NULL); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index 1e4cb74d..e144a032 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/21 18:10:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:23:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,5 @@ int plaunch_if(t_process *p) { data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH; ft_exec(&p->data.d_if.content); - /* set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?"))); */ return (0); } diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index 1f420b3e..dbe8e2fb 100644 --- a/42sh/src/exec/plaunch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/21 00:51:39 by wescande ### ########.fr */ +/* Updated: 2017/03/22 19:22:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index 7869a9b7..44c2d554 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/21 00:48:16 by wescande ### ########.fr */ +/* Updated: 2017/03/22 19:23:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 697d9194..5843705c 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/22 16:34:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:26:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,7 @@ int process_fork(t_process *p) pid_t pid; if ((pid = fork()) == -1) - { - ft_dprintf(3, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); - exit(1); - } + exit(SH_ERR("fork(): %s", strerror(errno))); else if (pid) return (pid); if (!p) diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index b4df8be9..de3b37f1 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/22 16:24:18 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:26:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_while.c b/42sh/src/exec/pset_while.c index c62b1180..6202f829 100644 --- a/42sh/src/exec/pset_while.c +++ b/42sh/src/exec/pset_while.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */ -/* Updated: 2017/03/20 16:26:47 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:24:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/glob/expand_bquote.c b/42sh/src/glob/expand_bquote.c index 22f265f5..5d3ee1fb 100644 --- a/42sh/src/glob/expand_bquote.c +++ b/42sh/src/glob/expand_bquote.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 17:47:53 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:10:32 by wescande ### ########.fr */ +/* Updated: 2017/03/22 19:24:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/glob/ft_strsplit_esc.c b/42sh/src/glob/ft_strsplit_esc.c index b47f6ca6..57bf1439 100644 --- a/42sh/src/glob/ft_strsplit_esc.c +++ b/42sh/src/glob/ft_strsplit_esc.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 22:18:46 by wescande #+# #+# */ -/* Updated: 2017/03/21 18:13:25 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:24:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ unsigned char **ft_strsplit_esc(const char *str, if ((pos = -1) && !str) return (NULL); - if (!(s1 = (unsigned char **)ft_malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1)))) + if (!(s1 = ft_malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1)))) return (NULL); i = 0; fix = str; diff --git a/42sh/src/job_control/builtin_bg.c b/42sh/src/job_control/builtin_bg.c index 269e9c2d..08c5fdfb 100644 --- a/42sh/src/job_control/builtin_bg.c +++ b/42sh/src/job_control/builtin_bg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ -/* Updated: 2017/03/16 16:49:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:29:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]) (void)envp; if (!SH_HAS_JOBC(data_singleton()->opts)) { - ft_dprintf(2, "{red}bg: %s{eoc}\n", SH_MSG_NOJOBC); + SH_ERR("bg: %s", SH_MSG_NOJOBC); return (-1); } jobc = &data_singleton()->jobc; @@ -35,8 +35,8 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]) return (0); } else if (av[1]) - ft_dprintf(2, "{red}bg: job not found: %i{eoc}\n", id); + SH_ERR("bg: job not found: [%i]", id); else - ft_dprintf(2, "{red}bg: no current job{eoc}\n"); + SH_ERR("bg: no current job"); return (1); } diff --git a/42sh/src/job_control/builtin_fg.c b/42sh/src/job_control/builtin_fg.c index eef63ca6..fd61c7ea 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/22 16:30:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:31:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,21 +28,15 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) } jobc = &data_singleton()->jobc; job_getrank(&rank); - if (av[1] ? (id = *av[1]) : 0) + id = av[1] ? ft_atoi(av[1]) : rank[0]; + if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) { - if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) - job_run(jlist->content, 1); - else - SH_ERR("{red}fg: job not found: [%i]", id); + job_run(jlist->content, 1); + return (0); } + else if (av[1]) + SH_ERR("fg: job not found: [%i]", id); else - { - if ((jlist = ft_lst_find(jobc->first_job, &rank[0], job_cmp_id))) - job_run(jlist->content, 1); - else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id))) - job_run(jlist->content, 1); - else - SH_ERR("fg: no current job"); - } + SH_ERR("fg: no current job"); return (0); } diff --git a/42sh/src/job_control/job_addprocess.c b/42sh/src/job_control/job_addprocess.c index 4822d25c..e69bf241 100644 --- a/42sh/src/job_control/job_addprocess.c +++ b/42sh/src/job_control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/21 01:30:10 by wescande ### ########.fr */ +/* Updated: 2017/03/22 19:36:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,7 @@ int job_addprocess(t_process *p) job_update_id(); job->id = jobc->current_id; job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? - /* p->pid : data_singleton()->jobc.shell_pgid; */ - p->pid : getpgid(0); + p->pid : getpgid(0); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } job = jobc->first_job->content; diff --git a/42sh/src/job_control/job_run.c b/42sh/src/job_control/job_run.c index 3f13a224..517b646f 100644 --- a/42sh/src/job_control/job_run.c +++ b/42sh/src/job_control/job_run.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ -/* Updated: 2017/03/21 14:24:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:30:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_wait.c b/42sh/src/job_control/job_wait.c index b34371d6..1ccdfbab 100644 --- a/42sh/src/job_control/job_wait.c +++ b/42sh/src/job_control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:31:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:48:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,9 +28,7 @@ int job_wait(int id) { if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1 && errno != ECHILD) - ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", - SHELL_NAME, errno); - DG("wait trigger pid=%i", pid); + SH_ERR("waitpid(): %s", strerror(errno)); if (pid <= 1 || mark_process_status(pid, status) || job_is_stopped(j) || job_is_completed(j)) diff --git a/42sh/src/job_control/process_free.c b/42sh/src/job_control/process_free.c index b00ebc17..1251fbc7 100644 --- a/42sh/src/job_control/process_free.c +++ b/42sh/src/job_control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/21 20:49:32 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:15:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/sigint_handler.c b/42sh/src/job_control/sigint_handler.c index 85c66843..2d1ca5b6 100644 --- a/42sh/src/job_control/sigint_handler.c +++ b/42sh/src/job_control/sigint_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ -/* Updated: 2017/01/22 20:56:45 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:17:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,5 +15,6 @@ void sigint_handler(int signo) { (void)signo; + set_exitstatus(1, 1); DG("pid:%i got SIGINT", getpid()); } diff --git a/42sh/src/lexer/lexer_curly_braces.c b/42sh/src/lexer/lexer_curly_braces.c index d6eee381..8648c30d 100644 --- a/42sh/src/lexer/lexer_curly_braces.c +++ b/42sh/src/lexer/lexer_curly_braces.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 16:29:35 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:29:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:15:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,12 +22,13 @@ int lexer_curly_braces(t_list **alst, t_lexer *lexer) if (lexer->str[lexer->pos] == '{') { token->type = TK_LBRACE; - push(&lexer->stack, PAREN); + push(&lexer->stack, CURLY_BRACKETS); } - else if (get_lexer_stack(*lexer)) + else { token->type = TK_RBRACE; - pop(&lexer->stack); + if (get_lexer_stack(*lexer) == CURLY_BRACKETS) + pop(&lexer->stack); } lexer->pos++; lexer->state = DEFAULT; diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index da0e33cf..53cec923 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:02:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:13:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_paren.c b/42sh/src/lexer/lexer_paren.c index 03efd44e..88d6c349 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/22 17:16:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:13:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index e65dc3e9..8fddad30 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:25:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:37:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,11 +43,10 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; - /* token_print(*token); */ if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); - else if (ret == 2) + else if (ret > 0) break ; } if (data->parser.state == SUCCESS && ft_exec(ast) < 0) diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index b734b6c5..4931fd36 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,11 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/22 16:08:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:36:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define SHELL_USAGE "42sh [-c command | [<]script] [--no-jobcontrol]" static t_cliopts g_opts[] = { @@ -42,16 +43,12 @@ static int get_input_fd(t_data *data) } else if ((file = *data->av_data)) { - DG("file=%s", file); if (stat(file, &buf) < 0) - ft_printf("{red}%s: %s: No such file or directory\n{eoc}", - data->argv[0], file); + SH_ERR("%s: No such file or directory", file); else if (S_ISDIR(buf.st_mode)) - ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], - file); + SH_ERR("%s: is a directory", file); else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0) - ft_printf("{red}%s: %s: No such file or directory\n{eoc}", - data->argv[0], file); + SH_ERR("%s: No such file or directory", file); } else return (STDIN); @@ -75,8 +72,7 @@ static int interactive_settings(void) shell_resetsig(); if (setpgid(*shell_pgid, *shell_pgid)) { - ft_dprintf(2, - "{red}Couldnt put the shell in it's own process group{eoc}\n"); + SH_ERR("setpgid(): %s", strerror(errno)); return (-1); } tcsetpgrp(STDIN, *shell_pgid); @@ -84,12 +80,6 @@ static int interactive_settings(void) return (0); } -static int usage(void) -{ - ft_dprintf(2, "usage: 42sh [-c command | [<]script] [--no-jobcontrol]\n"); - return (0); -} - int shell_init(int ac, char **av) { t_data *data; @@ -99,8 +89,8 @@ int shell_init(int ac, char **av) return (-1); if (cliopts_get(av, g_opts, data)) { - usage(); - return (ft_perror()); + ft_perror(); + return (SH_ERR("usage: %s", SHELL_USAGE)); } if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); diff --git a/42sh/src/main/shell_reset.c b/42sh/src/main/shell_reset.c index fd0d3546..125f30c6 100644 --- a/42sh/src/main/shell_reset.c +++ b/42sh/src/main/shell_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */ -/* Updated: 2017/03/22 16:25:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:49:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index f6b1c456..3e4988f4 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/22 16:52:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:21:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -100,7 +100,7 @@ t_list *is_already_func(t_btree **new) 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; + tmp = (ret) ? tmp->next : tmp; } ft_tabdel(&new_name); if (!ret) @@ -116,8 +116,10 @@ int add_one_func(t_btree **ast, t_list **lst) (void)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); + } ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 9dc025f4..21b6a56f 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/18 19:18:21 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,8 @@ t_aggrematch g_aggrematch[] = {TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO}, {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, {TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE}, + {TK_PAREN_CLOSE, SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, +// {TK_PAREN_CLOSE, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 458e17c9..40ff2389 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:11:11 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -578,6 +578,7 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_CLOSE, COMPOUND_LIST}, {TK_PAREN_CLOSE, FUNC_NAME}, {TK_PAREN_CLOSE, OPEN_FUNC}, + {TK_PAREN_CLOSE, SUBSHELL}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 9027522a..b2e3f4c8 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:10:09 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:26:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,14 +68,14 @@ t_prodmatch g_prodmatch[] = {TK_ASSIGNMENT_WORD, TK_ELIF, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, TK_ELSE, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_PREFIX}, + {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX}, + {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX}, + {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR_MAJOR, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, PIPE_SEMI_SEQUENCE, CMD_PREFIX}, + {TK_ASSIGNMENT_WORD, PIPE_SEMI_SEQUENCE, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, SEQUENCE, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_COMMANDS, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CMD_WORD, CMD_SUFFIX},