merged new lexer/line-edit architecture
This commit is contained in:
commit
665c593f5d
48 changed files with 674 additions and 746 deletions
|
|
@ -137,38 +137,39 @@ 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/expand_bquotes.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\
|
||||
lexer/lexer_dquote.c\
|
||||
lexer/lexer_end.c\
|
||||
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_paren.c\
|
||||
lexer/lexer_quote.c\
|
||||
lexer/lexer_sep.c\
|
||||
lexer/lexer_special.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\
|
||||
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/ft_prompt.c\
|
||||
line-editing/get_touch.c\
|
||||
line-editing/get_touch_toolz.c\
|
||||
line-editing/get_touch_toolz_2.c\
|
||||
|
|
@ -180,7 +181,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 +198,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\
|
||||
|
|
@ -245,7 +246,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
|||
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||
@printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
||||
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||
@$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\
|
||||
-I $(INC_DIR)\
|
||||
-I $(LIBFT_INC)
|
||||
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
|
@ -30,17 +30,12 @@ typedef long long t_type;
|
|||
# define TK_AMP (1 << 10)
|
||||
# define TK_PAREN_OPEN (1 << 11)
|
||||
# define TK_PAREN_CLOSE (1 << 12)
|
||||
# define TK_BQUOTE (1 << 13)
|
||||
# define TK_N_WORD (1 << 14)
|
||||
# define TK_Q_WORD (1 << 15)
|
||||
# define TK_DQ_WORD (1 << 16)
|
||||
# define TK_COMMAND (1 << 17)
|
||||
# define TK_SUBSHELL (1 << 18)
|
||||
# define TK_NEWLINE (1 << 19)
|
||||
# define TK_WORD (1 << 13)
|
||||
# define TK_COMMAND (1 << 14)
|
||||
# define TK_SUBSHELL (1 << 15)
|
||||
# define TK_NEWLINE (1 << 16)
|
||||
|
||||
# define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD)
|
||||
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||
# define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE)
|
||||
|
||||
enum e_lexstate
|
||||
{
|
||||
|
|
@ -56,9 +51,12 @@ enum e_lexstate
|
|||
LESSAND,
|
||||
QUOTE,
|
||||
DQUOTE,
|
||||
BQUOTE,
|
||||
DQUOTE_BQUOTE,
|
||||
BACKSLASH,
|
||||
SPECIAL,
|
||||
PAREN,
|
||||
COMMENT,
|
||||
END,
|
||||
};
|
||||
|
||||
struct s_token
|
||||
|
|
@ -70,45 +68,56 @@ 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);
|
||||
int token_append_char(t_token *token, char c,
|
||||
short int esc, short int esc2);
|
||||
int token_append_str(t_token *token, char *str,
|
||||
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);
|
||||
void token_expand_var(t_token *token);
|
||||
|
||||
int reduce_parens(t_list **alst, char *str);
|
||||
int reduce_bquotes(t_list **alst, char **str);
|
||||
int bquotes_expand(t_list **alst);
|
||||
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_paren(t_list **alst, t_lexer *lexer);
|
||||
int lexer_comment(t_list **alst, t_lexer *lexer);
|
||||
int lexer_end(t_list **alst, t_lexer *lexer);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,89 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* line-editing.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <curses.h>
|
||||
# include <term.h>
|
||||
|
||||
# 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
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lst.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit acd7e54fb8045b3958dd239d469f1476404468b7
|
||||
Subproject commit b9c0c4cbb1adf15f11e681951500f23ad1f34c60
|
||||
|
|
@ -13,10 +13,10 @@
|
|||
#include "builtin.h"
|
||||
|
||||
#define CDOPT_L (1 << 0)
|
||||
#define CDOPT_P (1 << 2)
|
||||
#define CDOPT_P (1 << 1)
|
||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||
#define CDERR_1 "cd: no such file or directory: %s\n"
|
||||
#define CDERR_1 "{red}cd: no such file or directory: %s{eoc}\n"
|
||||
|
||||
static char *builtin_cd_special(char *const av[], char *const env[])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ char *command_getoutput(char *command)
|
|||
ast = btree_create_node(&item, sizeof(item));
|
||||
pipe(fds);
|
||||
exec->process.fdout = fds[PIPE_WRITE];
|
||||
ft_exec(&ast);
|
||||
exec_command(&ast);
|
||||
exec->process.fdout = STDOUT;
|
||||
close(fds[PIPE_WRITE]);
|
||||
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)))
|
||||
|
|
|
|||
92
42sh/src/lexer/expand_bquotes.c
Normal file
92
42sh/src/lexer/expand_bquotes.c
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_bquotes.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 20:45:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int bquotes_insert_words(t_list *cur_word, char *word, char *after_bq)
|
||||
{
|
||||
char *ifs;
|
||||
t_list *new_word;
|
||||
t_list *after_word;
|
||||
t_token *token;
|
||||
|
||||
after_word = cur_word->next;
|
||||
ifs = ft_getenv(data_singleton()->env, "IFS");
|
||||
if (ifs)
|
||||
word = ft_strtok(word, ifs);
|
||||
token = cur_word->content;
|
||||
token_append_str(token, word, 0, 0);
|
||||
if (ifs)
|
||||
while ((word = ft_strtok(NULL, ifs)))
|
||||
{
|
||||
token = token_init();
|
||||
token->type = TK_WORD;
|
||||
token_append_str(token, word, 0, 0);
|
||||
new_word = ft_lstnew(token, sizeof(*token));
|
||||
cur_word->next = new_word;
|
||||
new_word->next = after_word;
|
||||
cur_word = new_word;
|
||||
}
|
||||
token = cur_word->content;
|
||||
ft_strappend(&token->data, after_bq);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bquotes_substitute(t_list *cur_word, char *bq_start, char *bq_end)
|
||||
{
|
||||
char *output;
|
||||
char *last_char;
|
||||
char *after_bq;
|
||||
|
||||
*bq_start = 0;
|
||||
*bq_end = 0;
|
||||
output = command_getoutput(bq_start + 1);
|
||||
after_bq = ft_strdup(bq_end + 1);
|
||||
last_char = output + ft_strlen(output) - 1;
|
||||
while (*last_char == '\n')
|
||||
*last_char++ = 0;
|
||||
bquotes_insert_words(cur_word, output, after_bq);
|
||||
ft_strdel(&output);
|
||||
ft_strdel(&after_bq);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bquotes_expand(t_list **alst)
|
||||
{
|
||||
t_list *cur_word;
|
||||
t_list *lst;
|
||||
char *bq_start;
|
||||
char *bq_end;
|
||||
t_flag tk;
|
||||
|
||||
tk = TK_WORD;
|
||||
cur_word = *alst;
|
||||
while ((lst = ft_lst_find(cur_word, &tk, token_cmp_type)))
|
||||
{
|
||||
cur_word = lst;
|
||||
if (!(bq_start = ft_strchr(((t_token*)cur_word->content)->data, '`')))
|
||||
{
|
||||
cur_word = cur_word->next;
|
||||
return (0);
|
||||
}
|
||||
if (!(bq_end = ft_strchr(bq_start + 1, '`')))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near '`'{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
}
|
||||
if (bquotes_substitute(cur_word, bq_start, bq_end))
|
||||
return (-1);
|
||||
cur_word = lst;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_post_tokenize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 14:33:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int ft_post_tokenize(t_list **alst, char **str)
|
||||
{
|
||||
int ret;
|
||||
t_flag tk;
|
||||
|
||||
while ((ret = reduce_parens(alst, *str)))
|
||||
if (ret == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near '('{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
}
|
||||
tk = TK_PAREN_CLOSE;
|
||||
if (ft_lst_find(*alst, &tk, token_cmp_type))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near ')'{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
}
|
||||
while ((ret = reduce_bquotes(alst, str)))
|
||||
if (ret == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near '`'{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
}
|
||||
DG("new command from bquotes: '%s'", *str);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,32 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_lexer_state.c :+: :+: :+: */
|
||||
/* get_state_global.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 (PAREN);
|
||||
else if (c == 0)
|
||||
return (END);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,28 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lexer.c :+: :+: :+: */
|
||||
/* get_state_redir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
@ -6,18 +6,21 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
54
42sh/src/lexer/lexer_bquote.c
Normal file
54
42sh/src/lexer/lexer_bquote.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lexer_bquote.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
int top_state;
|
||||
|
||||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
if (lexer->state == DQUOTE_BQUOTE)
|
||||
token_append(token, lexer, 1, 1);
|
||||
else
|
||||
token_append(token, lexer, 0, 0);
|
||||
if (lexer->str[lexer->pos] == '`')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (!(lexer->stack && (*(int*)lexer->stack->content == BQUOTE
|
||||
|| *(int*)lexer->stack->content == DQUOTE_BQUOTE)))
|
||||
{
|
||||
push(&lexer->stack, lexer->state);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
top_state = *(int*)pop(&lexer->stack)->content;
|
||||
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
if (lexer->str[lexer->pos] == '\\')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
{
|
||||
push(&lexer->stack, BACKSLASH);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst,lexer));
|
||||
}
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
@ -6,18 +6,18 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,29 +6,24 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
else
|
||||
state = WORD;
|
||||
c = lexer->str[lexer->pos];
|
||||
if ((lexer->state = get_state_global(lexer)))
|
||||
return (lexer_lex(alst, lexer));
|
||||
if ((lexer->state = get_state_redir(lexer)))
|
||||
return (lexer_lex(alst, lexer));
|
||||
lexer->state = ft_isdigit(c) ? NUMBER : WORD;
|
||||
token = (*alst)->content;
|
||||
token_append(token, *str, 0, 0);
|
||||
token->type = TK_N_WORD;
|
||||
return (ft_tokenize(alst, str + 1, state));
|
||||
token->type = TK_WORD;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,28 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++;
|
||||
lexer->state = DEFAULT;
|
||||
if (token->type)
|
||||
return (ft_tokenize(&(*alst)->next, str, DEFAULT));
|
||||
{
|
||||
return (lexer_lex(&(*alst)->next, lexer));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!*str)
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free);
|
||||
return (ft_tokenize(alst, str, DEFAULT));
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,28 +6,49 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 == '\\')
|
||||
token->type = TK_WORD;
|
||||
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++;
|
||||
if (!(lexer->stack && *(int*)lexer->stack->content == DQUOTE))
|
||||
{
|
||||
push(&lexer->stack, DQUOTE);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
lexer->state = WORD;
|
||||
pop(&lexer->stack);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
token_append(token, *str, 1, 0);
|
||||
return (lexer_dquote(alst, str));
|
||||
if (lexer->str[lexer->pos] == '\\')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
{
|
||||
push(&lexer->stack, BACKSLASH);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst,lexer));
|
||||
}
|
||||
else if (lexer->str[lexer->pos] == '`')
|
||||
{
|
||||
lexer->state = DQUOTE_BQUOTE;
|
||||
return (lexer_bquote(alst, lexer));
|
||||
}
|
||||
token_append(token, lexer, 1, 0);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
19
42sh/src/lexer/lexer_end.c
Normal file
19
42sh/src/lexer/lexer_end.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "lexer.h"
|
||||
|
||||
int lexer_end(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
DG("check");
|
||||
if (*alst && (lexer->state == QUOTE
|
||||
|| lexer->state == DQUOTE
|
||||
|| lexer->state == BQUOTE))
|
||||
{
|
||||
token = (*alst)->content;
|
||||
ft_strappend(&lexer->str, (char[]){'\n', 0});
|
||||
token_append(token, lexer, 1, 0);
|
||||
lexer->pos++;
|
||||
return (0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,33 +6,39 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,31 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,33 +6,39 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,31 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tokenize.c :+: :+: :+: */
|
||||
/* lexer_lex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,9 +26,12 @@ int (*g_lexer[])(t_list **alst, char *str) =
|
|||
&lexer_lessand,
|
||||
&lexer_quote,
|
||||
&lexer_dquote,
|
||||
&lexer_bquote,
|
||||
&lexer_bquote,
|
||||
&lexer_backslash,
|
||||
&lexer_special,
|
||||
&lexer_paren,
|
||||
&lexer_comment,
|
||||
&lexer_end,
|
||||
};
|
||||
|
||||
int ft_is_delim(char c)
|
||||
|
|
@ -36,16 +39,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)
|
||||
return (0);
|
||||
if (lexer->str[lexer->pos] == 0)
|
||||
return (lexer_end(alst, lexer));
|
||||
if (!*alst)
|
||||
{
|
||||
token = token_init();
|
||||
*alst = ft_lstnew(token, sizeof(*token));
|
||||
}
|
||||
return ((*g_lexer[state])(alst, str));
|
||||
return ((*g_lexer[lexer->state])(alst, lexer));
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,28 +6,31 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
31
42sh/src/lexer/lexer_paren.c
Normal file
31
42sh/src/lexer/lexer_paren.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "lexer.h"
|
||||
|
||||
int lexer_paren(t_list **alst, t_lexer *lexer)
|
||||
{
|
||||
t_token *token;
|
||||
t_list **lst;
|
||||
|
||||
lst = alst;
|
||||
if (*alst)
|
||||
{
|
||||
token = (*alst)->content;
|
||||
if (token->type)
|
||||
lst = &(*alst)->next;
|
||||
}
|
||||
token = token_init();
|
||||
*lst = ft_lstnew(token, sizeof(*token));
|
||||
token = (*lst)->content;
|
||||
if (lexer->str[lexer->pos] == '(')
|
||||
{
|
||||
token->type = TK_PAREN_OPEN;
|
||||
push(&lexer->stack, PAREN);
|
||||
}
|
||||
else if (lexer->stack && *(int*)lexer->stack->content == PAREN)
|
||||
{
|
||||
token->type = TK_PAREN_CLOSE;
|
||||
pop(&lexer->stack);
|
||||
}
|
||||
lexer->pos++;
|
||||
lexer->state = DEFAULT;
|
||||
return (lexer_lex(&(*lst)->next, lexer));
|
||||
}
|
||||
|
|
@ -6,21 +6,31 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
token->type = TK_WORD;
|
||||
if (lexer->str[lexer->pos] == '\'')
|
||||
{
|
||||
lexer->pos++;
|
||||
if (!(lexer->stack && *(int*)lexer->stack->content == QUOTE))
|
||||
{
|
||||
push(&lexer->stack, QUOTE);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
lexer->state = WORD;
|
||||
pop(&lexer->stack);
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
token_append(token, lexer, 1, 1);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,21 +6,23 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,30 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
token->type = TK_WORD;
|
||||
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));
|
||||
}
|
||||
token_append(token, lexer, 0, 0);
|
||||
lexer->pos++;
|
||||
return (lexer_lex(alst, lexer));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* reduce_bquotes.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 15:40:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int reduce_bquotes(t_list **alst, char **str)
|
||||
{
|
||||
t_list *start;
|
||||
t_list **end;
|
||||
t_token *token;
|
||||
int tk;
|
||||
char *new;
|
||||
char *fit;
|
||||
char *bq_start;
|
||||
char *bq_end;
|
||||
|
||||
tk = TK_BQUOTE;
|
||||
if ((start = ft_lst_find(*alst, &tk, token_cmp_type)))
|
||||
{
|
||||
end = &start->next;
|
||||
while (end && *end)
|
||||
{
|
||||
token = (*end)->content;
|
||||
if (token->type == TK_BQUOTE)
|
||||
break ;
|
||||
end = &(*end)->next;
|
||||
}
|
||||
if (!*end)
|
||||
return (-1);
|
||||
bq_start = ((t_token*)start->content)->data;
|
||||
bq_end = ((t_token*)(*end)->content)->data;
|
||||
ft_lstdel(end, token_free);
|
||||
fit = command_getoutput(ft_strbetween(bq_start + 1, bq_end));
|
||||
new = ft_strreplace(str, bq_start, bq_end, fit);
|
||||
ft_strdel(str);
|
||||
*str = new;
|
||||
ft_lstdel(alst, token_free);
|
||||
ft_tokenize(alst, new, DEFAULT);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -1,38 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lexer_special.c :+: :+: :+: */
|
||||
/* stack_to_prompt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 15:35:38 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 17:36:10 by jhalford ### ########.fr */
|
||||
/* Created: 2017/02/09 21:25:26 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 22:49:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int lexer_special(t_list **alst, char *str)
|
||||
char *stack_to_prompt(t_list *stack)
|
||||
{
|
||||
t_token *token;
|
||||
t_list **lst;
|
||||
t_flag top;
|
||||
|
||||
lst = alst;
|
||||
if (*alst)
|
||||
{
|
||||
token = (*alst)->content;
|
||||
if (token->type)
|
||||
lst = &(*alst)->next;
|
||||
}
|
||||
token = token_init();
|
||||
*lst = ft_lstnew(token, sizeof(*token));
|
||||
token = (*lst)->content;
|
||||
if (*str == '(')
|
||||
token->type = TK_PAREN_OPEN;
|
||||
else if (*str == ')')
|
||||
token->type = TK_PAREN_CLOSE;
|
||||
else if (*str == '`')
|
||||
token->type = TK_BQUOTE;
|
||||
token->data = str;
|
||||
return (ft_tokenize(&(*lst)->next, str + 1, DEFAULT));
|
||||
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 == DQUOTE_BQUOTE)
|
||||
return ("dquote bquote> ");
|
||||
else if (top == PAREN)
|
||||
return ("subsh> ");
|
||||
else
|
||||
return ("error> ");
|
||||
}
|
||||
|
|
@ -12,7 +12,9 @@
|
|||
|
||||
#include "lexer.h"
|
||||
|
||||
int token_append(t_token *token, char c, short int esc, short int esc2)
|
||||
|
||||
int token_append_char(t_token *token, char c,
|
||||
short int esc, short int esc2)
|
||||
{
|
||||
int len;
|
||||
|
||||
|
|
@ -24,14 +26,29 @@ int token_append(t_token *token, char c, short int esc, short int esc2)
|
|||
token->esc = (unsigned char *)ft_memrealloc(token->esc,
|
||||
(token->size >> 3),
|
||||
(token->size >> 3) + 1);
|
||||
token->esc[token->size >> 3] = 0;
|
||||
token->esc[token->size >> 3] = 0;
|
||||
token->esc2 = (unsigned char *)ft_memrealloc(token->esc2,
|
||||
(token->size >> 3),
|
||||
(token->size >> 3) + 1);
|
||||
token->esc2[token->size >> 3] = 0;
|
||||
token->esc2[token->size >> 3] = 0;
|
||||
}
|
||||
ft_strcat(token->data, (char[2]){c, '\0'});
|
||||
ft_strcat(token->data, (char[]){c, 0});
|
||||
token->esc[len >> 3] |= esc << (7 - len % 8);
|
||||
token->esc2[len >> 3] |= esc2 << (7 - len % 8);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int token_append_str(t_token *token, char *str,
|
||||
short int esc, short int esc2)
|
||||
{
|
||||
while (*str)
|
||||
if (token_append_char(token, *str++, esc, esc2))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int token_append(t_token *token, t_lexer *lexer,
|
||||
short int esc, short int esc2)
|
||||
{
|
||||
return (token_append_char(token, lexer->str[lexer->pos], esc, esc2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,8 @@ void token_free(void *data, size_t size)
|
|||
|
||||
(void)size;
|
||||
token = data;
|
||||
if (!(token->type & TK_NON_FREEABLE))
|
||||
{
|
||||
ft_strdel(&token->data);
|
||||
ft_memdel((void **)&token->esc);
|
||||
ft_memdel((void **)&token->esc2);
|
||||
}
|
||||
ft_strdel(&token->data);
|
||||
ft_memdel((void **)&token->esc);
|
||||
ft_memdel((void **)&token->esc2);
|
||||
free(token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void token_print(t_list *lst)
|
|||
type = token->type;
|
||||
while (type >> (i++ + 2))
|
||||
;
|
||||
DG("%02i '%s'", i, token->data);
|
||||
DG("%02i:[%s]", i, token->data);
|
||||
index = -1;
|
||||
lst = lst->next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,128 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_backslash.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ftprompt.c :+: :+: :+: */
|
||||
/* ft_prompt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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_termios(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);
|
||||
|
|
@ -54,46 +54,38 @@ struct termios *ft_save_stats_term(void)
|
|||
return (term_save);
|
||||
}
|
||||
|
||||
struct termios *ft_stats_term_termcaps(void)
|
||||
void ft_init_termios(void)
|
||||
{
|
||||
static struct termios *term = NULL;
|
||||
struct termios term;
|
||||
|
||||
if (!term)
|
||||
{
|
||||
ft_init_line();
|
||||
ft_init_history();
|
||||
term = (struct termios *)malloc(sizeof(struct termios));
|
||||
tcgetattr(0, term);
|
||||
(*term).c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
(*term).c_cc[VMIN] = 1;
|
||||
(*term).c_cc[VTIME] = 0;
|
||||
}
|
||||
return (term);
|
||||
tcgetattr(0, &term);
|
||||
term.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &term);
|
||||
}
|
||||
|
||||
int ft_readline(void)
|
||||
void readline_init(char *prompt)
|
||||
{
|
||||
ft_save_stats_term();
|
||||
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
||||
return (-1);
|
||||
ft_save_termios(1);
|
||||
ft_init_line();
|
||||
ft_init_history();
|
||||
ft_init_termios();
|
||||
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();
|
||||
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);
|
||||
prompt ? ft_putstr(prompt) : ft_prompt();
|
||||
}
|
||||
|
||||
char *readline(char *prompt)
|
||||
{
|
||||
char *input;
|
||||
|
||||
readline_init(prompt);
|
||||
input = ft_read_stdin();
|
||||
ft_putchar('\n');
|
||||
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
|
||||
return (NULL);
|
||||
return (input);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,28 +6,70 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 non_interactive_shell(char *command)
|
||||
{
|
||||
t_list *token;
|
||||
t_lexer lexer;
|
||||
t_btree *ast;
|
||||
|
||||
lexer.pos = 0;
|
||||
lexer.state = DEFAULT;
|
||||
lexer.str = command;
|
||||
lexer.stack = NULL;
|
||||
token = NULL;
|
||||
ast = NULL;
|
||||
while (lexer.str[lexer.pos])
|
||||
{
|
||||
if (lexer.stack && *(int*)lexer.stack->content == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
do {
|
||||
lexer_lex(&token, &lexer);
|
||||
} while (lexer.str[lexer.pos] == '\n');
|
||||
if (bquotes_expand(&token))
|
||||
return (1);
|
||||
token_print(token);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
if (ft_exec(&ast))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
int interactive_shell()
|
||||
{
|
||||
t_list *token;
|
||||
t_list *ltoken;
|
||||
t_lexer lexer;
|
||||
t_btree *ast;
|
||||
|
||||
DG("{inv}{mag}got command '%s'", command);
|
||||
if (ft_lexer(&token, &command) || !token)
|
||||
lexer.pos = 0;
|
||||
lexer.state = DEFAULT;
|
||||
lexer.str = NULL;
|
||||
token = NULL;
|
||||
lexer.stack = NULL;
|
||||
ast = 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);
|
||||
DG("[{mag}%s{eoc}] stack=[%i] state=[%i]", lexer.str, lexer.stack ? *(int*)lexer.stack->content : 0, lexer.state);
|
||||
token_print(token);
|
||||
} while (lexer.stack);
|
||||
if (!token)
|
||||
return (0);
|
||||
if (bquotes_expand(&token))
|
||||
return (1);
|
||||
|
||||
token_print(token);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
if (ft_exec(&ast))
|
||||
return (1);
|
||||
|
|
@ -40,20 +82,14 @@ 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();
|
||||
}
|
||||
else
|
||||
non_interactive_shell(shell_get_avdata());
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* token_expand_var.c :+: :+: :+: */
|
||||
/* remove_trailing_esc_nl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/10 14:57:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 13:16:04 by wescande ### ########.fr */
|
||||
/* Created: 2017/02/09 16:52:34 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 17:00:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
/*
|
||||
void token_expand_var(t_token *token)
|
||||
{
|
||||
char *dollar;
|
||||
char *val;
|
||||
#include "minishell.h"
|
||||
|
||||
dollar = ft_strchr(token->data, '$');
|
||||
if (!dollar[1])
|
||||
return ;
|
||||
val = ft_getenv(data_singleton()->env, dollar + 1);
|
||||
*dollar = 0;
|
||||
if (val)
|
||||
while (*val)
|
||||
token_append(token, *val++, 1, 1);
|
||||
int remove_trailing_esc_nl(char *str)
|
||||
{
|
||||
char *last;
|
||||
|
||||
last = str + ft_strlen(str) - 1;
|
||||
if (*last == '\\')
|
||||
{
|
||||
*last = 0;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
|
|
@ -16,6 +16,7 @@ void shell_exit(void)
|
|||
{
|
||||
DG("shell_exit()");
|
||||
data_exit();
|
||||
job_kill_all();
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
job_kill_all();
|
||||
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue