diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index c2ac1d27..d37a9653 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/27 17:42:17 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 08:13:56 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -179,6 +179,10 @@ void c_printer(t_comp *c); ** c_exclusion_foldr : Check for match folder. ** ft_sstrlen : Return size of char **. ** ft_sstrtostr : Create char * from char ** with char *sep between. +** ft_add_escape : Add escape char to str. +** c_lst_id : Repair ID list. +** c_is_delim : Check char for specific one. +** c_strdupi : Dupe */ int c_clear(t_data *s); @@ -189,6 +193,7 @@ int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); char *ft_add_escape(char *str, char to_escape); void c_lst_id(t_comp *c); +int c_is_delim(char c); char *c_strdupi(char *s, int (*f)(char)); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index ce602f64..05bb2fa7 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/27 15:46:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:22:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -135,7 +135,6 @@ struct s_exec int fdin; t_list *op_stack; char **case_pattern; - int control_count; }; int exec_init(t_exec *exec); diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 088122d9..344a1d97 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/23 16:49:31 by gwojda ### ########.fr # +# Updated: 2017/03/27 21:59:31 by gwojda ### ########.fr # # # # **************************************************************************** # @@ -19,7 +19,7 @@ RM = /bin/rm -rf W_FLAGS = -Wall -Wextra -Werror -g D_FLAGS = -g -V_FLAGS = -fvisibility=hidden +V_FLAGS = #-fvisibility=hidden FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS) DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/pdf/fdf.fr.pdf b/42sh/pdf/fdf.fr.pdf deleted file mode 100644 index 939a55ae..00000000 Binary files a/42sh/pdf/fdf.fr.pdf and /dev/null differ diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 12f0aca6..d1df5369 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 18:20:42 by ariard #+# #+# */ -/* Updated: 2017/03/27 18:08:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:15:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,8 +20,8 @@ #define CDERR_0 "cd: too many arguments" #define CDERR_1 "cd %s not set" #define CDERR_2 "cd : %s: No such file or directory" -#define CDERR_3 "cd : %s: Permission denied" -#define CDERR_4 "cd : %s: Not a directory" +#define CDERR_3 "cd : %s: Not a directory" +#define CDERR_4 "cd : %s: Permission denied" #define CDERR_5 "cd : unable to proceed: %s" static t_cliopts g_cdopts[] = diff --git a/42sh/src/completion/c_match.c b/42sh/src/completion/c_match.c index e41437e1..05c73d95 100644 --- a/42sh/src/completion/c_match.c +++ b/42sh/src/completion/c_match.c @@ -6,19 +6,27 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/27 18:51:59 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 08:15:31 by alao ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int c_is_delim(char c) +/* +** Check char +*/ + +int c_is_delim(char c) { if (c == ' ' || c == '<' || c == '>' || c == '\n' || c == ';') return (1); return (0); } +/* +** strdupi +*/ + char *c_strdupi(char *s, int (*f)(char)) { int i; diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index bda1b63b..e8f0ea68 100644 --- a/42sh/src/completion/c_match_update.c +++ b/42sh/src/completion/c_match_update.c @@ -6,12 +6,28 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 16:09:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +static char *c_current_words(void) +{ + size_t pos; + char *str; + + pos = data_singleton()->line.pos; + str = data_singleton()->line.input; + if (pos && c_is_delim(str[pos])) + --pos; + while (pos && !c_is_delim(str[pos])) + --pos; + if (c_is_delim(str[pos])) + ++pos; + return (c_strdupi(str + pos, &c_is_delim)); +} + /* ** Recreate a c->match value by adding the new key pressed to it. */ @@ -20,17 +36,22 @@ static int c_refresh_match(t_comp *c, long int keypress) { char *tmp; char kpconv[2]; + char *dump; kpconv[0] = (char)keypress; kpconv[1] = '\0'; tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv); c->match ? ft_memdel((void *)&c->match) : (0); + dump = c_current_words(); + if (!(ft_strchr(dump, '$'))) + c->match = ft_strdup(tmp); tmp ? ft_memdel((void *)&tmp) : (0); tmp = ft_strjoin(c->rcmd, kpconv); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd = ft_strdup(tmp); c->ircmd++; tmp ? ft_memdel((void *)&tmp) : (0); + dump ? ft_memdel((void *)&dump) : (0); return (0); } diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index c5f97f8a..f1f0ad27 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/24 14:52:00 by ariard ### ########.fr */ +/* Updated: 2017/03/28 20:29:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ int plaunch_for(t_process *p) return (SH_ERR(FORERR_0, var)); i = 0; av = token_to_argv(temp, 1); + data_singleton()->exec.job.attrs &= ~JOB_BG; while (av[++i]) { builtin_setenv("setenv", (char*[]){"local", var, av[i], 0}, diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index dbe8e2fb..17529fc1 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 19:22:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:30:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int plaunch_until(t_process *p) int ret; ret = 0; + data_singleton()->exec.job.attrs &= ~JOB_BG; ft_exec(&p->data.d_until.condition); while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) { diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index d4631982..9caaa1bd 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/24 22:43:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:29:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int plaunch_while(t_process *p) int ret; ret = 0; + data_singleton()->exec.job.attrs &= ~JOB_BG; ft_exec(&p->data.d_while.condition); while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) { diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 9e82b20b..e0ea77da 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/27 16:46:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:29:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,12 @@ int process_fork(t_process *p) { pid_t pid; - if (!p) - return (0); if ((pid = fork()) == -1) exit(SH_ERR("fork(): %s", strerror(errno))); else if (pid != 0) return (pid); + if (!p) + return (0); exec_destroy(&data_singleton()->exec); jobc_destroy(&data_singleton()->jobc); if ((pid = 1) && process_redirect(p) == 0) @@ -39,8 +39,7 @@ int process_fork(t_process *p) int process_launch(t_process *p) { p->state = PROCESS_RUNNING; - if (!IS_PIPESINGLE(*p) - || p->type == PROCESS_FILE + if (!IS_PIPESINGLE(*p) || p->type == PROCESS_FILE || p->type == PROCESS_SUBSHELL) { p->pid = process_fork(p); diff --git a/42sh/src/hash_table/is_hash.c b/42sh/src/hash_table/is_hash.c index 5f808380..f237795f 100644 --- a/42sh/src/hash_table/is_hash.c +++ b/42sh/src/hash_table/is_hash.c @@ -12,6 +12,18 @@ #include "minishell.h" +static char *h_free_one(t_list **head, t_list *list, t_list *ref) +{ + if (!((*head)->next)) + ft_lstdelone(head, &ft_hash_free); + else + { + ref->next = list->next; + ft_lstdelone(&list, &ft_hash_free); + } + return (NULL); +} + char *ft_is_hash(char *cmd) { t_list *list; @@ -25,12 +37,9 @@ char *ft_is_hash(char *cmd) { if (!ft_strcmp(((t_hash *)list->content)->key, cmd)) { - if (access(((t_hash *)list->content)->path, X_OK)) - { - ref->next = list->next; - ft_lstdelone(&list, &ft_hash_free); - return (NULL); - } + if (access(((t_hash *)list->content)->path, + X_OK | F_OK) < 0) + return (h_free_one(&g_hash[id], list, ref)); return (ft_strdup(((t_hash *)list->content)->path)); } ref = list; diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 6c16b270..bd943423 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 12:22:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,6 +61,8 @@ static int ft_modify_str(char *str_srch, size_t srch_pos, char **str, *str = ft_strdup(*str); ft_current_str(*str, *pos); ft_get_next_str(*str, pos); + if ((*str)[*pos]) + ++(*pos); } free(str_srch); return (0); diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index da51f6a6..3bb8579d 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/27 19:49:31 by ariard ### ########.fr */ +/* Updated: 2017/03/27 21:44:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,10 +80,7 @@ int get_reserved_words(t_list *temp) if (recognization_rvwords(pv_tk, ante_token)) match_words(token); if (token && token->type == TK_BANG && is_bang(pv_tk)) - { - DG("token type is %s", read_state(token->type)); token->type = TK_WORD; - } if (ante_token && (ante_token->type == TK_CASE || ante_token->type == TK_FOR) && ft_strncmp(token->data, "in", 2) == 0) diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 7a8ce91b..9f85136c 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,31 +6,35 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/03/27 18:52:15 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 19:55:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int lexer_dquote(t_list **alst, t_lexer *lexer) +static int is_spec_dquote_esc(char c) +{ + return (c == '"' || c == '$' || c == '`' + || c == '\\' || c == '!'); +} + +int lexer_dquote(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = token->type ? token->type : TK_WORD; if (lexer->str[lexer->pos] == '"') + get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD) ? + pop(&lexer->stack) : push(&lexer->stack, DQUOTE) && 0; + else if (lexer->str[lexer->pos] == '\\') { - if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD)) - pop(&lexer->stack); - else - push(&lexer->stack, DQUOTE); - } - else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0) - { - lexer->pos++; - if (lexer->str[lexer->pos] == 0) + if (lexer->str[++lexer->pos] == 0) return (push(&lexer->stack, BACKSLASH) ? 0 : 0); - token_append(token, lexer, 1, 0); + else if (is_spec_dquote_esc(lexer->str[lexer->pos])) + token_append(token, lexer, 1, 1); + else if (--lexer->pos || 1) + token_append(token, lexer, 1, 1); } else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) return (lexer_lex(alst, lexer)); diff --git a/42sh/src/line_editing/lib_line_editing/toolz_parseur.c b/42sh/src/line_editing/lib_line_editing/toolz_parseur.c index d74258ee..478db2dd 100644 --- a/42sh/src/line_editing/lib_line_editing/toolz_parseur.c +++ b/42sh/src/line_editing/lib_line_editing/toolz_parseur.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ -/* Updated: 2017/03/21 10:03:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 22:06:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line_editing/print_del_completion/print_and_del.c b/42sh/src/line_editing/print_del_completion/print_and_del.c index b52abcd7..9dd948ca 100644 --- a/42sh/src/line_editing/print_del_completion/print_and_del.c +++ b/42sh/src/line_editing/print_del_completion/print_and_del.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ -/* Updated: 2017/03/21 10:14:46 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 22:07:39 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,7 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp) ++(*i); ft_putnc('\b', *i - tmp); (*i) = tmp; - if (ft_strlen(*str) == 0) + if (!**str) ft_strdel(str); } @@ -105,5 +105,7 @@ int ft_del(char **str, size_t *pos) ++(*pos); ft_putnc('\b', *pos - tmp); *pos = tmp; + if (!**str) + ft_strdel(str); return (0); } diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index c88c7dfe..4e3170a8 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/27 18:10:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 14:57:13 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ int readline(int has_prompt, char **input) data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) { + ft_strdel(input); if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) return (!ret); return (ret); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a6c12e22..f3b7ee86 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/28 23:19:27 by ariard ### ########.fr */ +/* Updated: 2017/03/28 23:26:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,22 @@ static int do_readline_routine(char **stream) return (ret); } +static int exec_instruction(t_btree **ast, char **stream) +{ + t_data *data; + + data = data_singleton(); + if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) + ft_add_str_in_history(data->lexer.str); + else + ft_strdel(stream); + if (data->parser.state == SUCCESS && ft_exec(ast) < 0) + exit(1); + else if (data->parser.state != SUCCESS) + set_exitstatus(1, 1); + return (0); +} + static int handle_instruction(t_list **token, t_btree **ast) { int ret; @@ -46,20 +62,13 @@ 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); else if (ret > 0) break ; } - if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) - ft_add_str_in_history(data->lexer.str); - if (data->parser.state == SUCCESS && ft_exec(ast) < 0) - exit(1); - else if (data->parser.state != SUCCESS) - set_exitstatus(1, 1); - return (0); + return (exec_instruction(ast, &stream)); } int main(int ac, char **av, char **env) diff --git a/42sh/src/parser/do_parser_routine.c b/42sh/src/parser/do_parser_routine.c index 69f74340..0f31fb20 100644 --- a/42sh/src/parser/do_parser_routine.c +++ b/42sh/src/parser/do_parser_routine.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/19 14:24:14 by wescande #+# #+# */ -/* Updated: 2017/03/27 21:02:08 by ariard ### ########.fr */ +/* Updated: 2017/03/27 21:43:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ int do_parser_routine(t_list **token, t_btree **ast) token_print(*token); if (ft_parse(ast, token, &data->parser)) exit(1); - if (data->parser.state != ERROR && + if (data->parser.state != ERROR && (data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) return (0); if (data->parser.state == ERROR) diff --git a/42sh/test/fifi b/42sh/test/fifi deleted file mode 100644 index e69de29b..00000000