diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index 25f39efa..8526ef14 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:36:08 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 15:34:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 39fd9c94..6848b770 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/20 11:39:13 by wescande ### ########.fr */ +/* Updated: 2017/03/20 16:07:29 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,10 @@ # define IS_PIPEEND(p) ((p).fdout == STDOUT) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p)) -# define EXEC_AND_IF (1 << 2) -# define EXEC_OR_IF (1 << 3) -# define EXEC_IF_BRANCH (1 << 4) -# define EXEC_CASE_BRANCH (1 << 5) +# define EXEC_AND_IF (1 << 0) +# define EXEC_OR_IF (1 << 1) +# define EXEC_IF_BRANCH (1 << 2) +# define EXEC_CASE_BRANCH (1 << 3) # define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 78d034c5..12bc50b4 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:38:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:39:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ # include # include # include -/* # include "libft.h" */ # include "types.h" # include "exec.h" @@ -43,15 +42,14 @@ void job_update_rank(void); int do_job_notification(void); void job_notify_new(int id); -void job_notify_change(int id); void job_format(t_job *j, int opts); void job_format_head(t_job *j); void job_update_status(void); void mark_job_as_running (t_job *j); int mark_process_status(pid_t pid, int status); -int job_is_stopped(int id); -int job_is_completed(int id); +int job_is_stopped(t_job *job); +int job_is_completed(t_job *job); void job_new(char **av, pid_t pid); void job_run(t_job *job, int foreground); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 243e2063..13622138 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/20 16:24:10 by ariard ### ########.fr */ +/* Updated: 2017/03/20 16:44:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,6 @@ # include "libft.h" # include "types.h" -# define RW_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_WHILE | TK_DONE\ - | TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE) enum e_lexstate { DEFAULT, diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 638a8571..1c0fe8e9 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -72,6 +72,7 @@ ft_printf/ft_printf.c\ ft_printf/ft_printf_color.c\ ft_printf/ft_printf_parse.c\ ft_printf/ft_transform.c\ +ft_printf/ft_vprintf.c\ ft_printf/lib_fmt.c\ ft_printf/lib_fmt_error.c\ ft_printf/lib_pad.c\ diff --git a/42sh/libft/includes/cliopts.h b/42sh/libft/includes/cliopts.h index ad21c697..a4eaff23 100644 --- a/42sh/libft/includes/cliopts.h +++ b/42sh/libft/includes/cliopts.h @@ -6,12 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ -/* Updated: 2017/03/15 19:00:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:48:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef CLI_OPTS_H -# define CLI_OPTS_H +#ifndef CLIOPTS_H +# define CLIOPTS_H # include "libft.h" # include "error.h" diff --git a/42sh/libft/includes/error.h b/42sh/libft/includes/error.h index c564654b..50f0976f 100644 --- a/42sh/libft/includes/error.h +++ b/42sh/libft/includes/error.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ -/* Updated: 2017/03/16 14:19:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:48:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,15 @@ # include "libft.h" # include -# define DG_PROTO "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" -# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ -# define DG(s, ...) ft_dprintf(STDBUG, DG_PROTO s "{eoc}\n", DG_ARGS, ##__VA_ARGS__) +# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" +# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ +# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__) # define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__ # define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__) # define ERRMSG_MAX_SIZE 150 -enum e_errors +enum e_errors { E_NOERR, E_CO_INV, diff --git a/42sh/libft/includes/math.h b/42sh/libft/includes/math.h index 6b372f7d..2a54ae68 100644 --- a/42sh/libft/includes/math.h +++ b/42sh/libft/includes/math.h @@ -1,11 +1,12 @@ -/* ************************************************************************** */ /* */ +/* ************************************************************************** */ +/* */ /* ::: :::::::: */ /* math.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/18 13:19:12 by jhalford #+# #+# */ -/* Updated: 2017/02/18 13:19:57 by jhalford ### ########.fr */ +/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */ +/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/btree/btree_map.c b/42sh/libft/src/btree/btree_map.c index b7751156..42fd89a5 100644 --- a/42sh/libft/src/btree/btree_map.c +++ b/42sh/libft/src/btree/btree_map.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:43:15 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:09:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,9 @@ t_btree *btree_map(t_btree *root, void *(*f)(void *)) if (!root) return (NULL); - new = btree_create_node((*f)(root->item), root->content_size); + if (!(new = (t_btree *)malloc(sizeof(*new)))) + return (NULL); + new->item = (*f)(root->item); new->left = btree_map(root->left, f); new->right = btree_map(root->right, f); return (new); diff --git a/42sh/libft/src/cliopts/cliopts_get.c b/42sh/libft/src/cliopts/cliopts_get.c index 1c693cfa..e2aa284d 100644 --- a/42sh/libft/src/cliopts/cliopts_get.c +++ b/42sh/libft/src/cliopts/cliopts_get.c @@ -6,16 +6,16 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:28:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ /* - ** void *data must be a structure starting with `int flag` - ** to do polymorphism with t_data_template ! - */ +** void *data must be a structure starting with `int flag` +** to do polymorphism with t_data_template ! +*/ -# include "cliopts.h" +#include "cliopts.h" static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg) { @@ -39,7 +39,8 @@ static t_cliopts *get_map_short(t_cliopts opt_map[], char arg) return (NULL); } -static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data) +static int cliopts_parse_short( + char ***av, t_cliopts opt_map[], void *data) { t_cliopts *map; char *arg; @@ -67,7 +68,8 @@ static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data) return (0); } -static int cliopts_parse_long(char ***av, t_cliopts opt_map[], void *data) +static int cliopts_parse_long( + char ***av, t_cliopts opt_map[], void *data) { t_cliopts *map; char *arg; diff --git a/42sh/libft/src/cliopts/cliopts_has.c b/42sh/libft/src/cliopts/cliopts_has.c index 3d1fc5c5..9cc120b8 100644 --- a/42sh/libft/src/cliopts/cliopts_has.c +++ b/42sh/libft/src/cliopts/cliopts_has.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:24:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int cliopts_has(char **av, char c) { if (!av) return (0); - while (*av) + while (*av) { if (ft_strcmp(*av, "--") == 0) return (0); diff --git a/42sh/libft/src/ft_printf/ft_conversion.c b/42sh/libft/src/ft_printf/ft_conversion.c index 0a03d5c5..6303d971 100644 --- a/42sh/libft/src/ft_printf/ft_conversion.c +++ b/42sh/libft/src/ft_printf/ft_conversion.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2017/03/11 13:14:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:50:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ char *ft_signed_conversion(t_fmt *fmt, va_list ap) { - char base10[] = "0123456789"; + static char base10[] = "0123456789"; long long arg; arg = va_arg(ap, int); @@ -61,7 +61,7 @@ char *ft_str_conversion(t_fmt *fmt, va_list ap) (void)fmt; ret = va_arg(ap, char *); if (ret == NULL) - return(ft_strdup("NULL")); + return (ft_strdup("NULL")); ret = ft_strdup(ret); if (fmt->precision && fmt->precision < (int)ft_strlen(ret)) ret[fmt->precision] = '\0'; diff --git a/42sh/libft/src/ft_printf/ft_printf.c b/42sh/libft/src/ft_printf/ft_printf.c index f0647e09..e89f0aae 100644 --- a/42sh/libft/src/ft_printf/ft_printf.c +++ b/42sh/libft/src/ft_printf/ft_printf.c @@ -6,25 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:22:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:13:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -t_conv g_convs[] = -{ - {'d', "0- +", "0123456789", &ft_signed_conversion, NULL}, - {'i', "0- +", "0123456789", &ft_signed_conversion, NULL}, - {'u', "0-", "0123456789", &ft_unsigned_conversion, NULL}, - {'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o}, - {'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb}, - {'s', "-", "", &ft_str_conversion, NULL}, - {'c', "-", "", &ft_char_conversion, NULL}, -}; - int ft_printf(const char *format, ...) { va_list ap; @@ -44,64 +31,7 @@ int ft_dprintf(int fd, const char *format, ...) int ft_asprintf(char **ret, const char *format, ...) { va_list ap; + va_start(ap, format); return (ft_vasprintf(ret, format, ap)); } - -int ft_vdprintf(int fd, const char *format, va_list ap) -{ - char *ret; - - ret = NULL; - if (ft_vasprintf(&ret, format, ap)) - return (1); - ft_putstr_fd(ret, fd); - ft_strdel(&ret); - return (0); -} - -int ft_vasprintf(char **ret, const char *format, va_list ap) -{ - char *str; - char *tmp; - char *final; - - str = (char *)format; - final = ft_strnew(1); - while (*str) - { - tmp = final; - if (*str == '{') - ft_printf_color(&final, &str, ap); - else if (*str == '%') - { - if (ft_fmtcalc(&final, &str, ap)) - return (1); - } - else - final = ft_strjoin(final, (char[]){*str++, 0}); - ft_strdel(&tmp); - } - *ret = final; - return (0); -} - -int ft_fmtcalc(char **final, char **str, va_list ap) -{ - t_fmt *fmt; - char *transform; - - *str += 1; - if (!(fmt = ft_printf_parse(str, ap))) - return (1); - if (!fmt->valid) - ft_strncat(*final, &fmt->conversion, 1); - else - { - transform = ft_transform(fmt, ap); - *final = ft_strjoin(*final, transform); - ft_strdel(&transform); - } - free(fmt); - return (0); -} diff --git a/42sh/libft/src/ft_printf/ft_printf_color.c b/42sh/libft/src/ft_printf/ft_printf_color.c index d59547b4..85995f46 100644 --- a/42sh/libft/src/ft_printf/ft_printf_color.c +++ b/42sh/libft/src/ft_printf/ft_printf_color.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ -/* Updated: 2017/03/11 14:00:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,11 +40,10 @@ void ft_printf_color(char **final, char **str, va_list ap) *str += 5; return ; } - while(g_colors[i].key) + while (g_colors[i].key) { if (ft_strncmp(*str, g_colors[i].key, 5) == 0) { - /* if (isatty(fd)) */ *final = ft_strjoin(*final, g_colors[i].val); *str += 5; return ; diff --git a/42sh/libft/src/ft_printf/ft_printf_parse.c b/42sh/libft/src/ft_printf/ft_printf_parse.c index e051faea..14797fbf 100644 --- a/42sh/libft/src/ft_printf/ft_printf_parse.c +++ b/42sh/libft/src/ft_printf/ft_printf_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:17:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,4 +121,3 @@ t_fmt *ft_printf_parse(char **format, va_list ap) fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1; return (fmt); } - diff --git a/42sh/libft/src/ft_printf/ft_vprintf.c b/42sh/libft/src/ft_printf/ft_vprintf.c new file mode 100644 index 00000000..330c0fe4 --- /dev/null +++ b/42sh/libft/src/ft_printf/ft_vprintf.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */ +/* Updated: 2017/03/20 15:53:17 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +t_conv g_convs[] = +{ + {'d', "0- +", "0123456789", &ft_signed_conversion, NULL}, + {'i', "0- +", "0123456789", &ft_signed_conversion, NULL}, + {'u', "0-", "0123456789", &ft_unsigned_conversion, NULL}, + {'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o}, + {'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb}, + {'s', "-", "", &ft_str_conversion, NULL}, + {'c', "-", "", &ft_char_conversion, NULL}, +}; + +int ft_vdprintf(int fd, const char *format, va_list ap) +{ + char *ret; + + ret = NULL; + if (ft_vasprintf(&ret, format, ap)) + return (1); + ft_putstr_fd(ret, fd); + ft_strdel(&ret); + return (0); +} + +int ft_vasprintf(char **ret, const char *format, va_list ap) +{ + char *str; + char *tmp; + char *final; + + str = (char *)format; + final = ft_strnew(1); + while (*str) + { + tmp = final; + if (*str == '{') + ft_printf_color(&final, &str, ap); + else if (*str == '%') + { + if (ft_fmtcalc(&final, &str, ap)) + return (1); + } + else + final = ft_strjoin(final, (char[]){*str++, 0}); + ft_strdel(&tmp); + } + *ret = final; + return (0); +} + +int ft_fmtcalc(char **final, char **str, va_list ap) +{ + t_fmt *fmt; + char *transform; + + *str += 1; + if (!(fmt = ft_printf_parse(str, ap))) + return (1); + if (!fmt->valid) + ft_strncat(*final, &fmt->conversion, 1); + else + { + transform = ft_transform(fmt, ap); + *final = ft_strjoin(*final, transform); + ft_strdel(&transform); + } + free(fmt); + return (0); +} diff --git a/42sh/libft/src/ft_printf/lib_pad_sharp.c b/42sh/libft/src/ft_printf/lib_pad_sharp.c index db6fd9c9..5d065581 100644 --- a/42sh/libft/src/ft_printf/lib_pad_sharp.c +++ b/42sh/libft/src/ft_printf/lib_pad_sharp.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,11 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt) void ft_pad_sharp_xb(char *str, t_fmt *fmt) { - char start[3] = {'0',fmt->conversion, 0}; + char start[3]; + start[0] = '0'; + start[1] = fmt->conversion; + start[2] = 0; if (str[0] == '0') { if (str[1] == '0') diff --git a/42sh/libft/src/lst/ft_lstmap.c b/42sh/libft/src/lst/ft_lstmap.c index 3a36ef41..c233eff0 100644 --- a/42sh/libft/src/lst/ft_lstmap.c +++ b/42sh/libft/src/lst/ft_lstmap.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:25:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:06:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/mem/ft_memdel.c b/42sh/libft/src/mem/ft_memdel.c index 52e6508b..59a18066 100644 --- a/42sh/libft/src/mem/ft_memdel.c +++ b/42sh/libft/src/mem/ft_memdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */ -/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:19:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/str/ft_split_whitespaces.c b/42sh/libft/src/str/ft_split_whitespaces.c index 6cba8e7d..4124878a 100644 --- a/42sh/libft/src/str/ft_split_whitespaces.c +++ b/42sh/libft/src/str/ft_split_whitespaces.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */ -/* Updated: 2017/02/03 16:12:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:55:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -char *ft_strdupi_w(char const *s) +char *ft_strdupi_w(char const *s) { int i; char *str; diff --git a/42sh/libft/src/str/ft_strcspn.c b/42sh/libft/src/str/ft_strcspn.c index fe535487..d55d8081 100644 --- a/42sh/libft/src/str/ft_strcspn.c +++ b/42sh/libft/src/str/ft_strcspn.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcspn.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 15:55:33 by jhalford #+# #+# */ +/* Updated: 2017/03/20 16:00:37 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" size_t ft_strcspn(char *s, const char *delim) @@ -5,8 +17,8 @@ size_t ft_strcspn(char *s, const char *delim) char *str; str = s; - while(*str) - if(ft_strchr(delim,*str)) + while (*str) + if (ft_strchr(delim, *str)) return (str - s); else str++; diff --git a/42sh/libft/src/str/ft_stris.c b/42sh/libft/src/str/ft_stris.c index 3fc93a3b..ba809f85 100644 --- a/42sh/libft/src/str/ft_stris.c +++ b/42sh/libft/src/str/ft_stris.c @@ -6,16 +6,16 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/02 15:11:28 by ariard #+# #+# */ -/* Updated: 2017/03/07 11:44:29 by ariard ### ########.fr */ +/* Updated: 2017/03/20 16:01:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_stris(char *str, int (*f)()) +int ft_stris(char *str, int (*f)()) { while (*str) if (!(f)(*str++)) return (0); return (1); -} +} diff --git a/42sh/libft/src/str/ft_strsplit.c b/42sh/libft/src/str/ft_strsplit.c index a44c4ca1..10323439 100644 --- a/42sh/libft/src/str/ft_strsplit.c +++ b/42sh/libft/src/str/ft_strsplit.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */ -/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:10:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static int ft_countwords(char const *s, char c) +static int ft_countwords(char const *s, char c) { if (c == '\0') return ((*s == '\0') ? 0 : 1); @@ -36,9 +36,9 @@ static int get_word_len(char const *str, char c) i++; while (str[i] != c && str[i] != '\0') { - i++; - len++; - } + i++; + len++; + } return (len); } @@ -50,21 +50,21 @@ char **ft_strsplit(char const *s, char c) char **str2; if (!s || !(str2 = (char **)malloc(sizeof(*str2) * - (ft_countwords(s, c) + 1)))) + (ft_countwords(s, c) + 1)))) return (NULL); i = -1; j = 0; while (++i < ft_countwords(s, c)) { - k = 0; - if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) - str2[i] = NULL; - while (s[j] == c) - j++; - while (s[j] != c && s[j]) - str2[i][k++] = s[j++]; - str2[i][k] = '\0'; - } + k = 0; + if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) + str2[i] = NULL; + while (s[j] == c) + j++; + while (s[j] != c && s[j]) + str2[i][k++] = s[j++]; + str2[i][k] = '\0'; + } str2[i] = 0; return (str2); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 3474d32e..63da15d9 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:46:56 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:34:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index e8672cc8..e8c5306a 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/20 14:38:25 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:35:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 32267ccf..d1b714ac 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_and_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:26:32 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:40:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int exec_and_if(t_btree **ast) { - /* t_data *data; */ t_exec *exec; exec = &data_singleton()->exec; @@ -23,24 +22,5 @@ int exec_and_if(t_btree **ast) exec->attrs &= ~EXEC_OR_IF; exec->attrs |= EXEC_AND_IF; ft_exec(&(*ast)->right); - - /* data = data_singleton(); */ - /* if (data->exec.aol_status == NULL */ - /* || (data->exec.aol_search == TK_AND_IF */ - /* && *data->exec.aol_status == '0') */ - /* || (data->exec.aol_search == TK_OR_IF */ - /* && *data->exec.aol_status != '0')) */ - /* { */ - /* ft_exec(&(*ast)->left); */ - /* data->exec.aol_status = ft_getenv(data->env, "?"); */ - /* } */ - /* data->exec.aol_search = TK_AND_IF; */ - /* if (*data->exec.aol_status == '0' */ - /* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */ - /* ft_exec(&(*ast)->right); */ - /* data->exec.aol_status = NULL; */ - /* data->exec.aol_search = 0; */ - -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_bang.c b/42sh/src/exec/exec_bang.c index 3939d1a3..cce5d557 100644 --- a/42sh/src/exec/exec_bang.c +++ b/42sh/src/exec/exec_bang.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 14:46:27 by ariard #+# #+# */ -/* Updated: 2017/03/10 16:25:35 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:41:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int exec_bang(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_BANG); - ft_exec(&(*ast)->left); + ft_exec(&(*ast)->left); ft_exec(&(*ast)->right); set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?")) ? 0 : 1, 1); return (0); diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 9335cdaa..9a618168 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:21:45 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:42:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,19 +18,15 @@ int exec_case_branch(t_btree **ast) char **av; t_exec *exec; - DG("exec branch case"); exec = &data_singleton()->exec; if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); - DG("compare pattern %s ", av[0]); - DG("and case %s", ((char **)exec->case_pattern)[0]); - DG(); if (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0) - { + { exec->attrs |= EXEC_CASE_BRANCH; - ft_exec(&(*ast)->right); + ft_exec(&(*ast)->right); } return (0); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 86881c51..4e71d269 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/20 10:54:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:47:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index 50def42a..5885eb6d 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_or_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:18:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:40:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int exec_or_if(t_btree **ast) { - /* t_data *data; */ t_exec *exec; exec = &data_singleton()->exec; @@ -23,24 +22,5 @@ int exec_or_if(t_btree **ast) exec->attrs &= ~EXEC_AND_IF; exec->attrs = EXEC_OR_IF; ft_exec(&(*ast)->right); - - /* data = data_singleton(); */ - /* if (data->exec.aol_status == NULL */ - /* || (data->exec.aol_search == TK_AND_IF */ - /* && *data->exec.aol_status == '0') */ - /* || (data->exec.aol_search == TK_OR_IF */ - /* && *data->exec.aol_status != '0')) */ - /* { */ - /* ft_exec(&(*ast)->left); */ - /* data->exec.aol_status = ft_getenv(data->env, "?"); */ - /* } */ - /* data->exec.aol_search = TK_OR_IF; */ - /* if (*data->exec.aol_status != '0' */ - /* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */ - /* ft_exec(&(*ast)->right); */ - /* data->exec.aol_status = NULL; */ - /* data->exec.aol_search = 0; */ - -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index 3668da9e..0c015741 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_pipe.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:27:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:42:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,5 @@ int exec_pipe(t_btree **ast) push(&exec->op_stack, TK_PIPE); ft_exec(&(*ast)->left); ft_exec(&(*ast)->right); - /* btree_delone(ast, &ast_free); */ return (0); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 45e91663..161bf6a0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -3,28 +3,37 @@ /* ::: :::::::: */ /* exec_reset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:35:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:09:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int exec_reset(void) +static void print_error(char *std) +{ + ft_dprintf(2, "{red}%s: internal fcntl %s error errno=%i{eoc}\n", + SHELL_NAME, std, errno); +} + +int exec_reset(void) { t_exec *exec; t_jobc *jobc; exec = &data_singleton()->exec; jobc = &data_singleton()->jobc; - if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i{eoc}\n", SHELL_NAME, errno); - if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i{eoc}\n", SHELL_NAME, errno); - if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i{eoc}\n", SHELL_NAME, errno); + if (errno != EBADF) + { + if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDIN"); + if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDOUT"); + if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDERR"); + } exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 9b1136c2..dbeaea7c 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/14 23:55:40 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:43:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,16 +20,16 @@ static int set_var(char *stream, char **var, char **value) return (0); } -int exec_var(t_btree **ast) +int exec_var(t_btree **ast) { t_astnode *node; - char **av; + char **av; char *var; char *value; - + node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); - set_var(av[0], &var, &value); + set_var(av[0], &var, &value); if (ft_getenv(data_singleton()->env, var)) return (0); builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c index e3e954e4..58dc3795 100644 --- a/42sh/src/exec/is_function.c +++ b/42sh/src/exec/is_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ -/* Updated: 2017/03/15 18:57:03 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:07:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 6762e9e7..1e6c0f04 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:40:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:33:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,5 +32,5 @@ int mark_process_status(pid_t pid, int status) return (0); } ft_dprintf(2, "{red}No child process %d.\n", pid); - return (0); + return (1); } diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index c1785a81..b323fee7 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/15 16:48:40 by ariard ### ########.fr */ +/* Updated: 2017/03/20 16:28:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,8 @@ void *node_copy(void *data) new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } - if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE - || old->type == FNAME) + if (old->type == TK_FOR || old->type == TK_PAREN_OPEN + || old->type == TK_CASE || old->type == FNAME) new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/pfree_cmd.c b/42sh/src/exec/pfree_cmd.c index 9715ef1a..2047d654 100644 --- a/42sh/src/exec/pfree_cmd.c +++ b/42sh/src/exec/pfree_cmd.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_cmd.c :+: :+: :+: */ +/* pfree_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:29:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_cond.c b/42sh/src/exec/pfree_cond.c index 2dae0996..69c185e9 100644 --- a/42sh/src/exec/pfree_cond.c +++ b/42sh/src/exec/pfree_cond.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_cond.c :+: :+: :+: */ +/* pfree_cond.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:26:31 by wescande #+# #+# */ -/* Updated: 2017/03/15 02:04:14 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:49:52 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_list.c b/42sh/src/exec/pfree_list.c index ac896c97..22c8a012 100644 --- a/42sh/src/exec/pfree_list.c +++ b/42sh/src/exec/pfree_list.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_list.c :+: :+: :+: */ +/* pfree_list.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:05:43 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:50:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_subshell.c b/42sh/src/exec/pfree_subshell.c index d9968512..1b1357d8 100644 --- a/42sh/src/exec/pfree_subshell.c +++ b/42sh/src/exec/pfree_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_subshell.c :+: :+: :+: */ +/* pfree_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:38:12 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:50:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 791104d8..0406b81e 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_brace.c :+: :+: :+: */ +/* plaunch_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:35:24 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index f4506d45..00215451 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_builtin.c :+: :+: :+: */ +/* plaunch_builtin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:22:12 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 413c2ca8..753d221c 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_case.c :+: :+: :+: */ +/* plaunch_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:17:07 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_empty.c b/42sh/src/exec/plaunch_empty.c index 39173fb8..c550c3c8 100644 --- a/42sh/src/exec/plaunch_empty.c +++ b/42sh/src/exec/plaunch_empty.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_empty.c :+: :+: :+: */ +/* plaunch_empty.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:23:18 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:16 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,4 +17,3 @@ int plaunch_empty(t_process *p) (void)p; return (0); } - diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index 0ec58d4d..d084b35c 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_file.c :+: :+: :+: */ +/* plaunch_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:22:38 by wescande ### ########.fr */ +/* Updated: 2017/03/20 16:29:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int plaunch_file(t_process *p) { if (!p->data.cmd.path) error_launch("command not found: ", p->data.cmd.av[0], 127); - else if (!p->data.cmd.stat) + else if (access(p->data.cmd.path, F_OK) == -1) error_launch(p->data.cmd.av[0], ": no such file or directory", 127); else if (S_ISDIR(p->data.cmd.stat->st_mode)) error_launch(p->data.cmd.av[0], ": is a directory", 126); diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index c7c4d510..21e4f2bc 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/17 20:16:46 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:51:47 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int plaunch_for(t_process *p) av = token_to_argv(temp, 1); while (av[++i]) { - builtin_setenv("setenv", (char*[]){"local" ,var, av[i], 0}, + builtin_setenv("setenv", (char*[]){"local", var, av[i], 0}, NULL); ft_exec(&p->data.d_for.content); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index d312345e..af12c567 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_function.c :+: :+: :+: */ +/* plaunch_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:29:36 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index dccd5209..7b941d54 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_if.c :+: :+: :+: */ +/* plaunch_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:30:36 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_subshell.c b/42sh/src/exec/plaunch_subshell.c index ef8cd15a..980a6232 100644 --- a/42sh/src/exec/plaunch_subshell.c +++ b/42sh/src/exec/plaunch_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_subshell.c :+: :+: :+: */ +/* plaunch_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:28:08 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index 4fe8cadb..d9e55135 100644 --- a/42sh/src/exec/plaunch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_until.c :+: :+: :+: */ +/* plaunch_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/18 01:52:33 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index a98fe146..696059de 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_while.c :+: :+: :+: */ +/* plaunch_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/18 01:48:53 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:29 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 1b5f89ae..4a7c5825 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -3,16 +3,16 @@ /* ::: :::::::: */ /* process_launch.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:57:26 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:58:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int do_the_muther_forker(t_process *p) +int do_the_muther_forker(t_process *p) { pid_t pid; @@ -25,9 +25,8 @@ int do_the_muther_forker(t_process *p) return (pid); if (!p) return (pid); - DG("START OF FORK"); if (process_redirect(p)) - exit (1); + exit(1); process_setgroup(p, 0); process_setsig(); exec_reset(); @@ -51,19 +50,16 @@ static int do_the_fork_if_i_have_to(t_process *p) return (do_the_muther_forker(p)); } -int process_launch(t_process *p) +int process_launch(t_process *p) { pid_t pid; - DG("p->type=%i", p->type); p->state = PROCESS_RUNNING; if (!(pid = do_the_fork_if_i_have_to(p))) { - DG("launcher did not fork!"); process_resetfds(p); return (1); } - DG("launcher forked! with : %d ", pid); p->pid = pid; process_setgroup(p, pid); if (p->fdin != STDIN) diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 7afcb122..b8ac4278 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* process_redirect.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:28:44 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:57:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,36 +23,36 @@ t_itof g_redirmap[] = {0, NULL}, }; -int process_redirect(t_process *p) +static void process_close(int fd1, int fd2) +{ + if (fd1 != fd2) + close(fd1); +} + +int process_redirect(t_process *p) { t_list *redirs; t_redir *redir; int i; redirs = p->redirs; - if (p->to_close != STDIN) - close(p->to_close); + process_close(p->to_close, STDIN); while (redirs) { redir = redirs->content; if (redir->n > 9) return (bad_fd(redir->n)); - i = 0; - while (g_redirmap[i].id) - { + i = -1; + while (g_redirmap[++i].id) if (g_redirmap[i].id == redir->type) { if ((g_redirmap[i].f)(redir)) return (1); break ; } - i++; - } redirs = redirs->next; } - if (p->fdin != STDIN) - dup2_close(p->fdin, STDIN); - if (p->fdout != STDOUT) - dup2_close(p->fdout, STDOUT); + process_close(p->fdin, STDIN); + process_close(p->fdout, STDOUT); return (0); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index b2ce7cfc..2eebdef3 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process.c :+: :+: :+: */ +/* process_set.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:22:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:02:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int process_set(t_process *p, t_btree *ast) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) || (EXEC_IS_OR_IF(exec->attrs) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) - return (1); + return (1); fds[PIPE_WRITE] = STDOUT; fds[PIPE_READ] = STDIN; if (op == TK_PIPE) @@ -69,6 +69,7 @@ int process_set(t_process *p, t_btree *ast) exec->fdin = fds[PIPE_READ]; if (!ast) return (0); - p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); + p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, + &redir_copy); return (process_set_spec(p, ast)); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index b5424a8f..1632df9c 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* process_setgroup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/19 14:04:57 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:58:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,15 +23,10 @@ int process_setgroup(t_process *p, pid_t pid) j = &data->exec.job; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) 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); - /* if (JOB_IS_FG(j->attrs)) */ + ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", + SHELL_NAME, errno); if (pid == 0 && JOB_IS_FG(j->attrs)) - { - DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); - DG("after tcsetpgrp"); - } return (0); } diff --git a/42sh/src/exec/pset_brace.c b/42sh/src/exec/pset_brace.c index a61a3792..226297bb 100644 --- a/42sh/src/exec/pset_brace.c +++ b/42sh/src/exec/pset_brace.c @@ -1,16 +1,15 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_brace.c :+: :+: :+: */ +/* pset_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:07:34 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:29:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:58:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ - #include "minishell.h" int pset_brace(t_process *p, t_btree *ast) diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index 5e373168..8719f5d8 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_case.c :+: :+: :+: */ +/* pset_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:59:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ int pset_case(t_process *p, t_btree *ast) { - DG("set case"); - p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); + p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, + tab_esc_copy); p->data.d_case.content = btree_map(ast->right, &node_copy); p->type = PROCESS_CASE; return (0); diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 3e7f6139..eba06520 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -1,53 +1,40 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_cmd.c :+: :+: :+: */ +/* pset_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:28:38 by jhalford ### ########.fr */ +/* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */ +/* Updated: 2017/03/20 16:28:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int pset_cmd(t_process *p, t_btree *ast) +int pset_cmd(t_process *p, t_btree *ast) { - t_btree *func; + t_btree *func; - if (ast && !(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) - { - p->type = PROCESS_EMPTY; - return (0); - } - p->data.cmd.path = NULL; - p->data.cmd.execf = NULL; - p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); - p->type = PROCESS_FILE; + if (ast && !(p->data.cmd.av = + token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) + return ((p->type = PROCESS_EMPTY) ? 0 : 0); if ((func = is_function(p))) { - btree_print(STDBUG, func, &ft_putast); p->data.function.content = func; p->type = PROCESS_FUNCTION; } else if ((p->data.cmd.execf = is_builtin(p))) p->type = PROCESS_BUILTIN; - else if (ft_strchr(p->data.cmd.av[0], '/')) + else if ((p->type = PROCESS_FILE)) { + p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); p->data.cmd.execf = &execve; - p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - ft_memdel((void**)&p->data.cmd.stat); - } - else if ((p->data.cmd.path = ft_hash(p->data.cmd.av[0]))) - { - p->data.cmd.execf = &execve; - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - { - ft_memdel((void**)&p->data.cmd.stat); - ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); - } + p->data.cmd.path = ft_strchr(p->data.cmd.av[0], '/') ? + ft_strdup(p->data.cmd.av[0]) : ft_hash(p->data.cmd.av[0]); + if (p->data.cmd.path && !access(p->data.cmd.path, F_OK) + && stat(p->data.cmd.path, p->data.cmd.stat) == -1) + return (-1); } return (0); } diff --git a/42sh/src/exec/pset_for.c b/42sh/src/exec/pset_for.c index 19573f9c..c1b14dbb 100644 --- a/42sh/src/exec/pset_for.c +++ b/42sh/src/exec/pset_for.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_for.c :+: :+: :+: */ +/* pset_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:28:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:59:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int pset_for(t_process *p, t_btree *ast) { - p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); + p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, + tab_esc_copy); p->data.d_for.content = btree_map(ast->right, &node_copy); p->type = PROCESS_FOR; return (0); diff --git a/42sh/src/exec/pset_if.c b/42sh/src/exec/pset_if.c index 130af429..af80d078 100644 --- a/42sh/src/exec/pset_if.c +++ b/42sh/src/exec/pset_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_if.c :+: :+: :+: */ +/* pset_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_subshell.c b/42sh/src/exec/pset_subshell.c index e21b35de..7236a58c 100644 --- a/42sh/src/exec/pset_subshell.c +++ b/42sh/src/exec/pset_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_sub.c :+: :+: :+: */ +/* pset_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:28:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_until.c b/42sh/src/exec/pset_until.c index c5b91a3f..df32b275 100644 --- a/42sh/src/exec/pset_until.c +++ b/42sh/src/exec/pset_until.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_until.c :+: :+: :+: */ +/* pset_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:47 by jhalford ### ########.fr */ +/* Created: 2017/03/20 16:26:43 by gwojda #+# #+# */ +/* Updated: 2017/03/20 16:26:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_while.c b/42sh/src/exec/pset_while.c index f8d92c2f..c62b1180 100644 --- a/42sh/src/exec/pset_while.c +++ b/42sh/src/exec/pset_while.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_while.c :+: :+: :+: */ +/* pset_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:31 by jhalford ### ########.fr */ +/* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */ +/* Updated: 2017/03/20 16:26:47 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 5dd758c9..88a86d3a 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/20 12:21:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index 2cc00e05..afae3991 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/20 12:21:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,6 @@ void redir_free(void *data, size_t content_size) if (redir->type == TK_DLESS) ft_strdel(&redir->heredoc_data); redir->type = 0; - redir->n = 0; + redir->n = 0; free(redir); } diff --git a/42sh/src/exec/redirect_dless.c b/42sh/src/exec/redirect_dless.c index 15c16342..54aef89a 100644 --- a/42sh/src/exec/redirect_dless.c +++ b/42sh/src/exec/redirect_dless.c @@ -5,7 +5,8 @@ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Updated: 2017/02/07 16:05:09 by jhalford ### ########.fr */ +/* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */ +/* Updated: 2017/03/20 12:36:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 2298fecc..24506564 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:40:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:38:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int redirect_great(t_redir* redir) +int redirect_great(t_redir *redir) { int fdold; int fdnew; diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 0bd69f59..ee798a6b 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/16 19:07:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:36:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ int redirect_greatand(t_redir *redir) } if (!ft_stris(redir->word, ft_isdigit)) { - ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word); + ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", + data_singleton()->argv[0], redir->word); return (1); } fdold = ft_atoi(redir->word); diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 1a59bf2e..6c4e5c25 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/13 19:22:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:36:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int redirect_less(t_redir *redir) { ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, redir->word); - exit (1); + return (1); } dup2(fdold, fdnew); return (0); diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 1a5ccf64..a5c7efe4 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/15 17:49:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:36:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ int redirect_lessand(t_redir *redir) } if (!ft_stris(redir->word, ft_isdigit)) { - ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word); + ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", + data_singleton()->argv[0], redir->word); return (1); } fdold = ft_atoi(redir->word); diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index f56e71a4..c3f2e8e3 100644 --- a/42sh/src/exec/set_exitstatus.c +++ b/42sh/src/exec/set_exitstatus.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:38:34 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:35:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/token_to_argv.c b/42sh/src/exec/token_to_argv.c index 34547a15..ac355f26 100644 --- a/42sh/src/exec/token_to_argv.c +++ b/42sh/src/exec/token_to_argv.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:55:53 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:24:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:36:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/do_job_notification.c b/42sh/src/job_control/do_job_notification.c index a86208a8..dfcbbdff 100644 --- a/42sh/src/job_control/do_job_notification.c +++ b/42sh/src/job_control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:15:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:23:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,10 +27,11 @@ int do_job_notification(void) { j = jlist->content; jlist = jlist->next; - if ((job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) + if (job_is_completed(j) + || (job_is_stopped(j) && !(j->attrs & JOB_NOTIFIED))) { ret = 1; - job_notify_change(j->id); + job_format(j, JOBS_OPTS_L); j->attrs |= JOB_NOTIFIED; job_remove(j->id); } diff --git a/42sh/src/job_control/job_addprocess.c b/42sh/src/job_control/job_addprocess.c index a72895c0..4a4356d4 100644 --- a/42sh/src/job_control/job_addprocess.c +++ b/42sh/src/job_control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:32:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:16:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_getprocess.c b/42sh/src/job_control/job_getprocess.c index 17eec5d2..d1ad079c 100644 --- a/42sh/src/job_control/job_getprocess.c +++ b/42sh/src/job_control/job_getprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:42:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:18:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_getrank.c b/42sh/src/job_control/job_getrank.c index 8c766f23..3f8797b1 100644 --- a/42sh/src/job_control/job_getrank.c +++ b/42sh/src/job_control/job_getrank.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:10:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:27:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ void job_getrank(int (*rank)[2]) while (jlist && i < 2) { job = jlist->content; - if (job_is_stopped(job->id)) + if (job_is_stopped(job)) (*rank)[i++] = job->id; jlist = jlist->next; } diff --git a/42sh/src/job_control/job_is_completed.c b/42sh/src/job_control/job_is_completed.c index aa20bece..266cabbd 100644 --- a/42sh/src/job_control/job_is_completed.c +++ b/42sh/src/job_control/job_is_completed.c @@ -6,26 +6,22 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:30:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:37:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int job_is_completed(int id) +int job_is_completed(t_job *job) { t_list *lst; - t_job *job; - t_jobc *jobc; t_process *p; - jobc = &data_singleton()->jobc; - job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; lst = job->first_process; while (lst) { p = lst->content; - if (!(p->state == PROCESS_COMPLETED)) + if (p->state != PROCESS_COMPLETED) return (0); lst = lst->next; } diff --git a/42sh/src/job_control/job_is_stopped.c b/42sh/src/job_control/job_is_stopped.c index 8d342c0f..47605f59 100644 --- a/42sh/src/job_control/job_is_stopped.c +++ b/42sh/src/job_control/job_is_stopped.c @@ -6,27 +6,22 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:32:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:36:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int job_is_stopped(int id) +int job_is_stopped(t_job *job) { t_list *lst; - t_job *job; - t_jobc *jobc; t_process *p; - jobc = &data_singleton()->jobc; - job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; lst = job->first_process; while (lst) { p = lst->content; - if (!((p->state == PROCESS_COMPLETED) - || !(p->state == PROCESS_SUSPENDED))) + if (p->state != PROCESS_COMPLETED && p->state != PROCESS_SUSPENDED) return (0); lst = lst->next; } diff --git a/42sh/src/job_control/job_notify_change.c b/42sh/src/job_control/job_notify_change.c index 96c750dc..cc594cc6 100644 --- a/42sh/src/job_control/job_notify_change.c +++ b/42sh/src/job_control/job_notify_change.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:21:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:24:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_notify_new.c b/42sh/src/job_control/job_notify_new.c index dd7068f2..65c56a41 100644 --- a/42sh/src/job_control/job_notify_new.c +++ b/42sh/src/job_control/job_notify_new.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ -/* Updated: 2017/03/17 23:10:47 by wescande ### ########.fr */ +/* Updated: 2017/03/20 14:26:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_remove.c b/42sh/src/job_control/job_remove.c index e054c5c3..00cbb7dc 100644 --- a/42sh/src/job_control/job_remove.c +++ b/42sh/src/job_control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:40:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:31:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,14 @@ void job_remove(int id) if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) return ; j = jlist->content; - if (job_is_completed(id)) + if (job_is_completed(j)) { + DG(); p = ft_lstlast(j->first_process)->content; set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) data_singleton()->jobc.current_id = id; ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); + DG(); } } diff --git a/42sh/src/job_control/job_update_status.c b/42sh/src/job_control/job_update_status.c index c518decb..8e89d64e 100644 --- a/42sh/src/job_control/job_update_status.c +++ b/42sh/src/job_control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:12:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:36:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_wait.c b/42sh/src/job_control/job_wait.c index f6c40b86..2c80369c 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/16 18:01:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:31:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,11 +16,14 @@ int job_wait(int id) { pid_t pid; t_job *j; + t_list *jlist; t_jobc *jobc; int status; jobc = &data_singleton()->jobc; - j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; + if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) + return (-1); + j = jlist->content; while (1) { if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1 @@ -28,8 +31,8 @@ int job_wait(int id) ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno); if (pid <= 1 || mark_process_status(pid, status) - || job_is_stopped(id) - || job_is_completed(id)) + || job_is_stopped(j) + || job_is_completed(j)) break ; } return (0); diff --git a/42sh/src/job_control/process_free.c b/42sh/src/job_control/process_free.c index 29fab3f4..8ffb939d 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/20 11:39:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:55:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/do_lexer_routine.c b/42sh/src/lexer/do_lexer_routine.c index 4958965d..d442c402 100644 --- a/42sh/src/lexer/do_lexer_routine.c +++ b/42sh/src/lexer/do_lexer_routine.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/19 14:24:38 by wescande #+# #+# */ -/* Updated: 2017/03/20 16:42:26 by ariard ### ########.fr */ +/* Updated: 2017/03/20 16:44:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 31701a10..96b29593 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:02:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:00:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ t_lexstate get_state_global(t_lexer *lexer) if ((ft_is_delim(c) && (ret = DELIM)) || ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP)) || ((c == '\\') && (ret = BACKSLASH)) + || ((c == '\n') && (ret = NEWLINE)) || ((c == '\'') && (ret = QUOTE)) || ((c == '\"') && (ret = DQUOTE)) || ((c == '`') && (ret = BQUOTE)) diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index 72b7c47c..4bd59d71 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:09:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:32:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,10 +22,7 @@ int lexer_delim(t_list **alst, t_lexer *lexer) lexer->state = DEFAULT; if (token->type) return (lexer_lex(&(*alst)->next, lexer)); - else - { - if (lexer->str[lexer->pos] == 0) - ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free); - return (lexer_lex(alst, lexer)); - } + if (lexer->str[lexer->pos] == 0) + ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free); + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 9fa00061..da0e33cf 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/19 12:13:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 15:02:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,11 +37,6 @@ int ft_is_delim(char c) return (c == ' ' || c == '\t'); } -int ft_is_delim_list(char c) -{ - return (c == ';' || c == '\n' || c == '&'); -} - int lexer_lex(t_list **alst, t_lexer *lexer) { t_token *token; diff --git a/42sh/src/lexer/lexer_newline.c b/42sh/src/lexer/lexer_newline.c index b2256091..840acc6a 100644 --- a/42sh/src/lexer/lexer_newline.c +++ b/42sh/src/lexer/lexer_newline.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ -/* Updated: 2017/03/03 18:00:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:25:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,18 +16,10 @@ int lexer_newline(t_list **alst, t_lexer *lexer) { t_token *token; - if (*alst) - { - token = (*alst)->content; - if (*token->data) - return (lexer_newline(&(*alst)->next, lexer)); - } - else - { - token = token_init(); - *alst = ft_lstnew(token, sizeof(*token)); - } token = (*alst)->content; + if (token->type) + return (lexer_lex(&(*alst)->next, lexer)); + lexer->pos++; token->type = TK_NEWLINE; return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index b3f4fcf9..b7a5c67f 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:21:30 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:23:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c index 3ee2de29..8022dbfe 100644 --- a/42sh/src/parser/add_number.c +++ b/42sh/src/parser/add_number.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ -/* Updated: 2017/03/16 17:56:16 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:39:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */