This commit is contained in:
wescande 2017-03-24 23:08:25 +01:00
commit 422c685417
30 changed files with 169 additions and 332 deletions

View file

@ -1,235 +1,5 @@
.x....................xxx...xxxx..x. ....................................
----------------------------------------------------------------
21sh/misc/002-simple-command-line (FAILED)
Description:
 The purpose of this test is to check that the Shell is able to execute a simple command line that contains separators `;`, pipes `|`, and a right redirection `>`.
Before test:
 01: rm -rf "./size"
02: rm -rf "TOKEN201703241733"
03: echo '^'$(echo TOKEN201703241733_FILE_TOKEN201703241733_STDOUT | wc -c)'$' > "./size"
STDIN:
 01: mkdir TOKEN201703241733 ; cd TOKEN201703241733 ; touch TOKEN201703241733_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703241733_STDOUT ; cat TOKEN201703241733_STDOUT
STDOUT:
 SUCCESS expected_to match_regex `TOKEN201703241733_FILE$`
 FAILURE expected_to match_each_regex_of_file `./size`
 01: TOKEN201703241733_FILE
02: 94296 redirect_great.c 24 3 1
03: 23
STDERR:
 SUCCESS expected_to be_empty
 (no output)
----------------------------------------------------------------
21sh/redirections/outputs/truncating/001-creates-file-if-not-exits (FAILED)
Description:
 The right redirection `>` opens the file with the oflag `O_CREAT` so that the file is created if it does not exists.
Before test:
 01: rm -f new_file
STDIN:
 01: ./write_on_stdout TOKEN201703241733 >new_file
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703241733`
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`
 FAILURE expected_to create_file `new_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/002-truncates-file-if-exists (FAILED)
Description:
 The right redirection `>` opens the file with the oflag `O_TRUNC` so that the file size is truncated to 0 before writing in it.
Before test:
 01: ./write_on_stdout TOKEN201703241733_first >truncated_file
STDIN:
 01: ./write_on_stdout TOKEN201703241733_second >truncated_file
STDOUT:
 SUCCESS expected_to_not match_regex TOKEN201703241733_second
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `truncated_file` matching_regex `TOKEN201703241733_second`
 SUCCESS expected_to create_file `truncated_file` not_matching_regex `TOKEN201703241733_first`
 FAILURE expected_to create_file `truncated_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/003-whitespace-before-filename (FAILED)
Description:
 The file name for a right redirection can be specified closely to the character `>` or in a separated field.
Before test:
 01: rm -f "new_file"
