From b8e6fc6f958eecede04ec0c0d919c97dd33fc3d5 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 19:36:22 +0100 Subject: [PATCH] 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);