master steady, merged end

This commit is contained in:
Antoine Riard 2017-03-17 00:22:47 +01:00
parent ad3525b9d6
commit 1ad56ece41
4 changed files with 95 additions and 120 deletions

View file

@ -267,7 +267,6 @@ main/data_init.c\
main/data_singleton.c\ main/data_singleton.c\
main/error_msg.c\ main/error_msg.c\
main/ft_putast.c\ main/ft_putast.c\
main/instruction_free.c\
main/main.c\ main/main.c\
main/shell_init.c\ main/shell_init.c\
parser/add_bang.c\ parser/add_bang.c\

View file

@ -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/16 23:01:59 by jhalford ### ########.fr */ /* Updated: 2017/03/17 00:20:53 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,17 +40,21 @@
struct s_data struct s_data
{ {
t_flag opts; t_flag opts;
char **env; char **env;
int argc; int argc;
char **argv; char **argv;
t_line line; t_line line;
t_comp *comp; t_list *token;
t_exec exec; t_btree *ast;
t_jobc jobc; t_lexer lexer;
t_list *heredoc_queue; t_parser parser;
char **local_var; t_comp *comp;
t_list *lst_func; t_exec exec;
t_jobc jobc;
t_list *heredoc_queue;
char **local_var;
t_list *lst_func;
}; };
int shell_init(int ac, char **av); int shell_init(int ac, char **av);
@ -58,8 +62,6 @@ 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 instruction_free(t_list **token, t_parser *parser,
t_btree **ast);
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);

View file

@ -6,92 +6,92 @@
/* 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/17 00:02:12 by ariard ### ########.fr */ /* Updated: 2017/03/16 16:40:27 by jhalford ### ########.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; /* 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); */
} /* } */

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instruction_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */
/* Updated: 2017/03/16 18:27:57 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int instruction_free(t_list **token, t_btree **ast, t_lexer *lexer, t_parser *parser)
{
ft_lstdel(token, &token_free);
token = NULL;
ft_lstdel(&parser->stack, &ft_lst_cfree);
btree_del(ast, &ft_lst_cfree);
ft_lstdel(&data_singleton()->parser.heredoc_queue, &redir_free);
ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree);
ft_strdel(&lexer->str);
free(parser->new_sym);
return (0);
}