redirection printing on job control
This commit is contained in:
parent
1c8148af3f
commit
8ea584a42c
8 changed files with 121 additions and 101 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
|
||||
/* Updated: 2017/03/15 18:51:31 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 15:58:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
* TODO Same for MACOSX
|
||||
*/
|
||||
|
||||
# ifdef LINUX
|
||||
# ifdef __linux__
|
||||
# define RL_INSERT_CODE 0x7e325b1b
|
||||
# define RL_CLEAR_CODE 0xc
|
||||
# define RL_NL_CODE 0xa
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
# define RL_PASTE_CODE 0x761b
|
||||
# endif
|
||||
|
||||
# ifdef MACOSX
|
||||
# ifdef __APPLE__
|
||||
# define RL_INSERT_CODE 0x53323b315b1b
|
||||
# define RL_CLEAR_CODE 0xc
|
||||
# define RL_NL_CODE 0xa
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/16 12:10:24 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/16 16:02:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 0c1dbf5b89c99612c49d6fd63dd25d0310bad3d9
|
||||
Subproject commit 04b8d5cd090e86b0f9d8160b01e49d43666deddf
|
||||
|
|
@ -1,97 +1,97 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_math.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/15 21:02:59 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/* /1* ************************************************************************** *1/ */
|
||||
/* /1* *1/ */
|
||||
/* /1* ::: :::::::: *1/ */
|
||||
/* /1* exec_math.c :+: :+: :+: *1/ */
|
||||
/* /1* +:+ +:+ +:+ *1/ */
|
||||
/* /1* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ *1/ */
|
||||
/* /1* +#+#+#+#+#+ +#+ *1/ */
|
||||
/* /1* Created: 2017/03/07 10:58:49 by ariard #+# #+# *1/ */
|
||||
/* Updated: 2017/03/16 15:53:01 by jhalford ### ########.fr */
|
||||
/* /1* *1/ */
|
||||
/* /1* ************************************************************************** *1/ */
|
||||
|
||||
#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 (ft_error_message(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 (ft_error_message(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 (ft_error_message(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 (ft_error_message(MATHERR_2));
|
||||
operand = av[3];
|
||||
if (!ft_stris(operand, &ft_isdigit))
|
||||
return (ft_error_message(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); */
|
||||
/* } */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/15 20:01:03 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/16 15:54:15 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ t_stof g_builtin[] =
|
|||
{"read", &builtin_read},
|
||||
{"hash", &builtin_hash},
|
||||
{"history", &builtin_history},
|
||||
{"math", &builtin_math},
|
||||
/* {"math", &builtin_math}, */
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,32 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/14 20:21:46 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/16 16:39:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int redirection_print(t_redir *redir)
|
||||
{
|
||||
char symbol[3];
|
||||
|
||||
if (redir->type == TK_LESS)
|
||||
ft_strcpy(symbol, "<");
|
||||
else if (redir->type == TK_GREAT)
|
||||
ft_strcpy(symbol, ">");
|
||||
else if (redir->type == TK_DLESS)
|
||||
ft_strcpy(symbol, "<<");
|
||||
else if (redir->type == TK_DGREAT)
|
||||
ft_strcpy(symbol, ">>");
|
||||
else if (redir->type == TK_LESSAND)
|
||||
ft_strcpy(symbol, "<&");
|
||||
else if (redir->type == TK_GREATAND)
|
||||
ft_strcpy(symbol, ">&");
|
||||
ft_printf(" %i%s%s", redir->n, symbol, redir->word);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void process_format_state(t_process *p)
|
||||
{
|
||||
int state;
|
||||
|
|
@ -44,7 +64,7 @@ static void process_format_com_long(t_list **plist)
|
|||
p = (*plist)->content;
|
||||
if (p->map.print)
|
||||
(p->map.print)(p);
|
||||
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
||||
ft_lstiter(p->redirs, redirection_print);
|
||||
if ((*plist)->next)
|
||||
ft_putstr(" |");
|
||||
(*plist) = (*plist)->next;
|
||||
|
|
@ -67,7 +87,7 @@ static void process_format_com_short(t_list **plist, t_flag state)
|
|||
}
|
||||
if (p->map.print)
|
||||
(p->map.print)(p);
|
||||
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
||||
ft_lstiter(p->redirs, redirection_print);
|
||||
if ((*plist)->next)
|
||||
ft_putstr(" | ");
|
||||
(*plist) = (*plist)->next;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/15 17:55:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/16 16:36:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/15 04:12:31 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/16 15:52:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue