master steady, merged end
This commit is contained in:
parent
ad3525b9d6
commit
1ad56ece41
4 changed files with 95 additions and 120 deletions
|
|
@ -267,7 +267,6 @@ main/data_init.c\
|
|||
main/data_singleton.c\
|
||||
main/error_msg.c\
|
||||
main/ft_putast.c\
|
||||
main/instruction_free.c\
|
||||
main/main.c\
|
||||
main/shell_init.c\
|
||||
parser/add_bang.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
t_flag opts;
|
||||
char **env;
|
||||
int argc;
|
||||
char **argv;
|
||||
t_line line;
|
||||
t_comp *comp;
|
||||
t_exec exec;
|
||||
t_jobc jobc;
|
||||
t_list *heredoc_queue;
|
||||
char **local_var;
|
||||
t_list *lst_func;
|
||||
t_flag opts;
|
||||
char **env;
|
||||
int argc;
|
||||
char **argv;
|
||||
t_line line;
|
||||
t_list *token;
|
||||
t_btree *ast;
|
||||
t_lexer lexer;
|
||||
t_parser parser;
|
||||
t_comp *comp;
|
||||
t_exec exec;
|
||||
t_jobc jobc;
|
||||
t_list *heredoc_queue;
|
||||
char **local_var;
|
||||
t_list *lst_func;
|
||||
};
|
||||
|
||||
int shell_init(int ac, char **av);
|
||||
|
|
@ -58,8 +62,6 @@ void shell_exit(void);
|
|||
int data_init(int ac, char **av);
|
||||
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);
|
||||
|
||||
char *ft_putast(void *node);
|
||||
|
|
|
|||
|
|
@ -6,92 +6,92 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
*var = NULL;
|
||||
*value = NULL;
|
||||
*operator = NULL;
|
||||
*operand = NULL;
|
||||
return (0);
|
||||
}
|
||||
/* static int init_math(char **var, char **value, char **operator, char **operand) */
|
||||
/* { */
|
||||
/* *var = NULL; */
|
||||
/* *value = NULL; */
|
||||
/* *operator = NULL; */
|
||||
/* *operand = NULL; */
|
||||
/* return (0); */
|
||||
/* } */
|
||||
|
||||
static int get_value(char **var, char **value)
|
||||
{
|
||||
char *temp;
|
||||
/* static int get_value(char **var, char **value) */
|
||||
/* { */
|
||||
/* char *temp; */
|
||||
|
||||
if (!word_is_assignment(var))
|
||||
return (error_msg(MATHERR_1));
|
||||
temp = ft_sstrstr(data_singleton()->local_var, *var);
|
||||
if (temp)
|
||||
{
|
||||
temp += ft_strlenchr(temp, '=') + 1;
|
||||
*value = ft_strdup(temp);
|
||||
if (!(ft_stris(*value, &ft_isdigit)))
|
||||
{
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
*value = ft_itoa(0);
|
||||
return (0);
|
||||
}
|
||||
/* if (!word_is_assignment(var)) */
|
||||
/* return (error_msg(MATHERR_1)); */
|
||||
/* temp = ft_sstrstr(data_singleton()->local_var, *var); */
|
||||
/* if (temp) */
|
||||
/* { */
|
||||
/* temp += ft_strlenchr(temp, '=') + 1; */
|
||||
/* *value = ft_strdup(temp); */
|
||||
/* if (!(ft_stris(*value, &ft_isdigit))) */
|
||||
/* { */
|
||||
/* ft_strdel(value); */
|
||||
/* *value = ft_itoa(0); */
|
||||
/* } */
|
||||
/* } */
|
||||
/* else */
|
||||
/* *value = ft_itoa(0); */
|
||||
/* return (0); */
|
||||
/* } */
|
||||
|
||||
static int do_math(char **value, char *operator, char *operand)
|
||||
{
|
||||
long ope1;
|
||||
long ope2;
|
||||
/* static int do_math(char **value, char *operator, char *operand) */
|
||||
/* { */
|
||||
/* long ope1; */
|
||||
/* long ope2; */
|
||||
|
||||
ope1 = ft_atoi(*value);
|
||||
if (operand)
|
||||
ope2 = ft_atoi(operand);
|
||||
else
|
||||
ope2 = 0;
|
||||
if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0)
|
||||
return (error_msg(MATHERR_4));
|
||||
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;
|
||||
}
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(ope1);
|
||||
return (0);
|
||||
}
|
||||
/* ope1 = ft_atoi(*value); */
|
||||
/* if (operand) */
|
||||
/* ope2 = ft_atoi(operand); */
|
||||
/* else */
|
||||
/* ope2 = 0; */
|
||||
/* if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) */
|
||||
/* return (error_msg(MATHERR_4)); */
|
||||
/* 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; */
|
||||
/* } */
|
||||
/* ft_strdel(value); */
|
||||
/* *value = ft_itoa(ope1); */
|
||||
/* return (0); */
|
||||
/* } */
|
||||
|
||||
int builtin_math(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
char *var;
|
||||
char *value;
|
||||
char *operator;
|
||||
char *operand;
|
||||
/* int builtin_math(const char *path, char *const av[], char *const envp[]) */
|
||||
/* { */
|
||||
/* char *var; */
|
||||
/* char *value; */
|
||||
/* char *operator; */
|
||||
/* char *operand; */
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
if (!av || !av[1] || !av[2] || !av[3] || av[4])
|
||||
return (error_msg(MATHERR_0));
|
||||
init_math(&var, &value, &operator, &operand);
|
||||
var = av[1];
|
||||
if (get_value(&var, &value) == -1)
|
||||
return (-1);
|
||||
operator = av[2];
|
||||
if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-'
|
||||
|| operator[0] == '/' || operator[0] == '*' || operator[0] == '%')))
|
||||
return (error_msg(MATHERR_2));
|
||||
operand = av[3];
|
||||
if (!ft_stris(operand, &ft_isdigit))
|
||||
return (error_msg(MATHERR_3));
|
||||
if (do_math(&value, operator, operand) == -1)
|
||||
return (-1);
|
||||
builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var);
|
||||
return (0);
|
||||
}
|
||||
/* (void)path; */
|
||||
/* (void)envp; */
|
||||
/* if (!av || !av[1] || !av[2] || !av[3] || av[4]) */
|
||||
/* return (error_msg(MATHERR_0)); */
|
||||
/* init_math(&var, &value, &operator, &operand); */
|
||||
/* var = av[1]; */
|
||||
/* if (get_value(&var, &value) == -1) */
|
||||
/* return (-1); */
|
||||
/* operator = av[2]; */
|
||||
/* if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' */
|
||||
/* || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) */
|
||||
/* return (error_msg(MATHERR_2)); */
|
||||
/* operand = av[3]; */
|
||||
/* if (!ft_stris(operand, &ft_isdigit)) */
|
||||
/* return (error_msg(MATHERR_3)); */
|
||||
/* if (do_math(&value, operator, operand) == -1) */
|
||||
/* return (-1); */
|
||||
/* builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); */
|
||||
/* return (0); */
|
||||
/* } */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
Loading…
Reference in a new issue