diff --git a/42sh/Makefile b/42sh/Makefile index 846b7184..8f8e4c79 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/19 15:14:11 by gwojda ### ########.fr # +# Updated: 2017/03/20 12:04:31 by wescande ### ########.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) @@ -40,6 +40,7 @@ builtin/builtin_hash.c\ builtin/builtin_history.c\ builtin/builtin_math.c\ builtin/builtin_read.c\ +builtin/builtin_return_status.c\ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ @@ -302,7 +303,8 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make $(NAME) + @make -C $(LIBFT_DIR) + @make -j $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(OBJS) -o $(NAME) \ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index cc50725e..c95f8067 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ -/* Updated: 2017/03/17 18:59:55 by ariard ### ########.fr */ +/* Updated: 2017/03/20 12:51:23 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ # define BT_EXPORT_LP (1 << 0) t_execf *is_builtin(t_process *p); +int builtin_return_status(int ret, int status); int builtin_export(const char *path, char *const av[], char *const envp[]); int builtin_unset(const char *path, char *const av[], char *const envp[]); int builtin_env(const char *path, char *const argv[], char *const envp[]); diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index c40d11e4..8526ef14 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_read.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/15 19:13:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:34:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,18 @@ typedef struct s_readopt t_readopt; struct s_read { - t_flag opts; - char **names; - char delim; - int nchars; - char *prompt; - int timeout; - int fd; - char *input; + t_flag opts; + char **names; + char delim; + int nchars; + char *prompt; + int timeout; + int fd; + char *input; }; -int builtin_read(const char *path, char *const av[], char *const envp[]); +int builtin_read(const char *path, char *const av[], + char *const envp[]); int bt_read_init(t_read *data, char **av); diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 1df5ef0e..0ba4f1ea 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 14:05:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:34:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -140,6 +140,7 @@ struct s_exec }; int exec_reset(void); +int do_the_muther_forker(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); diff --git a/42sh/includes/ft_curs.h b/42sh/includes/ft_curs.h index 94b1a6bd..d411b2c5 100644 --- a/42sh/includes/ft_curs.h +++ b/42sh/includes/ft_curs.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */ -/* Updated: 2017/03/15 18:47:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:33:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ typedef struct s_curs t_curs; ** Cursor data : cursor's coordonate and windows size */ -struct s_curs +struct s_curs { int co; int li; @@ -79,6 +79,6 @@ void curs_write(t_curs *curs, char *str, size_t len); void curs_write_static(t_curs *curs, char *str, size_t len); void curs_video_write(t_curs *curs, char *str, size_t len); void curs_video_write_static( - t_curs *curs, char *str, size_t len); + t_curs *curs, char *str, size_t len); #endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 4282c854..9d78c82b 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 12:32:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,9 +57,6 @@ # define CORRUPT 1 -//# define STR data_singleton()->line.input -//# define POS data_singleton()->line.pos - # define ERROR_CNTL_R 1 typedef struct s_list_history diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 983ac789..88e6d434 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 15:10:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:34:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,9 +61,6 @@ struct s_rvwords int type; }; -/* extern t_rvwords g_rvwords[]; */ -/* extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); */ - int ft_post_tokenize(t_list **alst, char **str); t_token *token_init(); @@ -79,7 +76,8 @@ void token_print(t_list *lst); int reduce_parens(t_list **alst, char *str); int bquotes_expand(t_list **alst); -char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode); +char *command_getoutput(char *command); +int command_setoutput(char *const av[], char **env); int ft_is_delim(char c); int ft_is_delim_list(char c); diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 415c540f..638a8571 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/18 14:15:35 by gwojda ### ########.fr # +# Updated: 2017/03/20 12:05:06 by wescande ### ########.fr # # # # **************************************************************************** # @@ -207,7 +207,7 @@ all: $(NAME): $(OBJ_DIR) $(OBJS) @$(AR) $(NAME) $(OBJS) @ranlib $(NAME) - @strip -x $(NAME) + @# @strip -x $(NAME) @printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n" $(OBJ_DIR)%.o: $(SRC_DIR)%.c | $(OBJ_DIR) diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index 0ba68f65..2fb1d5f1 100644 --- a/42sh/src/builtin/bt_read_term.c +++ b/42sh/src/builtin/bt_read_term.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* bt_read_term.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 21:23:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:23:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ struct termios bt_read_term(int init) return (term); } -int bt_read_terminit(t_read *data) +int bt_read_terminit(t_read *data) { struct termios term; @@ -39,7 +39,7 @@ int bt_read_terminit(t_read *data) return (0); } -int bt_read_exit(t_read *data) +int bt_read_exit(t_read *data) { struct termios term; diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index d8f46e2e..29bd507e 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/16 14:17:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:54:02 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,14 +81,14 @@ int builtin_cd(const char *path, opts = CDOPT_L; i = builtin_cd_opts(av, &opts); if (!(target = builtin_cd_special(av + i, envp))) - return (1); + return (builtin_return_status(0, 1)); cwd = getcwd(NULL, 0); builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp); free(cwd); if (chdir(target)) { ft_dprintf(2, CDERR_1, target); - return (1); + return (builtin_return_status(0, 1)); } else if (target != av[i]) ft_printf("%s\n", target); @@ -97,5 +97,5 @@ int builtin_cd(const char *path, free(cwd); if (!ft_strcmp(*(av + i), "-")) free(target); - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_echo.c b/42sh/src/builtin/builtin_echo.c index 2fd4f3de..57dd30bd 100644 --- a/42sh/src/builtin/builtin_echo.c +++ b/42sh/src/builtin/builtin_echo.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:21:41 by jhalford #+# #+# */ -/* Updated: 2017/01/20 00:10:31 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:40:00 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,5 +25,5 @@ int builtin_echo(const char *path, char *const av[], char *const envp[]) ft_putchar(' '); } ft_putchar('\n'); - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index b6fc4c3b..400e0022 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,23 +6,24 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ -/* Updated: 2017/03/19 17:43:24 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:02:31 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define US_ENV "env [-i] [-u name] [name=value]... [utility [argument...]]" -static int env_usage(int arg_miss, char c) +static int env_usage(int arg_miss, char c) { if (arg_miss) ft_dprintf(2, "{red}env: option requires an argument -- u{eoc}\n"); else if (c) ft_dprintf(2, "{red}env: illegal option -- %c{eoc}\n", c); - ft_dprintf(2, "usage: env [-i] [-u name] ... [name=value] ... cmd\n"); + ft_dprintf(2, "usage: %s\n", US_ENV); return (1); } -static void env_freeone(char **env, char *arg) +static void env_freeone(char **env, char *arg) { int i; char *tmp; @@ -45,7 +46,7 @@ static void env_freeone(char **env, char *arg) } } -static void env_replace(char ***custom_env, char *arg) +static void env_replace(char ***custom_env, char *arg) { char **arg_split; @@ -57,7 +58,7 @@ static void env_replace(char ***custom_env, char *arg) *custom_env = ft_sstradd(*custom_env, arg); } -static int env_treat_flag(char ***custom_env, char *const *arg[]) +static int env_treat_flag(char ***custom_env, char *const *arg[]) { while (*(++*arg)) { @@ -86,18 +87,21 @@ static int env_treat_flag(char ***custom_env, char *const *arg[]) return (0); } -int builtin_env(const char *path, char *const argv[], char *const envp[]) +int builtin_env(const char *path, + char *const argv[], char *const envp[]) { char **env; + pid_t pid; (void)path; + pid = 0; if (!argv || ft_strcmp(*argv, "env")) - return (env_usage(0, 0)); + return (builtin_return_status(0, env_usage(0, 0))); env = ft_sstrdup((char **)envp); if (env_treat_flag(&env, &argv)) { ft_sstrfree(env); - return (1); + return (builtin_return_status(0, 1)); } if (!*argv) { @@ -106,7 +110,7 @@ int builtin_env(const char *path, char *const argv[], char *const envp[]) ft_putchar('\n'); } else - command_getoutput(NULL, argv, env, 0); + pid = command_setoutput(argv, env); ft_tabdel(&env); - return (0); + return (builtin_return_status(pid, 0)); } diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index f64c4a15..2e56a7d5 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:37:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:17:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,10 +30,8 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) data_singleton()->argv[0]); return (0); } - if (av && av[1]) - status = ft_atoi(av[1]); - else - status = ft_atoi(ft_getenv(data_singleton()->env, "?")); + status = (av && av[1]) ? + ft_atoi(av[1]) : ft_atoi(ft_getenv(data_singleton()->env, "?")); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); job_hup_all(); diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index 36772cf9..4eee266a 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ -/* Updated: 2017/03/18 11:46:32 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:44:02 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static t_cliopts export_opts[] = +static t_cliopts g_export_opts[] = { {'p', NULL, BT_EXPORT_LP, 0, NULL}, {0, NULL, 0, 0, NULL}, @@ -44,25 +44,22 @@ int builtin_export( (void)envp; (void)path; data.flag = 0; - if (cliopts_get((char**)av, export_opts, &data)) + if (cliopts_get((char**)av, g_export_opts, &data)) ft_perror(); if (data.flag & BT_EXPORT_LP) - return (bt_export_print()); + return (builtin_return_status(0, bt_export_print())); av = data.av_data; while (*av) { - if ((equal = ft_strchr(*av, '='))) - { + equal = ft_strchr(*av, '='); + if (equal) *equal = 0; - builtin_setenv("internal", (char*[]){"global", *av, equal + 1}, NULL); - } else - { equal = ft_getenv(data_singleton()->local_var, *av); - builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); - } + equal ? equal++ : equal; + builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL); av++; } - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_hash.c b/42sh/src/builtin/builtin_hash.c index f030a63d..539f04b5 100644 --- a/42sh/src/builtin/builtin_hash.c +++ b/42sh/src/builtin/builtin_hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 16:37:43 by gwojda #+# #+# */ -/* Updated: 2017/02/18 16:51:43 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:03:30 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,8 +43,8 @@ int builtin_hash(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; - if (ft_hash_opt(av)) - return (0); + if (!av || ft_hash_opt(av)) + return (builtin_return_status(0, 1)); i = 0; while (i < MAX_HASH) { @@ -52,5 +52,5 @@ int builtin_hash(const char *path, char *const av[], char *const envp[]) ft_hash_lst_print(g_hash[i]); ++i; } - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_history.c b/42sh/src/builtin/builtin_history.c index 0c653fbd..7d66d2b0 100644 --- a/42sh/src/builtin/builtin_history.c +++ b/42sh/src/builtin/builtin_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */ -/* Updated: 2017/02/20 20:30:18 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:04:02 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int builtin_history(const char *path, char *const av[], char *const envp[]) head = data_singleton()->line.list_end; len = 1; if (!head) - return (0); + return (builtin_return_status(0, 0)); if (head && !head->str) head = head->next; while (head && head->str) @@ -34,5 +34,5 @@ int builtin_history(const char *path, char *const av[], char *const envp[]) ++len; head = head->next; } - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 589b009a..c6658e9d 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,26 +6,26 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:59:42 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:45:09 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -# define MATHERR_0 "math : invalid number of arguments\n" -# define MATHERR_1 "math : invalid variable name\n" -# define MATHERR_2 "math : invalid operator\n" -# define MATHERR_3 "math : invalid operand\n" -# define MATHERR_4 "math : division by 0\n" +#define MATHERR_0 "math : invalid number of arguments\n" +#define MATHERR_1 "math : invalid variable name\n" +#define MATHERR_2 "math : invalid operator\n" +#define MATHERR_3 "math : invalid operand\n" +#define MATHERR_4 "math : division by 0\n" static int error_msg(char *msg) { ft_dprintf(2, "{red}%s{eoc}", msg); - return (-1); + return (1); } static int init_math(char **var, char **value, char **operator, - char **operand) + char **operand) { *var = NULL; *value = NULL; @@ -38,78 +38,77 @@ static int get_value(char *var, char **value) { char *temp; char *esc; - int ret; + int ret; esc = ft_strnew((ft_strlen(var) >> 3) + 1); ret = word_is_assignment((char *[]) {var, (esc + 1)}); ft_strdel(&esc); if (!ret) return (error_msg(MATHERR_1)); - temp = ft_sstrstr(data_singleton()->local_var, var); - if (temp) - { - temp += ft_strlenchr(temp, '=') + 1; - *value = ft_strdup(temp); - if (!(ft_stris(*value, &ft_isdigit))) - { - ft_strdel(value); - *value = ft_itoa(0); - } - } - else - *value = ft_itoa(0); - return (0); + temp = ft_sstrstr(data_singleton()->local_var, var); + if (temp) + { + temp += ft_strlenchr(temp, '=') + 1; + *value = ft_strdup(temp); + if (!(ft_stris(*value, &ft_isdigit))) + { + ft_strdel(value); + *value = ft_itoa(0); + } + } + else + *value = ft_itoa(0); + return (0); } static int do_math(char **value, char *operator, char *operand) { - long ope1; - long ope2; + long ope1; + long ope2; - ope1 = ft_atoi(*value); - if (operand) - ope2 = ft_atoi(operand); - else - ope2 = 0; - if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) - return (error_msg(MATHERR_4)); - else - { - ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; - ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; - ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; - ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; - ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; - } - ft_strdel(value); - *value = ft_itoa(ope1); - return (0); + ope1 = ft_atoi(*value); + if (operand) + ope2 = ft_atoi(operand); + else + ope2 = 0; + if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) + return (error_msg(MATHERR_4)); + else + { + ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; + ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; + ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; + ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; + ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; + } + ft_strdel(value); + *value = ft_itoa(ope1); + return (0); } int builtin_math(const char *path, char *const av[], char *const envp[]) { - char *var; - char *value; - char *operator; - char *operand; + char *var; + char *value; + char *operator; + char *operand; - (void)path; - (void)envp; - if (!av || !av[1] || !av[2] || !av[3] || av[4]) - return (error_msg(MATHERR_0)); - init_math(&var, &value, &operator, &operand); - var = av[1]; - if (get_value(var, &value) == -1) - return (-1); - operator = av[2]; - if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' - || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) - return (error_msg(MATHERR_2)); - operand = av[3]; - if (!ft_stris(operand, &ft_isdigit)) - return (error_msg(MATHERR_3)); - if (do_math(&value, operator, operand) == -1) - return (-1); - builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); - return (0); + (void)path; + (void)envp; + if (!av || !av[1] || !av[2] || !av[3] || av[4]) + return (builtin_return_status(0, error_msg(MATHERR_0))); + init_math(&var, &value, &operator, &operand); + var = av[1]; + if (get_value(var, &value)) + return (builtin_return_status(0, 1)); + operator = av[2]; + if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0]))) + return (builtin_return_status(0, error_msg(MATHERR_2))); + operand = av[3]; + if (!ft_stris(operand, &ft_isdigit)) + return (builtin_return_status(0, error_msg(MATHERR_3))); + if (do_math(&value, operator, operand)) + return (builtin_return_status(0, 1)); + builtin_setenv("setenv", (char *[]){"local", var, value, 0}, NULL); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index fa82f165..63da15d9 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -3,14 +3,16 @@ /* ::: :::::::: */ /* builtin_read.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:41:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:34:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define US_READ "read [-ers] [-u fd] [-t timeout] [-p prompt]" +#define US_READ_1 "[-n nchars] [-d delim] [name ...]" t_cliopts g_read_opts[] = { @@ -26,8 +28,7 @@ t_cliopts g_read_opts[] = void bt_read_usage(void) { - ft_dprintf(2, "{red}read: usage: read [-ers] [-u fd] [-t timeout]"); - ft_dprintf(2, " [-p prompt] [-n nchars] [-d delim] [name ...]{eoc}\n"); + ft_dprintf(2, "usage: read %s %s\n", US_READ, US_READ_1); } int bt_read_init(t_read *data, char **av) @@ -40,13 +41,13 @@ int bt_read_init(t_read *data, char **av) data->timeout = 0; data->input = NULL; if ((cliopts_get(av, g_read_opts, data))) - return(ft_perror() ? 2 : 2); + return (ft_perror() ? 2 : 2); if (bt_read_terminit(data) < 0) return (-1); return (0); } -int bt_read_loop(t_read *data) +int bt_read_loop(t_read *data) { int i; int esc; @@ -74,7 +75,7 @@ int bt_read_loop(t_read *data) return (0); } -int bt_read_assign(t_read *data) +int bt_read_assign(t_read *data) { char *input; char **names; @@ -97,7 +98,7 @@ int bt_read_assign(t_read *data) return (0); } -int builtin_read(const char *path, char *const av[], char *const envp[]) +int builtin_read(const char *path, char *const av[], char *const envp[]) { t_read data; int ret; @@ -117,5 +118,5 @@ int builtin_read(const char *path, char *const av[], char *const envp[]) bt_read_usage(); if (ret != 2) bt_read_exit(&data); - return (ret); + return (builtin_return_status(0, ret)); } diff --git a/42sh/src/builtin/builtin_return_status.c b/42sh/src/builtin/builtin_return_status.c new file mode 100644 index 00000000..c6dfaf8f --- /dev/null +++ b/42sh/src/builtin/builtin_return_status.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_return_status.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 12:48:04 by wescande #+# #+# */ +/* Updated: 2017/03/20 12:49:18 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int builtin_return_status(int ret, int status) +{ + set_exitstatus(status, 1); + return (ret); +} diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index dd852ce7..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 12:57:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:35:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,10 +39,9 @@ int builtin_setenv(const char *path, { char ***env; - (void)envp; (void)path; if (!av || !av[0]) - return (1); + return (builtin_return_status(0, 1)); if (ft_strcmp(av[0], "local") == 0) env = &data_singleton()->local_var; else @@ -53,6 +52,6 @@ int builtin_setenv(const char *path, ft_putchar('\n'); } else - return (assign_var(av, env)); - return (0); + assign_var(av, env); + return (envp ? builtin_return_status(0, 0) : 0); } diff --git a/42sh/src/builtin/builtin_unset.c b/42sh/src/builtin/builtin_unset.c index c3afa192..d335e53e 100644 --- a/42sh/src/builtin/builtin_unset.c +++ b/42sh/src/builtin/builtin_unset.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:43:34 by gwojda #+# #+# */ -/* Updated: 2017/02/15 11:58:22 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:27:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,5 +14,13 @@ int builtin_unset(const char *path, char *const av[], char *const envp[]) { + char *tmp; + char **av_tmp; + + tmp = av[0]; + av_tmp = (char **)av; + av_tmp[0] = "local"; + builtin_unsetenv(path, av, envp); + av_tmp[0] = tmp; return (builtin_unsetenv(path, av, envp)); } diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/src/builtin/builtin_unsetenv.c index 02896fa6..5275a6ff 100644 --- a/42sh/src/builtin/builtin_unsetenv.c +++ b/42sh/src/builtin/builtin_unsetenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */ -/* Updated: 2017/03/18 11:47:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:40:05 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,5 +35,5 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[]) } i++; } - return (0); + return (builtin_return_status(0, 0)); } diff --git a/42sh/src/completion/c_match.c b/42sh/src/completion/c_match.c index 06440ac5..4df444b5 100644 --- a/42sh/src/completion/c_match.c +++ b/42sh/src/completion/c_match.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/19 15:34:38 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:41:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ static int c_chevron(t_comp *c) pos = c->ircmd; if (pos >= ft_strlen(c->rcmd)) - pos = ft_strlen(c->rcmd) - (ft_strlen(data_singleton()->line.input) - pos); + pos = ft_strlen(c->rcmd) - (ft_strlen(data_singleton()->line.input) + - pos); while (pos) { if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 4bd9d9bc..1b5f89ae 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,27 +6,16 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:35:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:57:26 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" - int do_the_muther_forker(t_process *p) { pid_t pid; - if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) - { - if (process_redirect(p)) - { - set_exitstatus(1, 1); - return (0); - } - set_exitstatus(p->map.launch(p), 1); - return (0); - } if ((pid = fork()) == -1) { ft_dprintf(3, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); @@ -34,6 +23,8 @@ int do_the_muther_forker(t_process *p) } else if (pid) return (pid); + if (!p) + return (pid); DG("START OF FORK"); if (process_redirect(p)) exit (1); @@ -45,13 +36,28 @@ int do_the_muther_forker(t_process *p) exit(p->map.launch(p)); } +static int do_the_fork_if_i_have_to(t_process *p) +{ + if (IS_PIPESINGLE(*p) + && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) + { + if (process_redirect(p)) + { + set_exitstatus(1, 1); + return (0); + } + return (p->map.launch(p)); + } + return (do_the_muther_forker(p)); +} + int process_launch(t_process *p) { pid_t pid; DG("p->type=%i", p->type); p->state = PROCESS_RUNNING; - if (!(pid = do_the_muther_forker(p))) + if (!(pid = do_the_fork_if_i_have_to(p))) { DG("launcher did not fork!"); process_resetfds(p); diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index fb3d8fb3..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 12:58:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:35:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,6 @@ void set_exitstatus(int status, int override) } } astatus = ft_itoa(exitval); - builtin_setenv("setenv", (char*[]){"setenv", "?", astatus, 0}, - data_singleton()->env); + builtin_setenv("setenv", (char*[]){"setenv", "?", astatus, 0}, NULL); ft_strdel(&astatus); } diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 7a3f387f..f51688a7 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/19 17:42:45 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:10:40 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,11 +49,12 @@ static char *manage_command(char *const av_cmd[]) return (command); } -static void execute_command(char *command, char *const av[], char **env) +static void execute_command(char *const av[], char **env) { t_list *token; t_btree *ast; t_data *data; + char *command; token = NULL; ast = NULL; @@ -61,7 +62,7 @@ static void execute_command(char *command, char *const av[], char **env) data->env = env; data->opts &= ~SH_INTERACTIVE; data->opts &= ~SH_OPTS_JOBC; - command = command ? command : manage_command(av); + command = manage_command(av); DG("command is %s", command); if (do_lexer_routine(&token, command)) { @@ -78,27 +79,37 @@ static void execute_command(char *command, char *const av[], char **env) exit(data_singleton()->parser.state == SUCCESS && ft_exec(&ast) < 0); } -char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode) +char *command_getoutput(char *command) { int ret; int pid; int fds[2]; + char **av; - if (!command && !av) + if (!command) return (NULL); - if (pipe_mode) - pipe(fds); - if (!(pid = fork())) + pipe(fds); + if (!(pid = do_the_muther_forker(NULL))) { - if (pipe_mode) - { - close(fds[PIPE_READ]); - dup2_close(fds[PIPE_WRITE], STDOUT); - } - execute_command(command, av, env); + close(fds[PIPE_READ]); + dup2_close(fds[PIPE_WRITE], STDOUT); + av = ft_sstradd(NULL, data_singleton()->argv[0]); + av = ft_sstradd(av, "-c"); + av = ft_sstradd(av, command); + execve(data_singleton()->argv[0], av, data_singleton()->env); + exit(1); } waitpid(pid, &ret, WUNTRACED); - if (pipe_mode) - return (manage_output(fds)); - return (NULL); + return (manage_output(fds)); +} + +int command_setoutput(char *const av[], char **env) +{ + int pid; + + if (!av) + return (0); + if (!(pid = do_the_muther_forker(NULL))) + execute_command(av, env); + return (pid); } diff --git a/42sh/src/glob/expand_bquote.c b/42sh/src/glob/expand_bquote.c index 5a97fcb4..22f265f5 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/19 17:33:11 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:10:32 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ static char *get_output(char *command) char *output; int len; - if (!(output = command_getoutput(command, NULL, data_singleton()->env, 1))) + if (!(output = command_getoutput(command))) return (NULL); len = ft_strlen(output); while (output[--len] == '\n') @@ -80,18 +80,6 @@ static char *get_output(char *command) return (output); } -static char *treat_str(t_bquote *me, char *sta) -{ - if (sta && *me->str == '\n' - && !is_char_esc(me->esc, CH(*me->wk)[0], me->str)) - *me->str = ';'; - if (sta && *me->str == '\n' - && is_char_esc(me->esc, CH(*me->wk)[0], me->str)) - *me->str = ' '; - return (*me->str == '`' && !sta - && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta); -} - static int search_bquote(t_bquote *me) { char *sta; @@ -100,7 +88,8 @@ static int search_bquote(t_bquote *me) sta = NULL; while (*(++me->str)) { - sta = treat_str(me, sta); + sta = *me->str == '`' && !sta + && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta; if (sta && *me->str == '`' && me->str != sta && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str)) { diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 69c3a8a0..6c16b270 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/18 14:29:15 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ static void ft_clear_prompt(size_t *pos, size_t srch_pos) ft_puttermcaps("cd"); } -static int ft_surch_and_realloc(char **str, char **str_srch, +static int search(char **str, char **str_srch, int ret, size_t *srch_pos) { if (!(*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos))) @@ -51,7 +51,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos) } } -static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, +static int ft_modify_str(char *str_srch, size_t srch_pos, char **str, size_t *pos) { ft_clear_prompt(pos, srch_pos); @@ -63,6 +63,7 @@ static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, ft_get_next_str(*str, pos); } free(str_srch); + return (0); } int ft_surch_in_history(char **str, size_t *pos) @@ -79,9 +80,8 @@ int ft_surch_in_history(char **str, size_t *pos) ft_give_new_prompt(str_srch, srch_pos); ret = 0; read(0, &ret, sizeof(int)); - if (ft_isprint(ret) && - ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0) - return (-1); + if (ft_isprint(ret) && search(str, &str_srch, ret, &srch_pos) < 0) + return (-1); else if (!ft_isprint(ret) && ret == 127 && srch_pos) { --srch_pos; @@ -92,6 +92,5 @@ int ft_surch_in_history(char **str, size_t *pos) else if (ret != 127 && !ft_isprint(ret)) break ; } - ft_modify_str(str_srch, srch_pos, str, pos); - return (0); + return (ft_modify_str(str_srch, srch_pos, str, pos)); } diff --git a/42sh/src/job_control/builtin_fg.c b/42sh/src/job_control/builtin_fg.c index dfbe6104..74258367 100644 --- a/42sh/src/job_control/builtin_fg.c +++ b/42sh/src/job_control/builtin_fg.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_fg.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:12:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:42:22 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) return (-1); } jobc = &data_singleton()->jobc; - job_getrank(&rank); + job_getrank(&rank); if (av[1] ? (id = *av[1]) : 0) { if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 4bb37745..cbbc9438 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/20 09:57:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:49:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,11 @@ int readline(int has_prompt, char **input) if (!has_prompt) data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - return ((ret = get_next_line(data_singleton()->fd, input)) >= 0 ? !ret : ret); + { + if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) + return (!ret); + return (ret); + } readline_init(has_prompt); ret = ft_read_stdin(input); if (ret < 0) @@ -30,6 +34,7 @@ int readline(int has_prompt, char **input) ft_putchar('\n'); if (has_prompt) ret = ft_history_parsing(has_prompt, input); + ft_strdel(&data_singleton()->line.copy_tmp); if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1) return (-1); return (ret); diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index 566a1c23..d62a3ddb 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/18 15:43:07 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:44:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ void data_exit(void) t_data *data; data = data_singleton(); - /* ft_strdel(&data->line.input); */ ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); diff --git a/42sh/src/main/data_singleton.c b/42sh/src/main/data_singleton.c index 4dc9731c..31512ede 100644 --- a/42sh/src/main/data_singleton.c +++ b/42sh/src/main/data_singleton.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */ -/* Updated: 2017/03/16 15:12:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:45:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_data *data_singleton() +t_data *data_singleton(void) { static t_data *data = NULL; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index b76b695f..f5f5a4d6 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Updated: 2017/03/17 10:51:23 by gwojda ### ########.fr */ +/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ +/* Updated: 2017/03/20 14:46:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_readline_routine(char **stream) +static int do_readline_routine(char **stream) { int ret; int has_prompt; @@ -55,7 +56,7 @@ static int handle_instruction(t_list **token, t_btree **ast) return (0); } -int main(int ac, char **av) +int main(int ac, char **av) { int ret; t_data *data; @@ -67,7 +68,7 @@ int main(int ac, char **av) DG("{inv}{bol}{gre}start of shell{eoc}"); if (shell_init(ac, av) != 0) return (1); - DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); + DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts) ? "ON" : "OFF"); token = NULL; ast = NULL; data = data_singleton(); diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 5e1af3c5..0dc2c0f3 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/20 11:30:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:54:28 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ static t_cliopts g_opts[] = {0, 0, 0, 0, 0}, }; -int get_c_arg(char ***av, t_data *data) +int get_c_arg(char ***av, t_data *data) { if (!av || !*av) return (1); @@ -28,7 +28,7 @@ int get_c_arg(char ***av, t_data *data) return (0); } -static int get_input_fd(t_data *data) +static int get_input_fd(t_data *data) { static int fds[2] = {-1, STDIN}; char *file; @@ -47,7 +47,8 @@ static int get_input_fd(t_data *data) ft_printf("{red}%s: %s: No such file or directory\n{eoc}", data->argv[0], file); else if (S_ISDIR(buf.st_mode)) - ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], file); + ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], + file); else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0) ft_printf("{red}%s: %s: No such file or directory\n{eoc}", data->argv[0], file); @@ -115,7 +116,7 @@ int shell_init(int ac, char **av) if ((data->fd = get_input_fd(data)) < 0) return (-1); DG(); - if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) + if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) return (-1); return (0); } diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 5b70e8da..22bbb97e 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/18 15:50:28 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:57:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,16 +41,16 @@ int add_subshell_cmd(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; if ((token->type == SUBSHELL && node->type == SUBSHELL) - || (token->type == TK_LBRACE && node->type == TK_LBRACE)) - node->nest++; + || (token->type == TK_LBRACE && node->type == TK_LBRACE)) + node->nest++; if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL) - || (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0) + || (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0) node->nest--; else if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL - && node->nest == 0) + && node->nest == 0) return ((node->full = 1)); else if (token->type == TK_RBRACE && node->type == TK_LBRACE - && node->nest == 0) + && node->nest == 0) return ((node->full = 1)); return (add_cmd(&(*ast)->right, lst)); } diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index af8a85d7..c6ad591b 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/15 16:33:57 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:59:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -char *read_state(t_sym current) +char *read_state(t_sym current) { if (current == FNAME) return ("FNAME"); @@ -131,7 +131,7 @@ char *read_state(t_sym current) if (current == TK_DONE) return ("TK_DONE"); if (current == AND_OR_MINOR) - return("AND_OR_MINOR"); + return ("AND_OR_MINOR"); if (current == AND_OR_MAJOR) return ("AND_OR_MAJOR"); if (current == TK_COMMAND) @@ -227,7 +227,6 @@ int ft_read_stack(t_sym *stack) return (0); } - int ft_show_heredoc_data(t_astnode *node) { t_redir *redir; diff --git a/42sh/src/parser/sym_free.c b/42sh/src/parser/sym_free.c index 200be9ba..b26c2144 100644 --- a/42sh/src/parser/sym_free.c +++ b/42sh/src/parser/sym_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/18 17:13:31 by ariard #+# #+# */ -/* Updated: 2017/03/18 17:15:11 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:57:58 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,4 +19,4 @@ void sym_free(void *data, size_t size) (void)size; sym = data; free(sym); -} +}