merge
This commit is contained in:
commit
422c685417
30 changed files with 169 additions and 332 deletions
|
|
@ -1,235 +1,5 @@
|
|||
[31m[38;5;34m.[0m[31m[38;5;160mx[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;160mx[0m[31m[38;5;160mx[0m[31m[38;5;160mx[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;160mx[0m[31m[38;5;160mx[0m[31m[38;5;160mx[0m[31m[38;5;160mx[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;160mx[0m[31m[38;5;34m.[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/misc/002-simple-command-line[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m 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 `>`.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -rf "./size"
|
||||
02: rm -rf "TOKEN201703241733"
|
||||
03: echo '^'$(echo TOKEN201703241733_FILE_TOKEN201703241733_STDOUT | wc -c)'$' > "./size"[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: mkdir TOKEN201703241733 ; cd TOKEN201703241733 ; touch TOKEN201703241733_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703241733_STDOUT ; cat TOKEN201703241733_STDOUT[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to match_regex `TOKEN201703241733_FILE$`[0m
|
||||
[31m[38;5;160m FAILURE expected_to match_each_regex_of_file `./size`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_FILE
|
||||
02: 94296 redirect_great.c 24 3 1
|
||||
03: 23[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to be_empty[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/001-creates-file-if-not-exits[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m The right redirection `>` opens the file with the oflag `O_CREAT` so that the file is created if it does not exists.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f new_file[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout TOKEN201703241733 >new_file[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733`[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to be_empty[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file` with_nb_of_lines `1`[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/002-truncates-file-if-exists[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m The right redirection `>` opens the file with the oflag `O_TRUNC` so that the file size is truncated to 0 before writing in it.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: ./write_on_stdout TOKEN201703241733_first >truncated_file[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout TOKEN201703241733_second >truncated_file[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex TOKEN201703241733_second[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to be_empty[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to create_file `truncated_file` matching_regex `TOKEN201703241733_second`[0m
|
||||
[31m[38;5;34m SUCCESS expected_to create_file `truncated_file` not_matching_regex `TOKEN201703241733_first`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `truncated_file` with_nb_of_lines `1`[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/003-whitespace-before-filename[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m The file name for a right redirection can be specified closely to the character `>` or in a separated field.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f "new_file"[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout TOKEN201703241733 > new_file[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733`[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to be_empty[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to create_file `new_file` matching_regex `TOKEN201703241733`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file` with_nb_of_lines `1`[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/multiple/004-together[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f "new_file_stderr_and_stdout"[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &>new_file_stderr_and_stdout[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;160m FAILURE expected_to_not match_regex `TOKEN201703241733_1`[0m
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733_2`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_1[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733_1`[0m
|
||||
[31m[38;5;160m FAILURE expected_to_not match_regex `TOKEN201703241733_2`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_2[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/multiple/005-together-with-whitespaces[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m 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.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f new_file_stderr_and_stdout[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout_and_stderr TOKEN201703241733_1 TOKEN201703241733_2 &> new_file_stderr_and_stdout[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;160m FAILURE expected_to_not match_regex `TOKEN201703241733_1`[0m
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733_2`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_1[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733_1`[0m
|
||||
[31m[38;5;160m FAILURE expected_to_not match_regex `TOKEN201703241733_2`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_2[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_1$`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703241733_2$`[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/stderr/001-works[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m 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`.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f "./new_file_stderr"[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout_and_stderr TOKEN201703241733_STDOUT TOKEN201703241733_STDERR 2>new_file_stderr[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to match_regex `TOKEN201703241733_STDOUT`[0m
|
||||
[38;5;239m 01: TOKEN201703241733_STDOUT[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex `TOKEN201703241733_STDERR`[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to create_file `new_file_stderr` matching_regex `TOKEN201703241733_STDERR`[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file `new_file_stderr` with_nb_of_lines 1[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/redirections/outputs/truncating/stdout/001-with-explicit-fd[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m 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.[0m
|
||||
|
||||
Before test:
|
||||
[38;5;239m 01: rm -f new_file[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: /bin/echo TOKEN1 1>new_file[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to_not match_regex TOKEN1[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
STDERR:
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to create_file new_file matching_regex TOKEN1[0m
|
||||
[31m[38;5;160m FAILURE expected_to create_file new_file with_nb_of_lines 1[0m
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
[37;1m21sh/separators/semicolon/003-parse-error-empty-inline-command[0m [31m[38;5;160m(FAILED)[0m
|
||||
|
||||
Description:
|
||||
[38;5;239m The purpose of this test is to check that using the simicolon separator `;` with empty commands results in error.[0m
|
||||
|
||||
STDIN:
|
||||
[38;5;239m 01: ./write_on_stdout TOKEN201703241733 ; ; ./exit_with_status 42[0m
|
||||
|
||||
STDOUT:
|
||||
[31m[38;5;34m SUCCESS expected_to be_empty[0m
|
||||
[38;5;239m (no output)[0m
|
||||
|
||||
STDERR:
|
||||
[31m[38;5;34m SUCCESS expected_to_not be_empty[0m
|
||||
[31m[38;5;34m SUCCESS might match_regex `([Ss]yntax|[Pp]arse) error`[0m
|
||||
[38;5;239m 01: syntax error near unexpected token `;'[0m
|
||||
|
||||
MISC:
|
||||
[31m[38;5;34m SUCCESS expected_to_not exit_with_status `42`[0m
|
||||
[31m[38;5;160m FAILURE expected_to_not exit_with_status `0`[0m
|
||||
[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m[31m[38;5;34m.[0m
|
||||
|
||||
Total tests: 36
|
||||
Total failed tests: 9
|
||||
Total failed tests: 0
|
||||
Total pending tests: 0
|
||||
|
|
|
|||
23
42sh/VAR
Normal file
23
42sh/VAR
Normal 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
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
t_job job;
|
||||
int fd_save[10];
|
||||
t_list *fd_save[10];
|
||||
t_flag attrs;
|
||||
int fdin;
|
||||
t_list *op_stack;
|
||||
|
|
@ -140,6 +140,8 @@ struct s_exec
|
|||
};
|
||||
|
||||
int exec_reset(void);
|
||||
int exec_pushfds();
|
||||
int exec_popfds();
|
||||
int process_fork(t_process *p);
|
||||
int process_setgroup(t_process *p, pid_t pid);
|
||||
void process_setsig(void);
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ lst/ft_lstnew_range.c\
|
|||
lst/ft_lstsort.c\
|
||||
lst/pop.c\
|
||||
lst/push.c\
|
||||
lst/top.c\
|
||||
math/ft_addrcmp.c\
|
||||
math/ft_ilen.c\
|
||||
math/ft_ilen_base.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
t_list *push(t_list **stack, int elem);
|
||||
int top(t_list *top);
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
18
42sh/libft/src/lst/top.c
Normal 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);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
if (dup2(fd1, fd2))
|
||||
if (dup2(fd1, fd2) < 0)
|
||||
return (-1);
|
||||
if (close(fd1))
|
||||
if (close(fd1) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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_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[])
|
||||
{
|
||||
char *target;
|
||||
|
|
@ -44,30 +51,13 @@ static char *builtin_cd_special(char *const av[], char *const env[])
|
|||
return (target);
|
||||
}
|
||||
|
||||
static int builtin_cd_opts(char *const av[], int *opts)
|
||||
void setwd(char *var)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *cwd;
|
||||
|
||||
i = 1;
|
||||
if (av)
|
||||
while (av[i] && av[i][0] == '-' && av[i][1])
|
||||
{
|
||||
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);
|
||||
cwd = getcwd(NULL, 0);
|
||||
builtin_setenv(path, (char*[4]){"setenv", var, cwd, NULL}, envp);
|
||||
free(cwd);
|
||||
}
|
||||
|
||||
int builtin_cd(const char *path,
|
||||
|
|
@ -76,15 +66,13 @@ int builtin_cd(const char *path,
|
|||
int i;
|
||||
int opts;
|
||||
char *target;
|
||||
char *cwd;
|
||||
|
||||
opts = CDOPT_L;
|
||||
data->flag = CD_OPT_L;
|
||||
if (cliopts(av, g_cdopts, &data))
|
||||
i = builtin_cd_opts(av, &opts);
|
||||
setwd("OLDPWD");
|
||||
if (!(target = builtin_cd_special(av + i, envp)))
|
||||
return (1);
|
||||
cwd = getcwd(NULL, 0);
|
||||
builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp);
|
||||
free(cwd);
|
||||
if (chdir(target))
|
||||
{
|
||||
SH_ERR(CDERR_1, target);
|
||||
|
|
@ -92,9 +80,7 @@ int builtin_cd(const char *path,
|
|||
}
|
||||
else if (target != av[i])
|
||||
ft_printf("%s\n", target);
|
||||
cwd = getcwd(NULL, 0);
|
||||
builtin_setenv(path, (char*[4]){"setenv", "PWD", cwd, NULL}, envp);
|
||||
free(cwd);
|
||||
setwd("PWD");
|
||||
if (!ft_strcmp(*(av + i), "-"))
|
||||
free(target);
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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])
|
||||
{
|
||||
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);
|
||||
else
|
||||
j++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
t_exec *exec;
|
||||
t_jobc *jobc;
|
||||
int i;
|
||||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
jobc = &data_singleton()->jobc;
|
||||
i = -1;
|
||||
while (++i < 10)
|
||||
exec->fd_save[i] = fcntl(i, F_DUPFD, 10);
|
||||
exec_pushfds();
|
||||
exec->op_stack = NULL;
|
||||
exec->fdin = STDIN;
|
||||
exec->attrs = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
node = (*ast)->item;
|
||||
pop(&data_singleton()->exec.op_stack);
|
||||
if (!(av = token_to_argv(node->data.cmd.token, 1)))
|
||||
return (0);
|
||||
var = av[0];
|
||||
|
|
@ -29,5 +30,6 @@ int exec_var(t_btree **ast)
|
|||
value = equal ? equal + 1 : NULL;
|
||||
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
|
||||
ft_sstrfree(av);
|
||||
ft_exec(&(*ast)->right);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,26 +35,28 @@ int process_fork(t_process *p)
|
|||
int process_launch(t_process *p)
|
||||
{
|
||||
p->state = PROCESS_RUNNING;
|
||||
if (IS_PIPESINGLE(*p)
|
||||
&& p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL)
|
||||
if (!IS_PIPESINGLE(*p)
|
||||
|| 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);
|
||||
process_setgroup(p, p->pid);
|
||||
if (p->fdin != STDIN)
|
||||
close(p->fdin);
|
||||
if (p->fdout != STDOUT)
|
||||
close(p->fdout);
|
||||
return (1);
|
||||
}
|
||||
p->pid = process_fork(p);
|
||||
process_setgroup(p, p->pid);
|
||||
if (p->fdin != STDIN)
|
||||
close(p->fdin);
|
||||
if (p->fdout != STDOUT)
|
||||
close(p->fdout);
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
exec->fdin = fds[PIPE_READ];
|
||||
if (ast)
|
||||
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir,
|
||||
&redir_copy);
|
||||
p->redirs = ft_lstmap(
|
||||
((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
|
||||
return ((!ast) ? 0 : process_set_spec(p, ast));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
if ((fdold = open(redir->word,
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
exit(1);
|
||||
dup2_close(fdold, fdnew);
|
||||
{
|
||||
SH_ERR("open(): %s", strerror(errno));
|
||||
exit (1);
|
||||
}
|
||||
fd_replace(fdold, fdnew);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)envp;
|
||||
if (!SH_HAS_JOBC(data_singleton()->opts))
|
||||
{
|
||||
DG("no job control :(");
|
||||
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
|
||||
}
|
||||
do_job_notification();
|
||||
ft_bzero(&data, sizeof(t_data_template));
|
||||
if (cliopts_get((char**)av, g_jobs_opts, &data))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
if (lst->content)
|
||||
token = lst->content;
|
||||
if ((token = lst->content))
|
||||
DG("token : %s data [%s]", read_state(token->type), token->data);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
break ;
|
||||
}
|
||||
/* btree_print(3, *ast, ft_putast); */
|
||||
/* exit(1); */
|
||||
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
||||
exit(1);
|
||||
else if (data->parser.state != SUCCESS)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
return (-1);
|
||||
if (cliopts_get(av, g_opts, data))
|
||||
{
|
||||
ft_perror(NULL);
|
||||
return (SH_ERR("usage: %s", SHELL_USAGE));
|
||||
}
|
||||
return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE));
|
||||
if (!isatty(STDIN) || *data->av_data)
|
||||
data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
|
||||
if ((data->fd = get_input_fd(data, NULL)) < 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
int i;
|
||||
int fd;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
i = -1;
|
||||
while (++i < 10)
|
||||
{
|
||||
if (exec->fd_save[i] != -1)
|
||||
dup2(exec->fd_save[i], i);
|
||||
fd = top(exec->fd_save[i]);
|
||||
if (fd != -1)
|
||||
dup2(fd, i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
if (node->type != TK_DO && node->type != TK_THEN
|
||||
&& node->type != CMD && node->type != REDIR
|
||||
&& node->type != TK_ASSIGNMENT_WORD && node->type != TK_FOR)
|
||||
&& node->type != TK_FOR)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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, SEQUENCE},
|
||||
{WHILE_CLAUSE, TK_DO},
|
||||
{WHILE_CLAUSE, TK_PAREN_OPEN},
|
||||
{WHILE_CLAUSE, TK_PAREN_CLOSE},
|
||||
{WHILE_CLAUSE, TK_WHILE},
|
||||
{WHILE_CLAUSE, TK_LBRACE},
|
||||
|
|
@ -1295,3 +1296,5 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
|||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
//DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
else
|
||||
parser->state = UNDEFINED;
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
build_tree(ast, token);
|
||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||
insert_linebreak(token);
|
||||
|
|
|
|||
Loading…
Reference in a new issue