From d8e76dba3d2a038f45cdd6d3854eaef5e23f9e83 Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 14 Mar 2017 23:09:31 +0100 Subject: [PATCH 01/22] rectif lorsque get_next_line renvoi une erreur + modif des fd pour pas bug quand on reset --- 42sh/src/line-editing/readline.c | 6 ++++-- 42sh/src/main/main.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 17b476d9..c2fabd19 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/14 21:34:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:41:51 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ int readline(int fd, int prompt, char **input) { + int ret; + if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - return (get_next_line(fd, input) == 0); + return ((ret = get_next_line(fd, input)) >= 0 ? !ret : ret); readline_init(prompt); *input = ft_read_stdin(); if (STR) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 9140d82b..a41485ca 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/14 21:50:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:08:20 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -95,22 +95,24 @@ int get_input_fd(char **av) else if (data->opts & SH_OPTS_LC) { pipe(fds); - fd = fds[PIPE_READ]; + dup2_close(fds[PIPE_READ], 10); + fd = 10; + //fd = fds[PIPE_READ]; file = *cliopts_getdata(av); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); fcntl(fd, F_SETFD, FD_CLOEXEC); return (fd); } - else if ((file = *cliopts_getdata(av))) + else if ((file = *cliopts_getdata(av)) && !stat(file, &buf)) { - stat(file, &buf); fd = -1; if (S_ISDIR(buf.st_mode)) - ft_printf("{red}%s: %s: is a directory\n{eoc}", g_argv[0], file); + ft_printf("{red}%s: %s: is a directory\n{eoc}", av[0], file); else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) - ft_printf("{red}%s: %s: No such file or directory\n{eoc}", g_argv[0], file); - return (fd); + ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file); + if (fd > 0 && !dup2_close(fd, 10) && (fd = 10)) + return (fd); } return (STDIN); } From f2c3ae16e996fe56ea98017eff52e5761b07326d Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 15 Mar 2017 03:35:05 +0100 Subject: [PATCH 02/22] glob a la norme + close an issue --- 42sh/includes/glob.h | 4 ++-- 42sh/src/exec/plaunch_for.c | 7 +++---- 42sh/src/glob/command_getoutput.c | 4 ++-- 42sh/src/glob/dir_glob.c | 10 +++++----- 42sh/src/glob/expand_bquote.c | 22 ++++++++++------------ 42sh/src/glob/glob.c | 22 +++++++++++----------- 42sh/src/glob/is_char_esc.c | 3 +-- 42sh/src/glob/match_pattern.c | 6 +++--- 42sh/src/glob/tab_esc_copy.c | 6 ++++-- 9 files changed, 41 insertions(+), 43 deletions(-) diff --git a/42sh/includes/glob.h b/42sh/includes/glob.h index 42cf7b26..4e1bc3ca 100644 --- a/42sh/includes/glob.h +++ b/42sh/includes/glob.h @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:31:18 by wescande #+# #+# */ -/* Updated: 2017/03/08 23:24:38 by ariard ### ########.fr */ +/* Updated: 2017/03/14 23:14:14 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -100,7 +100,7 @@ void expand_home(t_glob *gl, char *str); void expand_var(t_glob *tglob); void expand_home(t_glob *gl, char *str); int match_pattern(t_glob *tglob, char *str, char *full_word); -int dir_research(t_glob *tglob, char *p, char *pat, int rec, int first); +int dir_research(t_glob *tglob, char *p, char *pat, int *mode); char **gen_tab(const char *pat, const unsigned char *esc, const unsigned char *esc2, int dup); char **ft_strsplit_spe(const char *str, diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index 46c8f5bb..38e3104f 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_for.c :+: :+: :+: */ +/* plaunch_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ +/* Updated: 2017/03/15 01:46:48 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,6 @@ static int do_for(t_process *p) builtin_setenv("setenv", (char*[]){var, av[i], 0}, data_singleton()->local_var); ft_exec(&p->data.d_for.content); - i++; } temp = temp->next; } diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index bfce6064..b82b745e 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 19:44:25 by wescande #+# #+# */ -/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:11:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,7 @@ char *command_getoutput(char *command) { close(fds[PIPE_READ]); dup2_close(fds[PIPE_WRITE], STDOUT); - execle(data_singleton()->argv[0],data_singleton()->argv[0], + execle(data_singleton()->argv[0], data_singleton()->argv[0], "-c", command, NULL, data_singleton()->env); exit(1); diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 895d6d08..0a5e0361 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 12:07:16 by wescande #+# #+# */ -/* Updated: 2017/03/09 03:24:59 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:14:19 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat, else path = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1); if (recursive) - dir_research(gl, path, pat, recursive, 0); + dir_research(gl, path, pat, (int[]){recursive, 0}); gl->pat = pat; if (match_pattern(gl, str[1], path)) { @@ -46,7 +46,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat, } int dir_research(t_glob *gl, char *p, - char *pat, int recursive, int first) + char *pat, int *mode) { DIR *dir; struct dirent *in; @@ -54,7 +54,7 @@ int dir_research(t_glob *gl, char *p, if (!*pat) { gl->found = 1; - if (!first) + if (!mode[1]) ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 * (p[0] == '.' && p[1] == '/'), "/")); else @@ -66,7 +66,7 @@ int dir_research(t_glob *gl, char *p, dir = opendir(p); while ((in = readdir(dir))) dir_list_content(gl, - (char *[2]){p, in->d_name}, pat, recursive); + (char *[2]){p, in->d_name}, pat, mode[0]); closedir(dir); } return (0); diff --git a/42sh/src/glob/expand_bquote.c b/42sh/src/glob/expand_bquote.c index 8e4e8bf9..08bd2da6 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/14 20:07:47 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:53:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,11 +49,9 @@ static void init_expand(t_bquote *me, char *content, int esc) { ft_ld_pushfront(me->wk, gen_tab(ft_strjoinf(ft_strjoin(me->s1, content), me->s2, 1), - calc_expand_esc(me->esc, ft_strlen(me->s1), - (int[2]){ft_strlen(content), 1}, - (int[2]){ft_strlen(me->s1) + ft_strlen(me->mid), - ft_strlen(me->s2)}), - calc_expand_esc(me->esc2, ft_strlen(me->s1), + calc_expand_esc(me->esc, ft_strlen(me->s1), (int[2]){ft_strlen(content), 1}, + (int[2]){ft_strlen(me->s1) + ft_strlen(me->mid), ft_strlen(me->s2)}), + calc_expand_esc(me->esc2, ft_strlen(me->s1), (int[2]){ft_strlen(content), 1}, (int[2]){ft_strlen(me->s1) + ft_strlen(me->mid), ft_strlen(me->s2)}), 0)); @@ -75,7 +73,7 @@ static char *get_output(char *command) int len; if (!(output = command_getoutput(command))) - return (NULL);//ft_strnew(0)); + return (NULL); len = ft_strlen(output); while (output[--len] == '\n') output[len] = '\0'; @@ -88,7 +86,7 @@ static int search_bquote(t_bquote *me) char *content; sta = NULL; - while (*me->str) + while (*(++me->str)) { sta = *me->str == '`' && !sta && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta; @@ -99,14 +97,14 @@ static int search_bquote(t_bquote *me) me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]); me->s2 = ft_strdup(me->str + 1); if ((content = get_output(me->mid))) - init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta)); + 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); ft_strdel(&content); return (1); } - ++me->str; } return (0); } @@ -118,6 +116,7 @@ void delete(t_ld **tmp, t_ld **src) else ft_ld_del(tmp, &ft_tabdel); } + void expand_bquote(t_glob *gl) { t_ld *tmp; @@ -135,11 +134,10 @@ void expand_bquote(t_glob *gl) me.wk = &gl->m_pat; me.esc = UCH(gl->m_pat)[1]; me.esc2 = UCH(gl->m_pat)[2]; - me.str = CH(gl->m_pat)[0]; + me.str = CH(gl->m_pat)[0] - 1; if ((tmp = gl->m_pat) && (do_it = search_bquote(&me)) == 1) 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/glob/glob.c b/42sh/src/glob/glob.c index 39b9c86c..0a56acfd 100644 --- a/42sh/src/glob/glob.c +++ b/42sh/src/glob/glob.c @@ -6,21 +6,21 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/03/09 03:24:24 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:30:59 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" /* - ** glob return expansion of a string. - ** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, ** - ** input parameters are : - ** -char *pat -> pattern string to be looking for match - ** -char *esc -> escape binary sequence of *pat - ** -char **env -> env var. could be NULL - ** to just expanse in local directory and not in path dir - */ +** glob return expansion of a string. +** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, ** +** input parameters are : +** -char *pat -> pattern string to be looking for match +** -char *esc -> escape binary sequence of *pat +** -char **env -> env var. could be NULL +** to just expanse in local directory and not in path dir +*/ static int order_glob(const char *s1, const char *s2) { @@ -96,9 +96,9 @@ char **glob(char *pat, unsigned char *esc, gl.cur_dir = 1; gl.pat = CH(gl.m_pat)[0]; if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/') - dir_research(&gl, ".", gl.pat, 0, 1); + dir_research(&gl, ".", gl.pat, (int[]){0, 1}); else - dir_research(&gl, "/", gl.pat + 1, 0, 1); + dir_research(&gl, "/", gl.pat + 1, (int[]){0, 1}); if (!gl.found) ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0])); else diff --git a/42sh/src/glob/is_char_esc.c b/42sh/src/glob/is_char_esc.c index cfb99d30..edc80cb7 100644 --- a/42sh/src/glob/is_char_esc.c +++ b/42sh/src/glob/is_char_esc.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/27 18:19:55 by wescande #+# #+# */ -/* Updated: 2017/02/20 20:43:38 by ariard ### ########.fr */ +/* Updated: 2017/03/14 23:11:59 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,5 @@ unsigned char *dup_char_esc(const unsigned char *esc, const int size) if (!(new_esc = (unsigned char *)ft_strnew(size))) return (NULL); new_esc = ft_memcpy(new_esc, esc, size); - return (new_esc); } diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index 17f5ae0d..cf9d95b0 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/24 17:30:23 by wescande #+# #+# */ -/* Updated: 2017/03/09 03:24:48 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:25:44 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,7 +73,7 @@ static int match_star(t_glob *gl, char *str, char *full_word) if (gl->pat[1] == '*' && !is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1)) - dir_research(gl, full_word, gl->pat + 1, 1, 0); + dir_research(gl, full_word, gl->pat + 1, (int[]){1, 0}); if (!*gl->pat || (*gl->pat == '*' && !*++gl->pat)) return (1); pat = gl->pat; @@ -119,7 +119,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word) else if (*gl->pat == '*') return (match_star(gl, str, full_word)); else if (*gl->pat == '/' && !*str && is_directory(full_word)) - return (dir_research(gl, full_word, gl->pat + 1, 0, 0)); + return (dir_research(gl, full_word, gl->pat + 1, (int[]){0, 0})); else if (*gl->pat != *str) return (0); ++str; diff --git a/42sh/src/glob/tab_esc_copy.c b/42sh/src/glob/tab_esc_copy.c index 0661d863..83087807 100644 --- a/42sh/src/glob/tab_esc_copy.c +++ b/42sh/src/glob/tab_esc_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/07 20:40:30 by wescande ### ########.fr */ +/* Updated: 2017/03/14 23:12:20 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,7 @@ void *tab_esc_copy(void *content) char **ch_cont; ch_cont = (char **)content; - return (gen_tab(ch_cont[0], (unsigned char *)ch_cont[1], (unsigned char *)ch_cont[2], 1)); + return (gen_tab(ch_cont[0], + (unsigned char *)ch_cont[1], + (unsigned char *)ch_cont[2], 1)); } From 7b6f848d00911ffbefd6f83db8974c3c911aa4fd Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 15 Mar 2017 04:26:17 +0100 Subject: [PATCH 03/22] minor tricks --- 42sh/src/exec/exec_leaf.c | 4 +++- 42sh/src/parser/error_syntax.c | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index e26f54d4..21a9219d 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/15 02:04:30 by ariard ### ########.fr */ +/* Updated: 2017/03/15 04:18:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,8 @@ int exec_leaf(t_btree **ast) job = &data_singleton()->exec.job; if (process_set(&p, *ast)) return (1); + if (p.type >= PROCESS_MAX) + return (1); p.map = g_process_map[p.type]; if (!(process_launch(&p))) { diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index f74ae423..58e09f82 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/03/13 14:41:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 04:12:31 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,6 @@ t_errormatch g_errormatch[] = {TK_DLESSDASH, "<<-"}, {TK_AND_IF, "&&"}, {TK_OR_IF, "||"}, - {TK_DSEMI, ";;"}, {TK_IF, "if"}, {TK_THEN, "then"}, {TK_ELSE, "else"}, @@ -66,17 +65,14 @@ int error_syntax(t_list **lst, t_parser *parser, { if (g_errormatch[i].token == token->type) { - ft_putstr_fd("syntax error near unexpected token `", 2); - ft_putstr_fd(g_errormatch[i].error, 2); - ft_putstr_fd("'\n", 2); + ft_dprintf(2, "syntax error near unexpected token « %s »\n", + g_errormatch[i].error); instruction_free(lst, parser, ast); return (0); } i++; } - ft_putstr_fd("syntax error near unexpected token`", 2); - ft_putstr_fd(token->data, 2); - ft_putstr_fd("'\n", 2); + ft_dprintf(2, "syntax error near unexpected token « %s »\n", token->data); instruction_free(lst, parser, ast); return (0); } From 15870d6a896713540d4d905755547252bc093de2 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 15 Mar 2017 04:26:54 +0100 Subject: [PATCH 04/22] ajout du super script pour pas push ses headers JUST DO IT --- 42sh/scriptheader.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 42sh/scriptheader.sh diff --git a/42sh/scriptheader.sh b/42sh/scriptheader.sh new file mode 100755 index 00000000..6331ec00 --- /dev/null +++ b/42sh/scriptheader.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +function elem_in_array() +{ + for cur in $2 + do + if [ "$1" == "$cur" ] + then + echo "1" + return 1 + fi + done + echo "0" + return 0 +} + +function array_in_array() +{ + for cur in $1 + do + match=$(elem_in_array "$cur" "$2") + if [ "$match" -ne 1 ] + then + echo "0" + return 0 + fi + done + echo "1" + return 1 +} + +word=$(git status -s | sed 's/.* //') +red="\033[38;5;1m" +gre="\033[38;5;2m" +cya="\033[38;5;6m" +res="\033[0m" + +for i in $word +do + if [ -e $i ] + then + if [ -f $i ] + then + diff=$(git diff -U0 --exit-code --color $i) + if [ "$?" -eq 1 ] + then + nb_lines=$(echo "$diff" | wc -l) + if [ "$nb_lines" -eq 7 ] + then + match=$(array_in_array "-9 +9 Updated: by ### ########.fr" "$diff") + if [ $match -eq 1 ] + then + echo "\n$cya CHANGES on $i :$res" + echo "$diff" + echo "$cya Are you sure?$res" + read -r -p " [y/N]" response + if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] + then + i_tmp=$(echo $i | sed 's/\//_/g') + cp $i "$HOME/Documents/.$i_tmp.back" + git checkout $i + echo "$gre D - O - N - E $res" + echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n" + else + echo "$cya Nothing done for $i$res\n" + fi + else + echo "$gre$i is not concerned (diff on the good lines)$res" + fi + else + echo "$gre$i is not concerned (diff is too big)$res" + fi + else + echo "$gre$i is not concerned (diff is null)$res" + fi + else + echo "$red$i is not a regular file$res" + fi + else + echo "$red$i doesn't exist$res" + fi +done From af97e96d608c8f8ec0424d3e70ba64e4dce80eb3 Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 15 Mar 2017 06:59:03 +0100 Subject: [PATCH 05/22] Fix #104 modified files c_abs_path.c and c_parser.c --- 42sh/src/completion/c_abs_path.c | 5 +++-- 42sh/src/completion/c_parser.c | 33 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/42sh/src/completion/c_abs_path.c b/42sh/src/completion/c_abs_path.c index cd2537c8..7706dbd8 100644 --- a/42sh/src/completion/c_abs_path.c +++ b/42sh/src/completion/c_abs_path.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/09 17:34:43 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 06:57:53 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,5 +48,6 @@ void c_seek_abs_path(t_comp *c, char *current_word) } !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; c_parser(c, c->cpath, c->match); - c_exclusion_folder(c); + if (c->lst == NULL || c->lst == c->lst->prev) + c_exclusion_folder(c); } diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index 67c6dc84..92358007 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/03/14 11:37:25 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 06:53:34 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ void c_add_to_lst(t_comp *c, t_clst *node) { + DG("\tADD %s", node->name); if (c->lst == NULL) { c->lst = node; @@ -41,6 +42,9 @@ void c_add_to_lst(t_comp *c, t_clst *node) ** created and the function above is called to add it. */ +//TODO: The above function doesn't reject . and .. folder for abs_path. Fix needed. + +/* static int c_storing(t_comp *c, char *value, unsigned char type) { t_clst *tmp; @@ -59,6 +63,33 @@ static int c_storing(t_comp *c, char *value, unsigned char type) c_add_to_lst(c, tmp); return (0); } +*/ + +static int c_storing(t_comp *c, char *value, unsigned char type) +{ + t_clst *tmp; + + if (c->match && c->match[0] == '.') + { + if (ft_strequ(".", value) || ft_strequ("..", value)) + return (0); + } + else + { + if (ft_strncmp(".", value, 1) == 0 || ft_strncmp("..", value, 2) == 0) + return (0); + } + if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1) + return (0); + if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) + return (-1); + tmp->name = ft_strdup(value); + tmp->len = ft_strlen(tmp->name); + tmp->type = (int)type; + tmp->cursor = 0; + c_add_to_lst(c, tmp); + return (0); +} /* ** Cycle through the path specified. From 26583e9027dcf80da9f07cf7e38b56ee619f8f4e Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 10:48:08 +0100 Subject: [PATCH 06/22] fix setenv #105' --- 42sh/src/builtin/builtin_setenv.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index a1cc7dc9..c436e331 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/15 02:12:56 by ariard ### ########.fr */ +/* Updated: 2017/03/15 10:47:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,17 +21,24 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[]) (void)envp; (void)path; i = 0; - env = ft_strcmp(av[0], "local") == 0 ? - &data_singleton()->local_var : &data_singleton()->env; + if (ft_strcmp(av[0], "local") == 0) + { + env = &data_singleton()->local_var; + av++; + } + else + env = &data_singleton()->env; av++; if (!av[0]) { ft_sstrprint(*env, '\n'); ft_putchar('\n'); } + else if (!av[1]) + ft_putendl_fd("usage : name [space] value", 2); else { - str = ft_str3join(av[0], "=", av[2]); + str = ft_str3join(av[0], "=", av[1]); while ((*env) && (*env)[i]) { if (ft_strcmp((*env)[i], av[0]) == '=') From c2b7a9e027d500c33b198e00472428038988c0e7 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 10:53:20 +0100 Subject: [PATCH 07/22] #107 --- 42sh/src/builtin/builtin_cd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 424c2c15..711a2828 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */ -/* Updated: 2017/03/09 14:58:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 10:52:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,7 @@ int builtin_cd(const char *path, if (!(target = builtin_cd_special(av + i, envp))) return (1); cwd = getcwd(NULL, 0); - builtin_setenv(path, (char*[3]){"OLDPWD", cwd, NULL}, envp); + builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp); free(cwd); if (chdir(target)) { @@ -93,7 +93,7 @@ int builtin_cd(const char *path, else if (target != av[i]) ft_printf("%s\n", target); cwd = getcwd(NULL, 0); - builtin_setenv(path, (char*[3]){"PWD", cwd, NULL}, envp); + builtin_setenv(path, (char*[4]){"setenv", "PWD", cwd, NULL}, envp); free(cwd); if (!ft_strcmp(*(av + i), "-")) free(target); From e685f977341667e42101ff6ef046931f00696990 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 11:25:27 +0100 Subject: [PATCH 08/22] job control notification correction invalid read --- 42sh/src/job-control/do_job_notification.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 2ea310d1..4f7a079d 100644 --- a/42sh/src/job-control/do_job_notification.c +++ b/42sh/src/job-control/do_job_notification.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* do_job_notification.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/03/10 12:40:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 11:24:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,11 @@ int do_job_notification(void) ret = 1; job_notify_change(j->id); if (job_is_completed(j->id)) + { + jlist = jlist->next; job_remove(j->id); + continue ; + } else j->attrs |= JOB_NOTIFIED; } From bcf72b5bd2931dc2cb8b831c7d906d58285a2ae6 Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 15 Mar 2017 14:27:31 +0100 Subject: [PATCH 09/22] Fix autocompletion arrow not propelly moving --- 42sh/src/completion/c_arrow.c | 141 +++++++++++++++------------------- 1 file changed, 63 insertions(+), 78 deletions(-) diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c index 4890cec9..b06481ec 100644 --- a/42sh/src/completion/c_arrow.c +++ b/42sh/src/completion/c_arrow.c @@ -6,100 +6,85 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 09:04:42 by alao #+# #+# */ -/* Updated: 2017/03/10 12:44:05 by alao ### ########.fr */ +/* Updated: 2017/03/15 14:26:11 by alao ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -static void c_arrow_right(t_comp *c) +/* +** +*/ + +static int c_idsolver(t_comp *c, int ids, int ids_bk) { - t_clst *ptr; - int i; + if (ids > c->lst->prev->id) + { + ids -= c->lst->prev->id; + if (ids_bk < ((c->lst->prev->id - (c->lst->prev->id % c->c_line)) + 1)) + ids = ids + (c->lst->prev->id % c->c_line); + else + ids = ids - (c->c_line - (c->lst->prev->id % c->c_line)); + } + else if (ids < c->lst->id) + { + if (ids_bk <= (c->lst->prev->id % c->c_line)) + ids = (c->lst->prev->id - (c->lst->prev->id % c->c_line)) + ids_bk; + else + ids = c->lst->prev->id - (ids * -1) - (c->lst->prev->id % c->c_line); + if (ids < c->lst->id) + { + DG("Failsafe %d", ids); + ids = 1; + } + } + return (ids); +} + +/* +** +*/ + +static void c_arrow_multi(t_comp *c, long int keypress) +{ + t_clst *ptr; + int ids; + int ids_bk; + + ids = 0; ptr = c->lst; - i = 0; while (!ptr->cursor) ptr = ptr->next; ptr->cursor = 0; - while (i < c->c_line) - { + ids = ptr->id; + ids_bk = ids; + (keypress == 4479771) ? (ids -= c->c_line) : (0); + (keypress == 4414235) ? (ids += c->c_line) : (0); + ids = c_idsolver(c, ids, ids_bk); + ptr = c->lst; + while (ptr->id != ids) ptr = ptr->next; - if (ptr == c->lst) - i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); - i++; - } - if (c->pos_x == (c->c_pline - 1)) - { - i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); - while (i < c->c_line) - { - ptr = ptr->next; - i++; - } - } ptr->cursor = 1; } -static void c_arrow_left(t_comp *c) -{ - t_clst *ptr; - int i; - - ptr = c->lst; - i = 0; - while (!ptr->cursor) - ptr = ptr->next; - ptr->cursor = 0; - while (i < c->c_line) - { - ptr = ptr->prev; - if (ptr == c->lst) - i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); - i++; - } -/* if (c->pos_x == 1) - { - i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); - while (i < c->c_line) - { - ptr = ptr->prev; - i++; - } - }*/ - ptr->cursor = 1; -} - -static void c_arrow_down(t_comp *c) -{ - t_clst *ptr; - - ptr = c->lst; - while (!ptr->cursor) - ptr = ptr->next; - ptr->cursor = 0; - ptr->next->cursor = 1; -} - -static void c_arrow_up(t_comp *c) -{ - t_clst *ptr; - - ptr = c->lst; - while (!ptr->cursor) - ptr = ptr->next; - ptr->cursor = 0; - ptr->prev->cursor = 1; -} +/* +** +*/ void c_arrow(t_comp *c, long int keypress) { - if (keypress == 4283163) - c_arrow_up(c); - if (keypress == 4348699) - c_arrow_down(c); - if (keypress == 4479771) - c_arrow_left(c); - if (keypress == 4414235) - c_arrow_right(c); + t_clst *ptr; + + ptr = c->lst; + if (keypress == 4479771 || keypress == 4414235) + c_arrow_multi(c, keypress); + else + { + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + (keypress == 4283163) ? (ptr->prev->cursor = 1) : (0); + (keypress == 4348699) ? (ptr->next->cursor = 1) : (0); + } } From 39d5b250847d87d42ca2cf115e29716b229ab4d4 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 14:40:19 +0100 Subject: [PATCH 10/22] fix bug completion resize sur fenetre minuscule --- 42sh/includes/completion.h | 5 +++-- 42sh/src/completion/c_files.c | 6 +----- 42sh/src/completion/c_matching.c | 2 +- 42sh/src/completion/c_printer.c | 5 +++-- 42sh/src/completion/c_seek_env.c | 9 ++++----- 42sh/src/completion/c_sizing.c | 4 ++-- 42sh/src/completion/c_terminal.c | 4 ++-- 42sh/src/completion/completion.c | 2 +- 42sh/src/job-control/put_job_in_foreground.c | 3 ++- 42sh/src/line-editing/ft_prompt.c | 2 +- 42sh/src/line-editing/get_key.c | 4 +++- 42sh/src/line-editing/resize.c | 3 +-- 42sh/src/main/main.c | 2 +- 42sh/src/main/shell_init.c | 3 +-- 14 files changed, 26 insertions(+), 28 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 1f341a15..7cb2ccf6 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/14 12:09:55 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 13:47:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ # define COMPLETION_H # include "minishell.h" -#define RETARDED_BEHAVIOR 0 +# define RETARDED_BEHAVIOR 0 /* ** Autocompletion list for the valid candidates from the parser. @@ -178,5 +178,6 @@ int c_seek_env(t_comp *c, char *current_word); void c_seek_abs_path(t_comp *c, char *current_word); void c_arrow(t_comp *c, long int keypress); int c_chevron(t_comp *c); +int c_dispatcher(t_data *s); #endif diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index 7144b386..b4fd8fed 100644 --- a/42sh/src/completion/c_files.c +++ b/42sh/src/completion/c_files.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */ -/* Updated: 2017/03/14 12:09:36 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 11:47:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,10 +70,6 @@ static char *c_slicer(t_comp *c) i--; tmp[i] == '/' ? i++ : (0); rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i); -/* if (c_chevron(c)) - c->match = ft_strdup(""); - else - c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);*/ tmp ? ft_memdel((void *)&tmp) : (0); return (rt); } diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index f9d6c375..ca3d6192 100644 --- a/42sh/src/completion/c_matching.c +++ b/42sh/src/completion/c_matching.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/14 12:29:12 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 17:22:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index 050212e8..85bd5adf 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/03/10 16:09:46 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 14:30:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -126,7 +126,8 @@ void c_printer(t_comp *c) //int offset; loop = c->c_line; - + if (!c->c_line) + return ; max_line = c->c_line - (c->m_size - 1); ptr = c_rolling(c); if ((c->pos_y * (c->m_size - 1)) > c->c_line) diff --git a/42sh/src/completion/c_seek_env.c b/42sh/src/completion/c_seek_env.c index dfc8198c..e63e1135 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 17:21:37 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 11:50:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,17 +28,16 @@ static int c_storing(t_comp *c, char *value) int c_seek_env(t_comp *c, char *current_word) { - char *match; char **env; int i; i = 0; env = data_singleton()->env; - match = ft_strdupi_w(current_word + 1); + c->match = ft_strdupi_w(current_word + 1); while (env[i]) { - if (!ft_strncmp(match, env[i], ft_strlen(match)) && - env[i][ft_strlen(match)] != '=') + if (!ft_strncmp(c->match, env[i], ft_strlen(c->match)) && + env[i][ft_strlen(c->match)] != '=') c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); ++i; } diff --git a/42sh/src/completion/c_sizing.c b/42sh/src/completion/c_sizing.c index 542f5a13..10da2078 100644 --- a/42sh/src/completion/c_sizing.c +++ b/42sh/src/completion/c_sizing.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 08:50:26 by alao #+# #+# */ -/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */ +/* Updated: 2017/03/15 14:25:54 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,7 @@ int c_sizing(t_comp *c) c->lst && c->lst->name ? c_max_length(c) : 0; c->c_pline = c->win_x / (c->c_sx + 2); c->c_line = 0; - while ((c->c_line * c->c_pline) < c->c_sy) + while (c->c_pline && (c->c_line * c->c_pline) < c->c_sy) c->c_line++; if ((c->win_x < c->c_sx)) { diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index ebef1cee..e441d5a5 100644 --- a/42sh/src/completion/c_terminal.c +++ b/42sh/src/completion/c_terminal.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/11 10:44:40 by alao #+# #+# */ -/* Updated: 2017/03/14 10:51:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 14:36:43 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,7 +92,7 @@ void c_term_mv_down(t_comp *c) value = c->m_size - 1; else value = c->c_line - 1; - while (i != value) + while (value >= 0 && i != value) { ft_putstr(tgetstr("up", NULL)); i++; diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index 498261a9..1eba71eb 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/03/14 11:22:04 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 14:37:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 5237ed9b..6b33dec1 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/14 12:45:22 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 11:14:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ int put_job_in_foreground(t_job *j, int cont) tcsetpgrp(STDIN, j->pgid); if (cont) { +// j->tmodes = pas initialisé ! tcsetattr(STDIN, TCSADRAIN, &j->tmodes); if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index cda5a0ad..908479b4 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 16:00:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 13:55:22 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/get_key.c b/42sh/src/line-editing/get_key.c index 03e45b7c..811d7aa8 100644 --- a/42sh/src/line-editing/get_key.c +++ b/42sh/src/line-editing/get_key.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/03/05 19:38:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 14:07:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,11 +57,13 @@ char *ft_read_stdin(void) ft_is_str(); if (data_singleton()->comp) c_clear(data_singleton()); + signal(SIGWINCH, sigwinch_resize); while (42) { ret = 0; j = 0; read(0, &ret, sizeof(int)); + DG("key hexa value = %X", ret); if (ft_completion(ret)) continue ; while (g_key[j].value && g_key[j].value != ret) diff --git a/42sh/src/line-editing/resize.c b/42sh/src/line-editing/resize.c index 8963c96d..8d6042e8 100644 --- a/42sh/src/line-editing/resize.c +++ b/42sh/src/line-editing/resize.c @@ -6,12 +6,11 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 10:56:08 by gwojda #+# #+# */ -/* Updated: 2017/03/14 12:00:29 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 14:25:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int c_dispatcher(t_data *s); void sigwinch_resize(int sig) { diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index ffe4a3c3..a5bedb24 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/15 03:52:32 by wescande ### ########.fr */ +/* Updated: 2017/03/15 13:46:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index ca14c64e..7d2fce00 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/14 23:25:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 13:55:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,6 @@ static int interactive_settings(void) signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGCHLD, SIG_DFL); - signal(SIGWINCH, sigwinch_resize); *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) { From 65013fcae63cfa0d1c4248a2689cb36d709ff155 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 15:51:52 +0100 Subject: [PATCH 11/22] #37 --- 42sh/src/job-control/put_job_in_foreground.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 6b33dec1..c90577a4 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/15 11:14:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 15:51:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,8 @@ int put_job_in_foreground(t_job *j, int cont) tcsetpgrp(STDIN, j->pgid); if (cont) { -// j->tmodes = pas initialisé ! - tcsetattr(STDIN, TCSADRAIN, &j->tmodes); + // j->tmodes = pas initialisé ! + //tcsetattr(STDIN, TCSADRAIN, &j->tmodes); if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } From dbdf84c00f8c6d372b908e151a2a791911ef23c0 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 16:18:15 +0100 Subject: [PATCH 12/22] fixe some leaks --- 42sh/Makefile | 1 + 42sh/includes/exec.h | 4 +++- 42sh/src/exec/exec_semi.c | 4 ++-- 42sh/src/main/instruction_free.c | 15 ++++++++++++++- 42sh/src/main/main.c | 3 ++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 2a885d45..7911a273 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -84,6 +84,7 @@ exec/ft_findexec.c\ exec/is_function.c\ exec/mark_process_status.c\ exec/node_copy.c\ +exec/op_stack_free.c\ exec/pfree_cmd.c\ exec/pfree_cond.c\ exec/pfree_list.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index d9f8261e..d5e2122f 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/15 01:07:00 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:06:24 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -133,6 +133,8 @@ struct s_exec int control_count; }; +void op_stack_free(void *data, size_t content_size); + int exec_reset(void); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index c042ffb6..25a34a94 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_semi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:55:05 by ariard ### ########.fr */ +/* Updated: 2017/03/15 15:55:43 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c index 92fd64d9..361923d1 100644 --- a/42sh/src/main/instruction_free.c +++ b/42sh/src/main/instruction_free.c @@ -1,11 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* instruction_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */ +/* Updated: 2017/03/15 16:06:34 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" int instruction_free(t_list **token, t_parser *parser, t_btree **ast) -{ +{ ft_lstdel(token, &token_free); token = NULL; ft_lstdel(&parser->stack, NULL); btree_del(ast, &ast_free); ft_lstdel(&data_singleton()->heredoc_queue, &redir_free); + ft_lstdel(&data_singleton()->exec.op_stack, &op_stack_free); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a5bedb24..32de297e 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/15 13:46:36 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:12:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,6 +74,7 @@ int handle_instruction(int fd) if (ft_exec(&ast)) return (2); instruction_free(&token, &parser, &ast); + ft_lstdel(&parser.stack, &op_stack_free); if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str) ft_add_str_in_history(lexer.str); ft_strdel(&lexer.str); From d4c4722884bdaf1f1c479ad0edd7131546531aa5 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 15 Mar 2017 16:34:16 +0100 Subject: [PATCH 13/22] rectif setenv et mise a la norme. Ajout data init des IFS + data init du SHLVL --- 42sh/src/builtin/builtin_setenv.c | 54 ++++++++++++++++--------------- 42sh/src/builtin/is_builtin.c | 6 +++- 42sh/src/main/data_init.c | 7 +++- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index c436e331..049ed1b4 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,51 +6,53 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/15 10:47:33 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:29:51 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int builtin_setenv(const char *path, char *const av[], char *const envp[]) +static int assign_var(char *const av[], char ***env) { char *str; - char ***env; int i; + i = -1; + str = ft_str3join(av[1], "=", av[2]); + while ((*env) && (*env)[++i]) + { + if (ft_strcmp((*env)[i], av[1]) == '=' + && ft_strlen(av[1]) == ft_strlenchr((*env)[i], '=')) + { + ft_strdel(&(*env)[i]); + (*env)[i] = str; + return (0); + } + } + *env = ft_sstradd(*env, str); + ft_strdel(&str); + return (0); +} + +int builtin_setenv(const char *path, + char *const av[], char *const envp[]) +{ + char ***env; + (void)envp; (void)path; - i = 0; + if (!av || !av[0]) + return (1); if (ft_strcmp(av[0], "local") == 0) - { env = &data_singleton()->local_var; - av++; - } else env = &data_singleton()->env; - av++; - if (!av[0]) + if (!av[1]) { ft_sstrprint(*env, '\n'); ft_putchar('\n'); } - else if (!av[1]) - ft_putendl_fd("usage : name [space] value", 2); else - { - str = ft_str3join(av[0], "=", av[1]); - while ((*env) && (*env)[i]) - { - if (ft_strcmp((*env)[i], av[0]) == '=') - { - ft_strdel(&(*env)[i]); - (*env)[i] = str; - return (0); - } - i++; - } - *env = ft_sstradd(*env, str); - ft_strdel(&str); - } + return (assign_var(av, env)); return (0); } diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 4bc3a2c3..06a2e33d 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/14 22:32:24 by ariard ### ########.fr */ +/* Updated: 2017/03/15 15:58:53 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ t_stof g_builtin[] = {"export", &builtin_export}, {"unset", &builtin_unset}, {"setenv", &builtin_setenv}, + {"local", &builtin_setenv}, {"unsetenv", &builtin_unsetenv}, {"env", &builtin_env}, {"exit", &builtin_exit}, @@ -40,7 +41,10 @@ t_execf *is_builtin(t_process *p) while (g_builtin[++i].name) { if (ft_strcmp(g_builtin[i].name, p->data.cmd.av[0]) == 0) + { + DG(); return (g_builtin[i].f); + } } return (NULL); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index a337be26..11e9f92e 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/14 21:39:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 16:23:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,13 +18,18 @@ int data_init(int ac, char **av) { t_data *data; char *term_name; + char* shlvl; data = data_singleton(); data->argc = ac; data->argv = ft_sstrdup(av); data->env = ft_sstrdup(environ); data->local_var = NULL; + builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL); set_exitstatus(0, 1); + shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1); + builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL); + ft_strdel(&shlvl); data->comp = NULL; data->opts = 0; exec_reset(); From 10ff285727e4c6e63690f29ff7d7002291452a36 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 16:38:04 +0100 Subject: [PATCH 14/22] fixe some leaks --- 42sh/Makefile | 2 +- 42sh/includes/exec.h | 4 +--- 42sh/includes/minishell.h | 3 ++- 42sh/src/lexer/insert_newline.c | 5 +++-- 42sh/src/main/instruction_free.c | 9 +++++---- 42sh/src/main/main.c | 4 +--- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 7911a273..76d15b32 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -84,7 +84,6 @@ exec/ft_findexec.c\ exec/is_function.c\ exec/mark_process_status.c\ exec/node_copy.c\ -exec/op_stack_free.c\ exec/pfree_cmd.c\ exec/pfree_cond.c\ exec/pfree_list.c\ @@ -265,6 +264,7 @@ line-editing/print_and_del.c\ line-editing/queue.c\ line-editing/readline.c\ line-editing/resize.c\ +main/content_free.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index d5e2122f..200b2b7c 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/15 16:06:24 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:35:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -133,8 +133,6 @@ struct s_exec int control_count; }; -void op_stack_free(void *data, size_t content_size); - int exec_reset(void); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index cf2d6d05..4d690594 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:34:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 16:35:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,7 @@ void data_exit(void); int instruction_free(t_list **token, t_parser *parser, t_btree **ast); +void content_free(void *data, size_t content_size); char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/src/lexer/insert_newline.c b/42sh/src/lexer/insert_newline.c index 8cd60a2a..47e7d1bf 100644 --- a/42sh/src/lexer/insert_newline.c +++ b/42sh/src/lexer/insert_newline.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 21:05:23 by ariard #+# #+# */ -/* Updated: 2017/03/08 18:33:31 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:31:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,6 @@ int insert_newline(t_list **alst) token = token_init(); token->type = TK_NEWLINE; ft_lsteadd(alst, ft_lstnew(token, sizeof(*token))); + free(token); return (0); -} +} diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c index 361923d1..03b4d989 100644 --- a/42sh/src/main/instruction_free.c +++ b/42sh/src/main/instruction_free.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/15 16:06:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:36:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,10 @@ int instruction_free(t_list **token, t_parser *parser, t_btree **ast) { ft_lstdel(token, &token_free); token = NULL; - ft_lstdel(&parser->stack, NULL); - btree_del(ast, &ast_free); + ft_lstdel(&parser->stack, &content_free); + btree_del(ast, &content_free); ft_lstdel(&data_singleton()->heredoc_queue, &redir_free); - ft_lstdel(&data_singleton()->exec.op_stack, &op_stack_free); + ft_lstdel(&data_singleton()->exec.op_stack, &content_free); + free(parser->new_sym); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 32de297e..bf8cdd41 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/15 16:12:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:33:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,11 +74,9 @@ int handle_instruction(int fd) if (ft_exec(&ast)) return (2); instruction_free(&token, &parser, &ast); - ft_lstdel(&parser.stack, &op_stack_free); 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 3bf8abe178ac4aca19f8a62f7200a0078fdbe8c3 Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 16:38:14 +0100 Subject: [PATCH 15/22] fixe some leaks --- 42sh/src/main/content_free.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 42sh/src/main/content_free.c diff --git a/42sh/src/main/content_free.c b/42sh/src/main/content_free.c new file mode 100644 index 00000000..3c025475 --- /dev/null +++ b/42sh/src/main/content_free.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* content_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/15 16:05:27 by gwojda #+# #+# */ +/* Updated: 2017/03/15 16:35:18 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void content_free(void *data, size_t content_size) +{ + (void)content_size; + free(data); +} From 26e20534cf5f1c7b5585eaee498f03cbfdc396ff Mon Sep 17 00:00:00 2001 From: gwojda Date: Wed, 15 Mar 2017 16:53:35 +0100 Subject: [PATCH 16/22] correction, merci wescande --- 42sh/Makefile | 1 - 42sh/src/main/content_free.c | 19 ------------------- 42sh/src/main/instruction_free.c | 8 ++++---- 3 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 42sh/src/main/content_free.c diff --git a/42sh/Makefile b/42sh/Makefile index 76d15b32..2a885d45 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -264,7 +264,6 @@ line-editing/print_and_del.c\ line-editing/queue.c\ line-editing/readline.c\ line-editing/resize.c\ -main/content_free.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ diff --git a/42sh/src/main/content_free.c b/42sh/src/main/content_free.c deleted file mode 100644 index 3c025475..00000000 --- a/42sh/src/main/content_free.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* content_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/15 16:05:27 by gwojda #+# #+# */ -/* Updated: 2017/03/15 16:35:18 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void content_free(void *data, size_t content_size) -{ - (void)content_size; - free(data); -} diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c index 03b4d989..e4b66c19 100644 --- a/42sh/src/main/instruction_free.c +++ b/42sh/src/main/instruction_free.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/15 16:36:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:49:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,10 @@ int instruction_free(t_list **token, t_parser *parser, t_btree **ast) { ft_lstdel(token, &token_free); token = NULL; - ft_lstdel(&parser->stack, &content_free); - btree_del(ast, &content_free); + ft_lstdel(&parser->stack, &ft_lst_cfree); + btree_del(ast, &ft_lst_cfree); ft_lstdel(&data_singleton()->heredoc_queue, &redir_free); - ft_lstdel(&data_singleton()->exec.op_stack, &content_free); + ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); free(parser->new_sym); return (0); } From 9f88ed37db59c9c47bc00a3bbce173db22220726 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 17:50:33 +0100 Subject: [PATCH 17/22] issue #92, inversion de O_RDONLY et O_WRONLY pour >& et <& --- 42sh/src/exec/fd_is_valid.c | 2 +- 42sh/src/exec/redirect_greatand.c | 7 +++---- 42sh/src/exec/redirect_lessand.c | 7 +++---- 42sh/src/job-control/job_wait.c | 2 +- 42sh/src/lexer/lexer_lessand.c | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/42sh/src/exec/fd_is_valid.c b/42sh/src/exec/fd_is_valid.c index b0347bcf..41114621 100644 --- a/42sh/src/exec/fd_is_valid.c +++ b/42sh/src/exec/fd_is_valid.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:59:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:48:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 8be9aecd..e42cf7eb 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/11 17:32:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:49:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,10 +33,9 @@ int redirect_greatand(t_redir *redir) return (0); if (fdold > 9) return (bad_fd(fdold)); - if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) + if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) dup2_close(fdold, fdnew); else - close(fdnew); - /* return (bad_fd(fdold)); */ + return (bad_fd(fdold)); return (0); } diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 30f11cdc..1a5ccf64 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:00:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:49:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,10 +33,9 @@ int redirect_lessand(t_redir *redir) return (0); if (fdold > 9) return (bad_fd(fdold)); - if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) + if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) dup2_close(fdold, fdnew); else - close(fdnew); - /* return (bad_fd(fdold)); */ + return (bad_fd(fdold)); return (0); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 3033978a..e1c36928 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/14 23:43:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:49:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/src/lexer/lexer_lessand.c index 3930c001..e7769130 100644 --- a/42sh/src/lexer/lexer_lessand.c +++ b/42sh/src/lexer/lexer_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:48:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From dec15b7ae26a1600445374f9e3766bff1c037de6 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 17:57:31 +0100 Subject: [PATCH 18/22] close p.to_close before redirections --- 42sh/src/exec/process_redirect.c | 6 +++--- 42sh/src/job-control/job_wait.c | 2 +- 42sh/src/main/main.c | 4 ++-- 42sh/src/parser/ft_parse.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index b433aa4d..abbe0ad1 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:01:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:57:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,8 @@ int process_redirect(t_process *p) int i; redirs = p->redirs; + if (p->to_close != STDIN) + close(p->to_close); while (redirs) { redir = redirs->content; @@ -54,8 +56,6 @@ int process_redirect(t_process *p) redirs = redirs->next; } /* DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); */ - if (p->to_close != STDIN) - close(p->to_close); if (p->fdin != STDIN) dup2_close(p->fdin, STDIN); if (p->fdout != STDOUT) diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index e1c36928..35a053e9 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 17:49:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:55:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index bf8cdd41..706b663d 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/15 16:33:07 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 17:55:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } - btree_print(STDBUG, ast, &ft_putast); + /* btree_print(STDBUG, ast, &ft_putast); */ if (ft_exec(&ast)) return (2); instruction_free(&token, &parser, &ast); diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 48c2df8c..5d5f8617 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/13 17:42:06 by ariard ### ########.fr */ +/* Updated: 2017/03/15 17:56:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); - btree_print(STDBUG, *ast, &ft_putast); + /* btree_print(STDBUG, *ast, &ft_putast); */ if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else From 124fb2138ae30765e8e9e9116080808f54f8125a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 18:08:54 +0100 Subject: [PATCH 19/22] Makefile update: binary stripping. #1 easier to see illegal functions --- 42sh/Makefile | 5 +++-- 42sh/src/exec/process_redirect.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 2a885d45..2a56b80e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/14 21:59:22 by ariard ### ########.fr # +# Updated: 2017/03/15 18:07:26 by jhalford ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -g +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) @@ -309,6 +309,7 @@ $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(LIBS) \ $(LIBFT_LIB) \ $(FLAGS) $(D_FLAGS) + @strip -x $@ @printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n" $(LIBFT_LIB): diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index abbe0ad1..fb2c6436 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/15 17:57:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:06:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 6bfd442e82cab7e772e8c324012797bb6fac26f0 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 18:12:10 +0100 Subject: [PATCH 20/22] #1, removed perror illegal function --- 42sh/Makefile | 2 +- 42sh/src/exec/process_setgroup.c | 5 +---- 42sh/src/job-control/job_wait.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 2a56b80e..425f7b38 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/15 18:07:26 by jhalford ### ########.fr # +# Updated: 2017/03/15 18:11:31 by jhalford ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 059e4f4a..575edca9 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:33:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:11:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,7 @@ int process_setgroup(t_process *p, pid_t pid) return (0); DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) - { ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); - perror(""); - } if (pid == 0 && JOB_IS_FG(j->attrs)) { DG("tcsetpgrp[%i]", j->pgid); diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 35a053e9..bc1d9f02 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 17:55:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:11:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 0b608c0b94bbe9ddc2eaf4d1d45972e2922030c7 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 18:15:09 +0100 Subject: [PATCH 21/22] ft_prompt uses ft_printf not printf --- 42sh/src/glob/esc_print.c | 8 ++++---- 42sh/src/job-control/job_wait.c | 2 +- 42sh/src/line-editing/ft_prompt.c | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/42sh/src/glob/esc_print.c b/42sh/src/glob/esc_print.c index 504e95bd..a91afb64 100644 --- a/42sh/src/glob/esc_print.c +++ b/42sh/src/glob/esc_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 15:38:14 by jhalford #+# #+# */ -/* Updated: 2017/02/24 22:05:04 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:12:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,10 @@ void esc_print(char *str, unsigned char *esc) while (*cur) { if (is_char_esc(esc, str, cur)) - printf("\\%c", *cur); + ft_printf("\\%c", *cur); else - printf("%c", *cur); + ft_printf("%c", *cur); ++cur; } - printf("\n"); + ft_printf("\n"); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index bc1d9f02..0cb2625a 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:11:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:12:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 908479b4..8a6614fa 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/15 13:55:22 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 18:14:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,10 +27,10 @@ static int promt_git_status(int fd) 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'✓'); + ft_printf("\x1b[38;5;83m ✓ "); else { - printf("\x1b[38;5;1m %C ", L'✗'); + ft_printf("\x1b[38;5;1m ✗ "); free(tmp); } while (get_next_line(fd, &tmp)) @@ -101,9 +101,9 @@ void ft_prompt(void) do_job_notification(); if (ft_getenv(data_singleton()->env, "?") && ft_atoi(ft_getenv(data_singleton()->env, "?"))) - printf("\x1b[38;5;1m%C ", L'➜'); + ft_printf("\x1b[38;5;1m➜ "); else - printf("\x1b[38;5;10m%C ", L'➜'); + ft_printf("\x1b[38;5;10m➜ "); fflush(NULL); ft_putstr("\x1b[38;5;361m"); ret += ft_currend_dir(); From 29f0b5835fdc52b2f9f1408f97ecd79b9819415e Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 18:22:24 +0100 Subject: [PATCH 22/22] fichier auteur --- 42sh/auteur | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 42sh/auteur diff --git a/42sh/auteur b/42sh/auteur new file mode 100644 index 00000000..127f9bf3 --- /dev/null +++ b/42sh/auteur @@ -0,0 +1,5 @@ +alao +ariard +gwojda +jhalford +wescande