started to work on lexer_stack
This commit is contained in:
parent
c5263b51d0
commit
e8cd4f45b0
40 changed files with 517 additions and 633 deletions
|
|
@ -137,11 +137,11 @@ job-control/sigtstp_handler.c\
|
||||||
job-control/sigttin_handler.c\
|
job-control/sigttin_handler.c\
|
||||||
job-control/sigttou_handler.c\
|
job-control/sigttou_handler.c\
|
||||||
lexer/command_getoutput.c\
|
lexer/command_getoutput.c\
|
||||||
lexer/ft_lexer.c\
|
|
||||||
lexer/ft_post_tokenize.c\
|
lexer/ft_post_tokenize.c\
|
||||||
lexer/ft_tokenize.c\
|
lexer/get_state_global.c\
|
||||||
lexer/get_lexer_state.c\
|
lexer/get_state_redir.c\
|
||||||
lexer/lexer_backslash.c\
|
lexer/lexer_backslash.c\
|
||||||
|
lexer/lexer_bquote.c\
|
||||||
lexer/lexer_comment.c\
|
lexer/lexer_comment.c\
|
||||||
lexer/lexer_default.c\
|
lexer/lexer_default.c\
|
||||||
lexer/lexer_delim.c\
|
lexer/lexer_delim.c\
|
||||||
|
|
@ -150,14 +150,16 @@ lexer/lexer_great.c\
|
||||||
lexer/lexer_greatand.c\
|
lexer/lexer_greatand.c\
|
||||||
lexer/lexer_less.c\
|
lexer/lexer_less.c\
|
||||||
lexer/lexer_lessand.c\
|
lexer/lexer_lessand.c\
|
||||||
|
lexer/lexer_lex.c\
|
||||||
lexer/lexer_newline.c\
|
lexer/lexer_newline.c\
|
||||||
lexer/lexer_number.c\
|
lexer/lexer_number.c\
|
||||||
lexer/lexer_quote.c\
|
lexer/lexer_quote.c\
|
||||||
lexer/lexer_sep.c\
|
lexer/lexer_sep.c\
|
||||||
lexer/lexer_special.c\
|
lexer/lexer_subshell.c\
|
||||||
lexer/lexer_word.c\
|
lexer/lexer_word.c\
|
||||||
lexer/reduce_bquotes.c\
|
lexer/reduce_bquotes.c\
|
||||||
lexer/reduce_parens.c\
|
lexer/reduce_parens.c\
|
||||||
|
lexer/stack_to_prompt.c\
|
||||||
lexer/token_append.c\
|
lexer/token_append.c\
|
||||||
lexer/token_cmp_type.c\
|
lexer/token_cmp_type.c\
|
||||||
lexer/token_expand_var.c\
|
lexer/token_expand_var.c\
|
||||||
|
|
@ -165,10 +167,10 @@ lexer/token_free.c\
|
||||||
lexer/token_init.c\
|
lexer/token_init.c\
|
||||||
lexer/token_print.c\
|
lexer/token_print.c\
|
||||||
line-editing/builtin_history.c\
|
line-editing/builtin_history.c\
|
||||||
line-editing/check_backslash.c\
|
|
||||||
line-editing/completion.c\
|
line-editing/completion.c\
|
||||||
line-editing/control_c_and_d.c\
|
line-editing/control_c_and_d.c\
|
||||||
line-editing/copy_cut_paste.c\
|
line-editing/copy_cut_paste.c\
|
||||||
|
line-editing/ftprompt.c\
|
||||||
line-editing/get_touch.c\
|
line-editing/get_touch.c\
|
||||||
line-editing/get_touch_toolz.c\
|
line-editing/get_touch_toolz.c\
|
||||||
line-editing/get_touch_toolz_2.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/list_toolz.c\
|
||||||
line-editing/move_to_line.c\
|
line-editing/move_to_line.c\
|
||||||
line-editing/print_and_del.c\
|
line-editing/print_and_del.c\
|
||||||
line-editing/prompt.c\
|
|
||||||
line-editing/reader.c\
|
line-editing/reader.c\
|
||||||
line-editing/readline.c\
|
line-editing/readline.c\
|
||||||
line-editing/surch_in_history.c\
|
line-editing/surch_in_history.c\
|
||||||
|
|
@ -198,6 +199,7 @@ main/ft_putast.c\
|
||||||
main/ft_putast2.c\
|
main/ft_putast2.c\
|
||||||
main/lib_expansion.c\
|
main/lib_expansion.c\
|
||||||
main/main.c\
|
main/main.c\
|
||||||
|
main/remove_trailing_esc_nl.c\
|
||||||
main/shell_exit.c\
|
main/shell_exit.c\
|
||||||
main/shell_get_avdata.c\
|
main/shell_get_avdata.c\
|
||||||
main/shell_get_opts.c\
|
main/shell_get_opts.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 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_F5 892427035
|
||||||
# define TOUCHE_F6 925981467
|
# define TOUCHE_F6 925981467
|
||||||
|
|
||||||
# define PROMPT_QUOTES "quote> "
|
/* # define PROMPT_QUOTES "quote> " */
|
||||||
# define PROMPT_DQUOTES "dquote> "
|
/* # define PROMPT_DQUOTES "dquote> " */
|
||||||
# define PROMPT_BQUOTES "bquote> "
|
/* # define PROMPT_BQUOTES "bquote> " */
|
||||||
# define PROMPT_ACCOLADE "cursh> "
|
/* # define PROMPT_ACCOLADE "cursh> " */
|
||||||
# define PROMPT_BRACKET "subsh> "
|
/* # define PROMPT_BRACKET "subsh> " */
|
||||||
# define PROMPT_BSLASH "> "
|
/* # define PROMPT_BSLASH "> " */
|
||||||
|
|
||||||
# define SIZE_PROMPT_QUOTES 7
|
/* # define SIZE_PROMPT_QUOTES 7 */
|
||||||
# define SIZE_PROMPT_DQUOTES 8
|
/* # define SIZE_PROMPT_DQUOTES 8 */
|
||||||
# define SIZE_PROMPT_BQUOTES 8
|
/* # define SIZE_PROMPT_BQUOTES 8 */
|
||||||
# define SIZE_PROMPT_ACCOLADE 7
|
/* # define SIZE_PROMPT_ACCOLADE 7 */
|
||||||
# define SIZE_PROMPT_BRACKET 7
|
/* # define SIZE_PROMPT_BRACKET 7 */
|
||||||
# define SIZE_PROMPT_BSLASH 2
|
/* # define SIZE_PROMPT_BSLASH 2 */
|
||||||
|
|
||||||
# define IS_QUOTES (1 << 0)
|
# define IS_QUOTES (1 << 0)
|
||||||
# define IS_BQUOTES (1 << 1)
|
# define IS_BQUOTES (1 << 1)
|
||||||
|
|
@ -177,7 +177,7 @@ void ft_x(void);
|
||||||
void ft_v(void);
|
void ft_v(void);
|
||||||
void ft_history_parsing(void);
|
void ft_history_parsing(void);
|
||||||
void ft_read_it(int input, size_t *pos, char **str);
|
void ft_read_it(int input, size_t *pos, char **str);
|
||||||
int ft_readline(void);
|
char *readline(char *);
|
||||||
int ft_completion(int ret);
|
int ft_completion(int ret);
|
||||||
|
|
||||||
void ft_check_heredoc(char **str);
|
void ft_check_heredoc(char **str);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:50 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
|
# define LEXER_H
|
||||||
|
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
# include "libft.h"
|
||||||
typedef long long t_type;
|
# include "types.h"
|
||||||
|
|
||||||
# define TK_LESS (1 << 0)
|
# define TK_LESS (1 << 0)
|
||||||
# define TK_GREAT (1 << 1)
|
# define TK_GREAT (1 << 1)
|
||||||
|
|
@ -56,8 +56,9 @@ enum e_lexstate
|
||||||
LESSAND,
|
LESSAND,
|
||||||
QUOTE,
|
QUOTE,
|
||||||
DQUOTE,
|
DQUOTE,
|
||||||
|
BQUOTE,
|
||||||
BACKSLASH,
|
BACKSLASH,
|
||||||
SPECIAL,
|
SUBSHELL,
|
||||||
COMMENT,
|
COMMENT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -70,19 +71,22 @@ struct s_token
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct s_data t_data;
|
struct s_lexer
|
||||||
typedef struct s_token t_token;
|
{
|
||||||
typedef enum e_lexstate t_lexstate;
|
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);
|
extern int (*g_lexer[])(t_list **alst, t_lexer *lexer);
|
||||||
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
|
||||||
int ft_post_tokenize(t_list **alst, char **str);
|
int ft_post_tokenize(t_list **alst, char **str);
|
||||||
|
|
||||||
t_token *token_init();
|
t_token *token_init();
|
||||||
int token_append(t_token *token, char c, short int esc,
|
int token_append(t_token *token, t_lexer *lexer,
|
||||||
short int dbl_esc);
|
short int esc, short int esc2);
|
||||||
void token_free(void *data, size_t size);
|
void token_free(void *data, size_t size);
|
||||||
int token_cmp_type(t_token *token, t_type *ref);
|
int token_cmp_type(t_token *token, t_type *ref);
|
||||||
void token_print(t_list *lst);
|
void token_print(t_list *lst);
|
||||||
|
|
@ -93,22 +97,26 @@ int reduce_bquotes(t_list **alst, char **str);
|
||||||
char *command_getoutput(char *command);
|
char *command_getoutput(char *command);
|
||||||
|
|
||||||
int ft_is_delim(char c);
|
int ft_is_delim(char c);
|
||||||
|
char *stack_to_prompt(t_list *stack);
|
||||||
|
|
||||||
t_lexstate get_lexer_state(char *str);
|
t_lexstate get_state_global(t_lexer *lexer);
|
||||||
int lexer_default(t_list **alst, char *str);
|
t_lexstate get_state_redir(t_lexer *lexer);
|
||||||
int lexer_newline(t_list **alst, char *str);
|
int lexer_lex(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_delim(t_list **alst, char *str);
|
int lexer_default(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_sep(t_list **alst, char *str);
|
int lexer_newline(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_word(t_list **alst, char *str);
|
int lexer_delim(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_number(t_list **alst, char *str);
|
int lexer_sep(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_less(t_list **alst, char *str);
|
int lexer_word(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_great(t_list **alst, char *str);
|
int lexer_number(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_lessand(t_list **alst, char *str);
|
int lexer_less(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_greatand(t_list **alst, char *str);
|
int lexer_great(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_quote(t_list **alst, char *str);
|
int lexer_lessand(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_dquote(t_list **alst, char *str);
|
int lexer_greatand(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_backslash(t_list **alst, char *str);
|
int lexer_quote(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_special(t_list **alst, char *str);
|
int lexer_dquote(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_comment(t_list **alst, char *str);
|
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
|
#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> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 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"
|
# define SHELL_NAME "minishell"
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "lexer.h"
|
# include "lexer.h"
|
||||||
# include "parser.h"
|
# include "parser.h"
|
||||||
|
|
@ -66,11 +65,11 @@ void shell_exit(void);
|
||||||
int data_init(void);
|
int data_init(void);
|
||||||
void data_exit(void);
|
void data_exit(void);
|
||||||
|
|
||||||
int shell_single_command(char *command);
|
|
||||||
|
|
||||||
void ft_expand_dollar(char **av, char **env);
|
void ft_expand_dollar(char **av, char **env);
|
||||||
char *ft_findexec(char *path, char *file);
|
char *ft_findexec(char *path, char *file);
|
||||||
|
|
||||||
|
int remove_trailing_esc_nl(char *str);
|
||||||
|
|
||||||
char *ft_putast(void *node);
|
char *ft_putast(void *node);
|
||||||
void ft_putast2(void *node);
|
void ft_putast2(void *node);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:11:48 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 struct s_jobc t_jobc;
|
||||||
typedef enum e_mode t_mode;
|
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_parser t_parser;
|
||||||
typedef struct s_ld t_ld;
|
typedef struct s_ld t_ld;
|
||||||
typedef struct s_astnode t_astnode;
|
typedef struct s_astnode t_astnode;
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit b53fcb9db8b4baf53c73b17726f1740c4af12be0
|
Subproject commit acd7e54fb8045b3958dd239d469f1476404468b7
|
||||||
|
|
@ -1,32 +1,37 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* get_lexer_state.c :+: :+: :+: */
|
/* get_state_global.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 13:45:46 by jhalford #+# #+# */
|
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/07 17:34:14 by wescande ### ########.fr */
|
/* Updated: 2017/02/09 22:12:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lexer.h"
|
#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);
|
return (DELIM);
|
||||||
else if (*str == '#')
|
else if (c == '#')
|
||||||
return (COMMENT);
|
return (COMMENT);
|
||||||
else if (*str == '&' || *str == ';' || *str == '|')
|
else if (c == '&' || c == ';' || c == '|')
|
||||||
return (SEP);
|
return (SEP);
|
||||||
else if (*str == '\\')
|
else if (c == '\\')
|
||||||
return (BACKSLASH);
|
return (BACKSLASH);
|
||||||
else if (*str == '\'')
|
else if (c == '\'')
|
||||||
return (QUOTE);
|
return (QUOTE);
|
||||||
else if (*str == '\"')
|
else if (c == '\"')
|
||||||
return (DQUOTE);
|
return (DQUOTE);
|
||||||
else if (*str == '(' || *str == ')' || *str == '`')
|
else if (c == '`')
|
||||||
return (SPECIAL);
|
return (BQUOTE);
|
||||||
|
else if (c == '(' || c == ')')
|
||||||
|
return (SUBSHELL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -1,28 +1,25 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_lexer.c :+: :+: :+: */
|
/* get_state_redir.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
|
/* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 21:49:55 by jhalford ### ########.fr */
|
/* Updated: 2017/02/09 20:39:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lexer.h"
|
#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)
|
c = lexer->str[lexer->pos];
|
||||||
return (1);
|
if (c == '>')
|
||||||
ret = 0;
|
return (GREAT);
|
||||||
if (ft_tokenize(alst, *command, DEFAULT))
|
else if (c == '<')
|
||||||
ret = 1;
|
return (LESS);
|
||||||
else if (ft_post_tokenize(alst, command))
|
return (0);
|
||||||
ret = 1;
|
|
||||||
ft_strdel(command);
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,18 +6,21 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:56:49 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_backslash(t_list **alst, char *str)
|
int lexer_backslash(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
token_append(token, str[1], 1, 1);
|
lexer->pos++;
|
||||||
return (ft_tokenize(alst, str + 2, WORD));
|
token_append(token, lexer, 1, 1);
|
||||||
|
lexer->pos++;
|
||||||
|
lexer->state = WORD;
|
||||||
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
42sh/src/lexer/lexer_bquote.c
Normal file
35
42sh/src/lexer/lexer_bquote.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -6,18 +6,18 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/07 12:15:59 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_comment(t_list **alst, char *str)
|
int lexer_comment(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (*str == '\n')
|
if (lexer->str[lexer->pos] == '\n')
|
||||||
return (ft_tokenize(&(*alst)->next, str, NEWLINE));
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
return (lexer_comment(alst, str + 1));
|
return (lexer_comment(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,29 +6,35 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:36:21 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_default(t_list **alst, char *str)
|
int lexer_default(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_lexstate state;
|
t_lexstate state;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
char c;
|
||||||
|
|
||||||
if ((state = get_lexer_state(str)))
|
c = lexer->str[lexer->pos];
|
||||||
return (ft_tokenize(alst, str, state));
|
if ((state = get_state_global(lexer)))
|
||||||
if (*str == '>')
|
{
|
||||||
return (ft_tokenize(alst, str, GREAT));
|
lexer->state = state;
|
||||||
else if (*str == '<')
|
return (lexer_lex(alst, lexer));
|
||||||
return (ft_tokenize(alst, str, LESS));
|
}
|
||||||
else if (ft_isdigit(*str))
|
if ((state = get_state_redir(lexer)))
|
||||||
state = NUMBER;
|
{
|
||||||
|
lexer->state = state;
|
||||||
|
return (lexer_lex(alst, lexer));
|
||||||
|
}
|
||||||
|
else if (ft_isdigit(c))
|
||||||
|
lexer->state = NUMBER;
|
||||||
else
|
else
|
||||||
state = WORD;
|
lexer->state = WORD;
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, *str, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
token->type = TK_N_WORD;
|
token->type = TK_N_WORD;
|
||||||
return (ft_tokenize(alst, str + 1, state));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,25 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:58:44 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_delim(t_list **alst, char *str)
|
int lexer_delim(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
while (ft_is_delim(*str))
|
while (ft_is_delim(lexer->str[lexer->pos]))
|
||||||
str++;
|
lexer->pos++;
|
||||||
if (token->type)
|
if (token->type)
|
||||||
return (ft_tokenize(&(*alst)->next, str, DEFAULT));
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!*str)
|
if (!lexer->str[lexer->pos])
|
||||||
ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(alst, (*alst)->content, &ft_addrcmp, &token_free);
|
||||||
return (ft_tokenize(alst, str, DEFAULT));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,28 +6,45 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:36:58 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_dquote(t_list **alst, char *str)
|
int lexer_dquote(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_DQ_WORD;
|
token->type = TK_DQ_WORD;
|
||||||
str++;
|
if (*(int*)lexer->stack->content != DQUOTE)
|
||||||
if (*str == '"')
|
push(&lexer->stack, DQUOTE);
|
||||||
return (ft_tokenize(alst, str + 1, DEFAULT));
|
lexer->pos++;
|
||||||
if (*str == '\\')
|
if (lexer->str[lexer->pos] == '"')
|
||||||
{
|
{
|
||||||
if (str[1] != '"')
|
lexer->pos++;
|
||||||
token_append(token, str[0], 1, 0);
|
lexer->state = WORD;
|
||||||
token_append(token, str[1], 1, 1);
|
pop(&lexer->stack);
|
||||||
return (lexer_dquote(alst, str + 1));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
token_append(token, *str, 1, 0);
|
else if (lexer->str[lexer->pos] == '\\')
|
||||||
return (lexer_dquote(alst, str));
|
{
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,33 +6,39 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:35 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_great(t_list **alst, char *str)
|
int lexer_great(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, str[0], 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
if (*(str + 1) == '&')
|
if (lexer->str[lexer->pos + 1] == '&')
|
||||||
{
|
{
|
||||||
token->type = TK_GREATAND;
|
token->type = TK_GREATAND;
|
||||||
token_append(token, str[1], 0, 0);
|
lexer->pos++;
|
||||||
return (lexer_greatand(alst, str + 2));
|
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->type = TK_DGREAT;
|
||||||
token_append(token, str[1], 0, 0);
|
lexer->pos++;
|
||||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
token_append(token, lexer, 0, 0);
|
||||||
|
lexer->pos++;
|
||||||
|
lexer->state = DEFAULT;
|
||||||
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
token->type = TK_GREAT;
|
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> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:56:58 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_greatand(t_list **alst, char *str)
|
int lexer_greatand(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_GREATAND;
|
token->type = TK_GREATAND;
|
||||||
if (ft_isdigit(*str))
|
if (ft_isdigit(lexer->str[lexer->pos]))
|
||||||
{
|
{
|
||||||
token_append(token, *str, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
return (lexer_greatand(alst, str + 1));
|
lexer->str++;
|
||||||
|
return (lexer_greatand(alst, lexer));
|
||||||
}
|
}
|
||||||
else if (*str == '-')
|
else if (lexer->str[lexer->pos] == '-')
|
||||||
{
|
{
|
||||||
token_append(token, *str, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
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> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:53 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_less(t_list **alst, char *str)
|
int lexer_less(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, str[0], 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
if (*(str + 1) == '&')
|
if (lexer->str[lexer->pos + 1] == '&')
|
||||||
{
|
{
|
||||||
token->type = TK_LESSAND;
|
token->type = TK_LESSAND;
|
||||||
token_append(token, str[1], 0, 0);
|
lexer->pos++;
|
||||||
return (lexer_lessand(alst, str + 2));
|
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->type = TK_DLESS;
|
||||||
token_append(token, str[1], 0, 0);
|
lexer->pos++;
|
||||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
token_append(token, lexer, 0, 0);
|
||||||
|
lexer->pos++;
|
||||||
|
lexer->state = DEFAULT;
|
||||||
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
token->type = TK_LESS;
|
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> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:58:51 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_lessand(t_list **alst, char *str)
|
int lexer_lessand(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_LESSAND;
|
token->type = TK_LESSAND;
|
||||||
if (ft_isdigit(*str))
|
if (ft_isdigit(lexer->str[lexer->pos]))
|
||||||
{
|
{
|
||||||
token_append(token, *str, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
return (lexer_lessand(alst, str + 1));
|
lexer->str++;
|
||||||
|
return (lexer_lessand(alst, lexer));
|
||||||
}
|
}
|
||||||
else if (*str == '-')
|
else if (lexer->str[lexer->pos] == '-')
|
||||||
{
|
{
|
||||||
token_append(token, *str, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
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 #+# #+# */
|
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/07 17:33:34 by wescande ### ########.fr */
|
/* Updated: 2017/02/09 22:58:48 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
int (*g_lexer[])(t_list **alst, char *str) =
|
int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
||||||
{
|
{
|
||||||
&lexer_default,
|
&lexer_default,
|
||||||
&lexer_newline,
|
&lexer_newline,
|
||||||
|
|
@ -26,8 +26,9 @@ int (*g_lexer[])(t_list **alst, char *str) =
|
||||||
&lexer_lessand,
|
&lexer_lessand,
|
||||||
&lexer_quote,
|
&lexer_quote,
|
||||||
&lexer_dquote,
|
&lexer_dquote,
|
||||||
|
&lexer_bquote,
|
||||||
&lexer_backslash,
|
&lexer_backslash,
|
||||||
&lexer_special,
|
&lexer_subshell,
|
||||||
&lexer_comment,
|
&lexer_comment,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -36,16 +37,16 @@ int ft_is_delim(char c)
|
||||||
return (c == ' ' || c == '\t' || c == '\n');
|
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;
|
t_token *token;
|
||||||
|
|
||||||
if (!*str)
|
if (!lexer->str[lexer->pos])
|
||||||
return (0);
|
return (0);
|
||||||
if (!*alst)
|
if (!*alst)
|
||||||
{
|
{
|
||||||
token = token_init();
|
token = token_init();
|
||||||
*alst = ft_lstnew(token, sizeof(*token));
|
*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> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 23:19:46 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_newline(t_list **alst, char *str)
|
int lexer_newline(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ int lexer_newline(t_list **alst, char *str)
|
||||||
{
|
{
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (*token->data)
|
if (*token->data)
|
||||||
return (lexer_newline(&(*alst)->next, str));
|
return (lexer_newline(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -29,5 +29,5 @@ int lexer_newline(t_list **alst, char *str)
|
||||||
}
|
}
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_NEWLINE;
|
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> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:45 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_number(t_list **alst, char *str)
|
int lexer_number(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_lexstate state;
|
t_lexstate state;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if ((state = get_lexer_state(str)))
|
if ((state = get_state_global(lexer)))
|
||||||
return (ft_tokenize(alst, str, state));
|
return (lexer_lex(alst, lexer));
|
||||||
if (*str == '>')
|
else if ((state = get_state_redir(lexer)))
|
||||||
return (ft_tokenize(alst, str, GREAT));
|
|
||||||
else if (*str == '<')
|
|
||||||
return (ft_tokenize(alst, str, LESS));
|
|
||||||
else if (ft_isdigit(*str))
|
|
||||||
{
|
{
|
||||||
token_append(token, *str, 0, 0);
|
lexer->state = state;
|
||||||
return (lexer_number(alst, str + 1));
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,29 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:08 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_quote(t_list **alst, char *str)
|
int lexer_quote(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_Q_WORD;
|
token->type = TK_Q_WORD;
|
||||||
str++;
|
lexer->pos++;
|
||||||
if (*str == '\'')
|
push(&lexer->stack, QUOTE);
|
||||||
return (ft_tokenize(alst, str + 1, WORD));
|
if (lexer->str[lexer->pos] == '\'')
|
||||||
token_append(token, *str, 1, 1);
|
{
|
||||||
return (lexer_quote(alst, str));
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,23 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 16:29:57 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"
|
#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)
|
if (*alst)
|
||||||
{
|
{
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (*token->data)
|
if (*token->data)
|
||||||
return (lexer_sep(&(*alst)->next, str));
|
return (lexer_sep(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -28,13 +30,13 @@ int lexer_sep(t_list **alst, char *str)
|
||||||
*alst = ft_lstnew(token, sizeof(*token));
|
*alst = ft_lstnew(token, sizeof(*token));
|
||||||
}
|
}
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (str[0] == '&')
|
c = lexer->str[lexer->pos];
|
||||||
token->type = str[1] == '&' ? TK_AND_IF : TK_AMP;
|
cn = lexer->str[lexer->pos + 1];
|
||||||
if (str[0] == '|')
|
if (c == '&')
|
||||||
token->type = str[1] == '|' ? TK_OR_IF : TK_PIPE;
|
token->type = cn == '&' ? TK_AND_IF : TK_AMP;
|
||||||
token->type = (*str == ';') ? TK_SEMI : token->type;
|
else if (c == '|')
|
||||||
return (ft_tokenize(&(*alst)->next,
|
token->type = cn == '|' ? TK_OR_IF : TK_PIPE;
|
||||||
str + 1 +
|
token->type = (c == ';') ? TK_SEMI : token->type;
|
||||||
(token->type & (TK_AND_IF | TK_OR_IF) ? 1 : 0),
|
lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF) ? 1 : 0);
|
||||||
DEFAULT));
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/11 15:35:38 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_special(t_list **alst, char *str)
|
int lexer_subshell(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_list **lst;
|
t_list **lst;
|
||||||
|
|
@ -27,12 +27,11 @@ int lexer_special(t_list **alst, char *str)
|
||||||
token = token_init();
|
token = token_init();
|
||||||
*lst = ft_lstnew(token, sizeof(*token));
|
*lst = ft_lstnew(token, sizeof(*token));
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (*str == '(')
|
if (lexer->str[lexer->pos] == '(')
|
||||||
token->type = TK_PAREN_OPEN;
|
token->type = TK_PAREN_OPEN;
|
||||||
else if (*str == ')')
|
else if (lexer->str[lexer->pos] == ')')
|
||||||
token->type = TK_PAREN_CLOSE;
|
token->type = TK_PAREN_CLOSE;
|
||||||
else if (*str == '`')
|
token->data = lexer->str;
|
||||||
token->type = TK_BQUOTE;
|
lexer->pos++;
|
||||||
token->data = str;
|
return (lexer_lex(&(*lst)->next, lexer));
|
||||||
return (ft_tokenize(&(*lst)->next, str + 1, DEFAULT));
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,25 +6,27 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:11 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"
|
#include "lexer.h"
|
||||||
|
|
||||||
int lexer_word(t_list **alst, char *str)
|
int lexer_word(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_lexstate state;
|
t_lexstate state;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_N_WORD;
|
token->type = TK_N_WORD;
|
||||||
if ((state = get_lexer_state(str)))
|
if ((state = get_state_global(lexer)))
|
||||||
return (ft_tokenize(alst, str, state));
|
return (lexer_lex(alst, lexer));
|
||||||
if (*str == '>')
|
if ((state = get_state_redir(lexer)))
|
||||||
return (ft_tokenize(&(*alst)->next, str, GREAT));
|
{
|
||||||
else if (*str == '<')
|
lexer->state = state;
|
||||||
return (ft_tokenize(&(*alst)->next, str, LESS));
|
return (lexer_lex(alst, lexer));
|
||||||
token_append(token, *str, 0, 0);
|
}
|
||||||
return (ft_tokenize(alst, str + 1, WORD));
|
token_append(token, lexer, 0, 0);
|
||||||
|
lexer->pos++;
|
||||||
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/11 16:46:27 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 *fit;
|
||||||
char *bq_start;
|
char *bq_start;
|
||||||
char *bq_end;
|
char *bq_end;
|
||||||
|
t_lexer lexer;
|
||||||
|
|
||||||
tk = TK_BQUOTE;
|
tk = TK_BQUOTE;
|
||||||
if ((start = ft_lst_find(*alst, &tk, token_cmp_type)))
|
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);
|
ft_strdel(str);
|
||||||
*str = new;
|
*str = new;
|
||||||
ft_lstdel(alst, token_free);
|
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 (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
34
42sh/src/lexer/stack_to_prompt.c
Normal file
34
42sh/src/lexer/stack_to_prompt.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* stack_to_prompt.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 (" > ");
|
||||||
|
}
|
||||||
|
|
@ -6,16 +6,18 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/11 17:18:42 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"
|
#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;
|
int len;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
c = lexer->str[lexer->pos];
|
||||||
len = ft_strlen(token->data);
|
len = ft_strlen(token->data);
|
||||||
if (len >= token->size)
|
if (len >= token->size)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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,12 +1,12 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* prompt.c :+: :+: :+: */
|
/* ft_prompt.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:51:33 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));
|
return (ft_strlen(env[i] + j + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_prompt(void)
|
void ft_prompt()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:28:49 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);
|
ft_print(ret);
|
||||||
else if (ret == 10)
|
else if (ret == 10)
|
||||||
return (STR);
|
return (STR);
|
||||||
else if (ft_isascii(ret) == 0)
|
/* else if (ft_isascii(ret) == 0) */
|
||||||
ft_read_it(ret, &POS, &STR);
|
/* ft_read_it(ret, &POS, &STR); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:22:19 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 11:39:47 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));
|
tmp = ft_nbr_len(ft_atoi(str + *i + 1));
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), *i,
|
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;
|
(*i) += tmp;
|
||||||
return (1);
|
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));
|
tmp = ft_nbr_len(ft_atoi(str + *i + 2));
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), *i,
|
ft_realloc_str_history(&(data_singleton()->line.input), *i,
|
||||||
data_singleton()->line.list_size - ft_atoi(str + *i + 2),
|
data_singleton()->line.list_size - ft_atoi(str + *i + 2),
|
||||||
ft_nbr_len(ft_atoi(str + *i + 2)) + 2);
|
ft_nbr_len(ft_atoi(str + *i + 2)) + 2);
|
||||||
i += tmp;
|
i += tmp;
|
||||||
}
|
}
|
||||||
else if (str[*i + 1] == '?')
|
else if (str[*i + 1] == '?')
|
||||||
ft_realloc_str_history_3(&(data_singleton()->line.input), *i,
|
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] != ' ')
|
else if (str[*i + 1] != ' ')
|
||||||
ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
|
ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
|
||||||
ft_strdupi_w(str + *i + 1));
|
ft_strdupi_w(str + *i + 1));
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
||||||
|
|
@ -6,66 +6,66 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:52:57 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)
|
/* static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j) */
|
||||||
{
|
/* { */
|
||||||
int i;
|
/* int i; */
|
||||||
|
|
||||||
i = 0;
|
/* i = 0; */
|
||||||
while (i < 4 && t[i] == '\0')
|
/* while (i < 4 && t[i] == '\0') */
|
||||||
++i;
|
/* ++i; */
|
||||||
while (i < 4)
|
/* while (i < 4) */
|
||||||
{
|
/* { */
|
||||||
if (t[i] && ft_isprint(t[i]))
|
/* if (t[i] && ft_isprint(t[i])) */
|
||||||
{
|
/* { */
|
||||||
*str = ft_realloc_imput(*str, t[i], *pos);
|
/* *str = ft_realloc_imput(*str, t[i], *pos); */
|
||||||
++(*pos);
|
/* ++(*pos); */
|
||||||
++(*j);
|
/* ++(*j); */
|
||||||
}
|
/* } */
|
||||||
++i;
|
/* ++i; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static void ft_read_it_2(int input, char t[5])
|
/* static void ft_read_it_2(int input, char t[5]) */
|
||||||
{
|
/* { */
|
||||||
t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0';
|
/* t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0'; */
|
||||||
if (t[3])
|
/* if (t[3]) */
|
||||||
input = input % ft_pow(256, 3);
|
/* input = input % ft_pow(256, 3); */
|
||||||
t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0';
|
/* t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0'; */
|
||||||
if (t[2])
|
/* if (t[2]) */
|
||||||
input = input % ft_pow(256, 2);
|
/* input = input % ft_pow(256, 2); */
|
||||||
t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0';
|
/* t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0'; */
|
||||||
if (t[1])
|
/* if (t[1]) */
|
||||||
input = input % ft_pow(256, 1);
|
/* input = input % ft_pow(256, 1); */
|
||||||
t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0';
|
/* t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0'; */
|
||||||
if (t[0])
|
/* if (t[0]) */
|
||||||
input = input % ft_pow(256, 0);
|
/* input = input % ft_pow(256, 0); */
|
||||||
t[4] = '\0';
|
/* t[4] = '\0'; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
void ft_read_it(int input, size_t *pos, char **str)
|
/* void ft_read_it(int input, size_t *pos, char **str) */
|
||||||
{
|
/* { */
|
||||||
int j;
|
/* int j; */
|
||||||
char t[5];
|
/* char t[5]; */
|
||||||
size_t pos_tmp;
|
/* size_t pos_tmp; */
|
||||||
|
|
||||||
j = 0;
|
/* j = 0; */
|
||||||
pos_tmp = *pos;
|
/* pos_tmp = *pos; */
|
||||||
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
|
/* if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || */
|
||||||
input == 126 || input == 993090331 || input == 925981467 ||
|
/* input == 126 || input == 993090331 || input == 925981467 || */
|
||||||
input == 21298 || input == 892427035 || input == 8270395 || input ==
|
/* input == 21298 || input == 892427035 || input == 8270395 || input == */
|
||||||
942758683 || input == 993090331 || input == 18489 || input == 17977)
|
/* 942758683 || input == 993090331 || input == 18489 || input == 17977) */
|
||||||
return ;
|
/* return ; */
|
||||||
ft_read_it_2(input, t);
|
/* ft_read_it_2(input, t); */
|
||||||
ft_read_it_3(str, t, pos, &j);
|
/* ft_read_it_3(str, t, pos, &j); */
|
||||||
*pos = pos_tmp;
|
/* *pos = pos_tmp; */
|
||||||
ft_current_str((*str), *pos);
|
/* ft_current_str((*str), *pos); */
|
||||||
ft_get_next_str((*str), pos);
|
/* ft_get_next_str((*str), pos); */
|
||||||
ft_putnc('\b', *pos - (pos_tmp + j));
|
/* ft_putnc('\b', *pos - (pos_tmp + j)); */
|
||||||
*pos = (pos_tmp + j);
|
/* *pos = (pos_tmp + j); */
|
||||||
}
|
/* } */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 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);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct termios *ft_save_stats_term(void)
|
struct termios *ft_save_stats_term(int save)
|
||||||
{
|
{
|
||||||
static struct termios *term_save = NULL;
|
static struct termios *term_save = NULL;
|
||||||
|
|
||||||
if (!term_save)
|
if (save)
|
||||||
{
|
{
|
||||||
term_save = (struct termios *)malloc(sizeof(struct termios));
|
term_save = (struct termios *)malloc(sizeof(struct termios));
|
||||||
tcgetattr(0, term_save);
|
tcgetattr(0, term_save);
|
||||||
|
|
@ -71,29 +71,32 @@ struct termios *ft_stats_term_termcaps(void)
|
||||||
return (term);
|
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)
|
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
||||||
return (-1);
|
return (NULL);
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_strdel(&STR);
|
ft_strdel(&STR);
|
||||||
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
||||||
POS = 0;
|
POS = 0;
|
||||||
ft_prompt();
|
prompt ? ft_putstr(prompt) : ft_prompt();
|
||||||
STR = ft_read_stdin();
|
input = ft_read_stdin();
|
||||||
ft_check_line();
|
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
ft_check_heredoc(&STR);
|
/* ft_check_line(); */
|
||||||
ft_history_parsing();
|
/* ft_check_heredoc(&STR); */
|
||||||
if (STR && (!data_singleton()->line.list_beg ||
|
if (tcsetattr(0, TCSANOW, ft_save_stats_term(0)) == -1)
|
||||||
ft_strcmp(data_singleton()->line.list_beg->prev->str, STR)))
|
return (NULL);
|
||||||
{
|
return (input);
|
||||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
|
||||||
ft_create_history_list(STR));
|
/* ft_history_parsing(); */
|
||||||
ft_add_in_history_file(STR);
|
/* if (STR && (!data_singleton()->line.list_beg || */
|
||||||
}
|
/* ft_strcmp(data_singleton()->line.list_beg->prev->str, STR))) */
|
||||||
if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1)
|
/* { */
|
||||||
return (-1);
|
/* ft_push_back_history(&data_singleton()->line.list_beg, */
|
||||||
return (0);
|
/* ft_create_history_list(STR)); */
|
||||||
|
/* ft_add_in_history_file(STR); */
|
||||||
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,32 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 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"
|
#include "minishell.h"
|
||||||
|
|
||||||
int shell_single_command(char *command)
|
int interactive_shell()
|
||||||
{
|
{
|
||||||
t_list *token;
|
t_list *token;
|
||||||
|
t_list *ltoken;
|
||||||
|
t_lexer lexer;
|
||||||
t_btree *ast;
|
t_btree *ast;
|
||||||
|
|
||||||
|
lexer.pos = 0;
|
||||||
|
lexer.state = DEFAULT;
|
||||||
|
lexer.str = NULL;
|
||||||
token = NULL;
|
token = NULL;
|
||||||
ast = NULL;
|
lexer.stack = NULL;
|
||||||
|
do {
|
||||||
DG("{inv}{mag}got command '%s'", command);
|
if (lexer.stack && *(int*)lexer.stack->content == BACKSLASH)
|
||||||
if (ft_lexer(&token, &command) || !token)
|
pop(&lexer.stack);
|
||||||
return (1);
|
ft_strappend(&lexer.str, readline(stack_to_prompt(lexer.stack)));
|
||||||
|
ltoken = ft_lstlast(token);
|
||||||
token_print(token);
|
lexer_lex((token ? <oken : &token), &lexer);
|
||||||
|
token_print(token);
|
||||||
|
} while (lexer.stack->content);
|
||||||
if (ft_parse(&ast, &token))
|
if (ft_parse(&ast, &token))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
|
@ -40,20 +47,12 @@ int main(int ac, char **av)
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
setlocale(LC_ALL, "");
|
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);
|
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");
|
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()));
|
while (1)
|
||||||
return (0);
|
interactive_shell();
|
||||||
}
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if (ft_readline())
|
|
||||||
return (1);
|
|
||||||
if (shell_single_command(ft_strdup(data_singleton()->line.input)) < 0)
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
42sh/src/main/remove_trailing_esc_nl.c
Normal file
26
42sh/src/main/remove_trailing_esc_nl.c
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* remove_trailing_esc_nl.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/11 14:04:48 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_LC;
|
||||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||||
|
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue