diff --git a/42sh/Makefile b/42sh/Makefile index 2e558060..8dcf5189 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -72,11 +72,6 @@ $(D_OBJ)/%.o: $(D_SRC)/job-control/%.c includes/job_control.h @$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS) @echo "Compiling "$<"..." -$(D_OBJ)/%.o: $(D_SRC)/read-script/%.c includes/readscript.h - @$(MKDIR) $(D_OBJ) - @$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS) - @echo "Compiling "$<"..." - libft/libft.a: libft/src/*/*.c @echo "libft/libft.a" @$(MAKE) -C libft 2>/dev/null diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h index 3e2188b4..b7820668 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/01/21 21:49:00 by ariard ### ########.fr */ +/* Updated: 2017/01/23 21:45:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 75cfab31..3263c231 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/01/22 23:30:39 by ariard ### ########.fr */ +/* Updated: 2017/01/24 00:45:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,10 @@ typedef long long t_type; # define TK_DQ_WORD (1 << 16) # define TK_COMMAND (1 << 17) # define TK_SUBSHELL (1 << 18) +# define TK_NEWLINE (1 << 19) +# define TK_LOOP (1 << 20) +# define TK_B_LOOP (1 << 21) +# define TK_E_LOOP (1 << 22) # define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD) # define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) @@ -44,6 +48,7 @@ typedef long long t_type; enum e_lexstate { DEFAULT, + NEWLINE, DELIM, SEP, WORD, @@ -89,6 +94,7 @@ int ft_is_delim(char c); t_lexstate get_lexer_state(char *str); int lexer_default(t_list **alst, char *str); +int lexer_newline(t_list **alst, char *str); int lexer_delim(t_list **alst, char *str); int lexer_sep(t_list **alst, char *str); int lexer_word(t_list **alst, char *str); diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h index 941853ac..13c408ec 100644 --- a/42sh/includes/line_editing.h +++ b/42sh/includes/line_editing.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:38:21 by jhalford #+# #+# */ -/* Updated: 2017/01/10 12:46:19 by jhalford ### ########.fr */ +/* Updated: 2017/01/23 21:45:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 0e5c6b2b..d211ec07 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:21:39 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:31:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ # include "libft.h" -# include "readscript.h" # include "types.h" # include "lexer.h" # include "parser.h" @@ -48,6 +47,14 @@ struct s_comp # define SHELL_MSG_NOJOBC "no job-control" +struct s_script +{ + char *buffer; + int q_size; + t_list *queue; +}; + +typedef struct s_script t_script; struct s_data { @@ -73,6 +80,7 @@ void data_exit(void); int shell_single_command(char *command); +int read_script(char *file); int shell_script(void); void ft_expand_dollar(char **av, char **env); diff --git a/42sh/includes/readscript.h b/42sh/includes/readscript.h deleted file mode 100644 index 29c91132..00000000 --- a/42sh/includes/readscript.h +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_script.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/21 22:50:22 by ariard #+# #+# */ -/* Updated: 2017/01/22 23:02:55 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READSCRIPT_H -# define READSCRIPT_H - -/* - * input : destination buffer - * b_size : allocated size of the destination buffer - * used : acutal used size in the destination buffer - * q_size : number of elements in the queue - * queue : list of queued lines, FIFO -*/ - -struct s_script -{ - char *buffer; - int b_size; - int q_size; - t_list *queue; -}; - -typedef struct s_script t_script; - -/* - * Read_script setup/cleanup -*/ - -int ft_read_script(char *file); - -int rs_shebang_check(char *file, t_script *script); - -#endif diff --git a/42sh/sample/20lines.sh b/42sh/sample/20lines.sh new file mode 100644 index 00000000..0e08c1ea --- /dev/null +++ b/42sh/sample/20lines.sh @@ -0,0 +1,20 @@ +ls +pwd +mkdir +cd +ls +pwd +mkdir +cd +ls +pwd +mkdir +cd +ls +pwd +mkdir +cd +ls +pwd +mkdir +cd diff --git a/42sh/sample/2lines.sh b/42sh/sample/2lines.sh new file mode 100644 index 00000000..7ef6d678 --- /dev/null +++ b/42sh/sample/2lines.sh @@ -0,0 +1,2 @@ +ls pwd +yolo diff --git a/42sh/script.sh b/42sh/script.sh index 35caedf2..deda5282 100755 --- a/42sh/script.sh +++ b/42sh/script.sh @@ -1,4 +1,4 @@ -#!/bin/minishell +#!/bin/bash while [ 1 ]; do sleep 1 diff --git a/42sh/src/lexer/.ft_post_tokenize.c.swo b/42sh/src/lexer/.ft_post_tokenize.c.swo deleted file mode 100644 index f9f7efee..00000000 Binary files a/42sh/src/lexer/.ft_post_tokenize.c.swo and /dev/null differ diff --git a/42sh/src/lexer/.ft_tokenize.c.swo b/42sh/src/lexer/.ft_tokenize.c.swo deleted file mode 100644 index c523a788..00000000 Binary files a/42sh/src/lexer/.ft_tokenize.c.swo and /dev/null differ diff --git a/42sh/src/lexer/.reduce_bquotes.c.swo b/42sh/src/lexer/.reduce_bquotes.c.swo deleted file mode 100644 index 20161d54..00000000 Binary files a/42sh/src/lexer/.reduce_bquotes.c.swo and /dev/null differ diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index a69df251..3de67de3 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:27:50 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:33:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index 1e5af252..d99d4652 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:18:13 by ariard ### ########.fr */ +/* Updated: 2017/01/24 01:25:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int (*g_lexer[])(t_list **alst, char *str) = { &lexer_default, + &lexer_newline, &lexer_delim, &lexer_sep, &lexer_word, @@ -32,7 +33,7 @@ int (*g_lexer[])(t_list **alst, char *str) = int ft_is_delim(char c) { - return (c == ' ' || c == '\t' || c == '\n'); + return (c == ' ' || c == '\t'); } int ft_tokenize(t_list **alst, char *str, t_lexstate state) diff --git a/42sh/src/lexer/get_lexer_state.c b/42sh/src/lexer/get_lexer_state.c index 4a35438f..63833382 100644 --- a/42sh/src/lexer/get_lexer_state.c +++ b/42sh/src/lexer/get_lexer_state.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 13:45:46 by jhalford #+# #+# */ -/* Updated: 2017/01/19 23:46:48 by ariard ### ########.fr */ +/* Updated: 2017/01/24 00:55:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,9 @@ t_lexstate get_lexer_state(char *str) { - if (ft_is_delim(*str)) + if (*str == '\n') + return (NEWLINE); + else if (ft_is_delim(*str)) return (DELIM); else if (*str == '$') return (VAR); diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index b1a6c908..9c94550d 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -/* Updated: 2017/01/19 22:06:43 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:24:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 2dc52117..4d9d18fc 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/01/19 23:58:36 by ariard ### ########.fr */ +/* Updated: 2017/01/24 01:01:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index 7542b57c..62507813 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -/* Updated: 2017/01/11 15:45:53 by jhalford ### ########.fr */ +/* Updated: 2017/01/24 00:32:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_great.c b/42sh/src/lexer/lexer_great.c index d02a183b..81f6a4f2 100644 --- a/42sh/src/lexer/lexer_great.c +++ b/42sh/src/lexer/lexer_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:48:49 by jhalford ### ########.fr */ +/* Updated: 2017/01/23 22:51:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index bc3fa958..f618c373 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:27:51 by jhalford ### ########.fr */ +/* Updated: 2017/01/24 00:45:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_newline.c b/42sh/src/lexer/lexer_newline.c new file mode 100644 index 00000000..de8cef47 --- /dev/null +++ b/42sh/src/lexer/lexer_newline.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_newline.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ +/* Updated: 2017/01/24 01:25:21 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "lexer.h" + +int lexer_newline(t_list **alst, char *str) +{ + t_token *token; + + if (*alst) + { + token = (*alst)->content; + if (*token->data) + return (lexer_newline(&(*alst)->next, str)); + } + else + { + token = token_init(); + *alst = ft_lstnew(token, sizeof(*token)); + } + token = (*alst)->content; + token->type = TK_NEWLINE; + return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); +} diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index b5cffe2d..2309f084 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:29:46 by jhalford ### ########.fr */ +/* Updated: 2017/01/23 22:54:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index 54f7c20e..2a96e303 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:39:52 by jhalford ### ########.fr */ +/* Updated: 2017/01/24 01:25:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 53ed4746..38e50350 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/01/11 15:38:03 by jhalford ### ########.fr */ +/* Updated: 2017/01/24 01:02:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index cb70ee1c..4247ceb0 100644 --- a/42sh/src/lexer/reduce_bquotes.c +++ b/42sh/src/lexer/reduce_bquotes.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:26:06 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:33:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 250574e3..8623f760 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/01/19 23:01:05 by ariard ### ########.fr */ +/* Updated: 2017/01/24 00:30:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_init.c b/42sh/src/lexer/token_init.c index 7f55464f..fcd796c5 100644 --- a/42sh/src/lexer/token_init.c +++ b/42sh/src/lexer/token_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */ -/* Updated: 2017/01/19 23:58:47 by ariard ### ########.fr */ +/* Updated: 2017/01/24 01:07:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 9453a0cd..285c77a7 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/01/19 23:44:34 by ariard ### ########.fr */ +/* Updated: 2017/01/24 01:25:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/.main.c.swo b/42sh/src/main/.main.c.swo deleted file mode 100644 index 5c8f87b2..00000000 Binary files a/42sh/src/main/.main.c.swo and /dev/null differ diff --git a/42sh/src/main/.shell_script.c.swp b/42sh/src/main/.shell_script.c.swp deleted file mode 100644 index f9ac3d8f..00000000 Binary files a/42sh/src/main/.shell_script.c.swp and /dev/null differ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 2b77bc85..8ca93754 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/01/22 17:20:04 by ariard ### ########.fr */ +/* Updated: 2017/01/23 22:37:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 6aceeb75..1833a11f 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/01/22 23:09:43 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:51:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ int shell_single_command(char *command) /* /1* btree_apply_infix(ast, &ft_putast2); *1/ */ if (ft_exec(&ast)) return (1); - return (0); } @@ -50,12 +49,9 @@ int main(int ac, char **av) shell_single_command(shell_get_avdata()); return (0); } - if (ft_read_script(av[1])) - { - if (data_singleton()->opts & SHELL_MODE_SCRIPT) - shell_script(); - else - shell_single_command(data_singleton()->line.input); + if (data_singleton()->opts & SHELL_MODE_SCRIPT) + { + shell_script(); return (0); } while (1) diff --git a/42sh/src/read-script/ft_read_script.c b/42sh/src/main/read_script.c similarity index 80% rename from 42sh/src/read-script/ft_read_script.c rename to 42sh/src/main/read_script.c index 6e1a9e8f..4341b747 100644 --- a/42sh/src/read-script/ft_read_script.c +++ b/42sh/src/main/read_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 22:49:31 by ariard #+# #+# */ -/* Updated: 2017/01/22 23:11:59 by ariard ### ########.fr */ +/* Updated: 2017/01/24 00:20:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,22 @@ static int rs_loop(char *file, t_script *script) { int fd; - script->queue = ft_memalloc(sizeof(t_list)); - fd = open(file, O_RDONLY); + if ((fd = open(file, O_RDONLY)) == -1) + return (0); while (get_next_line(fd, &script->buffer) > 0) { ft_lsteadd(&script->queue, ft_lstnew(script->buffer, ft_strlen(script->buffer))); ft_strdel(&script->buffer); + ft_lsteadd(&script->queue, ft_lstnew(ft_strdup("\n"), 1)); + script->q_size += 2; } close(fd); + if (script->q_size > 0) + { + data_singleton()->opts &= ~SHELL_MODE_MASK; + data_singleton()->opts |= SHELL_MODE_SCRIPT; + } return (0); } @@ -32,12 +39,12 @@ static int rs_setup(t_script *script) { ft_bzero(script, sizeof(script)); script->buffer = NULL; - script->b_size = 0; script->q_size = 0; + script->queue = NULL; return (0); } -int ft_read_script(char *file) +int read_script(char *file) { t_script *script; @@ -48,8 +55,6 @@ int ft_read_script(char *file) return (-1); if (rs_loop(file, script) < 0) return (-1); - if (rs_shebang_check(file, script) < 0) - return (-1); script->buffer = NULL; DG("{inv}{bol}{gre}read of script{eoc} script detected"); return (1); diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index 9096ee5e..b953af05 100644 --- a/42sh/src/main/shell_get_opts.c +++ b/42sh/src/main/shell_get_opts.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ -/* Updated: 2017/01/22 22:18:56 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:36:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index c6f549e0..14066b58 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/01/22 21:58:53 by ariard ### ########.fr */ +/* Updated: 2017/01/23 22:35:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,5 +41,6 @@ void shell_init(int ac, char **av) tcsetpgrp(STDIN, *shell_pgid); tcgetattr(STDIN, &data_singleton()->jobc.shell_tmodes); } + read_script(av[1]); shell_get_opts(ac, av); } diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 6b680e90..f0e9dd4a 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ -/* Updated: 2017/01/22 23:32:27 by ariard ### ########.fr */ +/* Updated: 2017/01/24 01:25:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,24 +15,29 @@ int shell_script() { t_list *token; + t_list *head; t_btree *ast; t_list *tmp; token = NULL; + head = NULL; ast = NULL; tmp = data_singleton()->script.queue; while (tmp) { if (ft_tokenize(&token, tmp->content , DEFAULT)) return (1); + if (!token) + return (0); + if (ft_post_tokenize(&token, tmp->content)) + return (1); tmp = tmp->next; + ft_lst_merge(&head, token); + token = NULL; } - if (!token) - return (0); -// if (ft_post_tokenize(&token, command)) -// return (1); DG("after post_tokenize"); - token_print(token); + token_print(head); + return (0); if (ft_parse(&ast, &token)) return (1); btree_print(STDBUG, ast, &ft_putast); diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 805fbfe6..cfd0faf7 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2017/01/20 16:37:29 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:15:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index 7f00ee86..65a506d2 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ -/* Updated: 2017/01/20 16:24:51 by ariard ### ########.fr */ +/* Updated: 2017/01/23 23:17:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/read-script/rs_shebang.c b/42sh/src/read-script/rs_shebang.c deleted file mode 100644 index bc1550f8..00000000 --- a/42sh/src/read-script/rs_shebang.c +++ /dev/null @@ -1,78 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rs_shebang.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/22 21:42:27 by ariard #+# #+# */ -/* Updated: 2017/01/22 23:11:57 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static char *rs_shebang_parse_interpreter(char *shebang) -{ - int i; - - i = ft_strlen(shebang) - 1; - while (shebang[i]) - { - if (shebang[i] == '/') - return (&shebang[++i]); - i--; - } - return (NULL); -} - -static int rs_valid_interpreter(char *interpreter) -{ - if (ft_strncmp(interpreter, "bash", ft_strlen("bash")) == 0) - return (1); - if (ft_strncmp(interpreter, "csh", ft_strlen("csh")) == 0) - return (1); - if (ft_strncmp(interpreter, "ksh", ft_strlen("bash")) == 0) - return (1); - if (ft_strncmp(interpreter, "sh", ft_strlen("bash")) == 0) - return (1); - if (ft_strncmp(interpreter, "tcsh", ft_strlen("bash")) == 0) - return (1); - if (ft_strncmp(interpreter, "tcsh", ft_strlen("bash")) == 0) - return (1); - if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) == 0) - return (1); - return (0); -} - -static void rs_set_line_input(char *interpreter, char *file) -{ - char *buffer; - - buffer = ft_strnew(1024); - ft_strncpy(buffer, interpreter, ft_strlen(interpreter)); - ft_strncat(buffer, " ", 1); - ft_strncat(buffer, file, ft_strlen(file)); - data_singleton()->line.input = buffer; - data_singleton()->opts &= ~SHELL_MODE_MASK; - data_singleton()->opts |= SHELL_MODE_INPUT; -} - -int rs_shebang_check(char *file, t_script *script) -{ - char *interpreter; - - if (!script || !script->queue || !script->queue->next) - return (0); - interpreter = rs_shebang_parse_interpreter(script->queue->next->content); - if (interpreter == NULL || rs_valid_interpreter(interpreter) == 0) - rs_set_line_input("sh", file); - else if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) != 0) - rs_set_line_input(interpreter, file); - else if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) == 0) - { - data_singleton()->opts &= ~SHELL_MODE_MASK; - data_singleton()->opts |= SHELL_MODE_SCRIPT; - } - return (0); -}