From 5547d38afa330905ebd95c83ff9b9447f67d3273 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 18:14:26 +0100 Subject: [PATCH] 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 */ /* */ /* ************************************************************************** */