From 9ee6c10884bc56b7ae1c4f1786a0d8b027e3079c Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 15:00:31 +0100 Subject: [PATCH 1/7] correction bug --- 42sh/src/history/add_str_in_history.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 0da0f1ee..79c80b30 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/14 09:50:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 14:58:41 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ void ft_add_in_history_file(char *str) return ; while (hist[i]) { - write(fd, hist[i], ft_strlen(str)); + write(fd, hist[i], ft_strlen(hist[i])); write(fd, "\n", 1); ++i; } From 864b8ec120cbff15343b1ffa2f35623429e643dd Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 15:03:31 +0100 Subject: [PATCH 2/7] rip leaks --- 42sh/src/parser/heredoc_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index 54a837c7..78a74e01 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 19:28:21 by ariard ### ########.fr */ +/* Updated: 2017/03/14 15:02:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int pop_heredoc(t_list **lst) t_token *token; t_list **head; t_redir *redir; + char *tmp; token = (*lst)->content; if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL) @@ -34,8 +35,10 @@ int pop_heredoc(t_list **lst) } else { + tmp = redir->heredoc_data; redir->heredoc_data = ft_str3join(redir->heredoc_data, - (char*)token->data, "\n"); + (char*)token->data, "\n"); + ft_strdel(&tmp); } } ft_lstdel(lst, &token_free); From 0d4f441670bda3e1078d475137fa3255c5f172c4 Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 16:37:40 +0100 Subject: [PATCH 3/7] rip leaks --- 42sh/libft | 2 +- 42sh/src/builtin/builtin_exit.c | 4 ++-- 42sh/src/completion/c_glob_matching.c | 3 +-- 42sh/src/history/list_toolz.c | 8 ++++++-- 42sh/src/line-editing/ft_prompt.c | 10 ++++++---- 42sh/src/main/data_exit.c | 6 ++++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/42sh/libft b/42sh/libft index b209bb1f..9382dc10 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 +Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71 diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index c4b4fd7f..e08a3563 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:52:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 15:22:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,9 +36,9 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) ft_save_termios(-1); ft_free_hash_table(); free_history_list(data_singleton()->line.list_beg); - data_exit(); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); + data_exit(); exit(status); return (0); } diff --git a/42sh/src/completion/c_glob_matching.c b/42sh/src/completion/c_glob_matching.c index 66f39d9d..4ff64652 100644 --- a/42sh/src/completion/c_glob_matching.c +++ b/42sh/src/completion/c_glob_matching.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ -/* Updated: 2017/03/10 17:43:15 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 14:00:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,7 +63,6 @@ int c_glob_matching(void) glob_echap = (unsigned char *)ft_strnew(ft_strlen(str) >> 3); ft_bzero(glob_echap, ft_strlen(str) >> 3); ss_glob = glob(current_word, glob_echap, glob_echap, 1); -// ss_glob = glob(current_word, glob_echap, glob_echap); free(current_word); if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) return (0); diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index a12fd6a8..abdf45fd 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/03/13 14:47:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 15:20:22 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,11 +18,15 @@ void free_history_list(t_list_history *head) if (!head) return ; + DG("free hist"); + if (head->next) + free(head->next); while (head) { ft_strdel(&head->str); prev = head; - head = head->next; + head = head->prev; + free(prev); } } diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index b8ea9529..cda5a0ad 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/14 12:32:38 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 16:00:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,16 +24,18 @@ static int promt_git_status(int fd) line = ft_strdup(ft_strrchr(line, '/') + 1); else line = ft_strdup(line + 3); - ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line); free(tmp); + ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line); if (!get_next_line(fd, &tmp)) printf("\x1b[38;5;83m %C ", L'✓'); else { printf("\x1b[38;5;1m %C ", L'✗'); - while (get_next_line(fd, &tmp)) - free(tmp); + free(tmp); } + while (get_next_line(fd, &tmp)) + free(tmp); + free(tmp); len = ft_strlen(line); ft_strdel(&line); fflush(NULL); diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index 30acbb44..27f59f26 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* data_exit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/01/22 17:20:29 by ariard ### ########.fr */ +/* Updated: 2017/03/14 15:21:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,4 +19,6 @@ void data_exit(void) data = data_singleton(); /* ft_strdel(&data->line.input); */ ft_sstrfree(data->env); + ft_sstrfree(data->argv); + free(data_singleton()); } From 4084439f7d3583b4240cf8670fc7e23445ece00c Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 17:07:59 +0100 Subject: [PATCH 4/7] rip leaks --- 42sh/libft | 2 +- 42sh/src/main/main.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/42sh/libft b/42sh/libft index 9382dc10..fb9b737b 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71 +Subproject commit fb9b737be2598ec204afb974ec02f7bce5261b6b diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 4da9ed74..52e16739 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:58:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 17:05:45 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,6 +79,8 @@ int handle_instruction(int fd) instruction_free(&token, &parser, &ast); if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str) ft_add_str_in_history(lexer.str); + ft_strdel(&lexer.str); + free(parser.new_sym); return (0); } From dce9df5008557a15b06fdabd6a10ce0446850fb2 Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 14 Mar 2017 17:21:56 +0100 Subject: [PATCH 5/7] correction rematch env --- 42sh/src/completion/c_seek_env.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/42sh/src/completion/c_seek_env.c b/42sh/src/completion/c_seek_env.c index 9fa8d0ea..dfc8198c 100644 --- a/42sh/src/completion/c_seek_env.c +++ b/42sh/src/completion/c_seek_env.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/14 10:10:19 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 17:21:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,8 @@ int c_seek_env(t_comp *c, char *current_word) match = ft_strdupi_w(current_word + 1); while (env[i]) { - if (!ft_strncmp(match, env[i], ft_strlen(match))) + if (!ft_strncmp(match, env[i], ft_strlen(match)) && + env[i][ft_strlen(match)] != '=') c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); ++i; } From 30556cdba2e6d85ce96b634163a3c2f23d3dd5aa Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 14 Mar 2017 20:20:19 +0100 Subject: [PATCH 6/7] le retour des BQUOTE --- 42sh/src/glob/command_getoutput.c | 106 +++++++++------------------- 42sh/src/glob/expand_bquote.c | 22 +++--- 42sh/src/job-control/process_free.c | 5 +- 3 files changed, 50 insertions(+), 83 deletions(-) diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 2588d318..bfce6064 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -3,93 +3,53 @@ /* ::: :::::::: */ /* command_getoutput.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:32:52 by jhalford ### ########.fr */ +/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */ +/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #define BUF_SIZE 1024 -/*static char *manage_output(int *fds) - { - int ret; - char buf[BUF_SIZE + 1]; - char *output; - - output = NULL; - while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0) - { - buf[ret] = 0; - ft_strappend(&output, buf); - } - close(fds[PIPE_READ]); - return (output); - } - */ - -static t_btree *gen_t_btree(const char *command) +static char *manage_output(int *fds) { - t_btree *ast; - t_astnode item; - int len; - unsigned char *esc; - - ft_bzero(&item, sizeof(t_astnode)); - item.type = SUBSHELL; - ast = btree_create_node(&item, sizeof(t_astnode)); - ft_bzero(&item, sizeof(t_astnode)); - item.type = CMD; - len = ft_strlen(command); - esc = ft_memalloc((len >> 3) + 1); - ft_ld_pushfront(&item.data.cmd.token, gen_tab(command, esc, esc, 1)); - ast->right = btree_create_node(&item, sizeof(t_astnode)); - return (ast); -} - -char *command_getoutput(char *command) -{ - t_btree *ast; - char *output; - char buf[BUF_SIZE + 1]; - t_exec *exec; - t_process p; int ret; - int pid; + char buf[BUF_SIZE + 1]; + char *output; - return (NULL); output = NULL; - exec = &data_singleton()->exec; - DG("%p exec ?", exec); - DG("\033[38;5;46mbefore"); - ast = gen_t_btree(command); - DG(); - if (process_set(&p, ast)) - return (NULL); - DG(); - if (!(pid = plaunch_subshell(&p))) - return (NULL); - waitpid(pid, &ret, WUNTRACED); - DG(); -// exec_leaf(&ast); - /* - DG(); - set_process(&p, ast); - DG(); - launch_process(&p); - DG(); - close(p.fdout);*/ - DG(); - while ((ret = read(exec->fdin, buf, BUF_SIZE)) > 0) + close(fds[PIPE_WRITE]); + while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0) { buf[ret] = 0; ft_strappend(&output, buf); } - DG(); - close(exec->fdin); - DG("done with %s\033[0m", output); - + close(fds[PIPE_READ]); + return (output); +} + +char *command_getoutput(char *command) +{ + char *output; + int ret; + int pid; + int fds[2]; + + if (!command) + return (NULL); + pipe(fds); + if (!(pid = fork())) + { + close(fds[PIPE_READ]); + dup2_close(fds[PIPE_WRITE], STDOUT); + execle(data_singleton()->argv[0],data_singleton()->argv[0], + "-c", command, NULL, + data_singleton()->env); + exit(1); + } + waitpid(pid, &ret, WUNTRACED); + output = manage_output(fds); return (output); } diff --git a/42sh/src/glob/expand_bquote.c b/42sh/src/glob/expand_bquote.c index cc5dfcb4..8e4e8bf9 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/02/24 22:04:59 by ariard ### ########.fr */ +/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ static char *get_output(char *command) int len; if (!(output = command_getoutput(command))) - return (ft_strnew(0)); + return (NULL);//ft_strnew(0)); len = ft_strlen(output); while (output[--len] == '\n') output[len] = '\0'; @@ -98,10 +98,8 @@ static int search_bquote(t_bquote *me) me->mid = ft_strsub(sta, 1, me->str - sta - 1); me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]); me->s2 = ft_strdup(me->str + 1); - content = get_output(me->mid); - DG(); - init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta)); - DG(); + if ((content = get_output(me->mid))) + init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta)); ft_strdel(&me->mid); ft_strdel(&me->s1); ft_strdel(&me->s2); @@ -113,6 +111,13 @@ static int search_bquote(t_bquote *me) return (0); } +void delete(t_ld **tmp, t_ld **src) +{ + if (*tmp == *src) + ft_ld_del(src, &ft_tabdel); + else + ft_ld_del(tmp, &ft_tabdel); +} void expand_bquote(t_glob *gl) { t_ld *tmp; @@ -133,8 +138,9 @@ void expand_bquote(t_glob *gl) me.str = CH(gl->m_pat)[0]; if ((tmp = gl->m_pat) && (do_it = search_bquote(&me)) == 1) - ft_ld_del(&tmp, &ft_tabdel); - if (!gl->m_pat->next) + delete(&tmp, &gl->m_pat); +// ft_ld_del(&tmp, &ft_tabdel); + if (!gl->m_pat || !gl->m_pat->next) break ; gl->m_pat = gl->m_pat->next; } diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 928ac258..f7c364f3 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/13 22:19:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 20:19:22 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,8 @@ void process_free(void *content, size_t content_size) /* return ; */ /* if (g_freemap[p->type].f) */ /* (g_freemap[p->type].f)(p); */ - (p->map.free)(p); + if (p->map.free) + (p->map.free)(p); ft_lstdel(&p->redirs, redir_free); free(p); } From 6799dc9c27ee96f18bab62efb0120be99fc7d707 Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 14 Mar 2017 20:22:09 +0100 Subject: [PATCH 7/7] protection des prints --- 42sh/src/job-control/process_format.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index 1dc3388c..32aa8272 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/13 22:29:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 20:21:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,8 @@ static void process_format_com_long(t_list **plist) t_process *p; p = (*plist)->content; - (p->map.print)(p); + if (p->map.print) + (p->map.print)(p); // faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense if ((*plist)->next) ft_putstr(" |"); @@ -64,7 +65,8 @@ static void process_format_com_short(t_list **plist, t_flag state) p->attrs &= ~PROCESS_STATE_MASK; p->attrs &= ~PROCESS_RUNNING; } - (p->map.print)(p); + if (p->map.print) + (p->map.print)(p); // faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense if ((*plist)->next) ft_putstr(" | ");