diff --git a/42sh/Makefile b/42sh/Makefile index 76d15b32..e77f118d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/14 21:59:22 by ariard ### ########.fr # +# Updated: 2017/03/15 18:11:31 by jhalford ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -g +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) @@ -30,7 +30,6 @@ OBJ_DIR = objs/ SRC_BASE = \ builtin/bt_read_get.c\ -builtin/bt_read_parse.c\ builtin/bt_read_term.c\ builtin/builtin_cd.c\ builtin/builtin_echo.c\ @@ -264,7 +263,6 @@ line-editing/print_and_del.c\ line-editing/queue.c\ line-editing/readline.c\ line-editing/resize.c\ -main/content_free.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ @@ -310,6 +308,7 @@ $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(LIBS) \ $(LIBFT_LIB) \ $(FLAGS) $(D_FLAGS) + @strip -x $@ @printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n" $(LIBFT_LIB): diff --git a/42sh/auteur b/42sh/auteur new file mode 100644 index 00000000..127f9bf3 --- /dev/null +++ b/42sh/auteur @@ -0,0 +1,5 @@ +alao +ariard +gwojda +jhalford +wescande diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index faa35a15..20c0be86 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/15 00:48:28 by ariard ### ########.fr */ +/* Updated: 2017/03/15 21:55:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,12 @@ # define BT_EXPORT_LP (1 << 0) +# define MATHERR_0 "{red}math : invalid number of arguments{eoc}\n" +# define MATHERR_1 "{red}math : invalid variable name{eoc}\n" +# define MATHERR_2 "{red}math : invalid operator{eoc}\n" +# define MATHERR_3 "{red}math : invalid operand{eoc}\n" +# define MATHERR_4 "{red}math : division by 0{eoc}\n" + t_execf *is_builtin(t_process *p); int builtin_export(const char *path, char *const av[], char *const envp[]); int builtin_unset(const char *path, char *const av[], char *const envp[]); @@ -26,8 +32,10 @@ int builtin_env(const char *path, char *const argv[], char *const envp[]); int builtin_echo(const char *path, char *const argv[], char *const envp[]); int builtin_cd(const char *path, char *const argv[], char *const envp[]); int builtin_exit(const char *path, char *const argv[], char *const envp[]); -int builtin_setenv(const char *path, char *const argv[], char *const envp[]); -int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]); +int builtin_setenv( + const char *path, char *const argv[], char *const envp[]); +int builtin_unsetenv( + const char *path, char *const argv[], char *const envp[]); int builtin_jobs(const char *path, char *const av[], char *const envp[]); int builtin_fg(const char *path, char *const av[], char *const envp[]); int builtin_bg(const char *path, char *const av[], char *const envp[]); diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index 1b656655..cf3edb5b 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/14 19:57:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 19:13:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,15 +44,6 @@ struct s_read char *input; }; -struct s_readopt -{ - char letter; - t_flag flag; - int (*get)(t_read *data, char *arg); -}; - -extern t_readopt g_readtab[]; - int builtin_read(const char *path, char *const av[], char *const envp[]); int bt_read_init(t_read *data, char **av); @@ -61,10 +52,10 @@ struct termios bt_read_term(int init); int bt_read_terminit(t_read *data); int bt_read_exit(t_read *data); -int bt_read_getdelim(t_read *data, char *arg); -int bt_read_getnchars(t_read *data, char *arg); -int bt_read_getprompt(t_read *data, char *arg); -int bt_read_gettimeout(t_read *data, char *arg); -int bt_read_getfd(t_read *data, char *arg); +int bt_read_getdelim(char ***argv, t_read *data); +int bt_read_getnchars(char ***argv, t_read *data); +int bt_read_getprompt(char ***argv, t_read *data); +int bt_read_gettimeout(char ***argv, t_read *data); +int bt_read_getfd(char ***argv, t_read *data); #endif diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 7cb2ccf6..c174bee0 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/15 13:47:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 18:46:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -120,7 +120,8 @@ int completion(long int key); void c_init(t_data *s, long int input); int c_matching(t_data *s, t_comp *c); int c_seek_binary(t_data *s, t_comp *c); -int c_seek_files(t_data *s, t_comp *c, char *current_word); +int c_seek_files( + t_data *s, t_comp *c, char *current_word); int c_parser(t_comp *c, char *path, char *name); int c_sizing(t_comp *c); diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 200b2b7c..06e5c1a6 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,16 +6,16 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/15 16:35:30 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 21:54:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef EXEC_H # define EXEC_H +# include "types.h" +# include "job_control.h" # include -/* # include "types.h" */ -/* # include "minishell.h" */ # define PIPE_READ 0 # define PIPE_WRITE 1 @@ -31,7 +31,6 @@ # define IS_PIPEEND(p) ((p).fdout == STDOUT) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p)) -/* # define EXEC_BG (1 << 1) */ # define EXEC_AND_IF (1 << 2) # define EXEC_OR_IF (1 << 3) # define EXEC_IF_BRANCH (1 << 4) @@ -122,6 +121,15 @@ struct s_process t_flag attrs; }; +struct s_job +{ + int id; + pid_t pgid; + t_flag attrs; + t_list *first_process; + struct termios tmodes; +}; + struct s_exec { t_job job; @@ -161,8 +169,6 @@ void redir_free(void *data, size_t content_size); char **token_to_argv(t_ld *ld, int do_match); -/* int add_new_job(t_job *job); */ - int error_badidentifier(char *name); t_btree *is_function(t_process *p); diff --git a/42sh/includes/ft_curs.h b/42sh/includes/ft_curs.h index 1f17a2c7..94b1a6bd 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/01/19 21:53:40 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:47:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ typedef struct s_curs t_curs; /* - * Cursor data : cursor's coordonate and windows size +** Cursor data : cursor's coordonate and windows size */ struct s_curs @@ -36,13 +36,13 @@ struct s_curs }; /* - * Cursor reference singleton +** Cursor reference singleton */ t_curs *curs_single(t_curs *curs, int set); /* - * Cursor setup +** Cursor setup */ int curs_li_ask(void); @@ -54,20 +54,20 @@ int curs_coo_setup(t_curs *curs); int curs_setup(t_curs *curs); /* - * Cursor cleanup +** Cursor cleanup */ int curs_term_cleanup(void); int curs_cleanup(t_curs *curs); /* - * Cursor's data reset +** Cursor's data reset */ void curs_reset(int sig); /* - * Cursor manipulation function +** Cursor manipulation function */ void curs_clear(t_curs *curs); @@ -78,6 +78,7 @@ void curs_backward(t_curs *curs, int offset); 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); +void curs_video_write_static( + t_curs *curs, char *str, size_t len); #endif diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h index a7e44e03..dcaab021 100644 --- a/42sh/includes/ft_input.h +++ b/42sh/includes/ft_input.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */ -/* Updated: 2017/02/03 15:18:27 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:51:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,34 +19,34 @@ */ # ifdef LINUX -# define RL_INSERT_CODE 0x7e325b1b /* Insert */ -# define RL_CLEAR_CODE 0xc /* Ctrl+L */ -# define RL_NL_CODE 0xa /* Enter */ -# define RL_COMP_CODE 0x9 /* Tab */ -# define RL_LEFT_CODE 0x445b1b /* Left */ -# define RL_RIGHT_CODE 0x435b1b /* Right */ -# define RL_WLEFT_CODE 0x44323b315b1b /* Maj+Left */ -# define RL_WRIGHT_CODE 0x43323b315b1b /* Maj+Right */ -# define RL_HOME_CODE 0x485b1b /* Home */ -# define RL_END_CODE 0x465b1b /* End */ -# define RL_PAGEUP_CODE 0x7e355b1b /* PageUp */ -# define RL_PAGEDOWN_CODE 0x7e365b1b /* PageDown */ -# define RL_SELECT_RIGHT_CODE 0x43333b315b1b /* Alt+Right */ -# define RL_SELECT_LEFT_CODE 0x44333b315b1b /* Alt+Left */ -# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b /* Alt+PageUp */ -# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b /* Alt+PageDown */ -# define RL_SELECT_HOME_CODE 0x48333b315b1b /* Alt+Home */ -# define RL_SELECT_END_CODE 0x46333b315b1b /* Alt+End */ -# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b /* Alt+Maj+Right */ -# define RL_SELECT_WLEFT_CODE 0x44343b315b1b /* Alt+Maj+Left */ -# define RL_RETARR_CODE 0x7f /* RetArr */ -# define RL_SUPPR_CODE 0x7e335b1b /* Suppr */ -# define RL_ESC_CODE 0x5c /* Escape `\` */ -# define RL_QUOTE_CODE 0x27 /* Quote `'` */ -# define RL_DQUOTE_CODE 0x22 /* Double Quote `"` */ -# define RL_COPY_CODE 0x631b /* Alt+C */ -# define RL_CUT_CODE 0x781b /* Alt+X */ -# define RL_PASTE_CODE 0x761b /* Alt+V */ +# define RL_INSERT_CODE 0x7e325b1b +# define RL_CLEAR_CODE 0xc +# define RL_NL_CODE 0xa +# define RL_COMP_CODE 0x9 +# define RL_LEFT_CODE 0x445b1b +# define RL_RIGHT_CODE 0x435b1b +# define RL_WLEFT_CODE 0x44323b315b1b +# define RL_WRIGHT_CODE 0x43323b315b1b +# define RL_HOME_CODE 0x485b1b +# define RL_END_CODE 0x465b1b +# define RL_PAGEUP_CODE 0x7e355b1b +# define RL_PAGEDOWN_CODE 0x7e365b1b +# define RL_SELECT_RIGHT_CODE 0x43333b315b1b +# define RL_SELECT_LEFT_CODE 0x44333b315b1b +# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b +# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b +# define RL_SELECT_HOME_CODE 0x48333b315b1b +# define RL_SELECT_END_CODE 0x46333b315b1b +# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b +# define RL_SELECT_WLEFT_CODE 0x44343b315b1b +# define RL_RETARR_CODE 0x7f +# define RL_SUPPR_CODE 0x7e335b1b +# define RL_ESC_CODE 0x5c +# define RL_QUOTE_CODE 0x27 +# define RL_DQUOTE_CODE 0x22 +# define RL_COPY_CODE 0x631b +# define RL_CUT_CODE 0x781b +# define RL_PASTE_CODE 0x761b # endif # ifdef MACOSX diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 3f8a1519..336d1809 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/14 13:47:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 18:52:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,13 +57,6 @@ # define CORRUPT 1 -/* # define IS_QUOTES (1 << 0) */ -/* # define IS_BQUOTES (1 << 1) */ -/* # define IS_DQUOTES (1 << 2) */ -/* # define IS_BSLASH (1 << 3) */ -/* # define IS_ACCOLADE (1 << 4) */ -/* # define IS_BRACKET (1 << 5) */ - # define STR data_singleton()->line.input # define POS data_singleton()->line.pos @@ -113,7 +106,8 @@ void ft_get_next_str(char *str, size_t *pos); void ft_putall_current_str(char *str, size_t *pos); void ft_current_str(char *str, size_t pos); int ft_strlen_next(char *str, size_t pos); -void ft_push_back_history(t_list_history **head, t_list_history *new); +void ft_push_back_history( + t_list_history **head, t_list_history *new); void ft_prompt(void); char *ft_remove_imput(char *str, size_t pos); char *ft_realloc_imput(char *str, int a, size_t pos); @@ -121,7 +115,8 @@ char *ft_strdupi(char const *s); char *ft_strndup(char const *s, int n); t_list_history *ft_create_history_list(char *str); char *ft_strdupi_w(char const *s); -void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len); +void ft_realloc_str_history( + char **str, size_t pos, int nb_his, int len); void ft_realloc_str_history_2(char **str, size_t pos, char *s); long long ft_pow(int nbr, int power); void ft_realloc_str_history_3(char **str, size_t pos, char *s); diff --git a/42sh/includes/glob.h b/42sh/includes/glob.h index 4e1bc3ca..e1b1795c 100644 --- a/42sh/includes/glob.h +++ b/42sh/includes/glob.h @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:31:18 by wescande #+# #+# */ -/* Updated: 2017/03/14 23:14:14 by wescande ### ########.fr */ +/* Updated: 2017/03/15 18:52:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ typedef struct s_bquote */ char **glob(char *str, unsigned char *esc, unsigned char *dbl_esc, int do_match); -void esc_print(char *str, unsigned char *esc); +void esc_print(char *str, unsigned char *esc); int word_is_assignment(char **content); void *tab_esc_copy(void *content); diff --git a/42sh/includes/hash.h b/42sh/includes/hash.h index ebdde0b7..bafc47db 100644 --- a/42sh/includes/hash.h +++ b/42sh/includes/hash.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:10:14 by gwojda #+# #+# */ -/* Updated: 2017/02/19 10:59:19 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 18:54:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,12 @@ typedef struct s_hash char *path; } t_hash; -int ft_add_hash(t_process *p); -int ft_hash(t_process *p); -int ft_is_hash(t_process *p); -int ft_hash_str(char *str); +int ft_add_hash(t_process *p); +int ft_hash(t_process *p); +int ft_is_hash(t_process *p); +int ft_hash_str(char *str); -void ft_hash_free(void *ptr, size_t size); -void ft_free_hash_table(void); +void ft_hash_free(void *ptr, size_t size); +void ft_free_hash_table(void); #endif diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 24c0432a..afb375d9 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/13 22:29:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 20:31:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,8 +16,9 @@ # include # include # include -# include "libft.h" +/* # include "libft.h" */ # include "types.h" +# include "exec.h" # define JOB_NOTIFIED (1 << 0) # define JOB_BG (1 << 1) @@ -27,15 +28,6 @@ # define JOBS_OPTS_L (1 << 0) -struct s_job -{ - int id; - pid_t pgid; - t_flag attrs; - t_list *first_process; - struct termios tmodes; -}; - struct s_jobc { t_list *first_job; @@ -44,8 +36,6 @@ struct s_jobc struct termios shell_tmodes; }; -# include "exec.h" - t_list *job_getprocess(pid_t pid); int job_addprocess(t_process *p); void job_update_id(void); diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 2f07a512..34fb8718 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -116,7 +116,6 @@ int add_pattern(t_btree **ast, t_list **lst); int add_subshell_cmd(t_btree **ast, t_list **lst); int add_subshell_sep(t_btree **ast, t_list **lst); int add_func_cmd(t_btree **ast, t_list **lst); -int add_func_sep(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst); int add_null(t_btree **ast, t_list **lst); @@ -178,10 +177,10 @@ union u_astdata struct s_astnode { - int pattern; - int nest; - int full; - int cache; + int pattern; + int nest; + int full; + int cache; t_type type; t_astdata data; }; diff --git a/42sh/libft b/42sh/libft index 938a355b..0c1dbf5b 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 938a355bac5f6d4c7941968d3ef0da0d984a9329 +Subproject commit 0c1dbf5b89c99612c49d6fd63dd25d0310bad3d9 diff --git a/42sh/src/builtin/bt_read_get.c b/42sh/src/builtin/bt_read_get.c index 24b79c3c..2f94336b 100644 --- a/42sh/src/builtin/bt_read_get.c +++ b/42sh/src/builtin/bt_read_get.c @@ -6,38 +6,50 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */ -/* Updated: 2017/03/14 18:11:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 21:15:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int bt_read_getdelim(t_read *data, char *arg) +int bt_read_getdelim(char ***av, t_read *data) { - data->delim = *arg; + if (!av || !*av) + return (1); + data->delim = ***av; return (0); } -int bt_read_getnchars(t_read *data, char *arg) +int bt_read_getnchars(char ***av, t_read *data) { - data->nchars = ft_atoi(arg); + if (!av || !*av) + return (1); + data->nchars = ft_atoi(**av); return (0); } -int bt_read_getprompt(t_read *data, char *arg) +int bt_read_getprompt(char ***av, t_read *data) { - data->prompt = arg; + DG("getting prompt"); + if (!av || !*av || !**av) + return (1); + data->prompt = **av; + DG("got prompt [%s]", data->prompt); return (0); } -int bt_read_gettimeout(t_read *data, char *arg) +int bt_read_gettimeout(char ***av, t_read *data) { - data->timeout = ft_atoi(arg); + if (!av || !*av) + return (1); + data->timeout = ft_atoi(**av); return (0); } -int bt_read_getfd(t_read *data, char *arg) +int bt_read_getfd(char ***av, t_read *data) { - data->fd = ft_atoi(arg); + if (!av || !*av) + return (1); + data->fd = ft_atoi(**av); return (0); } diff --git a/42sh/src/builtin/bt_read_parse.c b/42sh/src/builtin/bt_read_parse.c deleted file mode 100644 index c12080c3..00000000 --- a/42sh/src/builtin/bt_read_parse.c +++ /dev/null @@ -1,87 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* bt_read_parse.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/27 18:25:22 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:28:10 by wescande ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static t_readopt *bt_read_getopt(char letter) -{ - int i; - - i = 0; - while (g_readtab[i].letter) - { - if (g_readtab[i].letter == letter) - return (&g_readtab[i]); - i++; - } - return (NULL); -} - -int bt_read_parse(t_read *data, char **av) -{ - int i; - int j; - t_readopt *opt; - - i = 1; - while (av[i]) - { - j = 0; - if (av[i][j++] == '-') - { - if (av[i][j] == '-' && av[i][j + 1] == 0) - { - i++; - break ; - } - while (av[i][j]) - { - if (!(opt = bt_read_getopt(av[i][j]))) - { - ft_dprintf(2, "{red}%s: bad option: %c{eoc}\n", SHELL_NAME, av[i][j]); - return (2); - } - data->opts |= opt->flag; - if (opt->get) - { - (*opt->get)(data, av[++i]); - break ; - } - j++; - } - } - else - break ; - i++; - } - data->names = av[i] ? av + i : NULL; -// DG("read_opts: %b", data->opts); - DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i", - data->delim, data->nchars, data->prompt, data->timeout, data->fd); - return (0); -} - -int bt_read_init(t_read *data, char **av) -{ - data->opts = 0; - data->delim = '\n'; - data->nchars = -1; - data->prompt = NULL; - data->fd = 0; - data->input = NULL; - if ((bt_read_parse(data, av))) - return (1); - if (data->names) - DG("%s,%s", data->names[0], data->names[1]); - bt_read_terminit(data); - return (0); -} diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index b0a7477b..6438ff58 100644 --- a/42sh/src/builtin/bt_read_term.c +++ b/42sh/src/builtin/bt_read_term.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ -/* Updated: 2017/02/06 13:56:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 21:23:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,9 +27,7 @@ int bt_read_terminit(t_read *data) (void)data; term = bt_read_term(1); - term.c_lflag &= ~(ICANON); - if (data->opts & READ_OPT_LS) - term.c_lflag &= ~(ECHO); + term.c_lflag &= ~(ICANON | ECHO); if (data->opts & READ_OPT_LT) { term.c_cc[VTIME] = data->timeout * 10; diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 711a2828..c99503f6 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/15 10:52:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 20:55:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 3bcbd1ea..05f80f7f 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 10:58:49 by ariard #+# #+# */ -/* Updated: 2017/03/14 22:45:23 by ariard ### ########.fr */ +/* Updated: 2017/03/15 21:02:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,8 @@ static int get_value(char **var, char **value) { char *temp; + if (!word_is_assignment(var)) + return (ft_error_message(MATHERR_1)); temp = ft_sstrstr(data_singleton()->local_var, *var); if (temp) { @@ -51,10 +53,8 @@ static int do_math(char **value, char *operator, char *operand) ope2 = ft_atoi(operand); else ope2 = 0; - if (ft_strlen(operator) > 1) - return (0); if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) - ope1 = 0; + return (ft_error_message(MATHERR_4)); else { ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; @@ -77,13 +77,21 @@ int builtin_math(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; + if (!av || !av[1] || !av[2] || !av[3] || av[4]) + return (ft_error_message(MATHERR_0)); init_math(&var, &value, &operator, &operand); var = av[1]; - get_value(&var, &value); + if (get_value(&var, &value) == -1) + return (-1); operator = av[2]; - operand = av[3]; -// DG("math %s %s %s", var, operator, operand); - do_math(&value, operator, operand); + if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' + || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) + return (ft_error_message(MATHERR_2)); + operand = av[3]; + if (!ft_stris(operand, &ft_isdigit)) + return (ft_error_message(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); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 8fdc0361..31e923dd 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,29 +6,46 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/14 18:08:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 21:22:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_readopt g_readtab[] = +t_cliopts g_read_opts[] = { - /* {'a', READ_OPT_LA, NULL}, */ - {'d', READ_OPT_LD, bt_read_getdelim}, - /* {'e', READ_OPT_LE, NULL}, */ - /* {'i', READ_OPT_LI, NULL}, */ - {'n', READ_OPT_LN, bt_read_getnchars}, - /* {'N', READ_OPT_UN, bt_read_getnchars}, */ - {'p', READ_OPT_LP, bt_read_getprompt}, - {'r', READ_OPT_LR, NULL}, - {'s', READ_OPT_LS, NULL}, - {'t', READ_OPT_LT, bt_read_gettimeout}, - {'u', READ_OPT_LU, bt_read_getfd}, - {0, 0, 0}, + {'d', NULL, READ_OPT_LD, 0, bt_read_getdelim}, + {'n', NULL, READ_OPT_LN, 0, bt_read_getnchars}, + {'p', NULL, READ_OPT_LP, 0, bt_read_getprompt}, + {'r', NULL, READ_OPT_LR, 0, NULL}, + {'s', NULL, READ_OPT_LS, 0, NULL}, + {'t', NULL, READ_OPT_LT, 0, bt_read_gettimeout}, + {'u', NULL, READ_OPT_LU, 0, bt_read_getfd}, + {0, 0, 0, 0, 0}, }; +void bt_read_usage(void) +{ + ft_dprintf(2, "{red}read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]{eoc}\n"); +} +int bt_read_init(t_read *data, char **av) +{ + data->opts = 0; + data->delim = '\n'; + data->nchars = -1; + data->prompt = NULL; + data->fd = 0; + data->timeout = 0; + data->input = NULL; + data->names = NULL; + if ((cliopts_get(av, g_read_opts, data))) + return(ft_perror()); + if (data->names) + DG("%s,%s", data->names[0], data->names[1]); + bt_read_terminit(data); + return (0); +} int bt_read_loop(t_read *data) { int i; @@ -44,7 +61,8 @@ int bt_read_loop(t_read *data) if (read(data->fd, buf, 1) <= 0) return (1); buf[1] = 0; - DG("got input [%x]", *buf); + if (!(data->opts &READ_OPT_LS)) + ft_putchar(*buf); if (!esc && *buf == data->delim) break ; esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\'); @@ -54,7 +72,6 @@ int bt_read_loop(t_read *data) if ((data->opts & READ_OPT_LN) && ++i >= data->nchars) break ; } - ft_putchar('\n'); return (0); } @@ -62,24 +79,23 @@ int bt_read_assign(t_read *data) { char *input; char **names; - char *IFS; + char *ifs; char *start; input = data->input; names = data->names ? data->names : (char*[]){"REPLY", NULL}; - IFS = ft_getenv(data_singleton()->env, "IFS"); + ifs = ft_getenv(data_singleton()->env, "IFS"); start = input; while (*start && *names) { - if (!(names[1]) || !IFS) + if (!(names[1]) || !ifs) { - DG("setting env: %s=%x%x%x", *names, *start, start[1],start[2]); builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL); break ; } - while (*input && !ft_strchr(IFS, *input)) + while (*input && !ft_strchr(ifs, *input)) input++; - while (input && ft_strchr(IFS, *input)) + while (input && ft_strchr(ifs, *input)) *(input++) = 0; builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL); start = input; @@ -102,6 +118,9 @@ int builtin_read(const char *path, char *const av[], char *const envp[]) ret = 1; else if (bt_read_assign(&data)) ret = 1; - bt_read_exit(&data); + if (ret != 0) + bt_read_usage(); + if (ret != 2) + bt_read_exit(&data); return (ret); } diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 06a2e33d..12c85d25 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/15 15:58:53 by wescande ### ########.fr */ +/* Updated: 2017/03/15 20:01:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,7 @@ t_execf *is_builtin(t_process *p) { int i; + DG("in builtin"); i = -1; while (g_builtin[++i].name) { diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 4d7d2c93..89f0242a 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:59:53 by ariard ### ########.fr */ +/* Updated: 2017/03/15 19:18:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 21a9219d..698defbe 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/15 04:18:47 by wescande ### ########.fr */ +/* Updated: 2017/03/15 19:58:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/fd_is_valid.c b/42sh/src/exec/fd_is_valid.c index b0347bcf..41114621 100644 --- a/42sh/src/exec/fd_is_valid.c +++ b/42sh/src/exec/fd_is_valid.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:59:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:48:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c index 36bdcd5a..e3e954e4 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/08 03:22:34 by wescande ### ########.fr */ +/* Updated: 2017/03/15 18:57:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,21 @@ t_btree *is_function(t_process *p) { - t_list *tmp; + t_list *tmp; + t_btree **ast; + char **av; tmp = data_singleton()->lst_func; while (tmp) { - if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) - return (btree_map(p->data.subshell.content, node_copy)); + ast = tmp->content; + if (!*ast) + return (NULL); + av = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (!av || !av[0]) + return (NULL); + if (!ft_strcmp(av[0], p->data.cmd.av[0])) + return (btree_map((*ast)->right, node_copy)); tmp = tmp->next; } return (NULL); diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index d79e1e2a..c1785a81 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 01:24:26 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:48:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +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) + 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/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 728842e0..0574cd60 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:04:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:13:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ int plaunch_brace(t_process *p) { + DG(" do brace"); if (IS_PIPESINGLE(*p)) { + DG("is pipgesingle"); if (process_redirect(p)) set_exitstatus(1, 1); else diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index d0bc5bcf..ed07ac41 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 19:17:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ static int do_function(t_process *p) { + DG("do function"); ft_exec(&p->data.function.content); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index b433aa4d..fb2c6436 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:01:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:06:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,8 @@ int process_redirect(t_process *p) int i; redirs = p->redirs; + if (p->to_close != STDIN) + close(p->to_close); while (redirs) { redir = redirs->content; @@ -54,8 +56,6 @@ int process_redirect(t_process *p) redirs = redirs->next; } /* DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); */ - if (p->to_close != STDIN) - close(p->to_close); if (p->fdin != STDIN) dup2_close(p->fdin, STDIN); if (p->fdout != STDOUT) diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index c57402e4..74dcf000 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/15 00:57:31 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:20:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,7 @@ static int process_set_spec(t_process *p, t_btree *ast) if (!ast) return (0); item = ast->item; + DG("process set spec"); while (g_setprocessmap[++i].id) if (item->type == g_setprocessmap[i].id) { diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 059e4f4a..575edca9 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:33:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:11:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,7 @@ int process_setgroup(t_process *p, pid_t pid) return (0); DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) - { ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); - perror(""); - } if (pid == 0 && JOB_IS_FG(j->attrs)) { DG("tcsetpgrp[%i]", j->pgid); diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 408faeff..43153bb5 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/14 21:25:01 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:48:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,8 @@ int pset_cmd(t_process *p, t_btree *ast) p->type = PROCESS_FILE; if ((func = is_function(p))) { - p->data.subshell.content = func; + btree_print(STDBUG, func, &ft_putast); + p->data.function.content = func; p->type = PROCESS_FUNCTION; } else if ((p->data.cmd.execf = is_builtin(p))) diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 8be9aecd..e42cf7eb 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/11 17:32:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:49:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,10 +33,9 @@ int redirect_greatand(t_redir *redir) return (0); if (fdold > 9) return (bad_fd(fdold)); - if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) + if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) dup2_close(fdold, fdnew); else - close(fdnew); - /* return (bad_fd(fdold)); */ + return (bad_fd(fdold)); return (0); } diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 30f11cdc..1a5ccf64 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:00:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:49:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,10 +33,9 @@ int redirect_lessand(t_redir *redir) return (0); if (fdold > 9) return (bad_fd(fdold)); - if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) + if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) dup2_close(fdold, fdnew); else - close(fdnew); - /* return (bad_fd(fdold)); */ + return (bad_fd(fdold)); return (0); } diff --git a/42sh/src/glob/esc_print.c b/42sh/src/glob/esc_print.c index 504e95bd..a91afb64 100644 --- a/42sh/src/glob/esc_print.c +++ b/42sh/src/glob/esc_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 15:38:14 by jhalford #+# #+# */ -/* Updated: 2017/02/24 22:05:04 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:12:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,10 @@ void esc_print(char *str, unsigned char *esc) while (*cur) { if (is_char_esc(esc, str, cur)) - printf("\\%c", *cur); + ft_printf("\\%c", *cur); else - printf("%c", *cur); + ft_printf("%c", *cur); ++cur; } - printf("\n"); + ft_printf("\n"); } diff --git a/42sh/src/glob/word_is_assignment.c b/42sh/src/glob/word_is_assignment.c index e4dc0de8..cc010e51 100644 --- a/42sh/src/glob/word_is_assignment.c +++ b/42sh/src/glob/word_is_assignment.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 18:59:11 by wescande #+# #+# */ -/* Updated: 2017/03/11 20:47:05 by ariard ### ########.fr */ +/* Updated: 2017/03/15 20:55:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 3033978a..0cb2625a 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/14 23:43:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:12:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/src/lexer/lexer_lessand.c index 3930c001..e7769130 100644 --- a/42sh/src/lexer/lexer_lessand.c +++ b/42sh/src/lexer/lexer_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 17:48:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 908479b4..8a6614fa 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/15 13:55:22 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 18:14:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,10 +27,10 @@ static int promt_git_status(int fd) free(tmp); ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line); if (!get_next_line(fd, &tmp)) - printf("\x1b[38;5;83m %C ", L'✓'); + ft_printf("\x1b[38;5;83m ✓ "); else { - printf("\x1b[38;5;1m %C ", L'✗'); + ft_printf("\x1b[38;5;1m ✗ "); free(tmp); } while (get_next_line(fd, &tmp)) @@ -101,9 +101,9 @@ void ft_prompt(void) do_job_notification(); if (ft_getenv(data_singleton()->env, "?") && ft_atoi(ft_getenv(data_singleton()->env, "?"))) - printf("\x1b[38;5;1m%C ", L'➜'); + ft_printf("\x1b[38;5;1m➜ "); else - printf("\x1b[38;5;10m%C ", L'➜'); + ft_printf("\x1b[38;5;10m➜ "); fflush(NULL); ft_putstr("\x1b[38;5;361m"); ret += ft_currend_dir(); diff --git a/42sh/src/main/content_free.c b/42sh/src/main/content_free.c deleted file mode 100644 index 3c025475..00000000 --- a/42sh/src/main/content_free.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* content_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/15 16:05:27 by gwojda #+# #+# */ -/* Updated: 2017/03/15 16:35:18 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void content_free(void *data, size_t content_size) -{ - (void)content_size; - free(data); -} diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c index 03b4d989..e4b66c19 100644 --- a/42sh/src/main/instruction_free.c +++ b/42sh/src/main/instruction_free.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/15 16:36:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 16:49:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,10 @@ int instruction_free(t_list **token, t_parser *parser, t_btree **ast) { ft_lstdel(token, &token_free); token = NULL; - ft_lstdel(&parser->stack, &content_free); - btree_del(ast, &content_free); + ft_lstdel(&parser->stack, &ft_lst_cfree); + btree_del(ast, &ft_lst_cfree); ft_lstdel(&data_singleton()->heredoc_queue, &redir_free); - ft_lstdel(&data_singleton()->exec.op_stack, &content_free); + ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); free(parser->new_sym); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index bf8cdd41..706b663d 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/15 16:33:07 by gwojda ### ########.fr */ +/* Updated: 2017/03/15 17:55:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } - btree_print(STDBUG, ast, &ft_putast); + /* btree_print(STDBUG, ast, &ft_putast); */ if (ft_exec(&ast)) return (2); instruction_free(&token, &parser, &ast); diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 300a4c99..209eaedf 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/15 02:12:28 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:46:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -95,6 +95,7 @@ int add_cmd(t_btree **ast, t_list **lst) if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME) { DG("type is %s", read_state(node->type)); + DG("data is %s", token->data); ft_ld_pushback(&node->data.cmd.token, gen_tab(token->data, token->esc, token->esc2, 1)); } diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index a90a4b39..3ab6bdf6 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/15 00:26:57 by ariard ### ########.fr */ +/* Updated: 2017/03/15 20:07:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ int isfunc_name(t_btree **ast, t_list **lst) if (node->type == CMD && token->type == TK_PAREN_OPEN) { node->type = FNAME; - node->data.str = ft_strdup(token->data); return (1); } if (node->type == FNAME && token->type == TK_PAREN_CLOSE @@ -81,17 +80,39 @@ int add_func_cmd(t_btree **ast, t_list **lst) return (add_cmd(&(*ast)->right, lst)); } -int add_func_sep(t_btree **ast, t_list **lst) +t_list *is_already_func(t_btree **new) { - return (add_sep(&(*ast)->right, lst)); + t_list *tmp; + t_btree **ast; + char **new_name; + char **old_name; + + tmp = data_singleton()->lst_func; + new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1); + while (tmp) + { + ast = tmp->content; + if (!*ast) + return (NULL); + old_name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (!new_name || !new_name[0] || !old_name || !old_name[0]) + return (NULL); + if (!ft_strcmp(new_name[0], old_name[0])) + return (tmp); + tmp = tmp->next; + } + return (NULL); } int add_one_func(t_btree **ast, t_list **lst) { t_btree *func_ast; + t_list *old_func; (void)lst; func_ast = btree_map(*ast, node_copy); + if ((old_func = is_already_func(&func_ast))) + ft_lst_delif(&data_singleton()->lst_func, old_func->content, &ft_addrcmp, &ast_free); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); } diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index f61ba420..afb89bca 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/15 01:41:06 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:57:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int add_sep(t_btree **ast, t_list **lst) else if (issubshell(ast, lst)) return (add_subshell_sep(ast, lst)); else if (isfunc(ast, lst)) - return (add_func_sep(ast, lst)); + return (add_subshell_sep(ast, lst)); else if (isbang_sep(ast, lst)) return (add_bang_sep(ast, lst)); if (!*ast) diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 48c2df8c..079a4acd 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/13 17:42:06 by ariard ### ########.fr */ +/* Updated: 2017/03/15 19:59:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); - btree_print(STDBUG, *ast, &ft_putast); + /* btree_print(STDBUG, *ast, &ft_putast); */ if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 398023aa..af8a85d7 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/14 22:11:43 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:33:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == FNAME) + return ("FNAME"); if (current == PIPE_CLOSE_SEQUENCE) return ("PIPE_CLOSE_SEQUENCE"); if (current == TK_BANG)