diff --git a/42sh/Makefile b/42sh/Makefile index 5fddcd99..883ac512 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -36,6 +36,7 @@ builtin/builtin_echo.c\ builtin/builtin_env.c\ builtin/builtin_exit.c\ builtin/builtin_export.c\ +builtin/builtin_func.c\ builtin/builtin_hash.c\ builtin/builtin_history.c\ builtin/builtin_math.c\ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 96fb1253..289c7b09 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/22 17:28:02 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:13:06 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,7 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]); int builtin_history(const char *path, char *const av[], char *const envp[]); int builtin_hash(const char *path, char *const av[], char *const envp[]); int builtin_math(const char *path, char *const av[], char *const envp[]); +int builtin_func(const char *path, char *const av[], char *const envp[]); int bt_env_geti(char ***av, t_env_data *data); int error_msg(char *msg); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 8396bca3..ddf9e390 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/23 16:13:56 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 16:17:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,7 +81,7 @@ void process_format(t_list **p, int firstp, int opts); */ void pprint(t_process *p); -int pprint_subshell(t_process *p);; +int pprint_subshell(t_process *p); int pprint_brace(t_process *p); int pprint_while(t_process *p); int pprint_if(t_process *p); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index a45aa749..ddd2fe13 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* types.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/24 16:50:51 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:10:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,14 +48,13 @@ typedef struct s_data_template t_btexport; typedef enum e_lexstate t_lexstate; typedef struct s_token t_token; typedef struct s_rvwords t_rvwords; - typedef struct s_ld t_ld; /* ** Execution types */ -typedef int t_condition; +typedef int t_condition; typedef struct s_job t_job; typedef struct s_process t_process; typedef int (t_execf)(const char *path, @@ -64,11 +63,9 @@ typedef int (t_execf)(const char *path, typedef enum e_process_type t_process_type; typedef enum e_process_state t_process_state; typedef union u_process_data t_process_data; -typedef struct s_process_map t_process_map; +typedef struct s_process_map t_process_map; typedef struct s_data_cond t_data_while; typedef struct s_data_cond t_data_if; -typedef struct s_data_cond t_data_if; - /* ** Parser types diff --git a/42sh/libft/src/btree/btree_map.c b/42sh/libft/src/btree/btree_map.c index 85439a1a..47b92852 100644 --- a/42sh/libft/src/btree/btree_map.c +++ b/42sh/libft/src/btree/btree_map.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* btree_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ -/* Updated: 2017/03/21 15:42:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/error/error.c b/42sh/libft/src/error/error.c index 3bf7451d..1f8b980d 100644 --- a/42sh/libft/src/error/error.c +++ b/42sh/libft/src/error/error.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* error.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */ -/* Updated: 2017/03/24 15:10:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 16:22:55 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,6 +39,7 @@ int error_set(int n, ...) int ft_perror(char *utility) { - ft_dprintf(2, "{red}%s: %s{eoc}\n", utility ? utility : 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/log b/42sh/log deleted file mode 100644 index 4bb9c0c4..00000000 --- a/42sh/log +++ /dev/null @@ -1,63 +0,0 @@ -env lvl 2 -env lvl 3 -env lvl 4 -env lvl 5 -env lvl 6 -env lvl 7 -env lvl 8 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 6 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 5 -env lvl 6 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 9 -env lvl 10 -env lvl 11 -env lvl 4 -env lvl 5 -env lvl 6 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 9 -env lvl 10 -env lvl 11 -env lvl 6 -env lvl 7 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 9 -env lvl 10 -env lvl 11 -env lvl 8 -env lvl 9 -env lvl 10 -env lvl 11 -env lvl 10 -env lvl 11 -env lvl 12 diff --git a/42sh/src/builtin/builtin_func.c b/42sh/src/builtin/builtin_func.c new file mode 100644 index 00000000..bc23b27b --- /dev/null +++ b/42sh/src/builtin/builtin_func.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_func.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/24 15:03:02 by wescande #+# #+# */ +/* Updated: 2017/03/24 17:01:44 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +#define FUNC_USAGE "func" + +int builtin_func(const char *path, + char *const argv[], char *const envp[]) +{ + t_list *list; + char **name; + t_btree **ast; + + (void)envp; + (void)path; + if (!argv || !argv[0] || argv[1]) + return (SH_ERR("usage: %s", FUNC_USAGE) ? 1 : 1); + list = data_singleton()->lst_func; + while (list) + { + if (!(ast = list->content)) + return (SH_ERR("unexpected error")); + name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (name && name[0]) + { + DG(); + ft_putendl(name[0]); + } + ft_tabdel(&name); + list = list->next; + } + return (0); +} diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index abea9035..d003a988 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/24 15:10:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 16:23:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ int bt_read_init(t_read *data, char **av) if (isatty(STDIN)) data->opts |= BT_READ_INTER; if (bt_read_terminit(data) < 0) - exit (1); + exit(1); if ((cliopts_get(av, g_read_opts, data))) return (ft_perror("read")); return (0); diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 90a08144..dd931eba 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:24:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:12:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ t_stof g_builtin[] = {"hash", &builtin_hash}, {"history", &builtin_history}, {"math", &builtin_math}, + {"func", &builtin_func}, {NULL, NULL}, }; diff --git a/42sh/src/job_control/builtin_jobs.c b/42sh/src/job_control/builtin_jobs.c index 1be75003..22ef92a6 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 15:12:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:39:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_hup_all.c b/42sh/src/job_control/job_hup_all.c index 37944153..0933048b 100644 --- a/42sh/src/job_control/job_hup_all.c +++ b/42sh/src/job_control/job_hup_all.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */ -/* Updated: 2017/03/20 20:51:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:40:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,16 @@ void job_hup_all(void) jobc = &data_singleton()->jobc; jlist = jobc->first_job; + if (!SH_HAS_JOBC(data_singleton()->opts)) + return ; while (jlist) { job = jlist->content; + DG("gonna SIGHUP %i", job->pgid); + builtin_jobs(NULL, NULL, NULL); if (job->pgid != 1) kill(-job->pgid, SIGHUP); + DG("after SIGHUP %i", job->pgid); jlist = jlist->next; } } diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index c2749334..ff9fff8c 100644 --- a/42sh/src/lexer/lexer_bquote.c +++ b/42sh/src/lexer/lexer_bquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ -/* Updated: 2017/03/23 15:17:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 17:02:40 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,8 @@ int lexer_bquote(t_list **alst, t_lexer *lexer) if (get_lexer_stack(*lexer) != BQUOTE) push(&lexer->stack, lexer->state); else - { lexer->state = pop(&lexer->stack) && get_lexer_stack(*lexer) == DQUOTE ? DQUOTE : DEFAULT; - } } else if (lexer->str[lexer->pos] == '\\' && (back = 1)) { diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 1786990d..51e50643 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* lexer_dquote.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/03/22 23:56:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 16:08:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,9 +27,9 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) } else if (lexer->str[lexer->pos] == '\\') { - if (lexer->str[lexer->pos + 1] == 0) - return (lexer_backslash(alst, lexer)); - token_append(token, lexer, 1, 1); + lexer->pos++; + if (lexer->str[lexer->pos] == 0) + return (push(&lexer->stack, BACKSLASH) ? 0 : 0); } else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) return (lexer_lex(alst, lexer)); diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index e0f79a5f..dba5a2ba 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/24 12:40:41 by wescande ### ########.fr */ +/* Updated: 2017/03/24 15:55:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,14 +17,16 @@ void data_exit(void) t_data *data; data = data_singleton(); + ft_strdel(&data->binary); ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); lexer_destroy(&data->lexer); parser_destroy(&data->parser); ft_lstdel(&data->jobc.first_job, &job_free); + ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); - free_history_list(data_singleton()->line.list_beg); + free_history_list(data->line.list_beg); free(data_singleton()); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 46104d14..2594da36 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/24 13:51:24 by wescande ### ########.fr */ +/* Updated: 2017/03/24 16:27:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,12 +92,12 @@ int data_init(int ac, char **av) term_name = "dumb"; if (tgetent(NULL, term_name) != 1) { - ft_dprintf(2, "{red}TERM name is not a tty\n{eoc}"); + SH_ERR("TERM name is not a tty"); return (-1); } if (path_binary_save(av[0])) { - ft_dprintf(2, "{red}Failed to resolve binary name\n{eoc}"); + SH_ERR("Failed to resolve binary name"); return (-1); } return (0); diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 0d830c1c..30df296b 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* tree_type.c :+: :+: :+: */ +/* ft_putast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/03/14 22:11:26 by ariard ### ########.fr */ +/* Updated: 2017/03/24 16:28:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ char *ft_putast(void *nodein) { t_astnode *node; node = nodein; - + if (node->type == TK_BANG) return ("TK_BANG"); if (node->type == TK_DSEMI) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index b4986179..4f32fbba 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/24 15:18:55 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:30:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 16844a6f..c1882171 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/24 15:12:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 17:05:29 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,10 +29,9 @@ int get_c_arg(char ***av, t_data *data) return (0); } -static int get_input_fd(t_data *data) +static int get_input_fd(t_data *data, char *file) { static int fds[2] = {-1, STDIN}; - char *file; struct stat buf; if (data->opts & SH_OPTS_LC && (file = data->c_arg)) @@ -94,7 +93,7 @@ int shell_init(int ac, char **av) } if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); - if ((data->fd = get_input_fd(data)) < 0) + if ((data->fd = get_input_fd(data, NULL)) < 0) return (-1); if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) return (-1); diff --git a/42sh/test/fifi b/42sh/test/fifi deleted file mode 100644 index 43084821..00000000 --- a/42sh/test/fifi +++ /dev/null @@ -1 +0,0 @@ - 5