From e83a22b16b71fd0d966bf79f6093e5106c5964a1 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 17:28:32 +0100 Subject: [PATCH 1/9] builtin, lexer et parser .h a la nomre --- 42sh/includes/builtin.h | 4 ++-- 42sh/includes/lexer.h | 10 +++++----- 42sh/includes/minishell.h | 3 ++- 42sh/includes/parser.h | 26 +++++++++++--------------- 42sh/includes/types.h | 4 +++- 42sh/src/main/main.c | 4 ++-- 42sh/src/parser/aggregate_sym.c | 10 +++++++++- 42sh/src/parser/eval_sym.c | 5 ++++- 42sh/src/parser/produce_sym.c | 2 +- 9 files changed, 39 insertions(+), 29 deletions(-) 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/lexer.h b/42sh/includes/lexer.h index 13622138..f156068a 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/20 16:44:48 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:25:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ # include "libft.h" # include "types.h" -enum e_lexstate +enum e_lexstate { DEFAULT, PAREN, @@ -37,7 +37,7 @@ enum e_lexstate END, }; -struct s_token +struct s_token { t_type type; char *data; @@ -46,7 +46,7 @@ struct s_token int size; }; -struct s_lexer +struct s_lexer { char *str; int pos; @@ -55,7 +55,7 @@ struct s_lexer t_list *heredoc_stack; }; -struct s_rvwords +struct s_rvwords { char *word; int type; diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 26b20751..2be1b684 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/21 18:09:39 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:26:34 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 726270b3..5ca2429f 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/20 10:38:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 16:53:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -198,6 +198,8 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, + SEMI_SUBSHELL, + SEMI_BRACE, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index d0ac9720..ad444135 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 15:22:59 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:00:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; - /* token_print(*token); */ + token_print(*token); if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 9dc025f4..5e8450bc 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 16:54:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ 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, 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}, @@ -220,7 +221,9 @@ t_aggrematch g_aggrematch[] = {COMPOUND_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE}, {CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME}, + {SUBSHELL, TK_PAREN_OPEN, SEMI_SUBSHELL, 0}, {SUBSHELL, ALL, COMPOUND_COMMAND, 0}, + {BRACE_CLAUSE, TK_LBRACE, SEMI_BRACE, 0}, {BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0}, {COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME}, {AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE}, @@ -379,15 +382,20 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = -1; head = (*stack)->content; + DG("aggregate head %s && sym %s", + read_state(*head), read_state(*new_sym)); while (g_aggrematch[++i].top) if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { + + DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; + DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym) && !(*state = ERROR)) return (1); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 458e17c9..82db6598 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 16:56:05 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, SEMI_SUBSHELL}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, @@ -1047,6 +1048,7 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, COMPLETE_CONDITION}, {SUBSHELL, CONDITION}, {SUBSHELL, AND_OR_MAJOR}, + {SEMI_SUBSHELL, TK_PAREN_OPEN}, {COMPOUND_COMMAND, LINEBREAK}, {COMPOUND_COMMAND, TK_PAREN_OPEN}, {COMPOUND_COMMAND, TK_LBRACE}, @@ -1271,6 +1273,7 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; + DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); while (g_stackmatch[i].top) { if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 9027522a..090b39cd 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 16:34:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ From 7485dc7153d9ec7f89c95fb2d91a11ad3e81432c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 17:36:43 +0100 Subject: [PATCH 2/9] ariard's fix #154 and #155 --- 42sh/src/job_control/job_wait.c | 6 ++---- 42sh/src/main/main.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/42sh/src/job_control/job_wait.c b/42sh/src/job_control/job_wait.c index b34371d6..5158fbc5 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:29:38 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/main/main.c b/42sh/src/main/main.c index e65dc3e9..85575246 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 17:35:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ static int handle_instruction(t_list **token, t_btree **ast) 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) From 5547d38afa330905ebd95c83ff9b9447f67d3273 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 18:14:26 +0100 Subject: [PATCH 3/9] curly brackets lexing --- 42sh/includes/ft_input.h | 2 +- 42sh/includes/ft_readline.h | 2 +- 42sh/includes/lexer.h | 2 +- 42sh/src/exec/plaunch_until.c | 3 ++- 42sh/src/exec/plaunch_while.c | 3 ++- 42sh/src/exec/process_launch.c | 7 ++----- 42sh/src/job_control/job_wait.c | 2 +- 42sh/src/job_control/sigint_handler.c | 3 ++- 42sh/src/lexer/lexer_curly_braces.c | 9 +++++---- 42sh/src/lexer/lexer_lex.c | 2 +- 42sh/src/lexer/lexer_paren.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/main/shell_reset.c | 2 +- 13 files changed, 21 insertions(+), 20 deletions(-) diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h index 8a5ef926..1968d7ef 100644 --- a/42sh/includes/ft_input.h +++ b/42sh/includes/ft_input.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */ -/* Updated: 2017/03/16 15:58:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:51:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 60a1ec4f..db93900f 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/21 10:02:04 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 17:53:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 122b8365..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:29:24 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:13:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index 1f420b3e..35c4ffac 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 18:04:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int plaunch_until(t_process *p) ret = 0; ft_exec(&p->data.d_until.condition); + /* signal(SIGINT, sigint_handler); */ while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) { ft_exec(&p->data.d_until.content); diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index 7869a9b7..af3316c9 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 18:01:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ int plaunch_while(t_process *p) ret = 0; ft_exec(&p->data.d_while.condition); + signal(SIGINT, sigint_handler); while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) { ft_exec(&p->data.d_while.content); diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 697d9194..5db9acf3 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 17:52:47 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/job_control/job_wait.c b/42sh/src/job_control/job_wait.c index 5158fbc5..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/22 17:29:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:48:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/sigint_handler.c b/42sh/src/job_control/sigint_handler.c index 85c66843..7231b796 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:04:22 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..83c7551b 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:13:49 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 41b1100c..23405356 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:37:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:44:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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 */ /* */ /* ************************************************************************** */ From dc0fc094f4760255310599c63e31ca39d48943b8 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 18:22:17 +0100 Subject: [PATCH 4/9] brackets resolution --- 42sh/includes/types.h | 4 +--- 42sh/src/parser/aggregate_sym.c | 7 +++---- 42sh/src/parser/eval_sym.c | 5 ++--- 42sh/src/parser/produce_sym.c | 10 +++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 4ee154f1..bb9e85b5 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:30:06 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:15:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -196,8 +196,6 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, - SEMI_SUBSHELL, - SEMI_BRACE, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 5e8450bc..fbc02382 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/22 16:54:58 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:13:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +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, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, + {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}, @@ -221,9 +222,7 @@ t_aggrematch g_aggrematch[] = {COMPOUND_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE}, {CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME}, - {SUBSHELL, TK_PAREN_OPEN, SEMI_SUBSHELL, 0}, {SUBSHELL, ALL, COMPOUND_COMMAND, 0}, - {BRACE_CLAUSE, TK_LBRACE, SEMI_BRACE, 0}, {BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0}, {COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME}, {AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 82db6598..1ebd22ee 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:56:05 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:14:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -578,7 +578,7 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_CLOSE, COMPOUND_LIST}, {TK_PAREN_CLOSE, FUNC_NAME}, {TK_PAREN_CLOSE, OPEN_FUNC}, - {TK_PAREN_CLOSE, SEMI_SUBSHELL}, + {TK_PAREN_CLOSE, SUBSHELL}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, @@ -1048,7 +1048,6 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, COMPLETE_CONDITION}, {SUBSHELL, CONDITION}, {SUBSHELL, AND_OR_MAJOR}, - {SEMI_SUBSHELL, TK_PAREN_OPEN}, {COMPOUND_COMMAND, LINEBREAK}, {COMPOUND_COMMAND, TK_PAREN_OPEN}, {COMPOUND_COMMAND, TK_LBRACE}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 090b39cd..a7aceda1 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:34:24 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:15:08 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}, From 2d42874c482ae05363fbfbb365c48eb288b8902d Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 22 Mar 2017 18:24:21 +0100 Subject: [PATCH 5/9] Completion: Output spaced name with escape char --- 42sh/includes/completion.h | 3 +- 42sh/src/completion/c_misc.c | 51 +++++++++++++++++++++++++++++++++- 42sh/src/completion/c_output.c | 7 +++-- 3 files changed, 57 insertions(+), 4 deletions(-) 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/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); } From 16e23e8a632f8e588549391ad27306ec63c7fe3e Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 19:35:02 +0100 Subject: [PATCH 6/9] close #150 --- 42sh/src/exec/pfree_func.c | 3 +-- 42sh/src/exec/plaunch_function.c | 6 +++--- 42sh/src/main/main.c | 3 +-- 42sh/src/parser/add_func.c | 6 ++++-- 42sh/src/parser/aggregate_sym.c | 7 +------ 42sh/src/parser/eval_sym.c | 3 +-- 42sh/src/parser/produce_sym.c | 2 +- 7 files changed, 12 insertions(+), 18 deletions(-) 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..0d5364de 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:30:50 by ariard ### ########.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/main/main.c b/42sh/src/main/main.c index 23405356..60194ede 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:44:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:00:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,6 @@ 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); 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 fbc02382..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/22 18:13:04 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -381,20 +381,15 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = -1; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); while (g_aggrematch[++i].top) if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { - - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; - DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym) && !(*state = ERROR)) return (1); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 1ebd22ee..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 18:14:39 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -1272,7 +1272,6 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); while (g_stackmatch[i].top) { if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index a7aceda1..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 18:15:08 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:26:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ From b8e6fc6f958eecede04ec0c0d919c97dd33fc3d5 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 19:36:22 +0100 Subject: [PATCH 7/9] some norme --- 42sh/includes/builtin_read.h | 2 +- 42sh/includes/ft_input.h | 83 --------------------------- 42sh/includes/ft_readline.h | 4 +- 42sh/includes/types.h | 2 +- 42sh/src/builtin/bt_read_term.c | 2 +- 42sh/src/builtin/builtin_read.c | 4 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_reset.c | 2 +- 42sh/src/exec/plaunch_function.c | 2 +- 42sh/src/exec/plaunch_if.c | 3 +- 42sh/src/exec/plaunch_until.c | 3 +- 42sh/src/exec/plaunch_while.c | 3 +- 42sh/src/exec/process_launch.c | 2 +- 42sh/src/exec/process_set.c | 2 +- 42sh/src/exec/pset_while.c | 2 +- 42sh/src/glob/expand_bquote.c | 2 +- 42sh/src/glob/ft_strsplit_esc.c | 4 +- 42sh/src/job_control/builtin_bg.c | 8 +-- 42sh/src/job_control/builtin_fg.c | 22 +++---- 42sh/src/job_control/job_addprocess.c | 5 +- 42sh/src/job_control/job_run.c | 2 +- 42sh/src/job_control/process_free.c | 2 +- 42sh/src/job_control/sigint_handler.c | 2 +- 42sh/src/lexer/lexer_curly_braces.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/main/shell_init.c | 26 +++------ 26 files changed, 45 insertions(+), 150 deletions(-) delete mode 100644 42sh/includes/ft_input.h 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/ft_input.h b/42sh/includes/ft_input.h deleted file mode 100644 index 1968d7ef..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/22 17:51:49 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 db93900f..7a6833ab 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 17:53:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:21:28 by jhalford ### ########.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/types.h b/42sh/includes/types.h index 4ee154f1..c902884b 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:30:06 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:17:46 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/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/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 6a41a54a..e21a1d86 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,7 +6,7 @@ /* 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:30:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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 35c4ffac..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/22 18:04:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:22:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ int plaunch_until(t_process *p) ret = 0; ft_exec(&p->data.d_until.condition); - /* signal(SIGINT, sigint_handler); */ while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) { ft_exec(&p->data.d_until.content); diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index af3316c9..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/22 18:01:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:23:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ int plaunch_while(t_process *p) ret = 0; ft_exec(&p->data.d_while.condition); - signal(SIGINT, sigint_handler); while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) { ft_exec(&p->data.d_while.content); diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 5db9acf3..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 17:52:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:26:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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/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 7231b796..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/03/22 18:04:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:17:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_curly_braces.c b/42sh/src/lexer/lexer_curly_braces.c index 83c7551b..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/22 18:13:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 18:15:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 23405356..0bd92920 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:44:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:18:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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); From 428a41f4574c4101adc9d043497b473a8e01bdaf Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 22 Mar 2017 20:24:45 +0100 Subject: [PATCH 8/9] Completion: Fix #156, tilde leqd to wrong folder --- 42sh/src/completion/c_find_abspath.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/42sh/src/completion/c_find_abspath.c b/42sh/src/completion/c_find_abspath.c index b60a71e7..6f70604b 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:21:43 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,11 +30,12 @@ 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; c_parser(c, c->cpath, c->match); + DG("cpath [%s] match [%s]", c->cpath, c->match); if (c->lst == NULL || c->lst == c->lst->prev) c_exclusion_folder(c); } From 89cfc441addab2c87454f00bae78b408b436aae9 Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 22 Mar 2017 20:25:51 +0100 Subject: [PATCH 9/9] Remove DG --- 42sh/src/completion/c_find_abspath.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/42sh/src/completion/c_find_abspath.c b/42sh/src/completion/c_find_abspath.c index 6f70604b..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 20:21:43 by alao ### ########.fr */ +/* Updated: 2017/03/22 20:25:19 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,6 @@ void c_seek_abs_path(t_comp *c, char *current_word) } !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; c_parser(c, c->cpath, c->match); - DG("cpath [%s] match [%s]", c->cpath, c->match); if (c->lst == NULL || c->lst == c->lst->prev) c_exclusion_folder(c); }