This commit is contained in:
Jack Halford 2017-03-27 19:47:22 +02:00
commit 14314efec8
77 changed files with 703 additions and 174 deletions

10
42sh/42ShellTester/file Normal file
View file

@ -0,0 +1,10 @@
42ShellTester.sh
README.md
file
lib
log
minishell_error
spec
support
tasks
tmp

164
42sh/42ShellTester/log Normal file
View file

@ -0,0 +1,164 @@
.x........................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 "TOKEN201703270303"
03: echo '^'$(echo TOKEN201703270303_FILE_TOKEN201703270303_STDOUT | wc -c)'$' > "./size"
STDIN:
 01: mkdir TOKEN201703270303 ; cd TOKEN201703270303 ; touch TOKEN201703270303_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703270303_STDOUT ; cat TOKEN201703270303_STDOUT
STDOUT:
 SUCCESS expected_to match_regex `TOKEN201703270303_FILE$`
 FAILURE expected_to match_each_regex_of_file `./size`
 01: TOKEN201703270303_FILE
02: 23
STDERR:
 SUCCESS expected_to be_empty
 (no output)
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/002-together-stdout-first (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `M>&N`, that means `redirect M to where N is redirected`.
In this test the standard output is specified first.
Before test:
 01: rm -f new_file_stderr_and_stdout
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 1>new_file_stderr_and_stdout 2>&1
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 (no output)
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 (no output)
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$`
 SUCCESS expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$`
----------------------------------------------------------------
21sh/redirections/outputs/truncating/multiple/003-together-stderr-first (FAILED)
Description:
 A right redirection can be associated to the twice outputs by using `M>&N`, that means `redirect M to where N is redirected`.
In this test the standard error is specified first.
Before test:
 01: rm -f new_file_stderr_and_stdout
STDIN:
 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 2>new_file_stderr_and_stdout 1>&2
STDOUT:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 (no output)
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 (no output)
MISC:
 SUCCESS expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$`
----------------------------------------------------------------
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 TOKEN201703270303_1 TOKEN201703270303_2 &>new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 01: TOKEN201703270303_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 FAILURE expected_to_not match_regex `TOKEN201703270303_2`
 01: TOKEN201703270303_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_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 TOKEN201703270303_1 TOKEN201703270303_2 &> new_file_stderr_and_stdout
STDOUT:
 FAILURE expected_to_not match_regex `TOKEN201703270303_1`
 SUCCESS expected_to_not match_regex `TOKEN201703270303_2`
 01: TOKEN201703270303_1
STDERR:
 SUCCESS expected_to_not match_regex `TOKEN201703270303_1`
 FAILURE expected_to_not match_regex `TOKEN201703270303_2`
 01: TOKEN201703270303_2
MISC:
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$`
 FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$`
----------------------------------------------------------------
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 TOKEN201703270303 ; ; ./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 failed tests: 6
Total pending tests: 0

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/27 02:54:02 by jhalford ### ########.fr # # Updated: 2017/03/27 19:45:47 by jhalford ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -78,8 +78,6 @@ exec/exec_init.c\
exec/exec_leaf.c\ exec/exec_leaf.c\
exec/exec_or_if.c\ exec/exec_or_if.c\
exec/exec_pipe.c\ exec/exec_pipe.c\
exec/exec_popfds.c\
exec/exec_pushfds.c\
exec/exec_semi.c\ exec/exec_semi.c\
exec/exec_var.c\ exec/exec_var.c\
exec/fd_is_valid.c\ exec/fd_is_valid.c\
@ -197,6 +195,7 @@ job_control/job_update_id.c\
job_control/job_update_status.c\ job_control/job_update_status.c\
job_control/job_wait.c\ job_control/job_wait.c\
job_control/jobc_destroy.c\ job_control/jobc_destroy.c\
job_control/jobc_init.c\
job_control/mark_job_as_running.c\ job_control/mark_job_as_running.c\
job_control/pprint_brace.c\ job_control/pprint_brace.c\
job_control/pprint_case.c\ job_control/pprint_case.c\
@ -227,6 +226,7 @@ lexer/insert_newline.c\
lexer/isrw_delim.c\ lexer/isrw_delim.c\
lexer/keep_last_type.c\ lexer/keep_last_type.c\
lexer/lexer_backslash.c\ lexer/lexer_backslash.c\
lexer/lexer_bang.c\
lexer/lexer_bquote.c\ lexer/lexer_bquote.c\
lexer/lexer_curly_braces.c\ lexer/lexer_curly_braces.c\
lexer/lexer_default.c\ lexer/lexer_default.c\
@ -284,8 +284,9 @@ main/data_exit.c\
main/data_init.c\ main/data_init.c\
main/data_singleton.c\ main/data_singleton.c\
main/main.c\ main/main.c\
main/shell_fds.c\
main/shell_init.c\ main/shell_init.c\
main/shell_reset.c\ main/shell_sig.c\
parser/add_bang.c\ parser/add_bang.c\
parser/add_case.c\ parser/add_case.c\
parser/add_cmd.c\ parser/add_cmd.c\

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/03/23 15:41:32 by gwojda ### ########.fr */ /* Updated: 2017/03/27 17:42:17 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,8 @@
# define KP_D 4348699 # define KP_D 4348699
# define KP_L 4479771 # define KP_L 4479771
# define KP_R 4414235 # define KP_R 4414235
# define KP_T 9
# define KP_TS 5921563
/* /*
** Autocompletion list for the valid candidates from the parser. ** Autocompletion list for the valid candidates from the parser.
@ -187,5 +189,6 @@ int ft_sstrlen(char **s);
char *ft_sstrtostr(char **s, char *sep); char *ft_sstrtostr(char **s, char *sep);
char *ft_add_escape(char *str, char to_escape); char *ft_add_escape(char *str, char to_escape);
void c_lst_id(t_comp *c); void c_lst_id(t_comp *c);
char *c_strdupi(char *s, int (*f)(char));
#endif #endif

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/27 02:54:21 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:46:14 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -131,7 +131,6 @@ struct s_job
struct s_exec struct s_exec
{ {
t_job job; t_job job;
t_list *fd_save[10];
t_flag attrs; t_flag attrs;
int fdin; int fdin;
t_list *op_stack; t_list *op_stack;
@ -141,8 +140,6 @@ struct s_exec
int exec_init(t_exec *exec); int exec_init(t_exec *exec);
int exec_destroy(t_exec *exec); int exec_destroy(t_exec *exec);
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

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/23 16:16:57 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:00:07 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -134,6 +134,7 @@ int ft_nb_of_line(char *str, size_t pos);
int ft_get_size_prev(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos);
void sigwinch_resize(int sig); void sigwinch_resize(int sig);
size_t ft_hist_len(void); size_t ft_hist_len(void);
int hist_is_delim(char c);
int underline_right(char **str, size_t *pos, size_t pos_ref); int underline_right(char **str, size_t *pos, size_t pos_ref);
int underline_left(char **str, size_t *pos, size_t pos_ref); int underline_left(char **str, size_t *pos, size_t pos_ref);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:11:08 by jhalford ### ########.fr */ /* Updated: 2017/03/27 16:01:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,6 +35,7 @@ struct s_jobc
struct termios shell_tmodes; struct termios shell_tmodes;
}; };
int jobc_init(t_jobc *jobc);
int jobc_destroy(t_jobc *jobc); int jobc_destroy(t_jobc *jobc);
t_list *job_getprocess(pid_t pid); t_list *job_getprocess(pid_t pid);

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/23 15:18:36 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:17:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,6 +24,7 @@ enum e_lexstate
HEREDOC, HEREDOC,
NEWLINE, NEWLINE,
DELIM, DELIM,
BANG,
SEP, SEP,
WORD, WORD,
NUMBER, NUMBER,
@ -99,6 +100,7 @@ int lexer_default(t_list **alst, t_lexer *lexer);
int lexer_newline(t_list **alst, t_lexer *lexer); int lexer_newline(t_list **alst, t_lexer *lexer);
int lexer_heredoc(t_list **alst, t_lexer *lexer); int lexer_heredoc(t_list **alst, t_lexer *lexer);
int lexer_delim(t_list **alst, t_lexer *lexer); int lexer_delim(t_list **alst, t_lexer *lexer);
int lexer_bang(t_list **alst, t_lexer *lexer);
int lexer_sep(t_list **alst, t_lexer *lexer); int lexer_sep(t_list **alst, t_lexer *lexer);
int lexer_word(t_list **alst, t_lexer *lexer); int lexer_word(t_list **alst, t_lexer *lexer);
int lexer_number(t_list **alst, t_lexer *lexer); int lexer_number(t_list **alst, t_lexer *lexer);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/25 15:44:08 by ariard ### ########.fr */ /* Updated: 2017/03/27 15:55:04 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,6 +48,7 @@ struct s_data
char **argv; char **argv;
t_line line; t_line line;
t_lexer lexer; t_lexer lexer;
t_list *fd_save[10];
t_parser parser; t_parser parser;
t_comp *comp; t_comp *comp;
t_exec exec; t_exec exec;
@ -64,8 +65,14 @@ int data_init(int ac, char **av, char **env);
void data_exit(void); void data_exit(void);
int get_c_arg(char *opt_arg, t_data *data); int get_c_arg(char *opt_arg, t_data *data);
void shell_resetfds(void); void shell_sig_reset(void);
void shell_resetsig(void);
void shell_fds_init(void);
void shell_fds_destroy(void);
int shell_fds_pop(void);
int shell_fds_push(void);
void shell_fds_reset(void);
void shell_fds_destroy(void);
char *ft_putast(void *node); char *ft_putast(void *node);
void ft_putast2(void *node); void ft_putast2(void *node);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* cliopts.h :+: :+: :+: */ /* cliopts.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
/* Updated: 2017/03/25 21:31:28 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:46:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_lst_delif.c :+: :+: :+: */ /* ft_lst_delif.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:36:19 by jhalford ### ########.fr */ /* Updated: 2017/03/27 17:45:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */ /* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */
/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */ /* Updated: 2017/03/27 16:58:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ int is_directory(const char *path)
{ {
struct stat path_stat; struct stat path_stat;
stat(path, &path_stat); if (stat(path, &path_stat) != 0)
return (0);
return (S_ISDIR(path_stat.st_mode)); return (S_ISDIR(path_stat.st_mode));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ /* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
/* Updated: 2017/03/27 02:54:39 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:46:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,10 +15,10 @@
int try_access(char *file, int exists, t_flag a_flag) int try_access(char *file, int exists, t_flag a_flag)
{ {
if (exists && access(file, F_OK) != 0) if (exists && access(file, F_OK) != 0)
return (ERR_SET(E_SYS_NOFILE, file) * 0 - 1); return (ERR_SET(E_SYS_NOFILE, file));
else if (is_directory(file)) else if (is_directory(file))
return (ERR_SET(E_SYS_ISDIR, file) * 0 - 1); return (ERR_SET(E_SYS_ISDIR, file));
else if (access(file, F_OK) == 0 && access(file, a_flag) != 0) else if (access(file, F_OK) == 0 && access(file, a_flag) != 0)
return (ERR_SET(E_SYS_NOPERM, file) * 0 - 1); return (ERR_SET(E_SYS_NOPERM, file));
return (0); return (0);
} }

2
42sh/sample/again.sh Normal file
View file

@ -0,0 +1,2 @@
echo "echo hello" >> sample/again.sh
echo hello

8
42sh/sample/andor.sh Normal file
View file

@ -0,0 +1,8 @@
pwd > file && pwd >> file || ls | cat && ls | cat >> file || ls
cat -e file
sleep 2
echo "My sample :"
echo
cat sample/andor.sh

9
42sh/sample/brace.sh Normal file
View file

@ -0,0 +1,9 @@
{ ls ; pwd } > file
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/brace.sh

16
42sh/sample/case.sh Normal file
View file

@ -0,0 +1,16 @@
case toto in
( tutu ) echo PERDU ;;
( titi ) echo PERDU ;;
( toto ) case lala in
( lolo ) echo PERDU ;;
( lala ) echo GAGNE ;;
esac ;;
esac > file
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/case.sh

9
42sh/sample/comment.sh Normal file
View file

@ -0,0 +1,9 @@
ls # Da comment
pwd
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/comment.sh

3
42sh/sample/eof.sh Normal file
View file

@ -0,0 +1,3 @@
while [ 1 ]
do
ls

13
42sh/sample/for.sh Normal file
View file

@ -0,0 +1,13 @@
for i in src/*/*.c
do
echo $i | cat -e > file
cat -e file >> another_file
cat -e another_file
done
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/for.sh

14
42sh/sample/func.sh Normal file
View file

@ -0,0 +1,14 @@
hello() (
hello() (
echo hello ; hello )
hello
)
hello
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/func.sh

25
42sh/sample/if.sh Normal file
View file

@ -0,0 +1,25 @@
if false
then
echo PERDU
elif false
then
echo PERDU
elif true
then
if false
then
echo PERDU
elif
echo GAGNE
fi > file
else
echo PERDU
fi
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/if.sh

30
42sh/sample/mix.sh Normal file
View file

@ -0,0 +1,30 @@
VAR=10
if true
then
echo "Salut" ; echo "Correcteur"
while [ $VAR -gt 0 ]
do
until true
do
echo KO SI JE M AFFICHE
done
if true
then
echo OK SI JE M AFFICHE
elif [ -f Makefile ]
then
echo KO SI JE M AFFICHE
else
echo KO SI JE M AFFICHE
fi
echo "Encore un tour"
math VAR - 1
done
fi
sleep 2
echo
echo "My sample :"
sleep 3
echo
cat sample/mix/mix.sh

31
42sh/sample/muchloop.sh Normal file
View file

@ -0,0 +1,31 @@
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
echo "SO MUCH LOOOOP"
done
done
done
done
done
done
done
done
done
done

16
42sh/sample/script.sh Normal file
View file

@ -0,0 +1,16 @@
clear
YES=y
NO=n
echo "Welcome in 42Zash, new corrector, what is your login ?"
until [ $REP == $YES ]
do
read -p "> " LOGIN
echo
read -p "Ok, fine, your login is $LOGIN, right ?(y/n) " REP
if [ $REP = $NO ]
then
echo
echo "Don't worry let's do it again"
fi
done

17
42sh/sample/subshell.sh Normal file
View file

@ -0,0 +1,17 @@
echo aaa \
| (echo bbb 1; cat -e ;echo ccc 1) \
| (echo bbb 2; cat -e ;echo ccc 2) \
| (echo bbb 3; cat -e ;echo ccc 3) \
| (echo bbb 4; cat -e ;echo ccc 4) \
| (echo bbb 5; cat -e ;echo ccc 5) \
| (echo bbb 6; cat -e ;echo ccc 6) \
| (echo bbb 7; cat -e ;echo ccc 7) \
| (echo bbb 8; cat -e ;echo ccc 8) \
| (echo bbb 9; cat -e ;echo ccc 9)
sleep 2
echo "My sample :"
echo
sleep 2
cat sample/subshell.sh

View file

@ -0,0 +1,4 @@
while [ 1 ]
do
ls
done done

30
42sh/sample/until.sh Normal file
View file

@ -0,0 +1,30 @@
VAR1=0
until [ $VAR1 -gt 10 ]
do
VAR2=0
until [ $VAR2 -gt 10 ]
do
VAR3=0
until [ $VAR3 -gt 10 ]
do
math VAR3 + 1
echo "3rd is $VAR3"
done
math VAR2 + 1
echo "2nd is $VAR2"
done
math VAR1 + 1
echo "1st is $VAR1"
sleep 1
done
echo
echo "VAR1: $VAR1"
echo "VAR2: $VAR2"
echo "VAR3: $VAR3"
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/until.sh

11
42sh/sample/var.sh Normal file
View file

@ -0,0 +1,11 @@
HELLO=WORLD HELLO=SALUT HELLO="BUENOS DIAS"
echo $HELLO
SALUT=$HELLO
echo $SALUT
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/var.sh

24
42sh/sample/while.sh Normal file
View file

@ -0,0 +1,24 @@
VAR=10
while
while [ $VAR -gt 0 ]
do
echo "Inside inner loop" | cat -e
math VAR - 1
done
if [ $VAR -eq -42 ]
then
false
else
true
fi
do
echo "I'm the execution block"
VAR=-42
done
sleep 2
echo
echo "My sample :"
sleep 3
echo
cat sample/while.sh

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 18:20:42 by ariard #+# #+# */ /* Created: 2017/03/25 18:20:42 by ariard #+# #+# */
/* Updated: 2017/03/26 14:11:03 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:45:31 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */ /* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
/* Updated: 2017/03/25 20:40:41 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:52:26 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,7 +71,10 @@ int builtin_env(const char *path,
(void)envp; (void)envp;
if (bt_env_parse(&dat, (char**)argv)) if (bt_env_parse(&dat, (char**)argv))
{
ft_sstrfree(dat.custom_env);
return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE)); return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE));
}
if (!*dat.av_data) if (!*dat.av_data)
return (display_env(dat.custom_env)); return (display_env(dat.custom_env));
else if ((pid = fork()) == 0) else if ((pid = fork()) == 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/25 16:36:55 by ariard ### ########.fr */ /* Updated: 2017/03/27 16:03:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
/* Updated: 2017/03/23 19:07:56 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:50:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/23 19:02:28 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:51:59 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ static int c_is_delim(char c)
return (0); return (0);
} }
static char *c_strdupi(char *s, int (*f)(char)) char *c_strdupi(char *s, int (*f)(char))
{ {
int i; int i;
char *str; char *str;

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */
/* Updated: 2017/03/22 12:25:26 by alao ### ########.fr */ /* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,6 @@ static int c_refresh_match(t_comp *c, long int keypress)
kpconv[1] = '\0'; kpconv[1] = '\0';
tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv); tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv);
c->match ? ft_memdel((void *)&c->match) : (0); c->match ? ft_memdel((void *)&c->match) : (0);
c->match = ft_strdup(tmp);
tmp ? ft_memdel((void *)&tmp) : (0); tmp ? ft_memdel((void *)&tmp) : (0);
tmp = ft_strjoin(c->rcmd, kpconv); tmp = ft_strjoin(c->rcmd, kpconv);
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
@ -57,12 +56,12 @@ int c_rematch(t_comp *c, long int keypress)
c_term_clear(c); c_term_clear(c);
c_refresh_match(c, keypress); c_refresh_match(c, keypress);
c_clear_lst(c); c_clear_lst(c);
ft_print(keypress, &s->line.input, &s->line.pos);
c_matching(s, c); c_matching(s, c);
if (s->comp && c->lst == NULL) if (s->comp && c->lst == NULL)
c_clear(s); c_clear(s);
else if (s->comp && c->lst == c->lst->next) else if (s->comp && c->lst == c->lst->next)
return (1); return (ft_putchar('\b') + 1);
ft_print(keypress, &s->line.input, &s->line.pos);
return (1); return (1);
} }
else else

View file

@ -6,18 +6,18 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */
/* Updated: 2017/03/23 18:58:47 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:08:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "completion.h" #include "completion.h"
/* /*
** Function to select the next item in the list if it has already been created ** Function to select the next or previous item in the list if it has already
** and if the key pressed is tab. ** been created and if the key pressed is tab.
*/ */
static void c_next_item(t_comp *c) static void c_mv_tab(t_comp *c, int next)
{ {
t_clst *ptr; t_clst *ptr;
@ -25,7 +25,10 @@ static void c_next_item(t_comp *c)
while (!ptr->cursor) while (!ptr->cursor)
ptr = ptr->next; ptr = ptr->next;
ptr->cursor = 0; ptr->cursor = 0;
if (next)
ptr->next->cursor = 1; ptr->next->cursor = 1;
else
ptr->prev->cursor = 1;
} }
/* /*
@ -117,8 +120,8 @@ int completion(long int keypress)
else else
{ {
c_term_resize(s->comp); c_term_resize(s->comp);
if (keypress == TOUCHE_TAB) if (keypress == KP_T || keypress == KP_TS)
c_next_item(s->comp); keypress == KP_T ? c_mv_tab(s->comp, 1) : c_mv_tab(s->comp, 0);
else if (c_keypress(s->comp, keypress)) else if (c_keypress(s->comp, keypress))
return (1); return (1);
} }

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/22 22:10:26 by ariard ### ########.fr */ /* Updated: 2017/03/27 15:05:49 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ int exec_case_branch(t_btree **ast)
if (av && (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_tabdel(&exec->case_pattern);
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
} }
ft_tabdel(&av); ft_tabdel(&av);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 03:09:58 by jhalford #+# #+# */ /* Created: 2017/03/27 03:09:58 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:10:37 by jhalford ### ########.fr */ /* Updated: 2017/03/27 15:56:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,9 @@
int exec_destroy(t_exec *exec) int exec_destroy(t_exec *exec)
{ {
if (!exec) if (!exec)
return (0); return (1);
ft_lstdel(&exec->op_stack, ft_lst_cfree); ft_lstdel(&exec->op_stack, ft_lst_cfree);
exec->attrs = 0;
exec->fdin = STDIN;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */ /* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */
/* Updated: 2017/03/27 02:55:43 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:46:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,19 +24,9 @@ int job_init(t_job *job)
int exec_init(t_exec *exec) int exec_init(t_exec *exec)
{ {
t_jobc *jobc;
int i;
jobc = &data_singleton()->jobc;
job_init(&exec->job); job_init(&exec->job);
i = -1;
while (++i < 10)
exec->fd_save[i] = NULL;
exec_pushfds();
exec->attrs = 0; exec->attrs = 0;
exec->fdin = STDIN; exec->fdin = STDIN;
exec->op_stack = NULL; exec->op_stack = NULL;
jobc->first_job = NULL;
jobc->current_id = 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/07 15:48:24 by jhalford #+# #+# */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:56:11 by wescande ### ########.fr */ /* Updated: 2017/03/27 16:03:21 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/22 22:00:16 by ariard ### ########.fr */ /* Updated: 2017/03/27 15:06:42 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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/22 21:32:36 by wescande ### ########.fr */ /* Updated: 2017/03/27 16:46:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,8 +28,8 @@ int plaunch_file(t_process *p)
error_launch(p->data.cmd.av[0], ": is a directory", 126); error_launch(p->data.cmd.av[0], ": is a directory", 126);
else if (access(p->data.cmd.path, X_OK) == -1) else if (access(p->data.cmd.path, X_OK) == -1)
error_launch("permission denied: ", p->data.cmd.av[0], 126); error_launch("permission denied: ", p->data.cmd.av[0], 126);
(*p->data.cmd.execf)( shell_fds_destroy();
p->data.cmd.path, execve(p->data.cmd.path,
p->data.cmd.av, p->data.cmd.av,
data_singleton()->env); data_singleton()->env);
error_launch("internal execve error on ", p->data.cmd.av[0], 42); error_launch("internal execve error on ", p->data.cmd.av[0], 42);

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/27 02:54:51 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:45:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,21 +16,24 @@ int process_fork(t_process *p)
{ {
pid_t pid; pid_t pid;
if (!p)
return (0);
if ((pid = fork()) == -1) if ((pid = fork()) == -1)
exit(SH_ERR("fork(): %s", strerror(errno))); exit(SH_ERR("fork(): %s", strerror(errno)));
else if (pid) else if (pid != 0)
return (pid); return (pid);
if (!p) exec_destroy(&data_singleton()->exec);
return (pid); jobc_destroy(&data_singleton()->jobc);
if (process_redirect(p)) if ((pid = 1) && process_redirect(p) == 0)
exit(1); {
shell_fds_push();
process_setgroup(p, 0); process_setgroup(p, 0);
process_setsig(); process_setsig();
exec_destroy(&data_singleton()->exec); data_singleton()->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
exec_init(&data_singleton()->exec); pid = p->map.launch(p);
data_singleton()->opts &= ~SH_INTERACTIVE; }
data_singleton()->opts &= ~SH_OPTS_JOBC; shell_fds_destroy();
exit(p->map.launch(p)); exit(pid);
} }
int process_launch(t_process *p) int process_launch(t_process *p)
@ -52,12 +55,12 @@ int process_launch(t_process *p)
set_exitstatus(1, 1); set_exitstatus(1, 1);
else else
{ {
exec_pushfds(); shell_fds_push();
p->map.launch(p); p->map.launch(p);
exec_popfds(); shell_fds_pop();
shell_resetfds();
shell_resetsig();
} }
shell_fds_reset();
shell_sig_reset();
process_free(p, 0); process_free(p, 0);
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 20:36:04 by wescande #+# #+# */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */
/* Updated: 2017/03/23 00:31:39 by ariard ### ########.fr */ /* Updated: 2017/03/27 03:42:29 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */ /* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */
/* Updated: 2017/03/27 02:56:55 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:45:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */ /* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */
/* Updated: 2017/03/25 01:45:49 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:41:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,6 @@ int redirect_dless(t_redir *redir)
str = redir->heredoc_data; str = redir->heredoc_data;
write(fds[PIPE_WRITE], str, ft_strlen(str)); write(fds[PIPE_WRITE], str, ft_strlen(str));
close(fds[PIPE_WRITE]); close(fds[PIPE_WRITE]);
dup2(fds[PIPE_READ], redir->n); fd_replace(fds[PIPE_READ], redir->n);
close(fds[PIPE_READ]);
return (0); return (0);
} }

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/27 02:56:48 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:45:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
/* Updated: 2017/03/25 00:58:22 by jhalford ### ########.fr */ /* Updated: 2017/03/27 03:18:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ int redirect_greatand(t_redir *redir)
if (fdold > 9) if (fdold > 9)
return (bad_fd(fdold)); return (bad_fd(fdold));
if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) if (fd_is_valid(fdold, O_WRONLY | O_RDWR))
fd_replace(fdold, fdnew); dup2(fdold, fdnew);
else else
return (bad_fd(fdold)); return (bad_fd(fdold));
return (0); return (0);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* redirect_less.c :+: :+: :+: */ /* redirect_less.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
/* Updated: 2017/03/27 02:56:59 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:44:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
/* Updated: 2017/03/21 16:33:43 by jhalford ### ########.fr */ /* Updated: 2017/03/27 03:18:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ int redirect_lessand(t_redir *redir)
if (fdold > 9) if (fdold > 9)
return (bad_fd(fdold)); return (bad_fd(fdold));
if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) if (fd_is_valid(fdold, O_RDONLY | O_RDWR))
fd_replace(fdold, fdnew); dup2(fdold, fdnew);
else else
return (bad_fd(fdold)); return (bad_fd(fdold));
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
/* Updated: 2017/03/27 02:56:33 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:44:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -65,7 +65,7 @@ static int history_parsing_nb_and_name(char *str, int *i)
ft_strdupi_w(str + *i + 2)); ft_strdupi_w(str + *i + 2));
else if (str[*i + 1] && str[*i + 1] != ' ') else if (str[*i + 1] && str[*i + 1] != ' ')
ft_realloc_str_history_2(&(data_singleton()->line.input), *i, ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
ft_strdupi_w(str + *i + 1)); c_strdupi(str + *i + 1, hist_is_delim));
else else
return (0); return (0);
return (1); return (1);

View file

@ -6,12 +6,19 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */ /* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */
/* Updated: 2017/03/16 11:58:10 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:07:49 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int hist_is_delim(char c)
{
if (c == ' ' || c == '"')
return (1);
return (0);
}
static char *ft_nget_histo(size_t nb_his) static char *ft_nget_histo(size_t nb_his)
{ {
t_list_history *list; t_list_history *list;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:14:45 by jhalford ### ########.fr */ /* Updated: 2017/03/27 15:58:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:07:57 by jhalford ### ########.fr */ /* Updated: 2017/03/27 03:17:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,6 @@ void job_update_status(void)
if ((pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) == -1 if ((pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) == -1
&& errno != ECHILD) && errno != ECHILD)
SH_ERR("waitpid(): %s", strerror(errno)); SH_ERR("waitpid(): %s", strerror(errno));
DG("wait trigger pid=%i", pid);
if (pid <= 1 || mark_process_status(pid, status)) if (pid <= 1 || mark_process_status(pid, status))
break ; break ;
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 03:09:41 by jhalford #+# #+# */ /* Created: 2017/03/27 03:09:41 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:10:55 by jhalford ### ########.fr */ /* Updated: 2017/03/27 15:59:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,30 +1,20 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* exec_popfds.c :+: :+: :+: */ /* jobc_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:31:05 by jhalford #+# #+# */ /* Created: 2017/03/27 15:59:03 by jhalford #+# #+# */
/* Updated: 2017/03/27 00:58:34 by jhalford ### ########.fr */ /* Updated: 2017/03/27 16:01:41 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int exec_popfds(void) int jobc_init(t_jobc *jobc)
{ {
int i; jobc->first_job = NULL;
int fd; jobc->current_id = 1;
t_exec *exec;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
{
fd = pop(&exec->fd_save[i]);
if (fd != -1)
close(fd);
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:39:55 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,8 @@ t_lexstate get_state_global(t_lexer *lexer)
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0; cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
ret = 0; ret = 0;
if ((ft_is_delim(c) && (ret = DELIM)) if ((ft_is_delim(c) && (ret = DELIM))
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP)) || ((c == '&' || c == ';' || c == '|') && (ret = SEP))
|| ((c == '!') && (ret = BANG))
|| ((c == '\\') && (ret = BACKSLASH)) || ((c == '\\') && (ret = BACKSLASH))
|| ((c == '\n') && (ret = NEWLINE)) || ((c == '\n') && (ret = NEWLINE))
|| ((c == '\'') && (ret = QUOTE)) || ((c == '\'') && (ret = QUOTE))

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* lexer_backslash.c :+: :+: :+: */ /* lexer_backslash.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
/* Updated: 2017/03/27 02:16:36 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:14:22 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,29 +1,32 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* exec_pushfds.c :+: :+: :+: */ /* lexer_bang.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:31:46 by jhalford #+# #+# */ /* Created: 2017/03/27 18:12:03 by jhalford #+# #+# */
/* Updated: 2017/03/27 00:58:25 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:53:10 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int exec_pushfds(void) int lexer_bang(t_list **alst, t_lexer *lexer)
{ {
int i; t_token *token;
int fd;
t_exec *exec;
exec = &data_singleton()->exec; token = (*alst)->content;
i = -1; if (!token->type || token->type == TK_SEMI || token->type == TK_NEWLINE
while (++i < 10) || token->type == TK_AMP)
{ {
fd = fcntl(i, F_DUPFD_CLOEXEC, 10); token->type = TK_BANG;
push(&(exec->fd_save[i]), fd); lexer->state = DEFAULT;
lexer->pos++;
return (lexer_lex(&(*alst)->next, lexer));
} }
return (0); token->type = TK_WORD;
lexer->state = WORD;
lexer->pos++;
return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
/* Updated: 2017/03/24 16:08:35 by gwojda ### ########.fr */ /* Updated: 2017/03/27 18:52:15 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,11 +25,12 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
else else
push(&lexer->stack, DQUOTE); push(&lexer->stack, DQUOTE);
} }
else if (lexer->str[lexer->pos] == '\\') else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0)
{ {
lexer->pos++; lexer->pos++;
if (lexer->str[lexer->pos] == 0) if (lexer->str[lexer->pos] == 0)
return (push(&lexer->stack, BACKSLASH) ? 0 : 0); return (push(&lexer->stack, BACKSLASH) ? 0 : 0);
token_append(token, lexer, 1, 0);
} }
else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE))
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/22 18:13:29 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:13:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
&lexer_heredoc, &lexer_heredoc,
&lexer_newline, &lexer_newline,
&lexer_delim, &lexer_delim,
&lexer_bang,
&lexer_sep, &lexer_sep,
&lexer_word, &lexer_word,
&lexer_number, &lexer_number,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:23:35 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:11:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
/* Updated: 2017/03/24 11:57:45 by gwojda ### ########.fr */ /* Updated: 2017/03/27 16:59:59 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -104,7 +104,7 @@ int ft_v(char **str, size_t *pos)
} }
ft_current_str(*str, *pos); ft_current_str(*str, *pos);
ft_get_next_str(*str, pos); ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - tmp_pos); ft_putnc('\b', *pos - tmp_pos + (((*str)[*pos]) ? 1 : 0));
*pos = tmp_pos; *pos = tmp_pos;
return (0); return (0);
} }

View file

@ -19,7 +19,6 @@ static int promt_git_status(int fd)
char *line; char *line;
get_next_line(fd, &line); get_next_line(fd, &line);
close(fd);
tmp = line; tmp = line;
if (ft_strrchr(line, '/')) if (ft_strrchr(line, '/'))
line = ft_strdup(ft_strrchr(line, '/') + 1); line = ft_strdup(ft_strrchr(line, '/') + 1);
@ -36,6 +35,7 @@ static int promt_git_status(int fd)
ft_strdel(&tmp); ft_strdel(&tmp);
while (get_next_line(fd, &tmp) > 0) while (get_next_line(fd, &tmp) > 0)
ft_strdel(&tmp); ft_strdel(&tmp);
close(fd);
ft_strdel(&tmp); ft_strdel(&tmp);
return (len + 8); return (len + 8);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */ /* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */
/* Updated: 2017/03/21 18:11:13 by gwojda ### ########.fr */ /* Updated: 2017/03/27 17:37:40 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/25 18:17:57 by ariard ### ########.fr */ /* Updated: 2017/03/27 18:10:21 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:12:52 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:44:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,6 @@
void data_exit(void) void data_exit(void)
{ {
t_data *data; t_data *data;
int i;
data = data_singleton(); data = data_singleton();
ft_strdel(&data->binary); ft_strdel(&data->binary);
@ -26,9 +25,7 @@ void data_exit(void)
parser_destroy(&data->parser); parser_destroy(&data->parser);
exec_destroy(&data->exec); exec_destroy(&data->exec);
jobc_destroy(&data->jobc); jobc_destroy(&data->jobc);
i = -1; shell_fds_destroy();
while (++i < 10)
ft_lstdel(&data->exec.fd_save[i], ft_lst_cfree);
ft_lstdel(&data->lst_func, &tree_func_free); ft_lstdel(&data->lst_func, &tree_func_free);
ft_save_termios(-1); ft_save_termios(-1);
ft_free_hash_table(); ft_free_hash_table();

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/26 21:54:19 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:04:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,6 +66,15 @@ static int shlvl_inc(void)
return (0); return (0);
} }
int modules_init(t_data *data)
{
lexer_init(&data->lexer);
parser_init(&data->parser);
exec_init(&data->exec);
jobc_init(&data->jobc);
return (0);
}
int data_init(int ac, char **av, char **env) int data_init(int ac, char **av, char **env)
{ {
t_data *data; t_data *data;
@ -80,12 +89,10 @@ int data_init(int ac, char **av, char **env)
localenv_init(); localenv_init();
if (shlvl_inc()) if (shlvl_inc())
return (-1); return (-1);
modules_init(data);
data->comp = NULL; data->comp = NULL;
data->opts = SH_INTERACTIVE | SH_OPTS_JOBC; data->opts = SH_INTERACTIVE | SH_OPTS_JOBC;
data->lst_func = NULL; data->lst_func = NULL;
lexer_init(&data->lexer);
parser_init(&data->parser);
exec_init(&data->exec);
if ((term_name = ft_getenv(data->env, "TERM")) == NULL) if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
term_name = "dumb"; term_name = "dumb";
if (tgetent(NULL, term_name) != 1) if (tgetent(NULL, term_name) != 1)

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/26 21:57:37 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:47:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

84
42sh/src/main/shell_fds.c Normal file
View file

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shell_fds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 15:32:13 by jhalford #+# #+# */
/* Updated: 2017/03/27 18:02:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void shell_fds_init(void)
{
t_data *data;
int i;
data = data_singleton();
i = -1;
while (++i < 10)
data->fd_save[i] = NULL;
}
int shell_fds_push(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = fcntl(i, F_DUPFD_CLOEXEC, 10);
push(&(data->fd_save[i]), fd);
}
return (0);
}
int shell_fds_pop(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = pop(&data->fd_save[i]);
if (fd != -1)
close(fd);
}
return (0);
}
void shell_fds_reset(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = top(data->fd_save[i]);
if (fd != -1)
dup2(fd, i);
}
}
void shell_fds_destroy(void)
{
t_data *data;
int i;
data = data_singleton();
i = -1;
while (++i < 10)
ft_lstdel(&data->fd_save[i], ft_lst_cfree);
}

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/27 02:55:15 by jhalford ### ########.fr */ /* Updated: 2017/03/27 19:44:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,7 +70,7 @@ static int interactive_settings(void)
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
kill(-*shell_pgid, SIGTTIN); kill(-*shell_pgid, SIGTTIN);
*shell_pgid = getpid(); *shell_pgid = getpid();
shell_resetsig(); shell_sig_reset();
if (setpgid(*shell_pgid, *shell_pgid)) if (setpgid(*shell_pgid, *shell_pgid))
{ {
SH_ERR("setpgid(): %s", strerror(errno)); SH_ERR("setpgid(): %s", strerror(errno));
@ -99,5 +99,7 @@ int shell_init(int ac, char **av, char **env)
return (-1); return (-1);
if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0)
return (-1); return (-1);
shell_fds_init();
shell_fds_push();
return (0); return (0);
} }

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* shell_reset.c :+: :+: :+: */ /* shell_sig_reset.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */ /* Created: 2017/03/27 15:35:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 20:09:29 by jhalford ### ########.fr */ /* Updated: 2017/03/27 15:35:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void shell_resetsig(void) void shell_sig_reset(void)
{ {
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
@ -21,19 +21,3 @@ void shell_resetsig(void)
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_DFL);
} }
void shell_resetfds(void)
{
t_exec *exec;
int i;
int fd;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
{
fd = top(exec->fd_save[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/03/11 15:58:38 by ariard #+# #+# */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/24 23:26:22 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:23:36 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -89,6 +89,7 @@ static t_aggrematch g_aggrematch[] =
{NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF}, {NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF},
{NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE}, {NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE},
{NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE}, {NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE},
{NEWLINE_LIST, LOOP, LOOP, LOOP},
{NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE}, {NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE},
{NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL}, {NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL},
{NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS},
@ -148,6 +149,7 @@ static t_aggrematch g_aggrematch[] =
{CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX}, {CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX},
{CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME}, {CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME},
{CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, {CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR},
{CMD_SUFFIX, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST},
{CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, {CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE},
{CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE},
{CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0}, {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0},

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 23:26:06 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:29:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -605,6 +605,7 @@ static t_stackmatch g_stackmatch[] =
{NEWLINE_LIST, FOR_WORDLIST}, {NEWLINE_LIST, FOR_WORDLIST},
{NEWLINE_LIST, TK_IN}, {NEWLINE_LIST, TK_IN},
{NEWLINE_LIST, TK_WHILE}, {NEWLINE_LIST, TK_WHILE},
{NEWLINE_LIST, LOOP},
{NEWLINE_LIST, FUNC_NAME}, {NEWLINE_LIST, FUNC_NAME},
{NEWLINE_LIST, TK_UNTIL}, {NEWLINE_LIST, TK_UNTIL},
{NEWLINE_LIST, TK_IF}, {NEWLINE_LIST, TK_IF},

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/23 16:47:59 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:22:10 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,7 +71,7 @@ static t_prodmatch g_prodmatch[] =
{TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX},
{TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX},
{TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX},
@ -94,6 +94,7 @@ static t_prodmatch g_prodmatch[] =
{TK_NEWLINE, TK_RBRACE, CMD_NAME}, {TK_NEWLINE, TK_RBRACE, CMD_NAME},
{TK_NEWLINE, TK_IN, NEWLINE_LIST}, {TK_NEWLINE, TK_IN, NEWLINE_LIST},
{TK_NEWLINE, TK_WHILE, NEWLINE_LIST}, {TK_NEWLINE, TK_WHILE, NEWLINE_LIST},
{TK_NEWLINE, LOOP, NEWLINE_LIST},
{TK_NEWLINE, TK_UNTIL, NEWLINE_LIST}, {TK_NEWLINE, TK_UNTIL, NEWLINE_LIST},
{TK_NEWLINE, TK_FOR, NEWLINE_LIST}, {TK_NEWLINE, TK_FOR, NEWLINE_LIST},
{TK_NEWLINE, TK_IF, NEWLINE_LIST}, {TK_NEWLINE, TK_IF, NEWLINE_LIST},

0
42sh/test/fifi Normal file
View file