STDIN:
 01: ./write_on_stdout TOKEN201703241733 > new_file
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703241733`
 (no output)
STDERR:
 SUCCESS expected_to be_empty
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`
 FAILURE expected_to create_file `new_file` with_nb_of_lines `1`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/004-together (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`.
Before test:
 01: rm -f "new_file_stderr_and_stdout"
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &>new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703241733_1`
 SUCCESS expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_1`
 FAILURE expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/005-together-with-whitespaces (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`.
In this test, we specify the file name in a separate field.
Before test:
 01: rm -f new_file_stderr_and_stdout
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &> new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703241733_1`
 SUCCESS expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_1`
 FAILURE expected_to_not match_regex `TOKEN201703241733_2`
 01: TOKEN201703241733_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/stderr/001-works (FAILED)
Description:
 The purpose of this test is to check that redirecting the standard error STDERR to a file `2>` works. In this test, the binary writes a token on each standard and error output, so that only the STDOUT is outputted and STDERR is written in a file `new_file_stderr`.
Before test:
 01: rm -f "./new_file_stderr"
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703241733_STDOUT TOKEN201703241733_STDERR 2>new_file_stderr
STDOUT:
 SUCCESS expected_to match_regex `TOKEN201703241733_STDOUT`
 01: TOKEN201703241733_STDOUT
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703241733_STDERR`
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file_stderr` matching_regex `TOKEN201703241733_STDERR`
 FAILURE expected_to create_file `new_file_stderr` with_nb_of_lines 1
----------------------------------------------------------------
21sh/redirections/outputs/truncating/stdout/001-with-explicit-fd (FAILED)
Description:
 The purpose of this test is to check if '1>' redirect STDIN to a file.
We are using echo with one argument. The output should NOT return anything on the standard output.
Before test:
 01: rm -f new_file
STDIN:
 01: /bin/echo TOKEN1 1>new_file
STDOUT:
 SUCCESS expected_to_not match_regex TOKEN1
 (no output)
STDERR:
 (no output)
MISC:
 SUCCESS expected_to create_file new_file matching_regex TOKEN1
 FAILURE expected_to create_file new_file with_nb_of_lines 1
----------------------------------------------------------------
21sh/separators/semicolon/003-parse-error-empty-inline-command (FAILED)
Description:
 The purpose of this test is to check that using the simicolon separator `;` with empty commands results in error.
STDIN:
 01: ./write_on_stdout TOKEN201703241733 ; ; ./exit_with_status 42
STDOUT:
 SUCCESS expected_to be_empty
 (no output)
STDERR:
 SUCCESS expected_to_not be_empty
 SUCCESS might match_regex `([Ss]yntax|[Pp]arse) error`
 01: syntax error near unexpected token `;'
MISC:
 SUCCESS expected_to_not exit_with_status `42`
 FAILURE expected_to_not exit_with_status `0`
Total tests: 36 Total tests: 36
Total failed tests: 9 Total failed tests: 0
Total pending tests: 0 Total pending tests: 0

23
42sh/VAR Normal file
View file

@ -0,0 +1,23 @@
$TOKEN201703241737_NAME
21sh_error
42ShellTester
42sh
42sh_error
Makefile
README.md
STDBUG
VAR
auteur
donovan_segaults_06-02
file
includes
libft
minishell_error
new_file
objs
pdf
sample
scriptheader.sh
src
update_makefile.sh
write_on_stdout_and_stderr

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:47:12 by ariard ### ########.fr */ /* Updated: 2017/03/24 20:07:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -131,7 +131,7 @@ struct s_job
struct s_exec struct s_exec
{ {
t_job job; t_job job;
int fd_save[10]; t_list *fd_save[10];
t_flag attrs; t_flag attrs;
int fdin; int fdin;
t_list *op_stack; t_list *op_stack;
@ -140,6 +140,8 @@ struct s_exec
}; };
int exec_reset(void); int exec_reset(void);
int exec_pushfds();
int exec_popfds();
int process_fork(t_process *p); int process_fork(t_process *p);
int process_setgroup(t_process *p, pid_t pid); int process_setgroup(t_process *p, pid_t pid);
void process_setsig(void); void process_setsig(void);

View file

@ -108,6 +108,7 @@ lst/ft_lstnew_range.c\
lst/ft_lstsort.c\ lst/ft_lstsort.c\
lst/pop.c\ lst/pop.c\
lst/push.c\ lst/push.c\
lst/top.c\
math/ft_addrcmp.c\ math/ft_addrcmp.c\
math/ft_ilen.c\ math/ft_ilen.c\
math/ft_ilen_base.c\ math/ft_ilen_base.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2017/03/21 16:32:40 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:08:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
/* Updated: 2017/03/11 16:18:00 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:09:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ typedef struct s_list t_list;
int pop(t_list **lst); int pop(t_list **lst);
t_list *push(t_list **stack, int elem); t_list *push(t_list **stack, int elem);
int top(t_list *top);
t_list *ft_lstnew(void const *content, size_t content_size); t_list *ft_lstnew(void const *content, size_t content_size);
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); void ft_lstdel(t_list **alst, void (*del)(void *, size_t));

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:49:59 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:05:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

18
42sh/libft/src/lst/top.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* top.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 20:04:27 by jhalford #+# #+# */
/* Updated: 2017/03/24 20:09:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int top(t_list *top)
{
return (top ? *(int*)top->content : 0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */ /* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */
/* Updated: 2017/02/07 16:15:52 by jhalford ### ########.fr */ /* Updated: 2017/03/24 19:33:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,9 @@
int dup2_close(int fd1, int fd2) int dup2_close(int fd1, int fd2)
{ {
if (dup2(fd1, fd2)) if (dup2(fd1, fd2) < 0)
return (-1); return (-1);
if (close(fd1)) if (close(fd1) < 0)
return (-1); return (-1);
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/21 16:32:26 by jhalford #+# #+# */ /* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:22:55 by gwojda ### ########.fr */ /* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/21 15:28:51 by jhalford ### ########.fr */ /* Updated: 2017/03/24 23:03:58 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,13 @@
#define CDERR_2 "cd: HOME not set" #define CDERR_2 "cd: HOME not set"
#define CDERR_3 "cd: too many arguments{eoc}" #define CDERR_3 "cd: too many arguments{eoc}"
static g_cliopts g_cdotps =
{
{'P', NULL, CD_OPT_P, CD_OPT_L, NULL},
{'L', NULL, CD_OPT_L, CD_OPT_P, NULL},
{0, NULL, 0, 0, NULL},
}
static char *builtin_cd_special(char *const av[], char *const env[]) static char *builtin_cd_special(char *const av[], char *const env[])
{ {
char *target; char *target;
@ -44,30 +51,13 @@ static char *builtin_cd_special(char *const av[], char *const env[])
return (target); return (target);
} }
static int builtin_cd_opts(char *const av[], int *opts) void setwd(char *var)
{ {
int i; char *cwd;
int j;
i = 1; cwd = getcwd(NULL, 0);
if (av) builtin_setenv(path, (char*[4]){"setenv", var, cwd, NULL}, envp);
while (av[i] && av[i][0] == '-' && av[i][1]) free(cwd);
{
j = 0;
while (av[i][++j])
{
if (av[i][j] == 'P')
*opts = CDOPT_P;
else if (av[i][j] == 'L')
*opts = CDOPT_L;
else if (av[i][j] == '-')
return (i + 1);
else
return (i);
}
++i;
}
return (i);
} }
int builtin_cd(const char *path, int builtin_cd(const char *path,
@ -76,15 +66,13 @@ int builtin_cd(const char *path,
int i; int i;
int opts; int opts;
char *target; char *target;
char *cwd;
opts = CDOPT_L; data->flag = CD_OPT_L;
if (cliopts(av, g_cdopts, &data))
i = builtin_cd_opts(av, &opts); i = builtin_cd_opts(av, &opts);
setwd("OLDPWD");
if (!(target = builtin_cd_special(av + i, envp))) if (!(target = builtin_cd_special(av + i, envp)))
return (1); return (1);
cwd = getcwd(NULL, 0);
builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp);
free(cwd);
if (chdir(target)) if (chdir(target))
{ {
SH_ERR(CDERR_1, target); SH_ERR(CDERR_1, target);
@ -92,9 +80,7 @@ int builtin_cd(const char *path,
} }
else if (target != av[i]) else if (target != av[i])
ft_printf("%s\n", target); ft_printf("%s\n", target);
cwd = getcwd(NULL, 0); setwd("PWD");
builtin_setenv(path, (char*[4]){"setenv", "PWD", cwd, NULL}, envp);
free(cwd);
if (!ft_strcmp(*(av + i), "-")) if (!ft_strcmp(*(av + i), "-"))
free(target); free(target);
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/24 19:33:37 by wescande ### ########.fr */ /* Updated: 2017/03/24 23:08:13 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */ /* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */
/* Updated: 2017/03/23 18:24:41 by jhalford ### ########.fr */ /* Updated: 2017/03/24 22:59:17 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,7 +29,7 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[])
while (*env && (*env)[j]) while (*env && (*env)[j])
{ {
if (ft_strcmp((*env)[j], av[i]) == '=' if (ft_strcmp((*env)[j], av[i]) == '='
&& ft_strlen(av[1]) == ft_strlenchr((*env)[i], '=')) && ft_strlen(av[i]) == ft_strlenchr((*env)[j], '='))
ft_sstrdel(*env, j); ft_sstrdel(*env, j);
else else
j++; j++;

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 21:48:12 by jhalford ### ########.fr */ /* Updated: 2017/03/24 19:24:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:23:49 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:09:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,17 +22,38 @@ int exec_reset_job(t_job *job)
return (0); return (0);
} }
int exec_pushfds()
{
int i;
t_exec *exec;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
push(&(exec->fd_save[i]), fcntl(i, F_DUPFD_CLOEXEC, 10));
return (0);
}
int exec_popfds()
{
int i;
t_exec *exec;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
pop(&exec->fd_save[i]);
return (0);
}
int exec_reset(void) int exec_reset(void)
{ {
t_exec *exec;
t_jobc *jobc; t_jobc *jobc;
int i; t_exec *exec;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
i = -1; exec_pushfds();
while (++i < 10)
exec->fd_save[i] = fcntl(i, F_DUPFD, 10);
exec->op_stack = NULL; exec->op_stack = NULL;
exec->fdin = STDIN; exec->fdin = STDIN;
exec->attrs = 0; exec->attrs = 0;

View file

@ -6,7 +6,7 @@
/* 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/24 15:40:00 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:44:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,7 @@ int exec_var(t_btree **ast)
char *equal; char *equal;
node = (*ast)->item; node = (*ast)->item;
pop(&data_singleton()->exec.op_stack);
if (!(av = token_to_argv(node->data.cmd.token, 1))) if (!(av = token_to_argv(node->data.cmd.token, 1)))
return (0); return (0);
var = av[0]; var = av[0];
@ -29,5 +30,6 @@ int exec_var(t_btree **ast)
value = equal ? equal + 1 : NULL; 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); ft_sstrfree(av);
ft_exec(&(*ast)->right);
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 17:20:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/22 19:23:55 by jhalford ### ########.fr */ /* Updated: 2017/03/24 22:43:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:22:16 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:02:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,21 +35,10 @@ int process_fork(t_process *p)
int process_launch(t_process *p) int process_launch(t_process *p)
{ {
p->state = PROCESS_RUNNING; p->state = PROCESS_RUNNING;
if (IS_PIPESINGLE(*p) if (!IS_PIPESINGLE(*p)
&& p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) || p->type == PROCESS_FILE
|| p->type == PROCESS_SUBSHELL)
{ {
if (process_redirect(p))
set_exitstatus(1, 1);
else
{
exec_reset();
p->map.launch(p);
}
shell_resetfds();
shell_resetsig();
process_free(p, 0);
return (0);
}
p->pid = process_fork(p); p->pid = process_fork(p);
process_setgroup(p, p->pid); process_setgroup(p, p->pid);
if (p->fdin != STDIN) if (p->fdin != STDIN)
@ -58,3 +47,16 @@ int process_launch(t_process *p)
close(p->fdout); close(p->fdout);
return (1); return (1);
} }
if (process_redirect(p))
set_exitstatus(1, 1);
else
{
exec_pushfds();
p->map.launch(p);
}
exec_popfds();
shell_resetfds();
shell_resetsig();
process_free(p, 0);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/22 18:26:37 by jhalford ### ########.fr */ /* Updated: 2017/03/24 19:19:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -68,7 +68,7 @@ int process_set(t_process *p, t_btree *ast)
p->pid = 0; p->pid = 0;
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
if (ast) if (ast)
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, p->redirs = ft_lstmap(
&redir_copy); ((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
return ((!ast) ? 0 : process_set_spec(p, ast)); return ((!ast) ? 0 : process_set_spec(p, ast));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:25:41 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:09:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,10 @@ int redirect_great(t_redir *redir)
fdnew = redir->n; fdnew = redir->n;
if ((fdold = open(redir->word, if ((fdold = open(redir->word,
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
{
SH_ERR("open(): %s", strerror(errno));
exit (1); exit (1);
dup2_close(fdold, fdnew); }
fd_replace(fdold, fdnew);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:17:02 by jhalford ### ########.fr */ /* Updated: 2017/03/24 18:48:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -67,7 +67,10 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
(void)path; (void)path;
(void)envp; (void)envp;
if (!SH_HAS_JOBC(data_singleton()->opts)) if (!SH_HAS_JOBC(data_singleton()->opts))
{
DG("no job control :(");
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC)); return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
}
do_job_notification(); do_job_notification();
ft_bzero(&data, sizeof(t_data_template)); ft_bzero(&data, sizeof(t_data_template));
if (cliopts_get((char**)av, g_jobs_opts, &data)) if (cliopts_get((char**)av, g_jobs_opts, &data))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */ /* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */
/* Updated: 2017/03/16 22:50:16 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:04:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:24:09 by gwojda ### ########.fr */ /* Updated: 2017/03/24 19:23:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,8 +18,8 @@ void token_print(t_list *lst)
while (lst) while (lst)
{ {
if (lst->content) if ((token = lst->content))
token = lst->content; DG("token : %s data [%s]", read_state(token->type), token->data);
lst = lst->next; lst = lst->next;
} }
} }

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/24 18:25:10 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:02:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,8 +52,6 @@ static int handle_instruction(t_list **token, t_btree **ast)
else if (ret > 0) else if (ret > 0)
break ; break ;
} }
/* btree_print(3, *ast, ft_putast); */
/* exit(1); */
if (data->parser.state == SUCCESS && ft_exec(ast) < 0) if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
exit(1); exit(1);
else if (data->parser.state != SUCCESS) else if (data->parser.state != SUCCESS)

View file

@ -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/24 17:11:20 by wescande ### ########.fr */ /* Updated: 2017/03/24 18:57:17 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -87,10 +87,7 @@ int shell_init(int ac, char **av, char **env)
if (data_init(ac, av, env) < 0) if (data_init(ac, av, env) < 0)
return (-1); return (-1);
if (cliopts_get(av, g_opts, data)) if (cliopts_get(av, g_opts, data))
{ return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE));
ft_perror(NULL);
return (SH_ERR("usage: %s", SHELL_USAGE));
}
if (!isatty(STDIN) || *data->av_data) if (!isatty(STDIN) || *data->av_data)
data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
if ((data->fd = get_input_fd(data, NULL)) < 0) if ((data->fd = get_input_fd(data, NULL)) < 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */ /* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:49:38 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:09:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,12 +26,14 @@ void shell_resetfds(void)
{ {
t_exec *exec; t_exec *exec;
int i; int i;
int fd;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
i = -1; i = -1;
while (++i < 10) while (++i < 10)
{ {
if (exec->fd_save[i] != -1) fd = top(exec->fd_save[i]);
dup2(exec->fd_save[i], i); if (fd != -1)
dup2(fd, i);
} }
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/24 16:56:50 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:25:02 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -59,7 +59,7 @@ static int emblematic_token(t_btree **ast, t_list **lst)
return (0); return (0);
if (node->type != TK_DO && node->type != TK_THEN if (node->type != TK_DO && node->type != TK_THEN
&& node->type != CMD && node->type != REDIR && node->type != CMD && node->type != REDIR
&& node->type != TK_ASSIGNMENT_WORD && node->type != TK_FOR) && node->type != TK_FOR)
return (1); return (1);
} }
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/24 17:23:26 by gwojda ### ########.fr */ /* Updated: 2017/03/24 19:26:26 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -397,3 +397,7 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
} }
return (0); return (0);
} }
// DG("aggregate head %s && sym %s", read_state(*head), read_state(*new_sym));
// DG("MATH: %s", read_state(g_aggrematch[i].new_sym));
// DG("stack after pop %s", read_state(*head));

View file

@ -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/24 17:23:52 by gwojda ### ########.fr */ /* Updated: 2017/03/24 19:25:44 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -905,6 +905,7 @@ static t_stackmatch g_stackmatch[] =
{WHILE_CLAUSE, NEWLINE_LIST}, {WHILE_CLAUSE, NEWLINE_LIST},
{WHILE_CLAUSE, SEQUENCE}, {WHILE_CLAUSE, SEQUENCE},
{WHILE_CLAUSE, TK_DO}, {WHILE_CLAUSE, TK_DO},
{WHILE_CLAUSE, TK_PAREN_OPEN},
{WHILE_CLAUSE, TK_PAREN_CLOSE}, {WHILE_CLAUSE, TK_PAREN_CLOSE},
{WHILE_CLAUSE, TK_WHILE}, {WHILE_CLAUSE, TK_WHILE},
{WHILE_CLAUSE, TK_LBRACE}, {WHILE_CLAUSE, TK_LBRACE},
@ -1295,3 +1296,5 @@ int eval_sym(t_list **stack, t_sym new_sym)
} }
return (1); return (1);
} }
//DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));

View file

@ -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/24 17:01:05 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:26:48 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,6 +49,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
parser->state = SUCCESS; parser->state = SUCCESS;
else else
parser->state = UNDEFINED; parser->state = UNDEFINED;
btree_print(STDBUG, *ast, &ft_putast);
build_tree(ast, token); build_tree(ast, token);
if ((end_instruction(&parser->stack) && !(*token)->next)) if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token); insert_linebreak(token);