This commit is contained in:
gwojda 2017-03-22 23:46:09 +01:00
commit ebb85a3d0d
26 changed files with 72 additions and 177 deletions

View file

@ -13,7 +13,7 @@
NAME = 42sh NAME = 42sh
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden# -fsanitize=address FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address
D_FLAGS = -g D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc) DELTA = $$(echo "$$(tput cols)-47"|bc)

View file

@ -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/22 18:13:32 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:07:49 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -77,7 +77,6 @@ void token_print(t_list *lst);
int reduce_parens(t_list **alst, char *str); int reduce_parens(t_list **alst, char *str);
int bquotes_expand(t_list **alst); int bquotes_expand(t_list **alst);
char *command_getoutput(char *command); char *command_getoutput(char *command);
int command_setoutput(char *const av[], char **env);
int ft_is_delim(char c); int ft_is_delim(char c);
int ft_is_delim_list(char c); int ft_is_delim_list(char c);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 17:22:51 by ariard #+# #+# */ /* Created: 2017/03/22 17:22:51 by ariard #+# #+# */
/* Updated: 2017/03/22 17:25:11 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:50:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ /* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */
/* Updated: 2017/01/11 14:42:45 by jhalford ### ########.fr */ /* Updated: 2017/03/22 23:19:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:29:54 by ariard #+# #+# */ /* Created: 2017/03/07 11:29:54 by ariard #+# #+# */
/* Updated: 2017/03/21 18:14:45 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:54:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2017/03/17 20:36:22 by wescande ### ########.fr */ /* Updated: 2017/03/22 22:21:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:01:15 by ariard #+# #+# */ /* Created: 2017/03/07 11:01:15 by ariard #+# #+# */
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ /* Updated: 2017/03/22 23:12:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */ /* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 16:10:54 by ariard #+# #+# */ /* Created: 2016/12/01 16:10:54 by ariard #+# #+# */
/* Updated: 2017/03/07 11:30:02 by ariard ### ########.fr */ /* Updated: 2017/03/22 22:12:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 18:08:31 by jhalford #+# #+# */ /* Created: 2017/03/07 18:08:31 by jhalford #+# #+# */
/* Updated: 2017/03/07 18:18:30 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:23:33 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@ char *ft_strtok(char *s, const char *delim)
if ((ch = *s++) == 0) if ((ch = *s++) == 0)
return (0); return (0);
while (ft_strchr(delim, ch)) while (ft_strchr(delim, ch))
if ((ch = *s) == 0) if ((ch = *s++) == 0)
return (0); return (0);
--s; --s;
lasts = s + ft_strcspn(s, delim); lasts = s + ft_strcspn(s, delim);

View file

@ -6,103 +6,60 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */
/* Updated: 2017/03/21 18:08:31 by ariard ### ########.fr */ /* Updated: 2017/03/22 22:26:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#define MATHERR_0 "math : invalid number of arguments" #define MATHERR_0 "usage: math variable operator(+-/*%) operand"
#define MATHERR_1 "math : invalid variable name" #define MATHERR_2 "math: %c: invalid operator"
#define MATHERR_2 "math : invalid operator" #define MATHERR_3 "math: %s: operand must be digits only"
#define MATHERR_3 "math : invalid operand"
#define MATHERR_4 "math: division by 0" #define MATHERR_4 "math: division by 0"
#define MATHERR_5 "math: modulo by 0"
static int init_math(char **var, char **value, char **operator, static char *do_math(char *value, char operator, char *operand)
char **operand)
{
*var = NULL;
*value = NULL;
*operator = NULL;
*operand = NULL;
return (0);
}
static int get_value(char *var, char **value)
{
char *temp;
char *esc;
int ret;
esc = ft_strnew((ft_strlen(var) >> 3) + 1);
ret = word_is_assignment((char *[]) {var, (esc + 1)});
ft_strdel(&esc);
if (!ret)
return (SH_ERR(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 ope1;
long ope2; long ope2;
ope1 = ft_atoi(*value); ope1 = ft_atoi(value);
if (operand)
ope2 = ft_atoi(operand); ope2 = ft_atoi(operand);
else DG("value %s -> %i", value, ope1);
ope2 = 0; DG("operand %s -> %i", operand, ope2);
if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) if ((operator == '/') && ope2 == 0)
return (SH_ERR(MATHERR_4)); return (SH_ERR(MATHERR_4) ? NULL : NULL);
else if ((operator == '%') && ope2 == 0)
{ return (SH_ERR(MATHERR_5) ? NULL : NULL);
ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; ope1 = (operator == '+') ? ope1 + ope2 : ope1;
ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; ope1 = (operator == '-') ? ope1 - ope2 : ope1;
ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; ope1 = (operator == '/') ? ope1 / ope2 : ope1;
ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; ope1 = (operator == '*') ? ope1 * ope2 : ope1;
ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; ope1 = (operator == '%') ? ope1 % ope2 : ope1;
} DG("output=%s (%i)", ft_itoa(ope1), ope1);
ft_strdel(value); return (ft_itoa(ope1));
*value = ft_itoa(ope1);
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 *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 (SH_ERR(MATHERR_0)); return (SH_ERR(MATHERR_0));
init_math(&var, &value, &operator, &operand); value = ft_getenv(data_singleton()->local_var, av[1]);
var = av[1]; operator = av[2][0];
if (get_value(var, &value)) if (!(ft_strchr("+-/*%", operator)))
return (1); return (SH_ERR(MATHERR_2, operator));
operator = av[2];
if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0])))
return (SH_ERR(MATHERR_2));
operand = av[3]; operand = av[3];
if (!ft_stris(operand, &ft_isdigit)) if (!ft_stris(operand, &ft_isdigit))
return (SH_ERR(MATHERR_3)); return (SH_ERR(MATHERR_3, operand));
if (do_math(&value, operator, operand)) if (!(value = do_math(value, operator, operand)))
return (1); return (1);
builtin_setenv("setenv", (char *[]){"local", var, value, 0}, NULL); builtin_setenv("setenv", (char *[]){"math", av[1], value, 0}, NULL);
ft_strdel(&value);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2017/03/22 16:21:49 by gwojda ### ########.fr */ /* Updated: 2017/03/22 22:08:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
/* Updated: 2017/03/21 19:14:31 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:50:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */
/* Updated: 2017/03/20 15:42:17 by gwojda ### ########.fr */ /* Updated: 2017/03/22 22:06:11 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,10 +23,11 @@ int exec_case_branch(t_btree **ast)
return (0); return (0);
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node->data.cmd.token, 1); av = token_to_argv(node->data.cmd.token, 1);
if (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0) if (av && (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0))
{ {
exec->attrs |= EXEC_CASE_BRANCH; exec->attrs |= EXEC_CASE_BRANCH;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
} }
ft_tabdel(&av);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/22 18:27:03 by jhalford ### ########.fr */ /* Updated: 2017/03/22 21:48:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,32 +6,28 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
/* Updated: 2017/03/20 15:43:34 by gwojda ### ########.fr */ /* Updated: 2017/03/22 23:23:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int set_var(char *stream, char **var, char **value)
{
*var = ft_strdupchr(stream, '=');
stream += ft_strlenchr(stream, '=') + 1;
*value = ft_strdup(stream);
return (0);
}
int exec_var(t_btree **ast) int exec_var(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char **av; char **av;
char *var; char *var;
char *value; char *value;
char *equal;
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node->data.cmd.token, 1); if (!(av = token_to_argv(node->data.cmd.token, 1)))
set_var(av[0], &var, &value);
if (ft_getenv(data_singleton()->env, var))
return (0); return (0);
var = av[0];
if ((equal = ft_strchr(av[0], '=')))
*equal = 0;
value = equal ? equal + 1 : NULL;
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
ft_sstrfree(av);
return (0); return (0);
} }

View file

@ -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 23:38:29 by ariard ### ########.fr */ /* Updated: 2017/03/22 19:52:58 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
/* Updated: 2017/03/21 18:44:57 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:50:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */
/* Updated: 2017/03/20 16:29:37 by gwojda ### ########.fr */ /* Updated: 2017/03/22 23:17:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */
/* Updated: 2017/03/20 15:50:03 by gwojda ### ########.fr */ /* Updated: 2017/03/22 21:48:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
/* Updated: 2017/03/20 18:15:17 by gwojda ### ########.fr */ /* Updated: 2017/03/22 22:00:16 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@ int plaunch_case(t_process *p)
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
exec->attrs &= ~EXEC_CASE_BRANCH; exec->attrs &= ~EXEC_CASE_BRANCH;
exec->case_pattern = token_to_argv(p->data.d_case.token, 1); exec->case_pattern = token_to_argv(p->data.d_case.token, 1);
ft_exec(&p->data.d_if.content); ft_exec(&p->data.d_case.content);
ft_tabdel(&exec->case_pattern);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:29:20 by gwojda ### ########.fr */ /* Updated: 2017/03/22 21:32:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
static void error_launch(char *error_ori, char *error_type, int error_code) static void error_launch(char *error_ori, char *error_type, int error_code)
{ {
SH_ERR("%s: %s%s", SHELL_NAME, error_ori, error_type); SH_ERR("%s%s", error_ori, error_type);
exit(error_code); exit(error_code);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */
/* Updated: 2017/03/20 15:59:05 by gwojda ### ########.fr */ /* Updated: 2017/03/22 21:48:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */ /* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
/* Updated: 2017/03/21 18:15:53 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:25:49 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,55 +29,6 @@ static char *manage_output(int *fds)
return (output); return (output);
} }
static char *manage_command(char *const av_cmd[])
{
char *command;
int i;
if (!av_cmd)
return (NULL);
i = -1;
command = NULL;
while (av_cmd[++i])
{
if (!command)
command = ft_str3join("\"", av_cmd[i], "\"");
else
command = ft_strjoinf(command, ft_str3join("\"", av_cmd[i], "\""), 3);
}
return (command);
}
static void execute_command(char *const av[], char **env)
{
t_list *token;
t_btree *ast;
t_data *data;
char *command;
token = NULL;
ast = NULL;
data = data_singleton();
data->env = env;
data->opts &= ~SH_INTERACTIVE;
data->opts &= ~SH_OPTS_JOBC;
command = manage_command(av);
DG("DO THE EXEC");
if (do_lexer_routine(&token, command))
{
ft_dprintf(2, "{red}%s: syntax error in command substitution{eoc}\n",
SHELL_NAME);
exit(1);
}
if (do_parser_routine(&token, &ast) <= 0)
{
ft_dprintf(2, "{red}%s: parse error in command substitution{eoc}\n",
SHELL_NAME);
exit(1);
}
exit(data_singleton()->parser.state == SUCCESS && ft_exec(&ast) < 0);
}
char *command_getoutput(char *command) char *command_getoutput(char *command)
{ {
int ret; int ret;
@ -101,15 +52,3 @@ char *command_getoutput(char *command)
waitpid(pid, &ret, WUNTRACED); waitpid(pid, &ret, WUNTRACED);
return (manage_output(fds)); return (manage_output(fds));
} }
int command_setoutput(char *const av[], char **env)
{
int pid;
if (!av)
return (0);
pid = 0;
if (!(pid = process_fork(NULL)))
execute_command(av, env);
return (pid);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */ /* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
/* Updated: 2017/03/14 23:14:19 by wescande ### ########.fr */ /* Updated: 2017/03/22 21:59:49 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -63,7 +63,8 @@ int dir_research(t_glob *gl, char *p,
} }
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
{ {
dir = opendir(p); if (!(dir = opendir(p)))
return (0);
while ((in = readdir(dir))) while ((in = readdir(dir)))
dir_list_content(gl, dir_list_content(gl,
(char *[2]){p, in->d_name}, pat, mode[0]); (char *[2]){p, in->d_name}, pat, mode[0]);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/22 19:37:21 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:02:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/22 19:26:03 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:51:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,6 +32,7 @@ t_prodmatch g_prodmatch[] =
{TK_WORD, TK_PIPE, CMD_NAME}, {TK_WORD, TK_PIPE, CMD_NAME},
{TK_WORD, AND_OR, CMD_NAME}, {TK_WORD, AND_OR, CMD_NAME},
{TK_WORD, AND_OR_MAJOR, CMD_NAME}, {TK_WORD, AND_OR_MAJOR, CMD_NAME},
{TK_WORD, TK_PAREN_CLOSE, CMD_NAME},
{TK_WORD, TK_WHILE, CMD_NAME}, {TK_WORD, TK_WHILE, CMD_NAME},
{TK_WORD, TK_UNTIL, CMD_NAME}, {TK_WORD, TK_UNTIL, CMD_NAME},
{TK_WORD, TK_DO, CMD_NAME}, {TK_WORD, TK_DO, CMD_NAME},