merge en cours
This commit is contained in:
commit
10d30cedb1
44 changed files with 402 additions and 273 deletions
|
|
@ -220,6 +220,7 @@ lexer/lexer_bquote.c\
|
||||||
lexer/lexer_curly_braces.c\
|
lexer/lexer_curly_braces.c\
|
||||||
lexer/lexer_default.c\
|
lexer/lexer_default.c\
|
||||||
lexer/lexer_delim.c\
|
lexer/lexer_delim.c\
|
||||||
|
lexer/lexer_destroy.c\
|
||||||
lexer/lexer_dquote.c\
|
lexer/lexer_dquote.c\
|
||||||
lexer/lexer_end.c\
|
lexer/lexer_end.c\
|
||||||
lexer/lexer_great.c\
|
lexer/lexer_great.c\
|
||||||
|
|
@ -266,6 +267,7 @@ line-editing/resize.c\
|
||||||
main/data_exit.c\
|
main/data_exit.c\
|
||||||
main/data_init.c\
|
main/data_init.c\
|
||||||
main/data_singleton.c\
|
main/data_singleton.c\
|
||||||
|
main/error_msg.c\
|
||||||
main/ft_putast.c\
|
main/ft_putast.c\
|
||||||
main/instruction_free.c\
|
main/instruction_free.c\
|
||||||
main/main.c\
|
main/main.c\
|
||||||
|
|
@ -286,11 +288,13 @@ parser/error_syntax.c\
|
||||||
parser/eval_sym.c\
|
parser/eval_sym.c\
|
||||||
parser/ft_parse.c\
|
parser/ft_parse.c\
|
||||||
parser/heredoc_parser.c\
|
parser/heredoc_parser.c\
|
||||||
|
parser/parser_destroy.c\
|
||||||
parser/parser_init.c\
|
parser/parser_init.c\
|
||||||
parser/pop_stack.c\
|
parser/pop_stack.c\
|
||||||
parser/produce_sym.c\
|
parser/produce_sym.c\
|
||||||
parser/push_stack.c\
|
parser/push_stack.c\
|
||||||
parser/read_stack.c\
|
parser/read_stack.c\
|
||||||
|
parser/stack_init.c\
|
||||||
parser/tree_wrapper.c
|
parser/tree_wrapper.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 21:55:22 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 14:19:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
# define BT_EXPORT_LP (1 << 0)
|
# define BT_EXPORT_LP (1 << 0)
|
||||||
|
|
||||||
# define MATHERR_0 "{red}math : invalid number of arguments{eoc}\n"
|
# define MATHERR_0 "math : invalid number of arguments\n"
|
||||||
# define MATHERR_1 "{red}math : invalid variable name{eoc}\n"
|
# define MATHERR_1 "math : invalid variable name\n"
|
||||||
# define MATHERR_2 "{red}math : invalid operator{eoc}\n"
|
# define MATHERR_2 "math : invalid operator\n"
|
||||||
# define MATHERR_3 "{red}math : invalid operand{eoc}\n"
|
# define MATHERR_3 "math : invalid operand\n"
|
||||||
# define MATHERR_4 "{red}math : division by 0{eoc}\n"
|
# define MATHERR_4 "math : division by 0\n"
|
||||||
|
|
||||||
t_execf *is_builtin(t_process *p);
|
t_execf *is_builtin(t_process *p);
|
||||||
int builtin_export(const char *path, char *const av[], char *const envp[]);
|
int builtin_export(const char *path, char *const av[], char *const envp[]);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@
|
||||||
/* 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 #+# #+# */
|
||||||
|
<<<<<<< HEAD
|
||||||
/* Updated: 2017/03/16 16:02:32 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 16:02:32 by jhalford ### ########.fr */
|
||||||
|
=======
|
||||||
|
/* Updated: 2017/03/16 15:13:25 by jhalford ### ########.fr */
|
||||||
|
>>>>>>> main_cleanup
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -74,6 +78,7 @@ typedef struct s_list_history
|
||||||
typedef struct s_line
|
typedef struct s_line
|
||||||
{
|
{
|
||||||
char *input;
|
char *input;
|
||||||
|
int fd;
|
||||||
char *copy_tmp;
|
char *copy_tmp;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
int prompt_size;
|
int prompt_size;
|
||||||
|
|
@ -155,7 +160,7 @@ void ft_c(void);
|
||||||
void ft_x(void);
|
void ft_x(void);
|
||||||
void ft_v(void);
|
void ft_v(void);
|
||||||
void ft_read_it(int input, size_t *pos, char **str);
|
void ft_read_it(int input, size_t *pos, char **str);
|
||||||
int readline(int fd, int prompt, char **input);
|
int readline(int prompt, char **input);
|
||||||
int ft_completion(int ret);
|
int ft_completion(int ret);
|
||||||
|
|
||||||
struct termios *ft_save_termios(int save);
|
struct termios *ft_save_termios(int save);
|
||||||
|
|
|
||||||
|
|
@ -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/03/16 19:07:42 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:36:02 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ int get_reserved_words(t_list **alst);
|
||||||
int insert_newline(t_list **alst);
|
int insert_newline(t_list **alst);
|
||||||
|
|
||||||
void lexer_init(t_lexer *lexer);
|
void lexer_init(t_lexer *lexer);
|
||||||
|
void lexer_destroy(t_lexer *lexer);
|
||||||
int lexer_lex(t_list **alst, t_lexer *lexer);
|
int lexer_lex(t_list **alst, t_lexer *lexer);
|
||||||
int lexer_default(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_newline(t_list **alst, t_lexer *lexer);
|
||||||
|
|
|
||||||
|
|
@ -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/03/15 16:35:42 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 22:18:45 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,27 +34,32 @@
|
||||||
|
|
||||||
struct s_data
|
struct s_data
|
||||||
{
|
{
|
||||||
t_flag opts;
|
t_flag opts;
|
||||||
char **env;
|
int fd;
|
||||||
int argc;
|
char **env;
|
||||||
char **argv;
|
int argc;
|
||||||
t_line line;
|
char **argv;
|
||||||
t_comp *comp;
|
t_line line;
|
||||||
t_exec exec;
|
t_list *token;
|
||||||
t_jobc jobc;
|
t_btree *ast;
|
||||||
t_list *heredoc_queue;
|
t_lexer lexer;
|
||||||
char **local_var;
|
t_parser parser;
|
||||||
t_list *lst_func;
|
t_comp *comp;
|
||||||
|
t_exec exec;
|
||||||
|
t_jobc jobc;
|
||||||
|
char **local_var;
|
||||||
|
t_list *lst_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
int shell_init(int ac, char **av);
|
int shell_init(int ac, char **av);
|
||||||
void shell_exit(void);
|
void shell_exit(void);
|
||||||
int data_init(int ac, char **av);
|
int data_init(int ac, char **av);
|
||||||
void data_exit(void);
|
void data_exit(void);
|
||||||
|
int error_msg(char *msg);
|
||||||
|
|
||||||
int instruction_free(t_list **token, t_parser *parser,
|
int instruction_free(
|
||||||
t_btree **ast);
|
t_list **token, t_btree **ast, t_lexer *lexer, t_parser *parser);
|
||||||
void content_free(void *data, size_t content_size);
|
/* void content_free(void *data, size_t content_size); */
|
||||||
|
|
||||||
char *ft_putast(void *node);
|
char *ft_putast(void *node);
|
||||||
void ft_putast2(void *node);
|
void ft_putast2(void *node);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ struct s_parser
|
||||||
t_parstate state;
|
t_parstate state;
|
||||||
t_list *stack;
|
t_list *stack;
|
||||||
t_sym *new_sym;
|
t_sym *new_sym;
|
||||||
|
t_list *heredoc_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_aggrematch
|
struct s_aggrematch
|
||||||
|
|
@ -59,12 +60,14 @@ struct s_errormatch
|
||||||
char *error;
|
char *error;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern t_aggrematch g_aggrematch[];
|
/* extern t_aggrematch g_aggrematch[]; */
|
||||||
extern t_prodmatch g_prodmatch[];
|
/* extern t_prodmatch g_prodmatch[]; */
|
||||||
extern t_stackmatch g_stackmatch[];
|
/* extern t_stackmatch g_stackmatch[]; */
|
||||||
extern t_errormatch g_errormatch[];
|
|
||||||
|
|
||||||
void parser_init(t_parser *parser);
|
void parser_init(t_parser *parser);
|
||||||
|
void parser_destroy(t_parser *parser);
|
||||||
|
int stack_init(t_parser *parser);
|
||||||
|
|
||||||
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
|
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
|
||||||
|
|
||||||
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);
|
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);
|
||||||
|
|
@ -76,8 +79,8 @@ int pop_stack(t_list **stack, t_sym erase_sym);
|
||||||
|
|
||||||
int pop_heredoc(t_list **lst);
|
int pop_heredoc(t_list **lst);
|
||||||
|
|
||||||
int error_syntax(t_list **token, t_parser *parser, t_btree **ast);
|
int error_syntax(t_list **token);
|
||||||
int error_eof(t_list **token, t_parser *parser, t_btree **ast);
|
int error_eof(void);
|
||||||
|
|
||||||
int ft_read_stack(t_sym *stack);
|
int ft_read_stack(t_sym *stack);
|
||||||
char *read_state(t_sym current);
|
char *read_state(t_sym current);
|
||||||
|
|
|
||||||
|
|
@ -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/03/14 22:53:17 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 18:17:16 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,6 +36,8 @@ typedef struct s_line t_line;
|
||||||
typedef struct s_comp t_comp;
|
typedef struct s_comp t_comp;
|
||||||
typedef struct s_exec t_exec;
|
typedef struct s_exec t_exec;
|
||||||
typedef struct s_jobc t_jobc;
|
typedef struct s_jobc t_jobc;
|
||||||
|
typedef struct s_lexer t_lexer;
|
||||||
|
typedef struct s_parser t_parser;
|
||||||
typedef enum e_mode t_mode;
|
typedef enum e_mode t_mode;
|
||||||
typedef struct s_data_template t_btexport;
|
typedef struct s_data_template t_btexport;
|
||||||
|
|
||||||
|
|
@ -43,7 +45,6 @@ typedef struct s_data_template t_btexport;
|
||||||
** Lexer types
|
** Lexer types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct s_lexer t_lexer;
|
|
||||||
typedef enum e_lexstate t_lexstate;
|
typedef enum e_lexstate t_lexstate;
|
||||||
typedef struct s_token t_token;
|
typedef struct s_token t_token;
|
||||||
typedef struct s_rvwords t_rvwords;
|
typedef struct s_rvwords t_rvwords;
|
||||||
|
|
@ -77,7 +78,6 @@ typedef struct s_redir t_redir;
|
||||||
typedef struct s_cmd t_cmd;
|
typedef struct s_cmd t_cmd;
|
||||||
typedef union u_astdata t_astdata;
|
typedef union u_astdata t_astdata;
|
||||||
typedef union u_word t_word;
|
typedef union u_word t_word;
|
||||||
typedef struct s_parser t_parser;
|
|
||||||
typedef int t_sym;
|
typedef int t_sym;
|
||||||
typedef enum e_parstate t_parstate;
|
typedef enum e_parstate t_parstate;
|
||||||
typedef struct s_aggrematch t_aggrematch;
|
typedef struct s_aggrematch t_aggrematch;
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 04b8d5cd090e86b0f9d8160b01e49d43666deddf
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 20:55:40 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 14:17:57 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,92 +6,91 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/16 16:40:27 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:35:33 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
/* #include "minishell.h" */
|
#include "minishell.h"
|
||||||
|
|
||||||
/* static int init_math(char **var, char **value, char **operator, char **operand) */
|
static int init_math(char **var, char **value, char **operator, char **operand)
|
||||||
/* { */
|
{
|
||||||
/* *var = NULL; */
|
*var = NULL;
|
||||||
/* *value = NULL; */
|
*value = NULL;
|
||||||
/* *operator = NULL; */
|
*operator = NULL;
|
||||||
/* *operand = NULL; */
|
*operand = NULL;
|
||||||
/* return (0); */
|
return (0);
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
/* static int get_value(char **var, char **value) */
|
static int get_value(char **var, char **value)
|
||||||
/* { */
|
{
|
||||||
/* char *temp; */
|
|
||||||
|
|
||||||
/* if (!word_is_assignment(var)) */
|
if (!word_is_assignment(var))
|
||||||
/* return (error_msg(MATHERR_1)); */
|
return (error_msg(MATHERR_1));
|
||||||
/* temp = ft_sstrstr(data_singleton()->local_var, *var); */
|
temp = ft_sstrstr(data_singleton()->local_var, *var);
|
||||||
/* if (temp) */
|
if (temp)
|
||||||
/* { */
|
{
|
||||||
/* temp += ft_strlenchr(temp, '=') + 1; */
|
temp += ft_strlenchr(temp, '=') + 1;
|
||||||
/* *value = ft_strdup(temp); */
|
*value = ft_strdup(temp);
|
||||||
/* if (!(ft_stris(*value, &ft_isdigit))) */
|
if (!(ft_stris(*value, &ft_isdigit)))
|
||||||
/* { */
|
{
|
||||||
/* ft_strdel(value); */
|
ft_strdel(value);
|
||||||
/* *value = ft_itoa(0); */
|
*value = ft_itoa(0);
|
||||||
/* } */
|
}
|
||||||
/* } */
|
}
|
||||||
/* else */
|
else
|
||||||
/* *value = ft_itoa(0); */
|
*value = ft_itoa(0);
|
||||||
/* return (0); */
|
return (0);
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
/* static int do_math(char **value, char *operator, char *operand) */
|
static int do_math(char **value, char *operator, char *operand)
|
||||||
/* { */
|
{
|
||||||
/* long ope1; */
|
long ope1;
|
||||||
/* long ope2; */
|
long ope2;
|
||||||
|
|
||||||
/* ope1 = ft_atoi(*value); */
|
ope1 = ft_atoi(*value);
|
||||||
/* if (operand) */
|
if (operand)
|
||||||
/* ope2 = ft_atoi(operand); */
|
ope2 = ft_atoi(operand);
|
||||||
/* else */
|
else
|
||||||
/* ope2 = 0; */
|
ope2 = 0;
|
||||||
/* if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) */
|
if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0)
|
||||||
/* return (error_msg(MATHERR_4)); */
|
return (error_msg(MATHERR_4));
|
||||||
/* else */
|
else
|
||||||
/* { */
|
{
|
||||||
/* ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; */
|
ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1;
|
||||||
/* ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; */
|
ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1;
|
||||||
/* ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; */
|
ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1;
|
||||||
/* ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; */
|
ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1;
|
||||||
/* ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; */
|
ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1;
|
||||||
/* } */
|
}
|
||||||
/* ft_strdel(value); */
|
ft_strdel(value);
|
||||||
/* *value = ft_itoa(ope1); */
|
*value = ft_itoa(ope1);
|
||||||
/* return (0); */
|
return (0);
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
/* int builtin_math(const char *path, char *const av[], char *const envp[]) */
|
int builtin_math(const char *path, char *const av[], char *const envp[])
|
||||||
/* { */
|
{
|
||||||
/* char *var; */
|
char *var;
|
||||||
/* char *value; */
|
char *value;
|
||||||
/* char *operator; */
|
char *operator;
|
||||||
/* char *operand; */
|
char *operand;
|
||||||
|
|
||||||
/* (void)path; */
|
(void)path;
|
||||||
/* (void)envp; */
|
(void)envp;
|
||||||
/* if (!av || !av[1] || !av[2] || !av[3] || av[4]) */
|
if (!av || !av[1] || !av[2] || !av[3] || av[4])
|
||||||
/* return (error_msg(MATHERR_0)); */
|
return (error_msg(MATHERR_0));
|
||||||
/* init_math(&var, &value, &operator, &operand); */
|
init_math(&var, &value, &operator, &operand);
|
||||||
/* var = av[1]; */
|
var = av[1];
|
||||||
/* if (get_value(&var, &value) == -1) */
|
if (get_value(&var, &value) == -1)
|
||||||
/* return (-1); */
|
return (-1);
|
||||||
/* operator = av[2]; */
|
operator = av[2];
|
||||||
/* if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' */
|
if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-'
|
||||||
/* || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) */
|
|| operator[0] == '/' || operator[0] == '*' || operator[0] == '%')))
|
||||||
/* return (error_msg(MATHERR_2)); */
|
return (error_msg(MATHERR_2));
|
||||||
/* operand = av[3]; */
|
operand = av[3];
|
||||||
/* if (!ft_stris(operand, &ft_isdigit)) */
|
if (!ft_stris(operand, &ft_isdigit))
|
||||||
/* return (error_msg(MATHERR_3)); */
|
return (error_msg(MATHERR_3));
|
||||||
/* if (do_math(&value, operator, operand) == -1) */
|
if (do_math(&value, operator, operand) == -1)
|
||||||
/* return (-1); */
|
return (-1);
|
||||||
/* builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); */
|
builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var);
|
||||||
/* return (0); */
|
return (0);
|
||||||
/* } */
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 18:38:09 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:38:29 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 19:06:25 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:28:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 18:11:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 13:54:18 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 16:55:08 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 14:41:00 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 19:03:43 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:00:30 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */
|
/* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 13:12:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:00:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/21 21:05:23 by ariard #+# #+# */
|
/* Created: 2017/02/21 21:05:23 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/15 16:31:49 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 14:41:14 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/03/05 16:20:18 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:05:25 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ int lexer_default(t_list **alst, t_lexer *lexer)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
c = lexer->str[lexer->pos];
|
c = lexer->str[lexer->pos];
|
||||||
if ((lexer->state = get_state_global(lexer)))
|
if ((lexer->state = get_state_global(lexer)))
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
if ((lexer->state = get_state_redir(lexer)))
|
if ((lexer->state = get_state_redir(lexer)))
|
||||||
|
|
|
||||||
22
42sh/src/lexer/lexer_destroy.c
Normal file
22
42sh/src/lexer/lexer_destroy.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lexer_destroy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/16 20:25:08 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/16 20:43:06 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void lexer_destroy(t_lexer *lexer)
|
||||||
|
{
|
||||||
|
ft_strdel(&lexer->str);
|
||||||
|
lexer->pos = 0;
|
||||||
|
lexer->state = 0;
|
||||||
|
lexer->stack = NULL;
|
||||||
|
lexer->heredoc_stack = NULL;
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
|
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 14:53:42 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 14:44:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/21 16:14:08 by ariard #+# #+# */
|
/* Created: 2017/02/21 16:14:08 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/04 16:32:15 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 17:57:47 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 19:07:45 by jhalford ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* 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/03/09 18:48:00 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 18:21:30 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lexer.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int lexer_sep(t_list **alst, t_lexer *lexer)
|
int lexer_sep(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/03/11 20:46:32 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 14:44:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 12:14:32 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:10:40 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ void token_print(t_list *lst)
|
||||||
|
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
|
DG("in token print");
|
||||||
if (lst->content)
|
if (lst->content)
|
||||||
token = lst->content;
|
token = lst->content;
|
||||||
if (token->type)
|
if (token->type)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
|
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 10:17:13 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 14:05:00 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */
|
/* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 10:37:03 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 15:32:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ void ft_init_line(void)
|
||||||
data_singleton()->line.opt = 0;
|
data_singleton()->line.opt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void readline_init(int prompt)
|
void readline_init(int has_prompt)
|
||||||
{
|
{
|
||||||
static int beg = 0;
|
static int beg = 0;
|
||||||
|
|
||||||
|
|
@ -40,6 +40,6 @@ void readline_init(int prompt)
|
||||||
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;
|
||||||
prompt ? ft_putstr("> ") : ft_prompt();
|
has_prompt ? ft_prompt() : ft_putstr("> ");
|
||||||
data_singleton()->line.is_prompt = prompt ? 0 : 1;
|
data_singleton()->line.is_prompt = has_prompt ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,24 @@
|
||||||
/* 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/03/15 03:52:15 by wescande ### ########.fr */
|
/* Updated: 2017/03/16 18:40:39 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int readline(int fd, int prompt, char **input)
|
int readline(int has_prompt, char **input)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
return ((ret = get_next_line(fd, input)) >= 0 ? !ret : ret);
|
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
|
||||||
readline_init(prompt);
|
readline_init(has_prompt);
|
||||||
*input = ft_read_stdin();
|
*input = ft_read_stdin();
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
if (!prompt)
|
if (has_prompt)
|
||||||
*input = ft_history_parsing();
|
*input = ft_history_parsing();
|
||||||
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
|
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 16:47:55 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:25:46 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,7 +34,10 @@ int data_init(int ac, char **av)
|
||||||
data->opts = 0;
|
data->opts = 0;
|
||||||
exec_reset();
|
exec_reset();
|
||||||
data->lst_func = NULL;
|
data->lst_func = NULL;
|
||||||
data->heredoc_queue = NULL;
|
data->token = NULL;
|
||||||
|
data->ast = NULL;
|
||||||
|
lexer_init(&data->lexer);
|
||||||
|
parser_init(&data->parser);
|
||||||
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (tgetent(NULL, term_name) != 1)
|
if (tgetent(NULL, term_name) != 1)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */
|
/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 15:22:54 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 15:12:53 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
19
42sh/src/main/error_msg.c
Normal file
19
42sh/src/main/error_msg.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error_msg.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/16 14:14:47 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2017/03/16 14:17:29 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int error_msg(char *msg)
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}%s{eoc}\n", msg);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
@ -6,20 +6,21 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */
|
/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/15 16:49:10 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 18:27:57 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int instruction_free(t_list **token, t_parser *parser, t_btree **ast)
|
int instruction_free(t_list **token, t_btree **ast, t_lexer *lexer, t_parser *parser)
|
||||||
{
|
{
|
||||||
ft_lstdel(token, &token_free);
|
ft_lstdel(token, &token_free);
|
||||||
token = NULL;
|
token = NULL;
|
||||||
ft_lstdel(&parser->stack, &ft_lst_cfree);
|
ft_lstdel(&parser->stack, &ft_lst_cfree);
|
||||||
btree_del(ast, &ft_lst_cfree);
|
btree_del(ast, &ft_lst_cfree);
|
||||||
ft_lstdel(&data_singleton()->heredoc_queue, &redir_free);
|
ft_lstdel(&data_singleton()->parser.heredoc_queue, &redir_free);
|
||||||
ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree);
|
ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree);
|
||||||
|
ft_strdel(&lexer->str);
|
||||||
free(parser->new_sym);
|
free(parser->new_sym);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,129 +6,124 @@
|
||||||
/* 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/03/16 18:01:32 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:38:05 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int handle_instruction(int fd)
|
static int do_readline_routine(char **stream)
|
||||||
{
|
{
|
||||||
t_list *token;
|
int ret;
|
||||||
t_list *ltoken;
|
int has_prompt;
|
||||||
t_lexer lexer;
|
t_data *data;
|
||||||
t_parser parser;
|
|
||||||
t_btree *ast;
|
|
||||||
char *str;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
lexer_init(&lexer);
|
data = data_singleton();
|
||||||
parser_init(&parser);
|
has_prompt = !(get_lexer_stack(data->lexer)
|
||||||
token = NULL;
|
|| data->parser.state == UNDEFINED || data->lexer.state == HEREDOC);
|
||||||
ast = NULL;
|
ret = readline(has_prompt, stream);
|
||||||
while (1)
|
if (ret == -1)
|
||||||
|
exit(1);
|
||||||
|
if (ret == 1 && data->parser.state == UNDEFINED)
|
||||||
|
error_eof();
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_lexer_routine(char *stream)
|
||||||
|
{
|
||||||
|
t_list *ltoken;
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
data = data_singleton();
|
||||||
|
if (data->lexer.state == HEREDOC || data->parser.state == UNDEFINED)
|
||||||
{
|
{
|
||||||
if ((ret = readline(fd, get_lexer_stack(lexer) ||
|
ft_strappend(&data->lexer.str, (char[]){'\n', 0});
|
||||||
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
|
data->lexer.pos++;
|
||||||
{
|
|
||||||
if (ret == -1)
|
|
||||||
return (-1);
|
|
||||||
return (parser.state == UNDEFINED ? error_eof(&token,
|
|
||||||
&parser, &ast) : 1);
|
|
||||||
}
|
|
||||||
if (lexer.state == HEREDOC)
|
|
||||||
{
|
|
||||||
ft_strappend(&lexer.str, (char[]){'\n', 0});
|
|
||||||
lexer.pos++;
|
|
||||||
}
|
|
||||||
ft_strappend(&lexer.str, str);
|
|
||||||
if (get_lexer_stack(lexer) == BACKSLASH)
|
|
||||||
pop(&lexer.stack);
|
|
||||||
ltoken = ft_lstlast(token);
|
|
||||||
if (lexer_lex(token ? <oken : &token, &lexer))
|
|
||||||
return (1);
|
|
||||||
if (get_lexer_stack(lexer) > 2)
|
|
||||||
continue ;
|
|
||||||
lexer.state = DEFAULT;
|
|
||||||
if (get_reserved_words(&token))
|
|
||||||
return (1);
|
|
||||||
token_print(token);
|
|
||||||
if (insert_newline(&token))
|
|
||||||
return (1);
|
|
||||||
if (ft_parse(&ast, &token, &parser))
|
|
||||||
continue ;
|
|
||||||
if (parser.state == ERROR)
|
|
||||||
error_syntax(&token, &parser, &ast);
|
|
||||||
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
|
||||||
if (lexer.state)
|
|
||||||
continue;
|
|
||||||
else if (parser.state == SUCCESS)
|
|
||||||
break ;
|
|
||||||
else if (parser.state == ERROR && SH_IS_INTERACTIVE(data_singleton()->opts))
|
|
||||||
{
|
|
||||||
ft_add_str_in_history(lexer.str);
|
|
||||||
return (error_syntax(&token, &parser, &ast));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* btree_print(STDBUG, ast, &ft_putast); */
|
ft_strappend(&data->lexer.str, stream);
|
||||||
if (ft_exec(&ast))
|
if (get_lexer_stack(data->lexer) == BACKSLASH)
|
||||||
return (2);
|
pop(&data->lexer.stack);
|
||||||
instruction_free(&token, &parser, &ast);
|
ltoken = ft_lstlast(data->token);
|
||||||
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
|
if (lexer_lex(data->token ? <oken : &data->token, &data->lexer) < 0)
|
||||||
ft_add_str_in_history(lexer.str);
|
exit(1);
|
||||||
ft_strdel(&lexer.str);
|
if (get_lexer_stack(data->lexer) > 2)
|
||||||
|
return (1);
|
||||||
|
data->lexer.state = DEFAULT;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_input_fd(char **av)
|
static int do_parser_routine(void)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
char *file;
|
|
||||||
int fds[2];
|
|
||||||
int fd;
|
|
||||||
struct stat buf;
|
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (SH_IS_INTERACTIVE(data->opts))
|
if (get_reserved_words(&data->token))
|
||||||
return (STDIN);
|
return (1);
|
||||||
else if (data->opts & SH_OPTS_LC)
|
if (insert_newline(&data->token))
|
||||||
|
return (1);
|
||||||
|
if (data->parser.state == SUCCESS && stack_init(&data->parser))
|
||||||
|
exit(1);
|
||||||
|
if (ft_parse(&data->ast, &data->token, &data->parser))
|
||||||
|
exit(1);
|
||||||
|
if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT))
|
||||||
|
return (0);
|
||||||
|
if (data->parser.state == ERROR)
|
||||||
{
|
{
|
||||||
pipe(fds);
|
error_syntax(&data->token);
|
||||||
dup2_close(fds[PIPE_READ], 10);
|
return (1);
|
||||||
fd = 10;
|
|
||||||
file = *cliopts_getdata(av);
|
|
||||||
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
|
||||||
close(fds[PIPE_WRITE]);
|
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
|
||||||
return (fd);
|
|
||||||
}
|
}
|
||||||
else if ((file = *cliopts_getdata(av)) && !stat(file, &buf))
|
else if (data->parser.state == SUCCESS)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int handle_instruction()
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char *stream;
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
stream = NULL;
|
||||||
|
data = data_singleton();
|
||||||
|
while (1)
|
||||||
{
|
{
|
||||||
fd = -1;
|
if ((ret = do_readline_routine(&stream)) > 0)
|
||||||
if (S_ISDIR(buf.st_mode))
|
return (ret);
|
||||||
ft_printf("{red}%s: %s: is a directory\n{eoc}", av[0], file);
|
if (do_lexer_routine(stream) > 0)
|
||||||
else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
|
continue ;
|
||||||
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file);
|
if (do_parser_routine() > 0)
|
||||||
if (fd > 0 && !dup2_close(fd, 10) && (fd = 10))
|
break ;
|
||||||
return (fd);
|
|
||||||
}
|
}
|
||||||
return (STDIN);
|
/* btree_print(STDBUG, ast, &ft_putast); */
|
||||||
|
if (data->parser.state == SUCCESS && ft_exec(&data->ast) < 0)
|
||||||
|
exit(1);
|
||||||
|
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
|
||||||
|
ft_add_str_in_history(data->lexer.str);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
int fd;
|
int ret;
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
g_argv = av;
|
g_argv = av;
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
DG("{inv}{bol}{gre}start of shell{eoc}");
|
DG("{inv}{bol}{gre}start of shell{eoc}");
|
||||||
if (shell_init(ac, av))
|
if (shell_init(ac, av))
|
||||||
return (1);
|
return (1);
|
||||||
if ((fd = get_input_fd(av)) < 0)
|
DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
|
||||||
return (1);
|
data = data_singleton();
|
||||||
DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
|
while (1)
|
||||||
while (handle_instruction(fd) == 0)
|
{
|
||||||
;
|
ret = handle_instruction();
|
||||||
|
lexer_destroy(&data->lexer);
|
||||||
|
parser_destroy(&data->parser);
|
||||||
|
ft_lstdel(&data->token, &ft_lst_cfree);
|
||||||
|
btree_del(&data->ast, &ft_lst_cfree);
|
||||||
|
if (ret == 1)
|
||||||
|
break ;
|
||||||
|
}
|
||||||
builtin_exit(NULL, NULL, NULL);
|
builtin_exit(NULL, NULL, NULL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 16:47:50 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:25:29 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,6 +19,41 @@ static t_cliopts g_opts[] =
|
||||||
{0, 0, 0, 0, 0},
|
{0, 0, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int get_input_fd(char **av)
|
||||||
|
{
|
||||||
|
t_data *data;
|
||||||
|
char *file;
|
||||||
|
int fds[2];
|
||||||
|
int fd;
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
|
data = data_singleton();
|
||||||
|
if (SH_IS_INTERACTIVE(data->opts))
|
||||||
|
return (STDIN);
|
||||||
|
else if (data->opts & SH_OPTS_LC)
|
||||||
|
{
|
||||||
|
pipe(fds);
|
||||||
|
dup2_close(fds[PIPE_READ], 10);
|
||||||
|
fd = 10;
|
||||||
|
file = *cliopts_getdata(av);
|
||||||
|
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
||||||
|
close(fds[PIPE_WRITE]);
|
||||||
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
else if ((file = *cliopts_getdata(av)) && !stat(file, &buf))
|
||||||
|
{
|
||||||
|
fd = -1;
|
||||||
|
if (S_ISDIR(buf.st_mode))
|
||||||
|
ft_printf("{red}%s: %s: is a directory\n{eoc}", av[0], file);
|
||||||
|
else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
|
||||||
|
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file);
|
||||||
|
if (fd > 0 && !dup2_close(fd, 10) && (fd = 10))
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
return (STDIN);
|
||||||
|
}
|
||||||
|
|
||||||
static int interactive_settings(void)
|
static int interactive_settings(void)
|
||||||
{
|
{
|
||||||
int *shell_pgid;
|
int *shell_pgid;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 16:58:33 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 17:56:16 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/15 02:09:54 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 18:34:10 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ static int add_redir_type_number(t_btree **ast, t_list **lst)
|
||||||
t_list **queue;
|
t_list **queue;
|
||||||
t_list *redir_lst;
|
t_list *redir_lst;
|
||||||
|
|
||||||
queue = &data_singleton()->heredoc_queue;
|
queue = &data_singleton()->parser.heredoc_queue;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
redir_lst = ft_lstlast(node->data.cmd.redir);
|
redir_lst = ft_lstlast(node->data.cmd.redir);
|
||||||
|
|
@ -116,7 +116,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
||||||
t_list *redir_lst;
|
t_list *redir_lst;
|
||||||
t_list **queue;
|
t_list **queue;
|
||||||
|
|
||||||
queue = &data_singleton()->heredoc_queue;
|
queue = &data_singleton()->parser.heredoc_queue;
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
|
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/16 15:52:35 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 23:24:01 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_errormatch g_errormatch[] =
|
static t_errormatch g_errormatch[] =
|
||||||
{
|
{
|
||||||
{TK_NEWLINE, "newline"},
|
{TK_NEWLINE, "newline"},
|
||||||
{TK_SEMI, ";"},
|
{TK_SEMI, ";"},
|
||||||
|
|
@ -51,8 +51,7 @@ t_errormatch g_errormatch[] =
|
||||||
{0, NULL},
|
{0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
int error_syntax(t_list **lst, t_parser *parser,
|
int error_syntax(t_list **lst)
|
||||||
t_btree **ast)
|
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -65,21 +64,18 @@ int error_syntax(t_list **lst, t_parser *parser,
|
||||||
{
|
{
|
||||||
if (g_errormatch[i].token == token->type)
|
if (g_errormatch[i].token == token->type)
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "syntax error near unexpected token « %s »\n",
|
ft_dprintf(2, "{red}syntax error near unexpected token « %s »{eoc}\n",
|
||||||
g_errormatch[i].error);
|
g_errormatch[i].error);
|
||||||
instruction_free(lst, parser, ast);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
ft_dprintf(2, "syntax error near unexpected token « %s »\n", token->data);
|
ft_dprintf(2, "{red}syntax error near unexpected token « %s »\n{eoc}", token->data);
|
||||||
instruction_free(lst, parser, ast);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int error_eof(t_list **lst, t_parser *parser, t_btree **ast)
|
int error_eof(void)
|
||||||
{
|
{
|
||||||
ft_putstr_fd("syntax error near unexpected EOF", 2);
|
ft_dprintf(2, "{red}syntax error near unexpected EOF{eoc}");
|
||||||
instruction_free(lst, parser, ast);
|
return (1);
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
|
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:01:19 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 21:24:10 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -1243,7 +1243,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
||||||
if (!*stack)
|
if (!*stack)
|
||||||
return (1);
|
return (1);
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||||
i = 0;
|
i = 0;
|
||||||
while (g_stackmatch[i].top)
|
while (g_stackmatch[i].top)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
|
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/15 19:59:19 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 22:11:41 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,13 +35,12 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
{
|
{
|
||||||
t_sym *head;
|
t_sym *head;
|
||||||
|
|
||||||
(void)ast;
|
|
||||||
if (pop_heredoc(token))
|
if (pop_heredoc(token))
|
||||||
return (0);
|
return (0);
|
||||||
while (*token)
|
while (*token)
|
||||||
{
|
{
|
||||||
produce_sym(&parser->stack, parser->new_sym, token);
|
produce_sym(&parser->stack, parser->new_sym, token);
|
||||||
// DG("new sym %s", read_state(*parser->new_sym));
|
DG("new sym %s", read_state(*parser->new_sym));
|
||||||
if (eval_sym(&parser->stack, *parser->new_sym))
|
if (eval_sym(&parser->stack, *parser->new_sym))
|
||||||
return ((parser->state = ERROR));
|
return ((parser->state = ERROR));
|
||||||
else
|
else
|
||||||
|
|
@ -62,7 +61,5 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
else
|
else
|
||||||
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);
|
||||||
}
|
}
|
||||||
if (parser->state == SUCCESS)
|
|
||||||
DG("sucessful parsing");
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/14 15:02:34 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 17:51:54 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,9 +20,9 @@ int pop_heredoc(t_list **lst)
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
|
if (token->type == HEREDOCDATA && data_singleton()->parser.heredoc_queue != NULL)
|
||||||
{
|
{
|
||||||
head = &data_singleton()->heredoc_queue;
|
head = &data_singleton()->parser.heredoc_queue;
|
||||||
redir = *(t_redir**)(*head)->content;
|
redir = *(t_redir**)(*head)->content;
|
||||||
if (head && token)
|
if (head && token)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
22
42sh/src/parser/parser_destroy.c
Normal file
22
42sh/src/parser/parser_destroy.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parser_destroy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/16 19:30:17 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/16 23:21:28 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void parser_destroy(t_parser *parser)
|
||||||
|
{
|
||||||
|
parser->state = SUCCESS;
|
||||||
|
ft_lstdel(&parser->stack, &ft_lst_cfree);
|
||||||
|
ft_lstdel(&data_singleton()->parser.heredoc_queue, &ft_lst_cfree);
|
||||||
|
free(parser->new_sym);
|
||||||
|
parser->new_sym = NULL;
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/21 16:14:04 by ariard #+# #+# */
|
/* Created: 2017/02/21 16:14:04 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/11 16:20:31 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 22:13:39 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,8 +15,7 @@
|
||||||
void parser_init(t_parser *parser)
|
void parser_init(t_parser *parser)
|
||||||
{
|
{
|
||||||
parser->state = SUCCESS;
|
parser->state = SUCCESS;
|
||||||
parser->new_sym = ft_memalloc(sizeof(t_sym));
|
parser->new_sym = NULL;
|
||||||
parser->stack = NULL;
|
parser->stack = NULL;
|
||||||
push_stack(&parser->stack, TERMINUS);
|
parser->heredoc_queue = NULL;
|
||||||
push_stack(&parser->stack, LINEBREAK);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:03:42 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 21:31:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -127,12 +127,14 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
|
||||||
t_sym *head;
|
t_sym *head;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!*stack)
|
||||||
|
DG("stack absente");
|
||||||
if (!*stack || !*lst)
|
if (!*stack || !*lst)
|
||||||
return (1);
|
return (1);
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
// DG("produce stack : %s && token : %s", read_state(*head),
|
DG("produce stack : %s && token : %s", read_state(*head),
|
||||||
// read_state(token->type));
|
read_state(token->type));
|
||||||
i = 0;
|
i = 0;
|
||||||
*new_sym = 0;
|
*new_sym = 0;
|
||||||
while (g_prodmatch[i].new_sym)
|
while (g_prodmatch[i].new_sym)
|
||||||
|
|
|
||||||
23
42sh/src/parser/stack_init.c
Normal file
23
42sh/src/parser/stack_init.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* stack_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/16 20:31:32 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/16 22:11:59 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int stack_init(t_parser *parser)
|
||||||
|
{
|
||||||
|
ft_lstdel(&parser->stack, NULL);
|
||||||
|
push_stack(&parser->stack, TERMINUS);
|
||||||
|
push_stack(&parser->stack, LINEBREAK);
|
||||||
|
if (!parser->new_sym && !(parser->new_sym = ft_memalloc(sizeof(t_sym))))
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue