diff --git a/42sh/Makefile b/42sh/Makefile index 119c5015..d09f5200 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -137,11 +137,11 @@ job-control/sigtstp_handler.c\ job-control/sigttin_handler.c\ job-control/sigttou_handler.c\ lexer/command_getoutput.c\ -lexer/ft_lexer.c\ lexer/ft_post_tokenize.c\ -lexer/ft_tokenize.c\ -lexer/get_lexer_state.c\ +lexer/get_state_global.c\ +lexer/get_state_redir.c\ lexer/lexer_backslash.c\ +lexer/lexer_bquote.c\ lexer/lexer_comment.c\ lexer/lexer_default.c\ lexer/lexer_delim.c\ @@ -150,14 +150,16 @@ lexer/lexer_great.c\ lexer/lexer_greatand.c\ lexer/lexer_less.c\ lexer/lexer_lessand.c\ +lexer/lexer_lex.c\ lexer/lexer_newline.c\ lexer/lexer_number.c\ lexer/lexer_quote.c\ lexer/lexer_sep.c\ -lexer/lexer_special.c\ +lexer/lexer_subshell.c\ lexer/lexer_word.c\ lexer/reduce_bquotes.c\ lexer/reduce_parens.c\ +lexer/stack_to_prompt.c\ lexer/token_append.c\ lexer/token_cmp_type.c\ lexer/token_expand_var.c\ @@ -165,10 +167,10 @@ lexer/token_free.c\ lexer/token_init.c\ lexer/token_print.c\ line-editing/builtin_history.c\ -line-editing/check_backslash.c\ line-editing/completion.c\ line-editing/control_c_and_d.c\ line-editing/copy_cut_paste.c\ +line-editing/ftprompt.c\ line-editing/get_touch.c\ line-editing/get_touch_toolz.c\ line-editing/get_touch_toolz_2.c\ @@ -180,7 +182,6 @@ line-editing/history_parsing_toolz_2.c\ line-editing/list_toolz.c\ line-editing/move_to_line.c\ line-editing/print_and_del.c\ -line-editing/prompt.c\ line-editing/reader.c\ line-editing/readline.c\ line-editing/surch_in_history.c\ @@ -198,6 +199,7 @@ main/ft_putast.c\ main/ft_putast2.c\ main/lib_expansion.c\ main/main.c\ +main/remove_trailing_esc_nl.c\ main/shell_exit.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 97297893..df03cd61 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/02/05 17:44:07 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 17:24:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,19 +52,19 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 -# define PROMPT_QUOTES "quote> " -# define PROMPT_DQUOTES "dquote> " -# define PROMPT_BQUOTES "bquote> " -# define PROMPT_ACCOLADE "cursh> " -# define PROMPT_BRACKET "subsh> " -# define PROMPT_BSLASH "> " +/* # define PROMPT_QUOTES "quote> " */ +/* # define PROMPT_DQUOTES "dquote> " */ +/* # define PROMPT_BQUOTES "bquote> " */ +/* # define PROMPT_ACCOLADE "cursh> " */ +/* # define PROMPT_BRACKET "subsh> " */ +/* # define PROMPT_BSLASH "> " */ -# define SIZE_PROMPT_QUOTES 7 -# define SIZE_PROMPT_DQUOTES 8 -# define SIZE_PROMPT_BQUOTES 8 -# define SIZE_PROMPT_ACCOLADE 7 -# define SIZE_PROMPT_BRACKET 7 -# define SIZE_PROMPT_BSLASH 2 +/* # define SIZE_PROMPT_QUOTES 7 */ +/* # define SIZE_PROMPT_DQUOTES 8 */ +/* # define SIZE_PROMPT_BQUOTES 8 */ +/* # define SIZE_PROMPT_ACCOLADE 7 */ +/* # define SIZE_PROMPT_BRACKET 7 */ +/* # define SIZE_PROMPT_BSLASH 2 */ # define IS_QUOTES (1 << 0) # define IS_BQUOTES (1 << 1) @@ -177,7 +177,7 @@ void ft_x(void); void ft_v(void); void ft_history_parsing(void); void ft_read_it(int input, size_t *pos, char **str); -int ft_readline(void); +char *readline(char *); int ft_completion(int ret); void ft_check_heredoc(char **str); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index ffad6bcf..b9f11bde 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/02/07 18:06:47 by jhalford ### ########.fr */ +/* Updated: 2017/02/10 00:33:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ # define LEXER_H # include "minishell.h" - -typedef long long t_type; +# include "libft.h" +# include "types.h" # define TK_LESS (1 << 0) # define TK_GREAT (1 << 1) @@ -56,8 +56,9 @@ enum e_lexstate LESSAND, QUOTE, DQUOTE, + BQUOTE, BACKSLASH, - SPECIAL, + SUBSHELL, COMMENT, }; @@ -70,19 +71,22 @@ struct s_token int size; }; -typedef struct s_data t_data; -typedef struct s_token t_token; -typedef enum e_lexstate t_lexstate; +struct s_lexer +{ + char *str; + int pos; + t_lexstate state; + t_list *stack; +}; -extern int (*g_lexer[])(t_list **alst, char *str); -int ft_lexer(t_list **alst, char **str); -int ft_tokenize(t_list **alst, char *str, t_lexstate state); +extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); + int ft_post_tokenize(t_list **alst, char **str); t_token *token_init(); -int token_append(t_token *token, char c, short int esc, - short int dbl_esc); +int token_append(t_token *token, t_lexer *lexer, + short int esc, short int esc2); void token_free(void *data, size_t size); int token_cmp_type(t_token *token, t_type *ref); void token_print(t_list *lst); @@ -93,22 +97,26 @@ int reduce_bquotes(t_list **alst, char **str); char *command_getoutput(char *command); int ft_is_delim(char c); +char *stack_to_prompt(t_list *stack); -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); -int lexer_number(t_list **alst, char *str); -int lexer_less(t_list **alst, char *str); -int lexer_great(t_list **alst, char *str); -int lexer_lessand(t_list **alst, char *str); -int lexer_greatand(t_list **alst, char *str); -int lexer_quote(t_list **alst, char *str); -int lexer_dquote(t_list **alst, char *str); -int lexer_backslash(t_list **alst, char *str); -int lexer_special(t_list **alst, char *str); -int lexer_comment(t_list **alst, char *str); +t_lexstate get_state_global(t_lexer *lexer); +t_lexstate get_state_redir(t_lexer *lexer); +int lexer_lex(t_list **alst, t_lexer *lexer); +int lexer_default(t_list **alst, t_lexer *lexer); +int lexer_newline(t_list **alst, t_lexer *lexer); +int lexer_delim(t_list **alst, t_lexer *lexer); +int lexer_sep(t_list **alst, t_lexer *lexer); +int lexer_word(t_list **alst, t_lexer *lexer); +int lexer_number(t_list **alst, t_lexer *lexer); +int lexer_less(t_list **alst, t_lexer *lexer); +int lexer_great(t_list **alst, t_lexer *lexer); +int lexer_lessand(t_list **alst, t_lexer *lexer); +int lexer_greatand(t_list **alst, t_lexer *lexer); +int lexer_quote(t_list **alst, t_lexer *lexer); +int lexer_dquote(t_list **alst, t_lexer *lexer); +int lexer_bquote(t_list **alst, t_lexer *lexer); +int lexer_backslash(t_list **alst, t_lexer *lexer); +int lexer_subshell(t_list **alst, t_lexer *lexer); +int lexer_comment(t_list **alst, t_lexer *lexer); #endif diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h deleted file mode 100644 index 941853ac..00000000 --- a/42sh/includes/line_editing.h +++ /dev/null @@ -1,89 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* line-editing.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/10 13:38:21 by jhalford #+# #+# */ -/* Updated: 2017/01/10 12:46:19 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LINE_EDITING_H -# define LINE_EDITING_H - -# include "minishell.h" -# include -# include - -# define SHELL_PROMPT "$> " -# define BUFF_SIZE 32 -# define READ_BUF 32 -# define FT_KEY_C_C "\x3" -# define FT_KEY_C_D "\x4" -# define FT_KEY_C_H "\x8" -# define FT_KEY_TAB "\x9" -# define FT_KEY_ENTER "\xa" -# define FT_KEY_C_K "\xb" -# define FT_KEY_C_L "\xc" -# define FT_KEY_C_U "\x15" -# define FT_KEY_C_Z "\x1a" -# define FT_KEY_ESC "\x1b" -# define FT_KEY_UP "\x1b\x5b\x41" -# define FT_KEY_DOWN "\x1b\x5b\x42" -# define FT_KEY_RIGHT "\x1b\x5b\x43" -# define FT_KEY_LEFT "\x1b\x5b\x44" -# define FT_KEY_C_UP "\x1b\x4f\x41" -# define FT_KEY_C_DOWN "\x1b\x4f\x42" -# define FT_KEY_C_RIGHT "\x1b\x4f\x43" -# define FT_KEY_C_LEFT "\x1b\x4f\x44" -# define FT_KEY_SQUOTE "\x22" -# define FT_KEY_DQUOTE "\x27" -# define FT_KEY_BSLASH "\x5c" -# define FT_KEY_DEL "\x7f" - -enum e_qstate -{ - Q_NONE, - Q_QUOTE, - Q_DQUOTE, - Q_BACKSLASH, -}; - -typedef struct s_data t_data; -typedef enum e_qstate t_qstate; - -extern t_stof g_keys[]; - -int ft_interactive_sh(t_data *data); -int input_init(t_data *data); -int ft_set_termios(t_data *data, int input_mode); -int ft_prompt(void); - -int ft_history_add(t_data *data); - -int ft_clear_line(t_data *data, char *buf); -int ft_line_up(t_data *data, char *buf); -int ft_line_down(t_data *data, char *buf); -int ft_line_start(t_data *data, char *buf); -int ft_line_end(t_data *data, char *buf); - -int ft_key_del(t_data *data, char *buf); -int ft_key_enter(t_data *data, char *buf); -int ft_key_ctrl_d(t_data *data, char *buf); -int ft_key_ctrl_c(t_data *data, char *buf); -int ft_key_default(t_data *data, char *buf); - -int ft_history_up(t_data *data, char *buf); -int ft_history_down(t_data *data, char *buf); -int ft_cursor_left(t_data *data, char *buf); -int ft_cursor_right(t_data *data, char *buf); -int ft_word_left(t_data *data, char *buf); -int ft_word_right(t_data *data, char *buf); - -void qstate_none(t_qstate *new, char c); -void qstate_quote(t_qstate *new, char c); -void qstate_dquote(t_qstate *new, char c); - -#endif diff --git a/42sh/includes/lst.h b/42sh/includes/lst.h deleted file mode 100644 index ee4926df..00000000 --- a/42sh/includes/lst.h +++ /dev/null @@ -1,80 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* lst.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2016/12/12 14:59:12 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LST_H -# define LST_H - -# include "libft.h" - -struct s_list -{ - void *content; - size_t content_size; - struct s_list *next; -}; - -typedef struct s_list t_list; - -t_list *ft_lstnew(void const *content, size_t content_size); -void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); -void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); -void ft_lstadd(t_list **alst, t_list *new); -void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); -t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); - -t_list *ft_lstnew_range(int a, int b); -void ft_lsteadd(t_list **alst, t_list *new); -void ft_lstnadd(t_list **alst, t_list *new, int n); -void ft_lstsort(t_list **begin_list, int (*cmp)()); -void ft_lst_print(t_list *list, void (*printer)()); -int ft_lstsize(t_list *lst); -t_list *ft_lstlast(t_list *lst); -void ft_lst_sorted_merge( - t_list **begin_list1, - t_list *begin_list2, - int (*cmp)()); -void ft_lst_sorted_insert( - t_list **begin_list, - t_list *insert, - int (*cmp)()); -void ft_lst_delif( - t_list **alist, - void *data_ref, - int (*cmp)(), - void (*del)(void *, size_t)); -void ft_lst_delsub( - t_list **alst, - t_list *sub, int (*cmp)(), - void (*del)(void *, size_t)); -void ft_lst_cfree(void *ptr, size_t size); -void ft_lst_bfree(void *ptr, size_t size); -t_list *ft_lst_filter( - t_list *lst, - void const *data_ref, - t_list *(*f)(t_list *elem, void const *)); -t_list *ft_lst_removeif( - t_list **alst, - void *data_ref, - int (*cmp)()); -t_list *ft_lst_find( - t_list *begin_list, - void *data_ref, - int (*cmp)()); -t_list *ft_lstpop(t_list **lst); -void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); -void ft_lst_reverse(t_list **begin_list); - -int ft_diff(void *a, void *b); -t_list *ft_id(t_list *a); -t_list *ft_lst_at(t_list *list, unsigned int nbr); - -#endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index fbaaac4c..d1e3fa06 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/02/03 12:16:52 by alao ### ########.fr */ +/* Updated: 2017/02/10 00:26:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ # define SHELL_NAME "minishell" # include "libft.h" - # include "types.h" # include "lexer.h" # include "parser.h" @@ -66,11 +65,11 @@ void shell_exit(void); int data_init(void); void data_exit(void); -int shell_single_command(char *command); - void ft_expand_dollar(char **av, char **env); char *ft_findexec(char *path, char *file); +int remove_trailing_esc_nl(char *str); + char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 07cec9b7..d2d802aa 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/02/03 15:03:52 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 19:52:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,10 @@ typedef struct s_exec t_exec; typedef struct s_jobc t_jobc; typedef enum e_mode t_mode; +typedef struct s_lexer t_lexer; +typedef enum e_lexstate t_lexstate; +typedef struct s_token t_token; + typedef struct s_parser t_parser; typedef struct s_ld t_ld; typedef struct s_astnode t_astnode; diff --git a/42sh/libft b/42sh/libft index b53fcb9d..acd7e54f 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b53fcb9db8b4baf53c73b17726f1740c4af12be0 +Subproject commit acd7e54fb8045b3958dd239d469f1476404468b7 diff --git a/42sh/src/lexer/get_lexer_state.c b/42sh/src/lexer/get_state_global.c similarity index 62% rename from 42sh/src/lexer/get_lexer_state.c rename to 42sh/src/lexer/get_state_global.c index 9a738e65..3f59ab73 100644 --- a/42sh/src/lexer/get_lexer_state.c +++ b/42sh/src/lexer/get_state_global.c @@ -1,32 +1,37 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* get_lexer_state.c :+: :+: :+: */ +/* get_state_global.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/10 13:45:46 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:34:14 by wescande ### ########.fr */ +/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ +/* Updated: 2017/02/09 22:12:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -t_lexstate get_lexer_state(char *str) +t_lexstate get_state_global(t_lexer *lexer) { - if (ft_is_delim(*str)) + char c; + + c = lexer->str[lexer->pos]; + if (ft_is_delim(c)) return (DELIM); - else if (*str == '#') + else if (c == '#') return (COMMENT); - else if (*str == '&' || *str == ';' || *str == '|') + else if (c == '&' || c == ';' || c == '|') return (SEP); - else if (*str == '\\') + else if (c == '\\') return (BACKSLASH); - else if (*str == '\'') + else if (c == '\'') return (QUOTE); - else if (*str == '\"') + else if (c == '\"') return (DQUOTE); - else if (*str == '(' || *str == ')' || *str == '`') - return (SPECIAL); + else if (c == '`') + return (BQUOTE); + else if (c == '(' || c == ')') + return (SUBSHELL); return (0); } diff --git a/42sh/src/lexer/ft_lexer.c b/42sh/src/lexer/get_state_redir.c similarity index 62% rename from 42sh/src/lexer/ft_lexer.c rename to 42sh/src/lexer/get_state_redir.c index 71b033f1..7b6acd31 100644 --- a/42sh/src/lexer/ft_lexer.c +++ b/42sh/src/lexer/get_state_redir.c @@ -1,28 +1,25 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lexer.c :+: :+: :+: */ +/* get_state_redir.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */ -/* Updated: 2017/02/06 21:49:55 by jhalford ### ########.fr */ +/* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */ +/* Updated: 2017/02/09 20:39:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int ft_lexer(t_list **alst, char **command) +t_lexstate get_state_redir(t_lexer *lexer) { - int ret; + char c; - if (!*command) - return (1); - ret = 0; - if (ft_tokenize(alst, *command, DEFAULT)) - ret = 1; - else if (ft_post_tokenize(alst, command)) - ret = 1; - ft_strdel(command); - return (ret); + c = lexer->str[lexer->pos]; + if (c == '>') + return (GREAT); + else if (c == '<') + return (LESS); + return (0); } diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index eb339d0a..a2f02f7c 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,18 +6,21 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -/* Updated: 2017/02/07 11:39:15 by wescande ### ########.fr */ +/* Updated: 2017/02/09 19:53:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_backslash(t_list **alst, char *str) +int lexer_backslash(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = TK_WORD; - token_append(token, str[1], 1, 1); - return (ft_tokenize(alst, str + 2, WORD)); + lexer->pos++; + token_append(token, lexer, 1, 1); + lexer->pos++; + lexer->state = WORD; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c new file mode 100644 index 00000000..a9e32dda --- /dev/null +++ b/42sh/src/lexer/lexer_bquote.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_bquote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ +/* Updated: 2017/02/09 22:07:04 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "lexer.h" + +int lexer_bquote(t_list **alst, t_lexer *lexer) +{ + t_token *token; + + token = (*alst)->content; + token->type = TK_Q_WORD; + lexer->pos++; + push(&lexer->stack, BQUOTE); + if (lexer->str[lexer->pos] == '`') + { + lexer->state = WORD; + lexer->pos++; + pop(&lexer->stack); + return (lexer_lex(alst, lexer)); + } + else if (lexer->str[lexer->pos] == 0) + return (0); + token_append(token, lexer, 0, 0); + return (lexer_quote(alst, lexer)); +} + diff --git a/42sh/src/lexer/lexer_comment.c b/42sh/src/lexer/lexer_comment.c index f744ca44..71f053cd 100644 --- a/42sh/src/lexer/lexer_comment.c +++ b/42sh/src/lexer/lexer_comment.c @@ -6,18 +6,18 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/07 12:15:59 by jhalford #+# #+# */ -/* Updated: 2017/02/07 12:56:53 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 19:54:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_comment(t_list **alst, char *str) +int lexer_comment(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; - if (*str == '\n') - return (ft_tokenize(&(*alst)->next, str, NEWLINE)); - return (lexer_comment(alst, str + 1)); + if (lexer->str[lexer->pos] == '\n') + return (lexer_lex(&(*alst)->next, lexer)); + return (lexer_comment(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 0359269c..ed43b9d6 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,29 +6,35 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/02/07 11:39:07 by wescande ### ########.fr */ +/* Updated: 2017/02/09 20:40:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_default(t_list **alst, char *str) +int lexer_default(t_list **alst, t_lexer *lexer) { t_lexstate state; t_token *token; + char c; - if ((state = get_lexer_state(str))) - return (ft_tokenize(alst, str, state)); - if (*str == '>') - return (ft_tokenize(alst, str, GREAT)); - else if (*str == '<') - return (ft_tokenize(alst, str, LESS)); - else if (ft_isdigit(*str)) - state = NUMBER; + c = lexer->str[lexer->pos]; + if ((state = get_state_global(lexer))) + { + lexer->state = state; + return (lexer_lex(alst, lexer)); + } + if ((state = get_state_redir(lexer))) + { + lexer->state = state; + return (lexer_lex(alst, lexer)); + } + else if (ft_isdigit(c)) + lexer->state = NUMBER; else - state = WORD; + lexer->state = WORD; token = (*alst)->content; - token_append(token, *str, 0, 0); + token_append(token, lexer, 0, 0); token->type = TK_N_WORD; - return (ft_tokenize(alst, str + 1, state)); + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index 8e27dd19..6fa29b29 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,25 +6,25 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -/* Updated: 2017/02/07 12:48:11 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 20:02:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_delim(t_list **alst, char *str) +int lexer_delim(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; - while (ft_is_delim(*str)) - str++; + while (ft_is_delim(lexer->str[lexer->pos])) + lexer->pos++; if (token->type) - return (ft_tokenize(&(*alst)->next, str, DEFAULT)); + return (lexer_lex(&(*alst)->next, lexer)); else { - if (!*str) + if (!lexer->str[lexer->pos]) ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free); - return (ft_tokenize(alst, str, DEFAULT)); + return (lexer_lex(alst, lexer)); } } diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 9d52263b..7077fd7b 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,28 +6,45 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:35:38 by wescande ### ########.fr */ +/* Updated: 2017/02/10 00:33:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_dquote(t_list **alst, char *str) +int lexer_dquote(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = TK_DQ_WORD; - str++; - if (*str == '"') - return (ft_tokenize(alst, str + 1, DEFAULT)); - if (*str == '\\') + if (*(int*)lexer->stack->content != DQUOTE) + push(&lexer->stack, DQUOTE); + lexer->pos++; + if (lexer->str[lexer->pos] == '"') { - if (str[1] != '"') - token_append(token, str[0], 1, 0); - token_append(token, str[1], 1, 1); - return (lexer_dquote(alst, str + 1)); + lexer->pos++; + lexer->state = WORD; + pop(&lexer->stack); + return (lexer_lex(alst, lexer)); } - token_append(token, *str, 1, 0); - return (lexer_dquote(alst, str)); + else if (lexer->str[lexer->pos] == '\\') + { + if (lexer->str[lexer->pos + 1] == '"') + token_append(token, lexer, 1, 0); + else if (lexer->str[lexer->pos + 1] == 0) + { + push(&lexer->stack, BACKSLASH); + return (0); + } + lexer->pos++; + token_append(token, lexer, 1, 1); + return (lexer_dquote(alst,lexer)); + } + else if (lexer->str[lexer->pos] == '`') + lexer_bquote(alst, lexer); + else if (lexer->str[lexer->pos] == 0) + return (0); + token_append(token, lexer, 1, 0); + return (lexer_dquote(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_great.c b/42sh/src/lexer/lexer_great.c index a0f069c8..5731cdae 100644 --- a/42sh/src/lexer/lexer_great.c +++ b/42sh/src/lexer/lexer_great.c @@ -6,33 +6,39 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:36:19 by wescande ### ########.fr */ +/* Updated: 2017/02/09 19:57:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_great(t_list **alst, char *str) +int lexer_great(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; - token_append(token, str[0], 0, 0); - if (*(str + 1) == '&') + token_append(token, lexer, 0, 0); + if (lexer->str[lexer->pos + 1] == '&') { token->type = TK_GREATAND; - token_append(token, str[1], 0, 0); - return (lexer_greatand(alst, str + 2)); + lexer->pos++; + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_greatand(alst, lexer)); } - else if (*(str + 1) == '>') + if (lexer->str[lexer->pos + 1] == '>') { token->type = TK_DGREAT; - token_append(token, str[1], 0, 0); - return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT)); + lexer->pos++; + token_append(token, lexer, 0, 0); + lexer->pos++; + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } else { token->type = TK_GREAT; - return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } } diff --git a/42sh/src/lexer/lexer_greatand.c b/42sh/src/lexer/lexer_greatand.c index d9f9787f..d2da04ed 100644 --- a/42sh/src/lexer/lexer_greatand.c +++ b/42sh/src/lexer/lexer_greatand.c @@ -6,27 +6,31 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */ -/* Updated: 2017/02/07 11:37:08 by wescande ### ########.fr */ +/* Updated: 2017/02/09 19:56:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_greatand(t_list **alst, char *str) +int lexer_greatand(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = TK_GREATAND; - if (ft_isdigit(*str)) + if (ft_isdigit(lexer->str[lexer->pos])) { - token_append(token, *str, 0, 0); - return (lexer_greatand(alst, str + 1)); + token_append(token, lexer, 0, 0); + lexer->str++; + return (lexer_greatand(alst, lexer)); } - else if (*str == '-') + else if (lexer->str[lexer->pos] == '-') { - token_append(token, *str, 0, 0); - return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); + token_append(token, lexer, 0, 0); + lexer->str++; + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } - return (ft_tokenize(alst, str, DEFAULT)); + lexer->state = DEFAULT; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 7f067ab0..00798f44 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,33 +6,39 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:36:42 by wescande ### ########.fr */ +/* Updated: 2017/02/09 20:37:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_less(t_list **alst, char *str) +int lexer_less(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; - token_append(token, str[0], 0, 0); - if (*(str + 1) == '&') + token_append(token, lexer, 0, 0); + if (lexer->str[lexer->pos + 1] == '&') { token->type = TK_LESSAND; - token_append(token, str[1], 0, 0); - return (lexer_lessand(alst, str + 2)); + lexer->pos++; + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_lessand(alst, lexer)); } - else if (*(str + 1) == '<') + if (lexer->str[lexer->pos + 1] == '<') { token->type = TK_DLESS; - token_append(token, str[1], 0, 0); - return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT)); + lexer->pos++; + token_append(token, lexer, 0, 0); + lexer->pos++; + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } else { token->type = TK_LESS; - return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } } diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/src/lexer/lexer_lessand.c index 04c7fe8e..cf1547cc 100644 --- a/42sh/src/lexer/lexer_lessand.c +++ b/42sh/src/lexer/lexer_lessand.c @@ -6,27 +6,31 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:37:07 by wescande ### ########.fr */ +/* Updated: 2017/02/09 19:56:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_lessand(t_list **alst, char *str) +int lexer_lessand(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = TK_LESSAND; - if (ft_isdigit(*str)) + if (ft_isdigit(lexer->str[lexer->pos])) { - token_append(token, *str, 0, 0); - return (lexer_lessand(alst, str + 1)); + token_append(token, lexer, 0, 0); + lexer->str++; + return (lexer_lessand(alst, lexer)); } - else if (*str == '-') + else if (lexer->str[lexer->pos] == '-') { - token_append(token, *str, 0, 0); - return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); + token_append(token, lexer, 0, 0); + lexer->str++; + lexer->state = DEFAULT; + return (lexer_lex(&(*alst)->next, lexer)); } - return (ft_tokenize(alst, str, DEFAULT)); + lexer->state = DEFAULT; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/lexer_lex.c similarity index 69% rename from 42sh/src/lexer/ft_tokenize.c rename to 42sh/src/lexer/lexer_lex.c index fccf7a7a..a406fbc8 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/lexer_lex.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_tokenize.c :+: :+: :+: */ +/* lexer_lex.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:33:34 by wescande ### ########.fr */ +/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ +/* Updated: 2017/02/09 22:58:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int (*g_lexer[])(t_list **alst, char *str) = +int (*g_lexer[])(t_list **alst, t_lexer *lexer) = { &lexer_default, &lexer_newline, @@ -26,8 +26,9 @@ int (*g_lexer[])(t_list **alst, char *str) = &lexer_lessand, &lexer_quote, &lexer_dquote, + &lexer_bquote, &lexer_backslash, - &lexer_special, + &lexer_subshell, &lexer_comment, }; @@ -36,16 +37,16 @@ int ft_is_delim(char c) return (c == ' ' || c == '\t' || c == '\n'); } -int ft_tokenize(t_list **alst, char *str, t_lexstate state) +int lexer_lex(t_list **alst, t_lexer *lexer) { t_token *token; - if (!*str) + if (!lexer->str[lexer->pos]) return (0); if (!*alst) { token = token_init(); *alst = ft_lstnew(token, sizeof(*token)); } - return ((*g_lexer[state])(alst, str)); + return ((*g_lexer[lexer->state])(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_newline.c b/42sh/src/lexer/lexer_newline.c index c563d2eb..396dc6d3 100644 --- a/42sh/src/lexer/lexer_newline.c +++ b/42sh/src/lexer/lexer_newline.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ -/* Updated: 2017/02/07 12:54:48 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 19:55:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_newline(t_list **alst, char *str) +int lexer_newline(t_list **alst, t_lexer *lexer) { t_token *token; @@ -20,7 +20,7 @@ int lexer_newline(t_list **alst, char *str) { token = (*alst)->content; if (*token->data) - return (lexer_newline(&(*alst)->next, str)); + return (lexer_newline(&(*alst)->next, lexer)); } else { @@ -29,5 +29,5 @@ int lexer_newline(t_list **alst, char *str) } token = (*alst)->content; token->type = TK_NEWLINE; - return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); + return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index 5cb3fa24..b7519817 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,28 +6,31 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -/* Updated: 2017/02/07 11:39:29 by wescande ### ########.fr */ +/* Updated: 2017/02/09 20:41:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_number(t_list **alst, char *str) +int lexer_number(t_list **alst, t_lexer *lexer) { t_token *token; t_lexstate state; token = (*alst)->content; - if ((state = get_lexer_state(str))) - return (ft_tokenize(alst, str, state)); - if (*str == '>') - return (ft_tokenize(alst, str, GREAT)); - else if (*str == '<') - return (ft_tokenize(alst, str, LESS)); - else if (ft_isdigit(*str)) + if ((state = get_state_global(lexer))) + return (lexer_lex(alst, lexer)); + else if ((state = get_state_redir(lexer))) { - token_append(token, *str, 0, 0); - return (lexer_number(alst, str + 1)); + lexer->state = state; + return (lexer_lex(alst, lexer)); } - return (ft_tokenize(alst, str, DEFAULT)); + else if (ft_isdigit(lexer->str[lexer->pos])) + { + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_number(alst, lexer)); + } + lexer->state = DEFAULT; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_quote.c b/42sh/src/lexer/lexer_quote.c index 647ac038..b0764b7d 100644 --- a/42sh/src/lexer/lexer_quote.c +++ b/42sh/src/lexer/lexer_quote.c @@ -6,21 +6,29 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */ -/* Updated: 2017/02/07 11:39:24 by wescande ### ########.fr */ +/* Updated: 2017/02/09 22:13:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_quote(t_list **alst, char *str) +int lexer_quote(t_list **alst, t_lexer *lexer) { t_token *token; token = (*alst)->content; token->type = TK_Q_WORD; - str++; - if (*str == '\'') - return (ft_tokenize(alst, str + 1, WORD)); - token_append(token, *str, 1, 1); - return (lexer_quote(alst, str)); + lexer->pos++; + push(&lexer->stack, QUOTE); + if (lexer->str[lexer->pos] == '\'') + { + lexer->state = WORD; + lexer->pos++; + pop(&lexer->stack); + return (lexer_lex(alst, lexer)); + } + else if (lexer->str[lexer->pos] == 0) + return (0); + token_append(token, lexer, 1, 1); + return (lexer_quote(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index c9b20e78..581f2395 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,21 +6,23 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/02/07 12:53:46 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 20:43:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_sep(t_list **alst, char *str) +int lexer_sep(t_list **alst, t_lexer *lexer) { - t_token *token; + t_token *token; + char c; + char cn; if (*alst) { token = (*alst)->content; if (*token->data) - return (lexer_sep(&(*alst)->next, str)); + return (lexer_sep(&(*alst)->next, lexer)); } else { @@ -28,13 +30,13 @@ int lexer_sep(t_list **alst, char *str) *alst = ft_lstnew(token, sizeof(*token)); } token = (*alst)->content; - if (str[0] == '&') - token->type = str[1] == '&' ? TK_AND_IF : TK_AMP; - if (str[0] == '|') - token->type = str[1] == '|' ? TK_OR_IF : TK_PIPE; - token->type = (*str == ';') ? TK_SEMI : token->type; - return (ft_tokenize(&(*alst)->next, - str + 1 + - (token->type & (TK_AND_IF | TK_OR_IF) ? 1 : 0), - DEFAULT)); + c = lexer->str[lexer->pos]; + cn = lexer->str[lexer->pos + 1]; + if (c == '&') + token->type = cn == '&' ? TK_AND_IF : TK_AMP; + else if (c == '|') + token->type = cn == '|' ? TK_OR_IF : TK_PIPE; + token->type = (c == ';') ? TK_SEMI : token->type; + lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF) ? 1 : 0); + return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_special.c b/42sh/src/lexer/lexer_subshell.c similarity index 80% rename from 42sh/src/lexer/lexer_special.c rename to 42sh/src/lexer/lexer_subshell.c index 7d3d7800..278849bb 100644 --- a/42sh/src/lexer/lexer_special.c +++ b/42sh/src/lexer/lexer_subshell.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 15:35:38 by jhalford #+# #+# */ -/* Updated: 2017/01/11 17:36:10 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 22:09:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_special(t_list **alst, char *str) +int lexer_subshell(t_list **alst, t_lexer *lexer) { t_token *token; t_list **lst; @@ -27,12 +27,11 @@ int lexer_special(t_list **alst, char *str) token = token_init(); *lst = ft_lstnew(token, sizeof(*token)); token = (*lst)->content; - if (*str == '(') + if (lexer->str[lexer->pos] == '(') token->type = TK_PAREN_OPEN; - else if (*str == ')') + else if (lexer->str[lexer->pos] == ')') token->type = TK_PAREN_CLOSE; - else if (*str == '`') - token->type = TK_BQUOTE; - token->data = str; - return (ft_tokenize(&(*lst)->next, str + 1, DEFAULT)); + token->data = lexer->str; + lexer->pos++; + return (lexer_lex(&(*lst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index c952c6f5..b5fa0ae9 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,25 +6,27 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:37:44 by wescande ### ########.fr */ +/* Updated: 2017/02/09 20:43:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int lexer_word(t_list **alst, char *str) +int lexer_word(t_list **alst, t_lexer *lexer) { t_token *token; t_lexstate state; token = (*alst)->content; token->type = TK_N_WORD; - if ((state = get_lexer_state(str))) - return (ft_tokenize(alst, str, state)); - if (*str == '>') - return (ft_tokenize(&(*alst)->next, str, GREAT)); - else if (*str == '<') - return (ft_tokenize(&(*alst)->next, str, LESS)); - token_append(token, *str, 0, 0); - return (ft_tokenize(alst, str + 1, WORD)); + if ((state = get_state_global(lexer))) + return (lexer_lex(alst, lexer)); + if ((state = get_state_redir(lexer))) + { + lexer->state = state; + return (lexer_lex(alst, lexer)); + } + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index 4e293684..f7c416de 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/02/03 15:40:36 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 20:45:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ int reduce_bquotes(t_list **alst, char **str) char *fit; char *bq_start; char *bq_end; + t_lexer lexer; tk = TK_BQUOTE; if ((start = ft_lst_find(*alst, &tk, token_cmp_type))) @@ -44,7 +45,11 @@ int reduce_bquotes(t_list **alst, char **str) ft_strdel(str); *str = new; ft_lstdel(alst, token_free); - ft_tokenize(alst, new, DEFAULT); + + lexer.pos = 0; + lexer.str = *str; + lexer.state = DEFAULT; + lexer_lex(alst, &lexer); return (1); } return (0); diff --git a/42sh/src/lexer/stack_to_prompt.c b/42sh/src/lexer/stack_to_prompt.c new file mode 100644 index 00000000..0343dcb2 --- /dev/null +++ b/42sh/src/lexer/stack_to_prompt.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack_to_prompt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/09 21:25:26 by jhalford #+# #+# */ +/* Updated: 2017/02/09 22:49:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "lexer.h" + +char *stack_to_prompt(t_list *stack) +{ + t_flag top; + + if (!stack) + return (NULL); + top = *(int*)stack->content; + if (top == BACKSLASH) + return ("> "); + else if (top == QUOTE) + return ("quote >"); + else if (top == DQUOTE) + return ("dquote >"); + else if (top == BQUOTE) + return ("bquote >"); + else if (top == SUBSHELL) + return ("subsh >"); + else + return (" > "); +} diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index d7205017..b2b00fb3 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,16 +6,18 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/02/08 13:55:31 by wescande ### ########.fr */ +/* Updated: 2017/02/09 19:37:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int token_append(t_token *token, char c, short int esc, short int esc2) +int token_append(t_token *token, t_lexer *lexer, short int esc, short int esc2) { int len; + char c; + c = lexer->str[lexer->pos]; len = ft_strlen(token->data); if (len >= token->size) { diff --git a/42sh/src/line-editing/check_backslash.c b/42sh/src/line-editing/check_backslash.c deleted file mode 100644 index 4d8412b9..00000000 --- a/42sh/src/line-editing/check_backslash.c +++ /dev/null @@ -1,128 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* check_backslash.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */ -/* Updated: 2017/02/05 17:43:44 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -t_prompt_type g_prompt_tab[] = -{ - {IS_QUOTES , SIZE_PROMPT_QUOTES , PROMPT_QUOTES }, - {IS_BQUOTES , SIZE_PROMPT_BQUOTES , PROMPT_BQUOTES }, - {IS_DQUOTES , SIZE_PROMPT_DQUOTES , PROMPT_DQUOTES }, - {IS_ACCOLADE , SIZE_PROMPT_ACCOLADE , PROMPT_ACCOLADE }, - {IS_BRACKET , SIZE_PROMPT_BRACKET , PROMPT_BRACKET }, - {IS_BSLASH , SIZE_PROMPT_BSLASH , PROMPT_BSLASH }, - {0 , 0 , 0 }, -}; - -t_brackets g_brackets = {0 , {0}}; - -void ft_read_more(short c) -{ - char *str_tmp; - char *str_tmp2; - int i; - - i = 0; - str_tmp2 = data_singleton()->line.input; - str_tmp = ft_strjoin(str_tmp2, "\n"); - free(str_tmp2); - STR = NULL; - POS = 0; - while (g_prompt_tab[i].key && !(g_prompt_tab[i].key & c)) - ++i; - data_singleton()->line.prompt_size = g_prompt_tab[i].value; - ft_printf("\n%s", g_prompt_tab[i].new_prompt); - str_tmp2 = ft_read_stdin(); - str_tmp2 = ft_strjoin(str_tmp, STR); - free(str_tmp); - free(STR); - STR = str_tmp2; - ft_check_line(); -} - -static void ft_check_this_char_quotes(char c, short *status) -{ - int i; - char *stats; - - i = 0; - stats = "\'`\"\\"; - while (stats[i] && stats[i] != c) - ++i; - if (!stats[i]) - return ; - if ((1 << i) & ~(*status)) - { - if (((1 << i) > *status && (*status == 0 && !(IS_QUOTES & *status) - && (!(IS_DQUOTES & *status)))) - || (((1 << i) == IS_BQUOTES) && !(IS_QUOTES & *status))) - (*status) = (*status) | (1 << i); - } - else - (*status) = (*status) ^ (1 << i); -} - -static int ft_brackets(char c) -{ - if (c == '(') - { - g_brackets.tabl[g_brackets.pos] = '('; - ++g_brackets.pos; - } - else if (c == '{') - { - g_brackets.tabl[g_brackets.pos] = '{'; - ++g_brackets.pos; - } - else if (c == '}') - { - if (!g_brackets.pos || g_brackets.tabl[g_brackets.pos - 1] != '{') - return (1); - g_brackets.tabl[--g_brackets.pos] = '\0'; - } - else if (c == ')') - { - if (!g_brackets.pos || g_brackets.tabl[g_brackets.pos - 1] != '(') - return (1); - g_brackets.tabl[--g_brackets.pos] = '\0'; - } - return (0); -} - -void ft_check_line(void) -{ - int i; - short status; - - i = -1; - status = 0; - ft_reset_tab((char *)g_brackets.tabl); - g_brackets.pos = 0; - if (!STR) - return ; - while (STR[++i]) - { - if (IS_BSLASH & status) - status = status ^ IS_BSLASH; - else - { - ft_check_this_char_quotes(STR[i], &status); - if (!status && ft_brackets(STR[i])) - return ; - } - } - if (g_brackets.pos && g_brackets.tabl[0] == '(') - status = status | IS_BRACKET; - else if (g_brackets.pos && g_brackets.tabl[0] == '{') - status = status | IS_ACCOLADE; - (status) ? ft_read_more(status) : 0; -} diff --git a/42sh/src/line-editing/prompt.c b/42sh/src/line-editing/ftprompt.c similarity index 92% rename from 42sh/src/line-editing/prompt.c rename to 42sh/src/line-editing/ftprompt.c index ea94ec3b..85f2427d 100644 --- a/42sh/src/line-editing/prompt.c +++ b/42sh/src/line-editing/ftprompt.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* prompt.c :+: :+: :+: */ +/* ft_prompt.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/02/05 17:42:23 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 16:49:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ static int ft_currend_dir(void) return (ft_strlen(env[i] + j + 1)); } -void ft_prompt(void) +void ft_prompt() { int ret; diff --git a/42sh/src/line-editing/get_touch.c b/42sh/src/line-editing/get_touch.c index bea7ad8a..71c31e85 100644 --- a/42sh/src/line-editing/get_touch.c +++ b/42sh/src/line-editing/get_touch.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/02/05 16:57:57 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 17:25:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ char *ft_read_stdin(void) ft_print(ret); else if (ret == 10) return (STR); - else if (ft_isascii(ret) == 0) - ft_read_it(ret, &POS, &STR); + /* else if (ft_isascii(ret) == 0) */ + /* ft_read_it(ret, &POS, &STR); */ } } diff --git a/42sh/src/line-editing/history.c b/42sh/src/line-editing/history.c index b2e40292..cab1a3ac 100644 --- a/42sh/src/line-editing/history.c +++ b/42sh/src/line-editing/history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */ -/* Updated: 2017/02/05 17:00:18 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 16:24:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/history_parsing.c b/42sh/src/line-editing/history_parsing.c index 15288f3c..b7187bc9 100644 --- a/42sh/src/line-editing/history_parsing.c +++ b/42sh/src/line-editing/history_parsing.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/02/05 16:58:43 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 16:25:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ static int ft_history_parsing_4(char *str, int *i) { tmp = ft_nbr_len(ft_atoi(str + *i + 1)); ft_realloc_str_history(&(data_singleton()->line.input), *i, - ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1); + ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1); (*i) += tmp; return (1); } @@ -43,16 +43,16 @@ static int ft_history_parsing_3(char *str, int *i) { tmp = ft_nbr_len(ft_atoi(str + *i + 2)); ft_realloc_str_history(&(data_singleton()->line.input), *i, - data_singleton()->line.list_size - ft_atoi(str + *i + 2), - ft_nbr_len(ft_atoi(str + *i + 2)) + 2); + data_singleton()->line.list_size - ft_atoi(str + *i + 2), + ft_nbr_len(ft_atoi(str + *i + 2)) + 2); i += tmp; } else if (str[*i + 1] == '?') ft_realloc_str_history_3(&(data_singleton()->line.input), *i, - ft_strdupi_w(str + *i + 2)); + ft_strdupi_w(str + *i + 2)); else if (str[*i + 1] != ' ') ft_realloc_str_history_2(&(data_singleton()->line.input), *i, - ft_strdupi_w(str + *i + 1)); + ft_strdupi_w(str + *i + 1)); else return (0); return (1); diff --git a/42sh/src/line-editing/reader.c b/42sh/src/line-editing/reader.c index 684afd69..3068e52d 100644 --- a/42sh/src/line-editing/reader.c +++ b/42sh/src/line-editing/reader.c @@ -6,66 +6,66 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */ -/* Updated: 2017/02/04 15:37:55 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 16:59:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +/* #include "minishell.h" */ -static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j) -{ - int i; +/* static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j) */ +/* { */ +/* int i; */ - i = 0; - while (i < 4 && t[i] == '\0') - ++i; - while (i < 4) - { - if (t[i] && ft_isprint(t[i])) - { - *str = ft_realloc_imput(*str, t[i], *pos); - ++(*pos); - ++(*j); - } - ++i; - } -} +/* i = 0; */ +/* while (i < 4 && t[i] == '\0') */ +/* ++i; */ +/* while (i < 4) */ +/* { */ +/* if (t[i] && ft_isprint(t[i])) */ +/* { */ +/* *str = ft_realloc_imput(*str, t[i], *pos); */ +/* ++(*pos); */ +/* ++(*j); */ +/* } */ +/* ++i; */ +/* } */ +/* } */ -static void ft_read_it_2(int input, char t[5]) -{ - t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0'; - if (t[3]) - input = input % ft_pow(256, 3); - t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0'; - if (t[2]) - input = input % ft_pow(256, 2); - t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0'; - if (t[1]) - input = input % ft_pow(256, 1); - t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0'; - if (t[0]) - input = input % ft_pow(256, 0); - t[4] = '\0'; -} +/* static void ft_read_it_2(int input, char t[5]) */ +/* { */ +/* t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0'; */ +/* if (t[3]) */ +/* input = input % ft_pow(256, 3); */ +/* t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0'; */ +/* if (t[2]) */ +/* input = input % ft_pow(256, 2); */ +/* t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0'; */ +/* if (t[1]) */ +/* input = input % ft_pow(256, 1); */ +/* t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0'; */ +/* if (t[0]) */ +/* input = input % ft_pow(256, 0); */ +/* t[4] = '\0'; */ +/* } */ -void ft_read_it(int input, size_t *pos, char **str) -{ - int j; - char t[5]; - size_t pos_tmp; +/* void ft_read_it(int input, size_t *pos, char **str) */ +/* { */ +/* int j; */ +/* char t[5]; */ +/* size_t pos_tmp; */ - j = 0; - pos_tmp = *pos; - if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || - input == 126 || input == 993090331 || input == 925981467 || - input == 21298 || input == 892427035 || input == 8270395 || input == - 942758683 || input == 993090331 || input == 18489 || input == 17977) - return ; - ft_read_it_2(input, t); - ft_read_it_3(str, t, pos, &j); - *pos = pos_tmp; - ft_current_str((*str), *pos); - ft_get_next_str((*str), pos); - ft_putnc('\b', *pos - (pos_tmp + j)); - *pos = (pos_tmp + j); -} +/* j = 0; */ +/* pos_tmp = *pos; */ +/* if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || */ +/* input == 126 || input == 993090331 || input == 925981467 || */ +/* input == 21298 || input == 892427035 || input == 8270395 || input == */ +/* 942758683 || input == 993090331 || input == 18489 || input == 17977) */ +/* return ; */ +/* ft_read_it_2(input, t); */ +/* ft_read_it_3(str, t, pos, &j); */ +/* *pos = pos_tmp; */ +/* ft_current_str((*str), *pos); */ +/* ft_get_next_str((*str), pos); */ +/* ft_putnc('\b', *pos - (pos_tmp + j)); */ +/* *pos = (pos_tmp + j); */ +/* } */ diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index efca1222..6a5079ac 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/02/04 16:19:36 by gwojda ### ########.fr */ +/* Updated: 2017/02/09 17:03:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,11 +42,11 @@ void ft_init_history(void) close(fd); } -struct termios *ft_save_stats_term(void) +struct termios *ft_save_stats_term(int save) { static struct termios *term_save = NULL; - if (!term_save) + if (save) { term_save = (struct termios *)malloc(sizeof(struct termios)); tcgetattr(0, term_save); @@ -71,29 +71,32 @@ struct termios *ft_stats_term_termcaps(void) return (term); } -int ft_readline(void) +char *readline(char *prompt) { - ft_save_stats_term(); + char *input; + + ft_save_stats_term(1); if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1) - return (-1); + return (NULL); if (STR) ft_strdel(&STR); data_singleton()->line.list_cur = data_singleton()->line.list_beg; POS = 0; - ft_prompt(); - STR = ft_read_stdin(); - ft_check_line(); + prompt ? ft_putstr(prompt) : ft_prompt(); + input = ft_read_stdin(); ft_putchar('\n'); - ft_check_heredoc(&STR); - ft_history_parsing(); - if (STR && (!data_singleton()->line.list_beg || - ft_strcmp(data_singleton()->line.list_beg->prev->str, STR))) - { - ft_push_back_history(&data_singleton()->line.list_beg, - ft_create_history_list(STR)); - ft_add_in_history_file(STR); - } - if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1) - return (-1); - return (0); + /* ft_check_line(); */ + /* ft_check_heredoc(&STR); */ + if (tcsetattr(0, TCSANOW, ft_save_stats_term(0)) == -1) + return (NULL); + return (input); + + /* ft_history_parsing(); */ + /* if (STR && (!data_singleton()->line.list_beg || */ + /* ft_strcmp(data_singleton()->line.list_beg->prev->str, STR))) */ + /* { */ + /* ft_push_back_history(&data_singleton()->line.list_beg, */ + /* ft_create_history_list(STR)); */ + /* ft_add_in_history_file(STR); */ + /* } */ } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index b9cc077b..4cdf0625 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,25 +6,32 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:18:21 by jhalford ### ########.fr */ +/* Updated: 2017/02/10 00:36:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int shell_single_command(char *command) +int interactive_shell() { t_list *token; + t_list *ltoken; + t_lexer lexer; t_btree *ast; + lexer.pos = 0; + lexer.state = DEFAULT; + lexer.str = NULL; token = NULL; - ast = NULL; - - DG("{inv}{mag}got command '%s'", command); - if (ft_lexer(&token, &command) || !token) - return (1); - - token_print(token); + lexer.stack = NULL; + do { + if (lexer.stack && *(int*)lexer.stack->content == BACKSLASH) + pop(&lexer.stack); + ft_strappend(&lexer.str, readline(stack_to_prompt(lexer.stack))); + ltoken = ft_lstlast(token); + lexer_lex((token ? <oken : &token), &lexer); + token_print(token); + } while (lexer.stack->content); if (ft_parse(&ast, &token)) return (1); @@ -40,20 +47,12 @@ int main(int ac, char **av) data = data_singleton(); setlocale(LC_ALL, ""); - DG("{inv}{bol}{gre}start of shell{eoc} pid=%i pgrp=%i job_control is %s", getpid(), getpgrp(), SH_HAS_JOBC(data->opts) ? "ON" : "OFF"); shell_init(ac, av); DG("{inv}{bol}{gre}start of shell{eoc} pid=%i pgrp=%i job_control is %s", getpid(), getpgrp(), SH_HAS_JOBC(data->opts) ? "ON" : "OFF"); - if (data_singleton()->opts & SH_OPTS_LC) + if (SH_IS_INTERACTIVE(data->opts)) { - shell_single_command(ft_strdup(shell_get_avdata())); - return (0); - } - while (1) - { - if (ft_readline()) - return (1); - if (shell_single_command(ft_strdup(data_singleton()->line.input)) < 0) - return (1); + while (1) + interactive_shell(); } return (0); } diff --git a/42sh/src/main/remove_trailing_esc_nl.c b/42sh/src/main/remove_trailing_esc_nl.c new file mode 100644 index 00000000..9d6fb232 --- /dev/null +++ b/42sh/src/main/remove_trailing_esc_nl.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* remove_trailing_esc_nl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/09 16:52:34 by jhalford #+# #+# */ +/* Updated: 2017/02/09 17:00:33 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int remove_trailing_esc_nl(char *str) +{ + char *last; + + last = str + ft_strlen(str) - 1; + if (*last == '\\') + { + *last = 0; + return (1); + } + return (0); +} diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index f9f861fc..86ce3c8e 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/11 17:14:35 by jhalford ### ########.fr */ +/* Updated: 2017/02/09 20:50:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,7 @@ static void shell_parse_short_opt(char *str) { data_singleton()->opts |= SH_OPTS_LC; data_singleton()->opts &= ~SH_OPTS_JOBC; + data_singleton()->opts &= ~SH_INTERACTIVE; } i++; }