diff --git a/42sh/libft/includes/error.h b/42sh/libft/includes/error.h index c9eb792b..896b5bcb 100644 --- a/42sh/libft/includes/error.h +++ b/42sh/libft/includes/error.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ -/* Updated: 2017/03/21 14:05:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:11:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,6 @@ extern int g_errnum; extern char **g_argv; int error_set(int n, ...); -int ft_perror(void); +int ft_perror(char *utility); #endif diff --git a/42sh/libft/src/cliopts/cliopts_get.c b/42sh/libft/src/cliopts/cliopts_get.c index e2aa284d..0576d5df 100644 --- a/42sh/libft/src/cliopts/cliopts_get.c +++ b/42sh/libft/src/cliopts/cliopts_get.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:02:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,7 +97,10 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data) while (av && *av) { if (ft_strcmp(*av, "--") == 0) - return (0); + { + av++; + break ; + } else if ((*av)[0] == '-' && (*av)[1] == '-') { if (cliopts_parse_long(&av, opt_map, data)) diff --git a/42sh/libft/src/error/error.c b/42sh/libft/src/error/error.c index 2c82901b..3bf7451d 100644 --- a/42sh/libft/src/error/error.c +++ b/42sh/libft/src/error/error.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */ -/* Updated: 2017/03/15 20:45:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:10:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,8 +37,8 @@ int error_set(int n, ...) return (g_errnum); } -int ft_perror(void) +int ft_perror(char *utility) { - ft_dprintf(2, "{red}%s: %s{eoc}\n", g_argv[0], g_errmsg); + ft_dprintf(2, "{red}%s: %s{eoc}\n", utility ? utility : g_argv[0], g_errmsg); return (g_errnum); } diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index 08c29937..838a9c24 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */ -/* Updated: 2017/03/22 17:17:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:11:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,7 +55,7 @@ int builtin_env(const char *path, (void)envp; if (bt_env_parse(&data, (char**)argv)) - return (ft_perror() && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0); + return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0); else if (!*data.av_data) return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL)); else if ((pid = fork()) == 0) diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index 56e47007..444218b3 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ -/* Updated: 2017/03/20 14:44:02 by wescande ### ########.fr */ +/* Updated: 2017/03/24 15:11:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ int builtin_export( (void)path; data.flag = 0; if (cliopts_get((char**)av, g_export_opts, &data)) - ft_perror(); + ft_perror("export"); if (data.flag & BT_EXPORT_LP) return (bt_export_print()); av = data.av_data; diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index ce94d408..abea9035 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,14 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/22 19:21:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:10:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #define US_READ "read [-ers] [-u fd] [-t timeout] [-p prompt]" -#define US_READ_1 "[-n nchars] [-d delim] [name ...]" +#define US_READ_1 " [-n nchars] [-d delim] [name ...]" t_cliopts g_read_opts[] = { @@ -36,12 +36,12 @@ int bt_read_init(t_read *data, char **av) data->fd = 0; data->timeout = 0; data->input = NULL; - if ((cliopts_get(av, g_read_opts, data))) - return (ft_perror() ? 2 : 2); if (isatty(STDIN)) data->opts |= BT_READ_INTER; if (bt_read_terminit(data) < 0) - return (-1); + exit (1); + if ((cliopts_get(av, g_read_opts, data))) + return (ft_perror("read")); return (0); } @@ -89,7 +89,8 @@ int bt_read_assign(t_read *data) tok = ft_strtok(input, ifs); while (*names) { - builtin_setenv("setenv", (char*[]){"setenv", *names, tok}, NULL); + if (!(builtin_setenv("setenv", (char*[]){"read", *names, tok}, NULL))) + return (1); ifs = names[1] ? ifs : NULL; tok = ft_strtok(NULL, ifs); names++; @@ -106,16 +107,11 @@ int builtin_read(const char *path, char *const av[], char *const envp[]) (void)envp; ret = 0; if ((ret = bt_read_init(&data, (char **)av)) != 0) - ; + SH_ERR("usage: %s%s", US_READ, US_READ_1); else if ((ret = bt_read_loop(&data))) ; - else if (data.input && bt_read_assign(&data)) - ret = 1; - if (ret == -1) - exit(1); - if (ret != 0) - SH_ERR("usage: read %s %s\n", US_READ, US_READ_1); - if (ret != 2) - bt_read_exit(&data); + else if (data.input && (ret = bt_read_assign(&data))) + ; + bt_read_exit(&data); return (ret); } diff --git a/42sh/src/job_control/builtin_jobs.c b/42sh/src/job_control/builtin_jobs.c index 15f0e33a..1be75003 100644 --- a/42sh/src/job_control/builtin_jobs.c +++ b/42sh/src/job_control/builtin_jobs.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ -/* Updated: 2017/03/24 14:08:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:12:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,7 +74,7 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[]) } ft_bzero(&data, sizeof(t_data_template)); if (cliopts_get((char**)av, g_jobs_opts, &data)) - return (ft_perror()); + return (ft_perror("jobs")); if (!*data.av_data) bt_jobs_all(data.flag); else if (bt_jobs_spec(data.av_data, data.flag)) diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index b3b1846c..aa08fe4e 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/24 14:20:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,6 @@ t_lexstate get_state_global(t_lexer *lexer) c = lexer->str[lexer->pos]; cn = lexer->str[lexer->pos + 1]; cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0; - DG("%i : '%c'", lexer->pos, cl); ret = 0; if ((ft_is_delim(c) && (ret = DELIM)) || ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP)) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 2b2f966c..3c88c29a 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/23 16:58:43 by ariard ### ########.fr */ +/* Updated: 2017/03/24 14:42:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ static int handle_instruction(t_list **token, t_btree **ast) continue ; if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) - return (ret); + return (ret); else if (ret > 0) break ; } diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 4931fd36..16844a6f 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/22 19:36:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:12:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,7 +89,7 @@ int shell_init(int ac, char **av) return (-1); if (cliopts_get(av, g_opts, data)) { - ft_perror(); + ft_perror(NULL); return (SH_ERR("usage: %s", SHELL_USAGE)); } if (!isatty(STDIN) || *data->av_data)