end merge
This commit is contained in:
commit
4d13a2e6e6
299 changed files with 6917 additions and 1772 deletions
7
42sh/.gitignore
vendored
7
42sh/.gitignore
vendored
|
|
@ -6,3 +6,10 @@ STDBUG
|
|||
debug
|
||||
.42sh_history
|
||||
*.dSYM
|
||||
.script.sh.swp
|
||||
*.swp
|
||||
*.swo
|
||||
*.o
|
||||
*.swn
|
||||
STDBUG
|
||||
STDEBUG
|
||||
|
|
|
|||
120
42sh/Makefile
120
42sh/Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||
# Updated: 2017/03/04 17:27:41 by gwojda ### ########.fr #
|
||||
#* Updated: 2017/03/05 15:36:45 by wescande ### ########.fr *#
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -60,23 +60,42 @@ completion/c_terminal.c\
|
|||
completion/completion.c\
|
||||
exec/ast_free.c\
|
||||
exec/bad_fd.c\
|
||||
exec/error_badidentifier.c\
|
||||
exec/exec_ampersand.c\
|
||||
exec/exec_and_if.c\
|
||||
exec/exec_case_branch.c\
|
||||
exec/exec_command.c\
|
||||
exec/exec_elif.c\
|
||||
exec/exec_else.c\
|
||||
exec/exec_leaf.c\
|
||||
exec/exec_math.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
exec/exec_redir.c\
|
||||
exec/exec_reset.c\
|
||||
exec/exec_semi.c\
|
||||
exec/exec_var.c\
|
||||
exec/fd_is_valid.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
exec/is_function.c\
|
||||
exec/launch_builtin.c\
|
||||
exec/launch_case.c\
|
||||
exec/launch_file.c\
|
||||
exec/launch_for.c\
|
||||
exec/launch_function.c\
|
||||
exec/launch_if.c\
|
||||
exec/launch_process.c\
|
||||
exec/launch_subshell.c\
|
||||
exec/launch_until.c\
|
||||
exec/launch_while.c\
|
||||
exec/mark_process_status.c\
|
||||
exec/node_copy.c\
|
||||
exec/process_redirect.c\
|
||||
exec/process_reset.c\
|
||||
exec/process_resetfds.c\
|
||||
exec/process_setexec.c\
|
||||
exec/process_setgroup.c\
|
||||
exec/process_setsig.c\
|
||||
exec/redir_copy.c\
|
||||
exec/redir_free.c\
|
||||
exec/redirect_dgreat.c\
|
||||
exec/redirect_dless.c\
|
||||
exec/redirect_great.c\
|
||||
|
|
@ -84,6 +103,16 @@ exec/redirect_greatand.c\
|
|||
exec/redirect_less.c\
|
||||
exec/redirect_lessand.c\
|
||||
exec/set_exitstatus.c\
|
||||
exec/set_process.c\
|
||||
exec/set_process_case.c\
|
||||
exec/set_process_cmd.c\
|
||||
exec/set_process_for.c\
|
||||
exec/set_process_if.c\
|
||||
exec/set_process_map.c\
|
||||
exec/set_process_subshell.c\
|
||||
exec/set_process_until.c\
|
||||
exec/set_process_while.c\
|
||||
exec/token_to_argv.c\
|
||||
glob/command_getoutput.c\
|
||||
glob/dir_glob.c\
|
||||
glob/esc_print.c\
|
||||
|
|
@ -94,10 +123,12 @@ glob/expand_home.c\
|
|||
glob/expand_var.c\
|
||||
glob/ft_strsplit_esc.c\
|
||||
glob/ft_strsplit_spe.c\
|
||||
glob/gen_tab_esc.c\
|
||||
glob/glob.c\
|
||||
glob/is_char_esc.c\
|
||||
glob/lib_perso/ft_ld_back.c\
|
||||
glob/lib_perso/ft_ld_clear.c\
|
||||
glob/lib_perso/ft_ld_copy.c\
|
||||
glob/lib_perso/ft_ld_del.c\
|
||||
glob/lib_perso/ft_ld_front.c\
|
||||
glob/lib_perso/ft_ld_new.c\
|
||||
|
|
@ -114,6 +145,8 @@ glob/lib_perso/ft_strsubf.c\
|
|||
glob/lib_perso/ft_tabdel.c\
|
||||
glob/lib_perso/ft_tablen.c\
|
||||
glob/match_pattern.c\
|
||||
glob/tab_esc_copy.c\
|
||||
glob/word_is_assignment.c\
|
||||
hash_table/ft_add_hash.c\
|
||||
hash_table/hash.c\
|
||||
hash_table/hash_free.c\
|
||||
|
|
@ -126,8 +159,6 @@ history/history_parsing_toolz.c\
|
|||
history/history_parsing_toolz_2.c\
|
||||
history/list_toolz.c\
|
||||
history/surch_in_history.c\
|
||||
init_history.c\
|
||||
init_line.c\
|
||||
job-control/builtin_bg.c\
|
||||
job-control/builtin_fg.c\
|
||||
job-control/builtin_jobs.c\
|
||||
|
|
@ -153,7 +184,19 @@ job-control/mark_job_as_running.c\
|
|||
job-control/process_cmp_pid.c\
|
||||
job-control/process_format.c\
|
||||
job-control/process_free.c\
|
||||
job-control/process_mark_status.c\
|
||||
job-control/process_free_cmd.c\
|
||||
job-control/process_free_cond.c\
|
||||
job-control/process_free_list.c\
|
||||
job-control/process_free_subshell.c\
|
||||
job-control/process_print.c\
|
||||
job-control/process_print_case.c\
|
||||
job-control/process_print_cmd.c\
|
||||
job-control/process_print_for.c\
|
||||
job-control/process_print_function.c\
|
||||
job-control/process_print_if.c\
|
||||
job-control/process_print_subshell.c\
|
||||
job-control/process_print_until.c\
|
||||
job-control/process_print_while.c\
|
||||
job-control/put_job_in_background.c\
|
||||
job-control/put_job_in_foreground.c\
|
||||
job-control/sigchld_handler.c\
|
||||
|
|
@ -162,18 +205,21 @@ job-control/sigtstp_handler.c\
|
|||
job-control/sigttin_handler.c\
|
||||
job-control/sigttou_handler.c\
|
||||
lexer/get_lexer_stack.c\
|
||||
lexer/get_reserved_words.c\
|
||||
lexer/get_state_global.c\
|
||||
lexer/get_state_redir.c\
|
||||
lexer/insert_newline.c\
|
||||
lexer/lexer_assignement_word.c\
|
||||
lexer/lexer_backslash.c\
|
||||
lexer/lexer_bquote.c\
|
||||
lexer/lexer_comment.c\
|
||||
lexer/lexer_curly_braces.c\
|
||||
lexer/lexer_default.c\
|
||||
lexer/lexer_delim.c\
|
||||
lexer/lexer_dless.c\
|
||||
lexer/lexer_dquote.c\
|
||||
lexer/lexer_end.c\
|
||||
lexer/lexer_great.c\
|
||||
lexer/lexer_greatand.c\
|
||||
lexer/lexer_heredoc.c\
|
||||
lexer/lexer_init.c\
|
||||
lexer/lexer_less.c\
|
||||
lexer/lexer_lessand.c\
|
||||
|
|
@ -184,8 +230,6 @@ lexer/lexer_paren.c\
|
|||
lexer/lexer_quote.c\
|
||||
lexer/lexer_sep.c\
|
||||
lexer/lexer_word.c\
|
||||
lexer/reduce_parens.c\
|
||||
lexer/stack_to_prompt.c\
|
||||
lexer/token_append.c\
|
||||
lexer/token_cmp_type.c\
|
||||
lexer/token_free.c\
|
||||
|
|
@ -197,6 +241,8 @@ line-editing/copy_cut_paste.c\
|
|||
line-editing/ft_prompt.c\
|
||||
line-editing/get_key.c\
|
||||
line-editing/home_end.c\
|
||||
line-editing/init_history.c\
|
||||
line-editing/init_line.c\
|
||||
line-editing/init_termcaps.c\
|
||||
line-editing/lib_line_editing/tool_line.c\
|
||||
line-editing/lib_line_editing/tool_line_2.c\
|
||||
|
|
@ -213,27 +259,35 @@ line-editing/readline.c\
|
|||
main/data_exit.c\
|
||||
main/data_init.c\
|
||||
main/data_singleton.c\
|
||||
main/ft_cleanup.c\
|
||||
main/ft_putast.c\
|
||||
main/ft_putast2.c\
|
||||
main/lib_expansion.c\
|
||||
main/instruction_free.c\
|
||||
main/main.c\
|
||||
main/remove_trailing_esc_nl.c\
|
||||
main/shell_get_avdata.c\
|
||||
main/shell_get_opts.c\
|
||||
main/shell_init.c\
|
||||
main/sig_handler.c\
|
||||
parser/add_case.c\
|
||||
parser/add_cmd.c\
|
||||
parser/add_condition.c\
|
||||
parser/add_func.c\
|
||||
parser/add_loop.c\
|
||||
parser/add_math.c\
|
||||
parser/add_number.c\
|
||||
parser/add_redir.c\
|
||||
parser/add_sep.c\
|
||||
parser/add_subshell.c\
|
||||
parser/add_var.c\
|
||||
parser/aggregate_sym.c\
|
||||
parser/build_tree.c\
|
||||
parser/error_syntax.c\
|
||||
parser/eval_sym.c\
|
||||
parser/ft_parse.c\
|
||||
parser/parse_dgreat.c\
|
||||
parser/parse_dless.c\
|
||||
parser/parse_great.c\
|
||||
parser/parse_greatand.c\
|
||||
parser/parse_less.c\
|
||||
parser/parse_lessand.c\
|
||||
parser/parse_redir.c\
|
||||
parser/parse_separator.c\
|
||||
parser/parse_subshell.c\
|
||||
parser/parse_word.c
|
||||
parser/heredoc_parser.c\
|
||||
parser/parser_init.c\
|
||||
parser/pop_stack.c\
|
||||
parser/produce_sym.c\
|
||||
parser/push_stack.c\
|
||||
parser/read_stack.c\
|
||||
parser/tree_wrapper.c
|
||||
|
||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||
|
|
@ -244,13 +298,13 @@ all :
|
|||
@make -j $(NAME)
|
||||
|
||||
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
||||
@$(CC) $(FLAGS) $(D_FLAGS) \
|
||||
@$(CC) $(OBJS) -o $(NAME) \
|
||||
-I $(INC_DIR) \
|
||||
-I $(LIBFT_INC) \
|
||||
$(LIBS) \
|
||||
$(LIBFT_LIB) $(OBJS) \
|
||||
-o $(NAME)
|
||||
@printf "\r\e[48;5;15;38;5;25m✅ MAKE $(NAME)\e[0m\e[K\n"
|
||||
$(LIBFT_LIB) \
|
||||
$(FLAGS) $(D_FLAGS)
|
||||
@printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n"
|
||||
|
||||
$(LIBFT_LIB):
|
||||
@make -C $(LIBFT_DIR)
|
||||
|
|
@ -264,7 +318,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
|||
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||
@printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
||||
@printf "\r\033[38;5;11m⌛ MAKE %10.10s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*.*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) $(DELTA) "$@"
|
||||
@$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\
|
||||
-I $(INC_DIR)\
|
||||
-I $(LIBFT_INC)
|
||||
|
|
@ -272,14 +326,14 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
|||
|
||||
clean: cleanlib
|
||||
@rm -rf $(OBJ_DIR)
|
||||
@printf "\r\e[38;5;202m✖ clean $(NAME).\e[0m\e[K\n"
|
||||
@printf "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K\n"
|
||||
|
||||
cleanlib:
|
||||
@make -C $(LIBFT_DIR) clean
|
||||
|
||||
fclean: clean fcleanlib
|
||||
@rm -f $(NAME)
|
||||
@printf "\r\e[38;5;196m❌ fclean $(NAME).\e[0m\e[K\n"
|
||||
@printf "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K\n"
|
||||
|
||||
fcleanlib: cleanlib
|
||||
@make -C $(LIBFT_DIR) fclean
|
||||
|
|
|
|||
1
42sh/TESTSHELL/simple_cmd/echo.test
Normal file
1
42sh/TESTSHELL/simple_cmd/echo.test
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo 'je suis un test'
|
||||
1
42sh/TESTSHELL/simple_cmd/ls.test
Normal file
1
42sh/TESTSHELL/simple_cmd/ls.test
Normal file
|
|
@ -0,0 +1 @@
|
|||
ls
|
||||
1
42sh/TESTSHELL/simple_cmd/pwd.test
Normal file
1
42sh/TESTSHELL/simple_cmd/pwd.test
Normal file
|
|
@ -0,0 +1 @@
|
|||
pwd
|
||||
0
42sh/TESTSHELL/stderr_ref
Normal file
0
42sh/TESTSHELL/stderr_ref
Normal file
0
42sh/TESTSHELL/stderr_test
Normal file
0
42sh/TESTSHELL/stderr_test
Normal file
14
42sh/TESTSHELL/stdin_ref
Normal file
14
42sh/TESTSHELL/stdin_ref
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
42sh
|
||||
Makefile
|
||||
TESTSHELL
|
||||
donovan_segaults_06-02
|
||||
file1
|
||||
file2
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
pdf
|
||||
sample
|
||||
src
|
||||
test_framework.sh
|
||||
update_makefile.sh
|
||||
43
42sh/TESTSHELL/stdin_test
Normal file
43
42sh/TESTSHELL/stdin_test
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
[7m[33m main.c [1m[34m107[0m[7m[1m[32mstart of shell[0m JOBC is ON[0m
|
||||
[7m[33m token_print.c [1m[34m21 [0mtoken print[0m
|
||||
[7m[33m token_print.c [1m[34m25 [0mtoken : TK_WORD data [ls]
|
||||
[0m
|
||||
[7m[33m insert_newline.c [1m[34m19 [0minsert newline[0m
|
||||
[7m[33m ft_parse.c [1m[34m45 [0m
|
||||
[0m
|
||||
[7m[33m build_tree.c [1m[34m83 [0mfunc TK : 'TK_WORD' TK : 'TK_WORD'[0m
|
||||
[7m[33m add_cmd.c [1m[34m55 [0madd data[0m
|
||||
[7m[33m ft_parse.c [1m[34m45 [0m
|
||||
[0m
|
||||
[7m[33m build_tree.c [1m[34m83 [0mfunc TK : 'TK_NEWLINE' TK : 'TK_NEWLINE'[0m
|
||||
[7m[33m add_sep.c [1m[34m21 [0madd sep[0m
|
||||
[7m[33m ft_parse.c [1m[34m45 [0m
|
||||
[0m
|
||||
[7m[33m ft_parse.c [1m[34m58 [0msucessful parsing[0m
|
||||
[7m[33m main.c [1m[34m64 [0mBefore execution:[0m
|
||||
NEW
|
||||
+----+
|
||||
CMD
|
||||
[7m[33m ft_exec.c [1m[34m39 [0m[0m
|
||||
[7m[33m ft_exec.c [1m[34m48 [0mmatch : TK_NEWLINE and TK_NEWLINE[0m
|
||||
[7m[33m exec_semi.c [1m[34m20 [0m[0m
|
||||
[7m[33m exec_semi.c [1m[34m22 [0m[0m
|
||||
[7m[33m ft_exec.c [1m[34m39 [0m[0m
|
||||
[7m[33m ft_exec.c [1m[34m48 [0mmatch : NON-DEFINED and NON-DEFINED[0m
|
||||
[7m[33m exec_command.c [1m[34m52 [0mop=2118139328[0m
|
||||
42sh
|
||||
Makefile
|
||||
TESTSHELL
|
||||
donovan_segaults_06-02
|
||||
file1
|
||||
file2
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
pdf
|
||||
sample
|
||||
src
|
||||
test_framework.sh
|
||||
update_makefile.sh
|
||||
[7m[33m exec_semi.c [1m[34m24 [0m[0m
|
||||
[7m[33m ft_exec.c [1m[34m39 [0m[0m
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/18 16:44:35 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,100 +6,139 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 17:49:55 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 19:15:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef EXEC_H
|
||||
# define EXEC_H
|
||||
|
||||
# include <sys/stat.h>
|
||||
# include "minishell.h"
|
||||
|
||||
# define PIPE_READ 0
|
||||
# define PIPE_WRITE 1
|
||||
|
||||
# define PROCESS_BUILTIN (1 << 0)
|
||||
# define PROCESS_BINARY (1 << 1)
|
||||
# define PROCESS_SCRIPT (1 << 2)
|
||||
# define PROCESS_SUBSHELL (1 << 3)
|
||||
# define PROCESS_UNKNOWN (1 << 4)
|
||||
# define PROCESS_PIPESTART (1 << 5)
|
||||
# define PROCESS_PIPEEND (1 << 6)
|
||||
# define PROCESS_COMPLETED (1 << 7)
|
||||
# define PROCESS_SUSPENDED (1 << 8)
|
||||
# define PROCESS_RUNNING (1 << 9)
|
||||
# define PROCESS_CONTINUED (1 << 10)
|
||||
# define PROCESS_COMPLETED (1 << 0)
|
||||
# define PROCESS_SUSPENDED (1 << 1)
|
||||
# define PROCESS_RUNNING (1 << 2)
|
||||
# define PROCESS_CONTINUED (1 << 3)
|
||||
|
||||
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4)
|
||||
# define PROCESS_STATE_MASK (1 << 7 | 1 << 8 | 1 << 9 | 1 << 10)
|
||||
# define PROCESS_STATE_MASK ((1 << 4) - (1 << 0))
|
||||
|
||||
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART)
|
||||
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND)
|
||||
# define IS_PIPESINGLE(a) ((a & PROCESS_PIPESTART) && (a & PROCESS_PIPEEND))
|
||||
# define IS_PIPESTART(p) ((p).fdin == STDIN)
|
||||
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||
|
||||
# include "libft.h"
|
||||
# include "types.h"
|
||||
# include "job_control.h"
|
||||
/* # define EXEC_BG (1 << 1) */
|
||||
# define EXEC_AND_IF (1 << 2)
|
||||
# define EXEC_OR_IF (1 << 3)
|
||||
# define EXEC_IF_BRANCH (1 << 4)
|
||||
# define EXEC_CASE_BRANCH (1 << 5)
|
||||
|
||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||
|
||||
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
||||
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
||||
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
||||
# define EXEC_IS_OR_IF(j) (j & EXEC_OR_IF)
|
||||
# define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH)
|
||||
# define EXEC_IS_CASE_BRANCH(j) (j & EXEC_CASE_BRANCH)
|
||||
|
||||
struct s_data_cmd
|
||||
{
|
||||
char **av;
|
||||
char *path;
|
||||
t_execf *execf;
|
||||
struct stat *stat;
|
||||
};
|
||||
|
||||
struct s_data_cond
|
||||
{
|
||||
t_btree *condition;
|
||||
t_btree *content;
|
||||
};
|
||||
|
||||
struct s_data_list
|
||||
{
|
||||
t_ld *list_word;
|
||||
t_btree *content;
|
||||
};
|
||||
|
||||
struct s_data_subshell
|
||||
{
|
||||
t_btree *content;
|
||||
};
|
||||
|
||||
union u_process_data
|
||||
{
|
||||
struct s_data_cmd cmd;
|
||||
struct s_data_subshell subshell;
|
||||
struct s_data_subshell function;
|
||||
struct s_data_cond d_while;
|
||||
struct s_data_cond d_until;
|
||||
struct s_data_cond d_if;
|
||||
struct s_data_list d_for;
|
||||
struct s_data_list d_case;
|
||||
};
|
||||
|
||||
enum e_process_type
|
||||
{
|
||||
PROCESS_FUNCTION,
|
||||
PROCESS_BUILTIN,
|
||||
PROCESS_FILE,
|
||||
PROCESS_SUBSHELL,
|
||||
PROCESS_WHILE,
|
||||
PROCESS_UNTIL,
|
||||
PROCESS_IF,
|
||||
PROCESS_FOR,
|
||||
PROCESS_CASE,
|
||||
PROCESS_MAX
|
||||
};
|
||||
|
||||
typedef enum e_process_type t_process_type;
|
||||
typedef union u_process_data t_process_data;
|
||||
typedef struct s_data_cond t_data_while;
|
||||
typedef struct s_data_cond t_data_if;
|
||||
typedef struct s_data_cond t_data_if;
|
||||
|
||||
struct s_process
|
||||
{
|
||||
char **av;
|
||||
char *path;
|
||||
t_execf *execf;
|
||||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
t_list *redirs;
|
||||
int toclose;
|
||||
int status;
|
||||
t_flag attributes;
|
||||
t_process_type type;
|
||||
t_process_data data;
|
||||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int to_close;
|
||||
t_list *redirs;
|
||||
int status;
|
||||
t_flag attrs;
|
||||
};
|
||||
|
||||
struct s_exec
|
||||
{
|
||||
char *aol_status;
|
||||
int aol_search;
|
||||
t_job job;
|
||||
t_process process;
|
||||
int fd0save;
|
||||
int fd1save;
|
||||
int fd2save;
|
||||
int fd_save[3];
|
||||
t_flag attrs;
|
||||
int fdin;
|
||||
t_list *op_stack;
|
||||
char **case_pattern;
|
||||
int control_count;
|
||||
};
|
||||
|
||||
struct s_execmap
|
||||
{
|
||||
t_type type;
|
||||
int (*f)(t_btree **ast);
|
||||
};
|
||||
|
||||
struct s_redirmap
|
||||
{
|
||||
t_flag type;
|
||||
int (*f)(t_redir *redir);
|
||||
};
|
||||
extern t_itof g_execmap[];
|
||||
extern t_itof g_redirmap[];
|
||||
extern t_itof g_launchmap[];
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
extern t_execmap g_execmap[];
|
||||
extern t_redirmap g_redirmap[];
|
||||
|
||||
int ft_exec(t_btree **ast);
|
||||
|
||||
int exec_semi(t_btree **ast);
|
||||
int exec_ampersand(t_btree **ast);
|
||||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
int exec_redir(t_btree **ast);
|
||||
int exec_command(t_btree **ast);
|
||||
|
||||
int launch_process(t_process *p);
|
||||
int process_setexec(t_type type, t_process *p);
|
||||
int exec_reset(void);
|
||||
int process_setgroup(t_process *p, pid_t pid);
|
||||
void process_setsig(void);
|
||||
void process_free(void *content, size_t content_size);
|
||||
void process_reset(t_process *p);
|
||||
void process_resetfds(void);
|
||||
|
||||
int fd_is_valid(int fd);
|
||||
int fd_is_valid(int fd, int flag);
|
||||
int bad_fd(int fd);
|
||||
int process_redirect(t_process *p);
|
||||
int redirect_great(t_redir *redir);
|
||||
|
|
@ -114,5 +153,69 @@ char *ft_findexec(char *path, char *file);
|
|||
void set_exitstatus(int status, int override);
|
||||
|
||||
void ast_free(void *data, size_t content_size);
|
||||
void *node_copy(void *data);
|
||||
void *redir_copy(void *data);
|
||||
|
||||
void redir_free(void *data, size_t content_size);
|
||||
|
||||
char **token_to_argv(t_ld *ld, int do_match);
|
||||
|
||||
int add_new_job(t_job *job);
|
||||
|
||||
int error_badidentifier(char *name);
|
||||
t_btree *is_function(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour free les process
|
||||
*/
|
||||
void process_free(void *content, size_t content_size);
|
||||
int process_free_cmd(t_process *p);
|
||||
int process_free_cond(t_process *p);
|
||||
int process_free_list(t_process *p);
|
||||
int process_free_subshell(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour launch les process
|
||||
*/
|
||||
int launch_process(t_process *p);
|
||||
int launch_if(t_process *p);
|
||||
int launch_while(t_process *p);
|
||||
int launch_until(t_process *p);
|
||||
int launch_for(t_process *p);
|
||||
int launch_case(t_process *p);
|
||||
int launch_file(t_process *p);
|
||||
int launch_builtin(t_process *p);
|
||||
int launch_subshell(t_process *p);
|
||||
int launch_function(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour set les process
|
||||
*/
|
||||
|
||||
int set_process(t_process *p, t_btree *ast);
|
||||
int set_process_map(t_process *p, t_btree *ast);
|
||||
int set_process_cmd(t_process *p, t_btree *ast);
|
||||
int set_process_while(t_process *p, t_btree *ast);
|
||||
int set_process_until(t_process *p, t_btree *ast);
|
||||
int set_process_if(t_process *p, t_btree *ast);
|
||||
int set_process_for(t_process *p, t_btree *ast);
|
||||
int set_process_case(t_process *p, t_btree *ast);
|
||||
int set_process_subshell(t_process *p, t_btree *ast);
|
||||
|
||||
/*
|
||||
** Mapping pour exec les process
|
||||
*/
|
||||
int ft_exec(t_btree **ast);
|
||||
int exec_leaf(t_btree **ast);
|
||||
int exec_semi(t_btree **ast);
|
||||
int exec_ampersand(t_btree **ast);
|
||||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
int exec_elif(t_btree **ast);
|
||||
int exec_else(t_btree **ast);
|
||||
int exec_var(t_btree **ast);
|
||||
int exec_case_branch(t_btree **ast);
|
||||
int exec_math(t_btree **ast);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
83
42sh/includes/ft_curs.h
Normal file
83
42sh/includes/ft_curs.h
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_curs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/19 21:53:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_CURS_H
|
||||
# define FT_CURS_H
|
||||
|
||||
# include "libft.h"
|
||||
|
||||
# include <sys/ioctl.h>
|
||||
# include <signal.h>
|
||||
# include <termios.h>
|
||||
# include <term.h>
|
||||
# include <curses.h>
|
||||
|
||||
typedef struct s_curs t_curs;
|
||||
|
||||
/*
|
||||
* Cursor data : cursor's coordonate and windows size
|
||||
*/
|
||||
|
||||
struct s_curs
|
||||
{
|
||||
int co;
|
||||
int li;
|
||||
int win_co;
|
||||
int win_li;
|
||||
};
|
||||
|
||||
/*
|
||||
* Cursor reference singleton
|
||||
*/
|
||||
|
||||
t_curs *curs_single(t_curs *curs, int set);
|
||||
|
||||
/*
|
||||
* Cursor setup
|
||||
*/
|
||||
|
||||
int curs_li_ask(void);
|
||||
int curs_co_ask(void);
|
||||
|
||||
int curs_term_setup(void);
|
||||
void curs_win_setup(t_curs *curs);
|
||||
int curs_coo_setup(t_curs *curs);
|
||||
int curs_setup(t_curs *curs);
|
||||
|
||||
/*
|
||||
* Cursor cleanup
|
||||
*/
|
||||
|
||||
int curs_term_cleanup(void);
|
||||
int curs_cleanup(t_curs *curs);
|
||||
|
||||
/*
|
||||
* Cursor's data reset
|
||||
*/
|
||||
|
||||
void curs_reset(int sig);
|
||||
|
||||
/*
|
||||
* Cursor manipulation function
|
||||
*/
|
||||
|
||||
void curs_clear(t_curs *curs);
|
||||
void curs_clear_post(t_curs *curs);
|
||||
void curs_goto(t_curs *curs, int li, int co);
|
||||
void curs_forward(t_curs *curs, int offset);
|
||||
void curs_backward(t_curs *curs, int offset);
|
||||
void curs_write(t_curs *curs, char *str, size_t len);
|
||||
void curs_write_static(t_curs *curs, char *str, size_t len);
|
||||
void curs_video_write(t_curs *curs, char *str, size_t len);
|
||||
void curs_video_write_static(t_curs *curs, char *str, size_t len);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/10 11:45:38 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 15:18:27 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 17:36:15 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/08 23:23:38 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,8 @@
|
|||
# include <dirent.h>
|
||||
# include <locale.h>
|
||||
|
||||
# include "ft_input.h"
|
||||
|
||||
# define FLECHE_HAUT 4283163
|
||||
# define FLECHE_BAS 4348699
|
||||
# define FLECHE_GAUCHE 4479771
|
||||
|
|
@ -53,12 +55,12 @@
|
|||
# define TOUCHE_F5 892427035
|
||||
# define TOUCHE_F6 925981467
|
||||
|
||||
# define IS_QUOTES (1 << 0)
|
||||
# define IS_BQUOTES (1 << 1)
|
||||
# define IS_DQUOTES (1 << 2)
|
||||
# define IS_BSLASH (1 << 3)
|
||||
# define IS_ACCOLADE (1 << 4)
|
||||
# define IS_BRACKET (1 << 5)
|
||||
/* # define IS_QUOTES (1 << 0) */
|
||||
/* # define IS_BQUOTES (1 << 1) */
|
||||
/* # define IS_DQUOTES (1 << 2) */
|
||||
/* # define IS_BSLASH (1 << 3) */
|
||||
/* # define IS_ACCOLADE (1 << 4) */
|
||||
/* # define IS_BRACKET (1 << 5) */
|
||||
|
||||
# define STR data_singleton()->line.input
|
||||
# define POS data_singleton()->line.pos
|
||||
|
|
@ -150,7 +152,7 @@ void ft_c(void);
|
|||
void ft_x(void);
|
||||
void ft_v(void);
|
||||
void ft_read_it(int input, size_t *pos, char **str);
|
||||
char *readline(char *);
|
||||
int readline(int fd, int prompt, char **input);
|
||||
int ft_completion(int ret);
|
||||
|
||||
struct termios *ft_save_termios(int save);
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/03 16:15:47 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 23:24:38 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GLOB_H
|
||||
# define GLOB_H
|
||||
|
||||
# include "minishell.h"
|
||||
|
||||
# define CH(x) ((char **)(x)->content)
|
||||
# define UCH(x) ((unsigned char **)(x)->content)
|
||||
# define SCH(x) ((char **)(x).content)
|
||||
|
|
@ -64,6 +62,8 @@ typedef struct s_bquote
|
|||
char **glob(char *str, unsigned char *esc,
|
||||
unsigned char *dbl_esc, int do_match);
|
||||
void esc_print(char *str, unsigned char *esc);
|
||||
int word_is_assignment(char **content);
|
||||
void *tab_esc_copy(void *content);
|
||||
|
||||
/*
|
||||
** return TRUE if path file is a directory.
|
||||
|
|
@ -97,6 +97,7 @@ void expand_brace(t_glob *tglob);
|
|||
void expand_bquote(t_glob *gl);
|
||||
void expand_home(t_glob *gl, char *str);
|
||||
void expand_var(t_glob *tglob);
|
||||
void expand_home(t_glob *gl, char *str);
|
||||
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||
int dir_research(t_glob *tglob, char *p, char *pat, int rec);
|
||||
char **gen_tab(const char *pat, const unsigned char *esc,
|
||||
|
|
@ -105,31 +106,5 @@ char **ft_strsplit_spe(const char *str,
|
|||
const unsigned char *esc, char c);
|
||||
unsigned char **ft_strsplit_esc(const char *str,
|
||||
const unsigned char *esc, char c);
|
||||
/*
|
||||
** LIST D:
|
||||
*/
|
||||
void ft_ld_new(t_ld **alst, void *content);
|
||||
t_ld *ft_ld_front(t_ld *ld);
|
||||
void ft_ld_pushfront(t_ld **alst, void *content);
|
||||
void ft_ld_pushback(t_ld **alst, void *content);
|
||||
size_t ft_ld_size(t_ld *ld);
|
||||
void ft_ld_del(t_ld **ld, void (*del)());
|
||||
void ft_ld_clear(t_ld **ld, void (*del)());
|
||||
void ft_ld_reverse(t_ld **lst);
|
||||
t_ld *ft_ld_back(t_ld *ld);
|
||||
t_ld *ft_ld_swap(t_ld *l_cur);
|
||||
char **ft_ld_to_tab(t_ld *ld);
|
||||
t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)());
|
||||
|
||||
/*
|
||||
** str:
|
||||
*/
|
||||
|
||||
char *ft_strjoinf(char *str, char *str2, int mode);
|
||||
char *ft_strsubf(char *s, unsigned int start,
|
||||
size_t len, short int mode);
|
||||
void ft_tabdel(char ***mytab);
|
||||
int ft_tablen(char **mytab);
|
||||
|
||||
void *ft_memrealloc(void *ptr, size_t old_s, size_t new_s);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 14:40:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 20:06:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,15 +22,15 @@
|
|||
# define JOB_NOTIFIED (1 << 0)
|
||||
# define JOB_BG (1 << 1)
|
||||
# define JOB_IS_BG(j) (j & JOB_BG)
|
||||
# define JOB_IS_FG(j) !(j & JOB_BG)
|
||||
# define JOB_IS_FG(j) (!JOB_IS_BG(j))
|
||||
|
||||
#define JOBS_OPTS_L (1 << 0)
|
||||
# define JOBS_OPTS_L (1 << 0)
|
||||
|
||||
struct s_job
|
||||
{
|
||||
int id;
|
||||
pid_t pgid;
|
||||
t_flag attributes;
|
||||
t_flag attrs;
|
||||
t_list *first_process;
|
||||
struct termios tmodes;
|
||||
};
|
||||
|
|
@ -58,7 +58,7 @@ void job_format_head(t_job *j);
|
|||
|
||||
void job_update_status(void);
|
||||
void mark_job_as_running (t_job *j);
|
||||
int process_mark_status(pid_t pid, int status);
|
||||
int mark_process_status(pid_t pid, int status);
|
||||
int job_is_stopped(int id);
|
||||
int job_is_completed(int id);
|
||||
|
||||
|
|
@ -84,5 +84,17 @@ void sigttou_handler(int signo);
|
|||
|
||||
int process_cmp_pid(t_process *p, pid_t *pid);
|
||||
void process_format(t_list **p, int firstp, int opts);
|
||||
/*
|
||||
** Mapping pour afficher les process
|
||||
*/
|
||||
void process_print(t_process *p);
|
||||
int process_print_subshell(t_process *p);
|
||||
int process_print_while(t_process *p);
|
||||
int process_print_if(t_process *p);
|
||||
int process_print_case(t_process *p);
|
||||
int process_print_until(t_process *p);
|
||||
int process_print_function(t_process *p);
|
||||
int process_print_for(t_process *p);
|
||||
int process_print_cmd(t_process *p);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/10 00:33:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 23:20:20 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,29 +17,15 @@
|
|||
# include "libft.h"
|
||||
# include "types.h"
|
||||
|
||||
# define TK_LESS (1 << 0)
|
||||
# define TK_GREAT (1 << 1)
|
||||
# define TK_DLESS (1 << 2)
|
||||
# define TK_DGREAT (1 << 3)
|
||||
# define TK_LESSAND (1 << 4)
|
||||
# define TK_GREATAND (1 << 5)
|
||||
# define TK_SEMI (1 << 6)
|
||||
# define TK_PIPE (1 << 7)
|
||||
# define TK_AND_IF (1 << 8)
|
||||
# define TK_OR_IF (1 << 9)
|
||||
# define TK_AMP (1 << 10)
|
||||
# define TK_PAREN_OPEN (1 << 11)
|
||||
# define TK_PAREN_CLOSE (1 << 12)
|
||||
# define TK_WORD (1 << 13)
|
||||
# define TK_COMMAND (1 << 14)
|
||||
# define TK_SUBSHELL (1 << 15)
|
||||
# define TK_NEWLINE (1 << 16)
|
||||
|
||||
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||
|
||||
//# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||
# define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE)
|
||||
# define RW_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_WHILE | TK_DONE\
|
||||
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
||||
enum e_lexstate
|
||||
{
|
||||
DEFAULT,
|
||||
PAREN,
|
||||
HEREDOC,
|
||||
NEWLINE,
|
||||
DELIM,
|
||||
SEP,
|
||||
|
|
@ -49,14 +35,13 @@ enum e_lexstate
|
|||
GREAT,
|
||||
LESSAND,
|
||||
GREATAND,
|
||||
DLESS,
|
||||
QUOTE,
|
||||
DQUOTE,
|
||||
BQUOTE,
|
||||
DQUOTE_BQUOTE,
|
||||
BACKSLASH,
|
||||
PAREN,
|
||||
COMMENT,
|
||||
CURLY_BRACKETS,
|
||||
ASSIGNEMENT_WORD,
|
||||
END,
|
||||
};
|
||||
|
||||
|
|
@ -78,6 +63,13 @@ struct s_lexer
|
|||
t_list *heredoc_stack;
|
||||
};
|
||||
|
||||
struct s_rvwords
|
||||
{
|
||||
char *word;
|
||||
int type;
|
||||
};
|
||||
|
||||
extern t_rvwords g_rvwords[];
|
||||
|
||||
extern int (*g_lexer[])(t_list **alst, t_lexer *lexer);
|
||||
|
||||
|
|
@ -99,15 +91,21 @@ int bquotes_expand(t_list **alst);
|
|||
char *command_getoutput(char *command);
|
||||
|
||||
int ft_is_delim(char c);
|
||||
char *stack_to_prompt(t_list *stack);
|
||||
int ft_is_delim_list(char c);
|
||||
|
||||
char *stack_to_prompt(t_list *stack);
|
||||
t_lexstate get_state_global(t_lexer *lexer);
|
||||
t_lexstate get_state_redir(t_lexer *lexer);
|
||||
int get_lexer_stack(t_lexer lexer);
|
||||
int get_reserved_words(t_list **alst);
|
||||
int insert_newline(t_list **alst);
|
||||
|
||||
void lexer_init(t_lexer *lexer);
|
||||
|
||||
int lexer_lex(t_list **alst, t_lexer *lexer);
|
||||
int lexer_default(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_delim(t_list **alst, t_lexer *lexer);
|
||||
int lexer_sep(t_list **alst, t_lexer *lexer);
|
||||
int lexer_word(t_list **alst, t_lexer *lexer);
|
||||
|
|
@ -116,12 +114,13 @@ int lexer_less(t_list **alst, t_lexer *lexer);
|
|||
int lexer_great(t_list **alst, t_lexer *lexer);
|
||||
int lexer_greatand(t_list **alst, t_lexer *lexer);
|
||||
int lexer_lessand(t_list **alst, t_lexer *lexer);
|
||||
int lexer_dless(t_list **alst, t_lexer *lexer);
|
||||
int lexer_quote(t_list **alst, t_lexer *lexer);
|
||||
int lexer_dquote(t_list **alst, t_lexer *lexer);
|
||||
int lexer_bquote(t_list **alst, t_lexer *lexer);
|
||||
int lexer_backslash(t_list **alst, t_lexer *lexer);
|
||||
int lexer_paren(t_list **alst, t_lexer *lexer);
|
||||
int lexer_curly_braces(t_list **alst, t_lexer *lexer);
|
||||
int lexer_assignement_word(t_list **alst, t_lexer *lexer);
|
||||
int lexer_comment(t_list **alst, t_lexer *lexer);
|
||||
int lexer_end(t_list **alst, t_lexer *lexer);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/18 11:10:50 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/08 20:53:04 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,36 +14,23 @@
|
|||
# define MINISHELL_H
|
||||
# define SHELL_NAME "minishell"
|
||||
|
||||
# include "libft.h"
|
||||
# include "types.h"
|
||||
# include "lexer.h"
|
||||
# include "parser.h"
|
||||
# include "ft_readline.h"
|
||||
# include "exec.h"
|
||||
# include "builtin.h"
|
||||
# include "job_control.h"
|
||||
# include "glob.h"
|
||||
# include "completion.h"
|
||||
# include "hash.h"
|
||||
|
||||
# include <dirent.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/types.h>
|
||||
# include <signal.h>
|
||||
# include <fcntl.h>
|
||||
# include <errno.h>
|
||||
|
||||
# define SH_INTERACTIVE (1 << 0)
|
||||
# define SH_OPTS_JOBC (1 << 1)
|
||||
# define SH_OPTS_LC (1 << 2)
|
||||
# define SH_MODE_INPUT (1 << 3)
|
||||
# define SH_MODE_EXEC (1 << 4)
|
||||
|
||||
# define SH_MODE_MASK (SH_MODE_INPUT | SH_MODE_EXEC)
|
||||
# define SH_HAS_JOBC(b) (b & SH_OPTS_JOBC)
|
||||
# define SH_IS_INTERACTIVE(b) (b & SH_INTERACTIVE)
|
||||
|
||||
# define SH_MSG_NOJOBC "no job-control"
|
||||
# include "../libft/includes/libft.h"
|
||||
# include "types.h"
|
||||
# include "lexer.h"
|
||||
# include "parser.h"
|
||||
# include "ft_readline.h"
|
||||
# include "job_control.h"
|
||||
# include "exec.h"
|
||||
# include "builtin.h"
|
||||
# include "glob.h"
|
||||
# include "completion.h"
|
||||
# include "hash.h"
|
||||
|
||||
struct s_data
|
||||
{
|
||||
|
|
@ -55,10 +42,11 @@ struct s_data
|
|||
t_comp *comp;
|
||||
t_exec exec;
|
||||
t_jobc jobc;
|
||||
t_list *heredoc_queue;
|
||||
char **local_var;
|
||||
t_list *lst_func;
|
||||
};
|
||||
|
||||
extern t_stof g_builtins[];
|
||||
|
||||
void shell_get_opts(int ac, char **av);
|
||||
char *shell_get_avdata();
|
||||
void shell_init(int ac, char **av);
|
||||
|
|
@ -66,10 +54,8 @@ void shell_exit(void);
|
|||
int data_init(void);
|
||||
void data_exit(void);
|
||||
|
||||
void ft_expand_dollar(char **av, char **env);
|
||||
char *ft_findexec(char *path, char *file);
|
||||
|
||||
int remove_trailing_esc_nl(char *str);
|
||||
int instruction_free(t_list **token, t_parser *parser,
|
||||
t_btree **ast);
|
||||
|
||||
char *ft_putast(void *node);
|
||||
void ft_putast2(void *node);
|
||||
|
|
|
|||
|
|
@ -1,66 +1,191 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 12:09:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSER_H
|
||||
# define PARSER_H
|
||||
|
||||
# include "minishell.h"
|
||||
/*
|
||||
** Parse POSIX grammar
|
||||
*/
|
||||
|
||||
enum e_parstate
|
||||
{
|
||||
ERROR = 0,
|
||||
UNDEFINED,
|
||||
SUCCESS,
|
||||
};
|
||||
|
||||
# define MATCH_STACK(x, y) (x == y || y == ALL)
|
||||
|
||||
struct s_parser
|
||||
{
|
||||
t_type type;
|
||||
int (*f)(t_btree **ast, t_list **start, t_list **token);
|
||||
t_parstate state;
|
||||
t_list *stack;
|
||||
t_sym *new_sym;
|
||||
t_list *heredoc_queue;
|
||||
};
|
||||
|
||||
union u_word
|
||||
struct s_aggrematch
|
||||
{
|
||||
char *word;
|
||||
int fd;
|
||||
t_sym top;
|
||||
t_sym under;
|
||||
t_sym new_sym;
|
||||
int erase_sym;
|
||||
};
|
||||
|
||||
struct s_prodmatch
|
||||
{
|
||||
t_type token;
|
||||
t_sym stack;
|
||||
t_sym new_sym;
|
||||
};
|
||||
|
||||
struct s_stackmatch
|
||||
{
|
||||
t_sym top;
|
||||
t_sym under;
|
||||
};
|
||||
|
||||
struct s_errormatch
|
||||
{
|
||||
t_type token;
|
||||
char *error;
|
||||
};
|
||||
|
||||
extern t_aggrematch g_aggrematch[];
|
||||
extern t_prodmatch g_prodmatch[];
|
||||
extern t_stackmatch g_stackmatch[];
|
||||
extern t_errormatch g_errormatch[];
|
||||
|
||||
void parser_init(t_parser *parser);
|
||||
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
|
||||
|
||||
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);
|
||||
int eval_sym(t_list **stack, t_sym new_sym);
|
||||
int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state);
|
||||
|
||||
int push_stack(t_list **stack, t_sym new_sym);
|
||||
int pop_stack(t_list **stack, t_sym erase_sym);
|
||||
|
||||
int pop_heredoc(t_list **heredoc_queue, t_list **lst);
|
||||
|
||||
int error_syntax(t_list **token, t_parser *parser, t_btree **ast);
|
||||
int error_EOF(t_list **token, t_parser *parser, t_btree **ast);
|
||||
|
||||
int ft_read_stack(t_sym *stack);
|
||||
char *read_state(t_sym current);
|
||||
|
||||
|
||||
/*
|
||||
* Build AST - rewriting
|
||||
*
|
||||
*/
|
||||
|
||||
struct s_treematch
|
||||
{
|
||||
t_type type;
|
||||
int (*add)(t_btree **ast, t_list **lst);
|
||||
};
|
||||
|
||||
extern t_treematch g_treematch[];
|
||||
|
||||
int build_tree(t_btree **ast, t_list **lst);
|
||||
|
||||
int add_sep(t_btree **ast, t_list **lst);
|
||||
int add_cmd(t_btree **ast, t_list **lst);
|
||||
|
||||
int add_file(t_btree **ast, t_list **lst);
|
||||
int add_loop_cmd(t_btree **ast, t_list **lst);
|
||||
int add_loop_sep(t_btree **ast, t_list **lst);
|
||||
int add_loop_condition(t_btree **ast, t_list **lst);
|
||||
int add_condition_cmd(t_btree **ast, t_list **lst);
|
||||
int add_condition_sep(t_btree **ast, t_list **lst);
|
||||
int add_branch(t_btree **ast, t_list **lst);
|
||||
int add_redir_word(t_btree **ast, t_list **lst);
|
||||
int add_redir_type(t_btree **ast, t_list **lst);
|
||||
int add_case_cmd(t_btree **ast, t_list **lst);
|
||||
int add_case_sep(t_btree **ast, t_list **lst);
|
||||
int add_pattern(t_btree **ast, t_list **lst);
|
||||
int add_subshell_cmd(t_btree **ast, t_list **lst);
|
||||
int add_subshell_sep(t_btree **ast, t_list **lst);
|
||||
int add_func_cmd(t_btree **ast, t_list **lst);
|
||||
int add_func_sep(t_btree **ast, t_list **lst);
|
||||
int add_one_func(t_btree **ast, t_list **lst);
|
||||
int add_pipe(t_btree **ast, t_list **lst);
|
||||
int add_var(t_btree **ast, t_list **lst);
|
||||
int add_null(t_btree **ast, t_list **lst);
|
||||
int add_ionumber(t_btree **ast, t_list **lst);
|
||||
|
||||
int isloop(t_btree **ast, t_list **lst);
|
||||
int isloop_condition(t_btree **ast, t_list **lst);
|
||||
int iscase(t_btree **ast, t_list **lst);
|
||||
int iscase_pattern(t_btree **ast, t_list **lst);
|
||||
int iscase_branch(t_btree **ast, t_list **lst);
|
||||
int iscondition(t_btree **ast, t_list **lst);
|
||||
int iscondition_branch(t_btree **ast, t_list **lst);
|
||||
int issubshell(t_btree **ast, t_list **lst);
|
||||
int isfunc(t_btree **ast, t_list **lst);
|
||||
int isfunc_name(t_btree **ast, t_list **lst);
|
||||
int isdir(t_btree **ast);
|
||||
int iscondition(t_btree **ast, t_list **list);
|
||||
int isdir_sep(t_btree **ast, t_list **list);
|
||||
int isdir_word(t_btree **ast, t_list **list);
|
||||
int isvar(t_btree **ast, t_list **list);
|
||||
int isnull(t_btree **ast, t_list **list);
|
||||
int isionumber(t_btree **ast, t_list **lst);
|
||||
int ismath(t_btree **ast, t_list **lst);
|
||||
int ismath_expr(t_btree **ast, t_list **lst);
|
||||
|
||||
int join_ast(t_btree **ast, t_btree **new_node);
|
||||
int gen_node(t_btree **ast);
|
||||
int superflous_token(t_btree **ast, t_list **list);
|
||||
|
||||
struct s_distrostree
|
||||
{
|
||||
int (*test)(t_btree **ast, t_list **lst);
|
||||
int (*add)(t_btree **ast, t_list **lst);
|
||||
};
|
||||
|
||||
extern t_distrostree g_distrostree[];
|
||||
|
||||
struct s_redir
|
||||
{
|
||||
t_flag type;
|
||||
t_type type;
|
||||
int n;
|
||||
t_word word;
|
||||
int close;
|
||||
char *word;
|
||||
char *heredoc_data;
|
||||
/* int close; */
|
||||
};
|
||||
|
||||
struct s_cmd
|
||||
{
|
||||
t_list *redir;
|
||||
t_ld *token;
|
||||
t_ld *wordlist;
|
||||
};
|
||||
|
||||
union u_astdata
|
||||
{
|
||||
t_redir redir;
|
||||
t_ld *token;
|
||||
t_cmd cmd;
|
||||
char **sstr;
|
||||
char *str;
|
||||
};
|
||||
|
||||
struct s_astnode
|
||||
{
|
||||
int pattern;
|
||||
int nest;
|
||||
int full;
|
||||
t_type type;
|
||||
t_astdata data;
|
||||
};
|
||||
|
||||
extern t_parser g_parser[];
|
||||
|
||||
int ft_parse(t_btree **ast, t_list **token);
|
||||
int parse_separator(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_redir(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_less(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_great(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_dless(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_dgreat(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_lessand(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_greatand(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_word(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_subshell(t_btree **ast, t_list **start, t_list **lst);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,40 +6,226 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/09 19:52:04 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 17:16:00 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_H
|
||||
# define TYPES_H
|
||||
|
||||
typedef struct s_data t_data;
|
||||
# include <sys/types.h>
|
||||
|
||||
typedef long long t_type;
|
||||
typedef long long t_flag;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_comp t_comp;
|
||||
typedef struct s_exec t_exec;
|
||||
typedef struct s_jobc t_jobc;
|
||||
typedef enum e_mode t_mode;
|
||||
# define SH_INTERACTIVE (1 << 0)
|
||||
# define SH_OPTS_JOBC (1 << 1)
|
||||
# define SH_OPTS_LC (1 << 2)
|
||||
# define SH_MODE_INPUT (1 << 3)
|
||||
# define SH_MODE_EXEC (1 << 4)
|
||||
|
||||
typedef struct s_lexer t_lexer;
|
||||
typedef enum e_lexstate t_lexstate;
|
||||
typedef struct s_token t_token;
|
||||
# define SH_MODE_MASK (SH_MODE_INPUT | SH_MODE_EXEC)
|
||||
# define SH_HAS_JOBC(b) (b & SH_OPTS_JOBC)
|
||||
# define SH_IS_INTERACTIVE(b) (b & SH_INTERACTIVE)
|
||||
# define SH_NO_INTERACTIVE(b) !(b & SH_INTERACTIVE)
|
||||
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_ld t_ld;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
# define SH_MSG_NOJOBC "no job-control"
|
||||
|
||||
typedef struct s_job t_job;
|
||||
typedef struct s_execmap t_execmap;
|
||||
typedef struct s_redirmap t_redirmap;
|
||||
typedef struct s_process t_process;
|
||||
typedef int (t_execf)(const char *path, char *const argv[], char *const envp[]);
|
||||
typedef long long t_type;
|
||||
typedef long long t_flag;
|
||||
|
||||
typedef struct s_data t_data;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_comp t_comp;
|
||||
typedef struct s_exec t_exec;
|
||||
typedef struct s_jobc t_jobc;
|
||||
typedef enum e_mode t_mode;
|
||||
|
||||
/*
|
||||
** Execution types
|
||||
*/
|
||||
|
||||
typedef struct s_lexer t_lexer;
|
||||
typedef enum e_lexstate t_lexstate;
|
||||
typedef struct s_token t_token;
|
||||
typedef struct s_rvwords t_rvwords;
|
||||
|
||||
typedef struct s_ld t_ld;
|
||||
|
||||
/*
|
||||
** Execution types
|
||||
*/
|
||||
|
||||
typedef int t_condition;
|
||||
typedef struct s_job t_job;
|
||||
typedef struct s_process t_process;
|
||||
typedef int (t_execf)(const char *path,
|
||||
char *const argv[],
|
||||
char *const envp[]);
|
||||
|
||||
/*
|
||||
** Parser types
|
||||
*/
|
||||
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
typedef struct s_cmd t_cmd;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
typedef struct s_parser t_parser;
|
||||
typedef int t_sym;
|
||||
typedef enum e_parstate t_parstate;
|
||||
typedef struct s_aggrematch t_aggrematch;
|
||||
typedef struct s_prodmatch t_prodmatch;
|
||||
typedef struct s_stackmatch t_stackmatch;
|
||||
typedef struct s_errormatch t_errormatch;
|
||||
typedef struct s_treematch t_treematch;
|
||||
typedef struct s_distrostree t_distrostree;
|
||||
|
||||
t_data *data_singleton();
|
||||
|
||||
enum e_sym
|
||||
{
|
||||
LINEBREAK = 1,
|
||||
TK_COMMAND,
|
||||
TK_LESS,
|
||||
TK_GREAT,
|
||||
TK_DLESS,
|
||||
TK_DGREAT,
|
||||
TK_LESSAND,
|
||||
TK_GREATAND,
|
||||
TK_SEMI,
|
||||
TK_PIPE,
|
||||
TK_AND_IF,
|
||||
TK_OR_IF,
|
||||
TK_AMP,
|
||||
TK_PAREN_OPEN,
|
||||
TK_PAREN_CLOSE,
|
||||
TK_BQUOTE,
|
||||
TK_NEWLINE,
|
||||
TK_WHILE,
|
||||
TK_DO,
|
||||
TK_DONE,
|
||||
TK_IF,
|
||||
TK_THEN,
|
||||
TK_FI,
|
||||
TK_ELIF,
|
||||
TK_ELSE,
|
||||
TK_UNTIL,
|
||||
TK_WORD,
|
||||
TK_ASSIGNEMENT_WORD = 50,
|
||||
TK_BANG,
|
||||
TK_NAME,
|
||||
TK_FOR,
|
||||
TK_IO_NUMBER,
|
||||
TK_DLESSDASH,
|
||||
TK_LESSGREAT,
|
||||
TK_CASE,
|
||||
TK_IN,
|
||||
TK_ESAC,
|
||||
TK_CLOBBER,
|
||||
TK_LBRACE,
|
||||
TK_RBRACE,
|
||||
TK_DSEMI,
|
||||
PROGRAM = 100,
|
||||
COMPLETE_COMMAND,
|
||||
COMPLETE_COMMANDS,
|
||||
LIST,
|
||||
AND_OR,
|
||||
PIPELINE,
|
||||
PIPE_SEQUENCE,
|
||||
COMMAND,
|
||||
COMPOUND_COMMAND,
|
||||
SUBSHELL,
|
||||
COMPOUND_LIST,
|
||||
TERM,
|
||||
FOR_CLAUSE,
|
||||
NAME,
|
||||
IN,
|
||||
WORDLIST,
|
||||
CASE_CLAUSE,
|
||||
CASE_LIST,
|
||||
CASE_LIST_NS,
|
||||
CASE_ITEM,
|
||||
CASE_ITEM_NS,
|
||||
PATTERN,
|
||||
IF_CLAUSE,
|
||||
BRACE_CLAUSE,
|
||||
ELSE_PART,
|
||||
WHILE_CLAUSE,
|
||||
UNTIL_CLAUSE,
|
||||
FUNCTION_DEFINITION,
|
||||
FUNCTION_BODY,
|
||||
FNAME,
|
||||
BRACE_GROUP,
|
||||
DO_GROUP,
|
||||
SIMPLE_COMMAND,
|
||||
CMD_NAME,
|
||||
CMD_WORD,
|
||||
CMD_PREFIX,
|
||||
CMD_SUFFIX,
|
||||
REDIRECT_LIST,
|
||||
IO_REDIRECT,
|
||||
IO_FILE,
|
||||
FILENAME,
|
||||
IO_HERE,
|
||||
HERE_END,
|
||||
NEWLINE_LIST,
|
||||
SEPARATOR_OP,
|
||||
SEPARATOR,
|
||||
SEQUENTIAL_SEP,
|
||||
BRACE,
|
||||
LOOP,
|
||||
FUNC,
|
||||
PIPE_SEMI_SEQUENCE,
|
||||
CMD_SUPERIOR,
|
||||
SEQUENCE,
|
||||
AND_OR_MAJOR,
|
||||
AND_OR_MINOR,
|
||||
END_COMMAND,
|
||||
CONDITION,
|
||||
COMPLETE_CONDITION,
|
||||
FOR_WORDLIST,
|
||||
PATTERN_CASE,
|
||||
FUNC_NAME,
|
||||
CLOSE_LIST,
|
||||
MATH,
|
||||
MATH_PLUS,
|
||||
MATH_SUP,
|
||||
REDIR,
|
||||
CMD,
|
||||
HEREDOCDATA,
|
||||
HEREDOC_DELIM,
|
||||
ALL = 200,
|
||||
TERMINUS = 300,
|
||||
};
|
||||
|
||||
/*
|
||||
** LIST D:
|
||||
*/
|
||||
|
||||
void ft_ld_new(t_ld **alst, void *content);
|
||||
t_ld *ft_ld_front(t_ld *ld);
|
||||
void ft_ld_pushfront(t_ld **alst, void *content);
|
||||
void ft_ld_pushback(t_ld **alst, void *content);
|
||||
size_t ft_ld_size(t_ld *ld);
|
||||
void ft_ld_del(t_ld **ld, void (*del)());
|
||||
void ft_ld_clear(t_ld **ld, void (*del)());
|
||||
void ft_ld_reverse(t_ld **lst);
|
||||
t_ld *ft_ld_back(t_ld *ld);
|
||||
t_ld *ft_ld_swap(t_ld *l_cur);
|
||||
char **ft_ld_to_tab(t_ld *ld);
|
||||
t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)());
|
||||
t_ld *ft_ld_copy(t_ld *src, void *(*f)(void *elem));
|
||||
|
||||
/*
|
||||
** str:
|
||||
*/
|
||||
|
||||
char *ft_strjoinf(char *str, char *str2, int mode);
|
||||
char *ft_strsubf(char *s, unsigned int start,
|
||||
size_t len, short int mode);
|
||||
void ft_tabdel(char ***mytab);
|
||||
int ft_tablen(char **mytab);
|
||||
|
||||
void *ft_memrealloc(void *ptr, size_t old_s, size_t new_s);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit bc489f8664fdc24317c31b3069811f54b1178643
|
||||
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6
|
||||
1
42sh/sample/assignement/var_01.sh
Normal file
1
42sh/sample/assignement/var_01.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
HELLO=WORLD
|
||||
1
42sh/sample/brace/brace_01.sh
Normal file
1
42sh/sample/brace/brace_01.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ ls | cat }
|
||||
5
42sh/sample/case/case.sh
Normal file
5
42sh/sample/case/case.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
case van in
|
||||
( "bus" ) echo Hello world ;;
|
||||
( "velo" ) echo Comment va ;;
|
||||
( "van" ) ls ;;
|
||||
esac
|
||||
2
42sh/sample/comment.sh
Normal file
2
42sh/sample/comment.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ls | cat
|
||||
pwd ; cd
|
||||
1
42sh/sample/dir.sh
Normal file
1
42sh/sample/dir.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
file1 <file1 ls
|
||||
1
42sh/sample/error.sh
Normal file
1
42sh/sample/error.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
ls ; pwd | |
|
||||
1
42sh/sample/file1
Normal file
1
42sh/sample/file1
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
8
42sh/sample/for/for.sh
Normal file
8
42sh/sample/for/for.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
for i in hello bonjour salut comment
|
||||
do
|
||||
while cat efezf
|
||||
do
|
||||
echo INSIDE
|
||||
done
|
||||
ls | cat
|
||||
done
|
||||
3
42sh/sample/func/func01.sh
Normal file
3
42sh/sample/func/func01.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
hello () (
|
||||
echo HELLO
|
||||
)
|
||||
11
42sh/sample/if.sh
Normal file
11
42sh/sample/if.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
if ls
|
||||
then
|
||||
pwd
|
||||
elif ls
|
||||
then
|
||||
pwd
|
||||
elif ls
|
||||
then
|
||||
pwd
|
||||
else ls
|
||||
fi
|
||||
9
42sh/sample/if/01_if_easy.sh
Normal file
9
42sh/sample/if/01_if_easy.sh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
if cat wef4eeef
|
||||
then
|
||||
echo Conditon 1
|
||||
elif cat yulu
|
||||
then
|
||||
echo Condition 2
|
||||
else
|
||||
echo Condition 3
|
||||
fi
|
||||
10
42sh/sample/if/02_if_elif.sh
Normal file
10
42sh/sample/if/02_if_elif.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
if ls ;
|
||||
then
|
||||
pwd
|
||||
elif ls
|
||||
then
|
||||
pwd
|
||||
elif ls
|
||||
then
|
||||
pwd
|
||||
fi
|
||||
5
42sh/sample/if/03_if_else.sh
Normal file
5
42sh/sample/if/03_if_else.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
if cat yolo ;
|
||||
then
|
||||
pwd
|
||||
else ls
|
||||
fi
|
||||
11
42sh/sample/if/04_if_elseelsif.sh
Normal file
11
42sh/sample/if/04_if_elseelsif.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
if cat yolo ;
|
||||
then
|
||||
pwd
|
||||
elif ls
|
||||
then
|
||||
pwd
|
||||
elif pwd
|
||||
then
|
||||
ls
|
||||
else ls
|
||||
fi
|
||||
1
42sh/sample/infinite.sh
Normal file
1
42sh/sample/infinite.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo "echo hello" >> sample/infinite.sh
|
||||
6
42sh/sample/laurier.sh
Normal file
6
42sh/sample/laurier.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
read -p "Quel est ton login ?" login
|
||||
while [ 1 ]
|
||||
do
|
||||
echo "Tu es le meilleur codeur de l'ecole $login"
|
||||
sleep 1
|
||||
done
|
||||
1
42sh/sample/ls
Normal file
1
42sh/sample/ls
Normal file
|
|
@ -0,0 +1 @@
|
|||
ls
|
||||
21
42sh/sample/mix/mix.sh
Normal file
21
42sh/sample/mix/mix.sh
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
if ls
|
||||
then
|
||||
pwd ; echo "Salut"
|
||||
while ls
|
||||
do
|
||||
until pwd
|
||||
do
|
||||
echo KO SI JE M AFFICHE
|
||||
done
|
||||
if cat faux
|
||||
then
|
||||
echo BONJOUR MAKEFILE
|
||||
elif [ -f Makefile ]
|
||||
then
|
||||
echo BONJOUR MAKEFILE
|
||||
else
|
||||
echo KO SI JE M M AFFICHE
|
||||
fi
|
||||
echo "Encore une"
|
||||
done
|
||||
fi
|
||||
3
42sh/sample/multiredir
Normal file
3
42sh/sample/multiredir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cat < file1 < file2 > file3 > file4
|
||||
|
||||
|
||||
1
42sh/sample/redir/redir.sh
Normal file
1
42sh/sample/redir/redir.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
3
42sh/sample/stack.sh
Normal file
3
42sh/sample/stack.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cat && ls || ls | cat && ls | cat || ls
|
||||
|
||||
|
||||
2
42sh/sample/subshell/subshell01.sh
Normal file
2
42sh/sample/subshell/subshell01.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(ls | cat
|
||||
pwd ; ls)
|
||||
8
42sh/sample/until.sh
Normal file
8
42sh/sample/until.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
until [ 1 ]
|
||||
do
|
||||
echo LOOP1
|
||||
until [ 1 ]
|
||||
do
|
||||
echo hello
|
||||
done
|
||||
done > file1
|
||||
11
42sh/sample/until/01_until.sh
Normal file
11
42sh/sample/until/01_until.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
until cat wefwef
|
||||
do
|
||||
until ls
|
||||
do
|
||||
pwd ; ls
|
||||
done
|
||||
until cat eqwfewf
|
||||
do
|
||||
ls | cat
|
||||
done
|
||||
done
|
||||
16
42sh/sample/until2.sh
Normal file
16
42sh/sample/until2.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ONE=0
|
||||
while [ $ONE -le 10 ]
|
||||
do
|
||||
TWO=0
|
||||
while [ $TWO -le 10 ]
|
||||
do
|
||||
THREE=0
|
||||
while [ $THREE -le 10 ]
|
||||
do
|
||||
echo world
|
||||
((THREE++))
|
||||
done
|
||||
((TWO++))
|
||||
done
|
||||
((ONE++))
|
||||
done > file1
|
||||
12
42sh/sample/while.sh
Normal file
12
42sh/sample/while.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
while
|
||||
while
|
||||
while ls | cat
|
||||
do
|
||||
ls
|
||||
done
|
||||
do
|
||||
ls | cat
|
||||
done
|
||||
do
|
||||
pwd
|
||||
done
|
||||
11
42sh/sample/while/while01.sh
Normal file
11
42sh/sample/while/while01.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
while ls
|
||||
do
|
||||
while cat rwgwghe
|
||||
do
|
||||
echo Hello World
|
||||
done
|
||||
while pwd
|
||||
do
|
||||
echo Bonjour ca va
|
||||
done
|
||||
done
|
||||
16
42sh/sample/while2.sh
Normal file
16
42sh/sample/while2.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ONE=11
|
||||
while [ $ONE -gt 1 ]
|
||||
do
|
||||
TWO=11
|
||||
while [ $TWO -gt 1 ]
|
||||
do
|
||||
THREE=11
|
||||
while [ $THREE -gt 1 ]
|
||||
do
|
||||
echo hello
|
||||
((THREE--))
|
||||
done
|
||||
((TWO--))
|
||||
done
|
||||
((ONE--))
|
||||
done > file1
|
||||
6
42sh/sample/while_error.sh
Normal file
6
42sh/sample/while_error.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
echo hello
|
||||
while ||
|
||||
do
|
||||
pwd ;
|
||||
done
|
||||
ls | cat
|
||||
1
42sh/sample/yale/yale0.ex
Normal file
1
42sh/sample/yale/yale0.ex
Normal file
|
|
@ -0,0 +1 @@
|
|||
< A B | ( C 2> D & E < F ) > G ; H=I J K
|
||||
1
42sh/sample/yale/yale1.ex
Normal file
1
42sh/sample/yale/yale1.ex
Normal file
|
|
@ -0,0 +1 @@
|
|||
< A B | C | D | E > F
|
||||
1
42sh/sample/yale/yale2.ex
Normal file
1
42sh/sample/yale/yale2.ex
Normal file
|
|
@ -0,0 +1 @@
|
|||
A && B || C && D
|
||||
1
42sh/sample/yale/yale3.ex
Normal file
1
42sh/sample/yale/yale3.ex
Normal file
|
|
@ -0,0 +1 @@
|
|||
A ; B & C ; D || E
|
||||
1
42sh/sample/yale/yale5.ex
Normal file
1
42sh/sample/yale/yale5.ex
Normal file
|
|
@ -0,0 +1 @@
|
|||
(A ; B &) | (C || D) && E
|
||||
1
42sh/sample/yale1.sh
Normal file
1
42sh/sample/yale1.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/sh
|
||||
while [ 1 ]; do
|
||||
sleep 1
|
||||
echo "a"
|
||||
done
|
||||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 15:58:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:27:49 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int bt_read_getdelim(t_read *data, char *arg)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/27 18:25:22 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/27 19:40:14 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 15:28:10 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
#include "minishell.h"
|
||||
|
||||
static t_readopt *bt_read_getopt(char letter)
|
||||
{
|
||||
|
|
@ -30,11 +30,9 @@ int bt_read_parse(t_read *data, char **av)
|
|||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
t_readopt *opt;
|
||||
|
||||
i = 1;
|
||||
k = 0;
|
||||
while (av[i])
|
||||
{
|
||||
j = 0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin.h"
|
||||
#include "minishell.h"
|
||||
|
||||
struct termios bt_read_term(int init)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,17 +6,19 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 13:51:18 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/03 20:12:45 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin.h"
|
||||
#include "minishell.h"
|
||||
|
||||
#define CDOPT_L (1 << 0)
|
||||
#define CDOPT_P (1 << 1)
|
||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||
#define CDERR_1 "{red}cd: no such file or directory: %s{eoc}\n"
|
||||
#define CDERR_2 "{red}cd: HOME not set{eoc}\n"
|
||||
#define CDERR_3 "{red}cd: too many arguments{eoc}\n"
|
||||
|
||||
static char *builtin_cd_special(char *const av[], char *const env[])
|
||||
{
|
||||
|
|
@ -25,7 +27,15 @@ static char *builtin_cd_special(char *const av[], char *const env[])
|
|||
if (!*av)
|
||||
{
|
||||
if (!(target = ft_getenv((char**)env, "HOME")))
|
||||
{
|
||||
ft_dprintf(2, CDERR_2);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
else if (*av && *(av + 1))
|
||||
{
|
||||
ft_dprintf(2, CDERR_3);
|
||||
return (NULL);
|
||||
}
|
||||
else if (ft_strcmp(*av, "-") == 0)
|
||||
target = ft_strdup(ft_getenv((char**)env, "OLDPWD"));
|
||||
|
|
@ -38,10 +48,8 @@ static int builtin_cd_opts(char *const av[], int *opts)
|
|||
{
|
||||
int i;
|
||||
int j;
|
||||
int tmp_opts;
|
||||
|
||||
i = 1;
|
||||
tmp_opts = 0;
|
||||
if (av)
|
||||
while (av[i] && av[i][0] == '-' && av[i][1])
|
||||
{
|
||||
|
|
@ -49,35 +57,37 @@ static int builtin_cd_opts(char *const av[], int *opts)
|
|||
while (av[i][++j])
|
||||
{
|
||||
if (av[i][j] == 'P')
|
||||
tmp_opts |= CDOPT_P;
|
||||
*opts = CDOPT_P;
|
||||
else if (av[i][j] == 'L')
|
||||
tmp_opts |= CDOPT_L;
|
||||
*opts = CDOPT_L;
|
||||
else if (av[i][j] == '-')
|
||||
return (i + 1);
|
||||
else
|
||||
return (i);
|
||||
}
|
||||
*opts |= tmp_opts;
|
||||
i++;
|
||||
++i;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int builtin_cd(const char *path, char *const av[], char *const envp[])
|
||||
int builtin_cd(const char *path,
|
||||
char *const av[], char *const envp[])
|
||||
{
|
||||
int i;
|
||||
int opts;
|
||||
char *target;
|
||||
char *cwd;
|
||||
|
||||
opts = 0;
|
||||
opts = CDOPT_L;
|
||||
i = builtin_cd_opts(av, &opts);
|
||||
if (!(target = builtin_cd_special(av + i, envp)))
|
||||
return (0);
|
||||
return (1);
|
||||
cwd = getcwd(NULL, 0);
|
||||
builtin_setenv(path, (char*[3]){"OLDPWD", cwd, NULL}, envp);
|
||||
free(cwd);
|
||||
if (chdir(target))
|
||||
{
|
||||
ft_printf(CDERR_1, target);
|
||||
ft_dprintf(2, CDERR_1, target);
|
||||
return (1);
|
||||
}
|
||||
else if (target != av[i])
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:21:41 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/13 17:58:14 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/20 00:10:31 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int builtin_echo(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 15:56:55 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:29:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 15:24:39 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 23:25:01 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,10 +32,7 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
|
|||
if (av && av[1])
|
||||
status = ft_atoi(av[1]);
|
||||
else
|
||||
{
|
||||
/* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */
|
||||
status = 0;
|
||||
}
|
||||
status = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
||||
ft_save_termios(-1);
|
||||
ft_free_hash_table();
|
||||
data_exit();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */
|
||||
/* Updated: 2017/01/26 14:58:41 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/20 20:30:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
#include "minishell.h"
|
||||
|
||||
t_readopt g_readtab[] =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 13:18:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:28:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/18 16:44:56 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 19:42:54 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,9 +25,9 @@ t_stof g_builtin[] =
|
|||
{"jobs", &builtin_jobs},
|
||||
{"fg", &builtin_fg},
|
||||
{"bg", &builtin_bg},
|
||||
{"history", &builtin_history},
|
||||
{"read", &builtin_read},
|
||||
{"hash", &builtin_hash},
|
||||
{"history", &builtin_history},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
@ -37,7 +37,9 @@ t_execf *is_builtin(t_process *p)
|
|||
|
||||
i = -1;
|
||||
while (g_builtin[++i].name)
|
||||
if (ft_strcmp(g_builtin[i].name, p->av[0]) == 0)
|
||||
{
|
||||
if (ft_strcmp(g_builtin[i].name, p->data.cmd.av[0]) == 0)
|
||||
return (g_builtin[i].f);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Retrieve the path from the env and create a char ** from the PATH pattern.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Clear the list from the memory
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** If the parsing for local file fail. The function is called to check if the
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Trim if there's many commands in a raw separed with a semi colon.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Start the parsing for the autocompletion.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Support: Return the size of a char**.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Update of the struct data.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Add the matching element to the list
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Solve the tilde pattern in the path
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Print the name with or without an underline and colored upon file type
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Recreate a c->match value by adding the new key pressed to it.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Get the max length from the list
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Clear the previous list from the screen and restore the same position.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "completion.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** Function to select the next item in the list if it has already been created
|
||||
|
|
|
|||
|
|
@ -6,11 +6,19 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 19:15:28 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/08 00:59:53 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
void read_redir(void *data)
|
||||
{
|
||||
t_redir *redir;
|
||||
|
||||
redir = data;
|
||||
DG("file : [%s]", redir->word);
|
||||
}
|
||||
|
||||
void ast_free(void *data, size_t content_size)
|
||||
{
|
||||
|
|
@ -18,15 +26,11 @@ void ast_free(void *data, size_t content_size)
|
|||
|
||||
(void)content_size;
|
||||
node = data;
|
||||
if (node->type == TK_COMMAND)
|
||||
ft_ld_clear(&node->data.token, &ft_tabdel);
|
||||
else if (node->type == TK_SUBSHELL)
|
||||
if (node->type == CMD)
|
||||
{
|
||||
ft_sstrfree(node->data.sstr);
|
||||
node->data.sstr = NULL;
|
||||
}
|
||||
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
||||
{
|
||||
ft_strdel(&node->data.redir.word.word);
|
||||
ft_ld_clear(&node->data.cmd.token, &ft_tabdel);
|
||||
// ft_lstdel(&node->data.cmd.redir, &redir_free);
|
||||
}
|
||||
// if (node->type == WORDLIST)
|
||||
// do clear
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sig_handler.c :+: :+: :+: */
|
||||
/* error_badidentifier.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:43:22 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/03 13:31:33 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/06 18:03:51 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/06 18:11:26 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
pid_t g_pid;
|
||||
|
||||
void sig_handler(int signo)
|
||||
int error_badidentifier(char *name)
|
||||
{
|
||||
(void)signo;
|
||||
if (signo == SIGINT)
|
||||
{
|
||||
if (g_pid)
|
||||
kill(g_pid, SIGINT);
|
||||
if (kill(g_pid, 0) == 0)
|
||||
ft_putendl("");
|
||||
}
|
||||
ft_putstr_fd("`", 2);
|
||||
ft_putstr(name);
|
||||
ft_putstr_fd("' not a valid identifier", 2);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -6,20 +6,23 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:41:54 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 16:46:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_ampersand(t_btree **ast)
|
||||
{
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
data_singleton()->exec.job.attributes |= JOB_BG;
|
||||
t_exec *exec;
|
||||
|
||||
if (!SH_HAS_JOBC(data_singleton()->opts))
|
||||
return (exec_semi(ast));
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_AMP);
|
||||
ft_exec(&(*ast)->left);
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
data_singleton()->exec.job.attributes &= ~JOB_BG;
|
||||
exec->attrs &= ~EXEC_AOL_MASK;
|
||||
exec->job.attrs &= ~JOB_BG;
|
||||
ft_exec(&(*ast)->right);
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,32 +6,41 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/12 18:01:06 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 15:18:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_and_if(t_btree **ast)
|
||||
{
|
||||
t_data *data;
|
||||
/* t_data *data; */
|
||||
t_exec *exec;
|
||||
|
||||
data = data_singleton();
|
||||
if (data->exec.aol_status == NULL
|
||||
|| (data->exec.aol_search == TK_AND_IF
|
||||
&& *data->exec.aol_status == '0')
|
||||
|| (data->exec.aol_search == TK_OR_IF
|
||||
&& *data->exec.aol_status != '0'))
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
data->exec.aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->exec.aol_search = TK_AND_IF;
|
||||
if (*data->exec.aol_status == '0'
|
||||
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND)
|
||||
ft_exec(&(*ast)->right);
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
btree_delone(ast, &ast_free);
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_AND_IF);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs &= ~EXEC_OR_IF;
|
||||
exec->attrs |= EXEC_AND_IF;
|
||||
ft_exec(&(*ast)->right);
|
||||
|
||||
/* data = data_singleton(); */
|
||||
/* if (data->exec.aol_status == NULL */
|
||||
/* || (data->exec.aol_search == TK_AND_IF */
|
||||
/* && *data->exec.aol_status == '0') */
|
||||
/* || (data->exec.aol_search == TK_OR_IF */
|
||||
/* && *data->exec.aol_status != '0')) */
|
||||
/* { */
|
||||
/* ft_exec(&(*ast)->left); */
|
||||
/* data->exec.aol_status = ft_getenv(data->env, "?"); */
|
||||
/* } */
|
||||
/* data->exec.aol_search = TK_AND_IF; */
|
||||
/* if (*data->exec.aol_status == '0' */
|
||||
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
|
||||
/* ft_exec(&(*ast)->right); */
|
||||
/* data->exec.aol_status = NULL; */
|
||||
/* data->exec.aol_search = 0; */
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_separator.c :+: :+: :+: */
|
||||
/* exec_case_branch.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/03 13:32:14 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/07 20:33:45 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 20:34:48 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int parse_separator(t_btree **ast, t_list **start, t_list **lst)
|
||||
int exec_case_branch(t_btree **ast)
|
||||
{
|
||||
t_token *token;
|
||||
t_astnode *node;
|
||||
char **av;
|
||||
t_exec *exec;
|
||||
int i;
|
||||
|
||||
token = (*lst)->content;
|
||||
exec = &data_singleton()->exec;
|
||||
if (EXEC_IS_CASE_BRANCH(exec->attrs))
|
||||
return (0);
|
||||
node = (*ast)->item;
|
||||
node->type = token->type;
|
||||
ft_parse(&(*ast)->right, &(*lst)->next);
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
av = token_to_argv(node->data.cmd.wordlist, 1);
|
||||
i = 0;
|
||||
while (av[i])
|
||||
{
|
||||
if (ft_strcmp(av[i], ((char **)exec->case_pattern)[0]) == 0)
|
||||
{
|
||||
exec->attrs |= EXEC_CASE_BRANCH;
|
||||
ft_exec(&(*ast)->right);
|
||||
break ;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_command.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 16:19:31 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
static char **token_to_argv(t_astnode *node)
|
||||
{
|
||||
char **my_tab;
|
||||
int index;
|
||||
char **expand;
|
||||
char **content;
|
||||
t_ld *ld;
|
||||
|
||||
if (node->type == TK_COMMAND)
|
||||
{
|
||||
ld = node->data.token;
|
||||
my_tab = NULL;
|
||||
while (ld)
|
||||
{
|
||||
content = ld->content;
|
||||
if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2], 1)))
|
||||
{
|
||||
index = -1;
|
||||
while (expand[++index])
|
||||
my_tab = ft_sstradd(my_tab, expand[index]);
|
||||
ft_tabdel(&expand);
|
||||
}
|
||||
ld = ld->next;
|
||||
}
|
||||
return (my_tab);
|
||||
}
|
||||
else if (node->type == TK_SUBSHELL)
|
||||
return (ft_sstrdup(node->data.sstr));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int exec_command(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_process *p;
|
||||
t_job *job;
|
||||
|
||||
node = (*ast)->item;
|
||||
p = &data_singleton()->exec.process;
|
||||
job = &data_singleton()->exec.job;
|
||||
p->av = token_to_argv(node);
|
||||
process_setexec(node->type, p);
|
||||
if (!(launch_process(p)))
|
||||
{
|
||||
job_addprocess(p);
|
||||
if (IS_PIPEEND(p->attributes))
|
||||
{
|
||||
JOB_IS_FG(job->attributes) ?
|
||||
put_job_in_foreground(job, 0):
|
||||
put_job_in_background(job, 0);
|
||||
job->pgid = 0;
|
||||
}
|
||||
}
|
||||
process_reset(p);
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,27 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_redir.c :+: :+: :+: */
|
||||
/* exec_elif.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 15:24:11 by jhalford ### ########.fr */
|
||||
/* Created: 2017/02/06 18:08:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/04 17:45:29 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_redir(t_btree **ast)
|
||||
int exec_elif(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_process *p;
|
||||
t_exec *exec;
|
||||
|
||||
p = &data_singleton()->exec.process;
|
||||
node = (*ast)->item;
|
||||
node->data.redir.type = node->type;
|
||||
ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir)));
|
||||
exec = &data_singleton()->exec;
|
||||
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||
return (0);
|
||||
ft_exec(&(*ast)->left);
|
||||
btree_delone(ast, &ast_free);
|
||||
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
|
||||
{
|
||||
exec->attrs |= EXEC_IF_BRANCH;
|
||||
ft_exec(&(*ast)->right);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,23 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* process_resetfds.c :+: :+: :+: */
|
||||
/* exec_else.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/07 17:39:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 17:50:52 by jhalford ### ########.fr */
|
||||
/* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/04 18:06:55 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void process_resetfds(void)
|
||||
int exec_else(t_btree **ast)
|
||||
{
|
||||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
dup2(exec->fd0save, 0);
|
||||
dup2(exec->fd1save, 1);
|
||||
dup2(exec->fd2save, 2);
|
||||
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||
return (0);
|
||||
exec->attrs |= EXEC_IF_BRANCH;
|
||||
ft_exec(&(*ast)->left);
|
||||
return (0);
|
||||
}
|
||||
39
42sh/src/exec/exec_leaf.c
Normal file
39
42sh/src/exec/exec_leaf.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_leaf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 20:31:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_leaf(t_btree **ast)
|
||||
{
|
||||
t_process p;
|
||||
t_job *job;
|
||||
|
||||
job = &data_singleton()->exec.job;
|
||||
if (set_process(&p, *ast))
|
||||
return (1);
|
||||
if (!(launch_process(&p)))
|
||||
{
|
||||
DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
|
||||
job_addprocess(&p);
|
||||
if (IS_PIPEEND(p))
|
||||
{
|
||||
if (JOB_IS_FG(job->attrs))
|
||||
put_job_in_foreground(job, 0);
|
||||
else
|
||||
put_job_in_background(job, 0);
|
||||
job->pgid = 0;
|
||||
}
|
||||
}
|
||||
if (p.fdout != STDOUT)
|
||||
close(p.fdout);
|
||||
return (0);
|
||||
}
|
||||
77
42sh/src/exec/exec_math.c
Normal file
77
42sh/src/exec/exec_math.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_math.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 16:00:24 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int get_math(char *stream, char **var, char **value, char **operator)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
*var = ft_strduptr(stream, &ft_isalpha);
|
||||
temp = ft_sstrstr(data_singleton()->env, *var);
|
||||
if (temp)
|
||||
{
|
||||
temp += ft_strlenchr(temp, '=') + 1;
|
||||
*value = ft_strdup(temp);
|
||||
if (!(ft_stris(*value, &ft_isdigit)))
|
||||
{
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
*value = ft_itoa(0);
|
||||
stream += ft_strlen(*var);
|
||||
*operator = ft_strdup(stream);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int do_math(char **value, char *operator)
|
||||
{
|
||||
long ope1;
|
||||
long ope2;
|
||||
|
||||
ope1 = ft_atoi(*value);
|
||||
if (operator[2])
|
||||
ope2 = ft_atoi(&operator[2]);
|
||||
else
|
||||
ope2 = 0;
|
||||
if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0)
|
||||
ope1 = 0;
|
||||
else
|
||||
{
|
||||
ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1;
|
||||
ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1;
|
||||
ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1;
|
||||
ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1;
|
||||
ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1;
|
||||
}
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(ope1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int exec_math(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
char **av;
|
||||
char *var;
|
||||
char *value;
|
||||
char *operator;
|
||||
|
||||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.wordlist, 1);
|
||||
get_math(av[0], &var, &value, &operator);
|
||||
do_math(&value, operator);
|
||||
builtin_setenv("setenv", (char *[]){var, value, 0}, data_singleton()->local_var);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,32 +6,41 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/02 18:10:21 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 15:18:49 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_or_if(t_btree **ast)
|
||||
{
|
||||
t_data *data;
|
||||
/* t_data *data; */
|
||||
t_exec *exec;
|
||||
|
||||
data = data_singleton();
|
||||
if (data->exec.aol_status == NULL
|
||||
|| (data->exec.aol_search == TK_AND_IF
|
||||
&& *data->exec.aol_status == '0')
|
||||
|| (data->exec.aol_search == TK_OR_IF
|
||||
&& *data->exec.aol_status != '0'))
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
data->exec.aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->exec.aol_search = TK_OR_IF;
|
||||
if (*data->exec.aol_status != '0'
|
||||
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND)
|
||||
ft_exec(&(*ast)->right);
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
btree_delone(ast, &ast_free);
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_OR_IF);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs &= ~EXEC_AND_IF;
|
||||
exec->attrs = EXEC_OR_IF;
|
||||
ft_exec(&(*ast)->right);
|
||||
|
||||
/* data = data_singleton(); */
|
||||
/* if (data->exec.aol_status == NULL */
|
||||
/* || (data->exec.aol_search == TK_AND_IF */
|
||||
/* && *data->exec.aol_status == '0') */
|
||||
/* || (data->exec.aol_search == TK_OR_IF */
|
||||
/* && *data->exec.aol_status != '0')) */
|
||||
/* { */
|
||||
/* ft_exec(&(*ast)->left); */
|
||||
/* data->exec.aol_status = ft_getenv(data->env, "?"); */
|
||||
/* } */
|
||||
/* data->exec.aol_search = TK_OR_IF; */
|
||||
/* if (*data->exec.aol_status != '0' */
|
||||
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
|
||||
/* ft_exec(&(*ast)->right); */
|
||||
/* data->exec.aol_status = NULL; */
|
||||
/* data->exec.aol_search = 0; */
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,43 +6,20 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 14:36:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/03 16:27:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_pipe(t_btree **ast)
|
||||
{
|
||||
int fds[2];
|
||||
int start;
|
||||
t_data *data;
|
||||
t_process *p;
|
||||
t_exec *exec;
|
||||
|
||||
data = data_singleton();
|
||||
p = &data_singleton()->exec.process;
|
||||
pipe(fds);
|
||||
/* DG("pipe %i->%i", fds[PIPE_WRITE], fds[PIPE_READ]); */
|
||||
p->fdout = fds[PIPE_WRITE];
|
||||
start = IS_PIPESTART(p->attributes);
|
||||
p->toclose = fds[PIPE_READ];
|
||||
|
||||
p->attributes &= ~PROCESS_PIPEEND;
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_PIPE);
|
||||
ft_exec(&(*ast)->left);
|
||||
p->attributes &= ~PROCESS_PIPESTART;
|
||||
|
||||
p->toclose = STDIN;
|
||||
close(fds[PIPE_WRITE]);
|
||||
p->fdout = STDOUT;
|
||||
p->fdin = fds[PIPE_READ];
|
||||
|
||||
p->attributes |= PROCESS_PIPEEND;
|
||||
ft_exec(&(*ast)->right);
|
||||
if (start)
|
||||
p->attributes |= PROCESS_PIPESTART;
|
||||
|
||||
close(fds[PIPE_READ]);
|
||||
p->fdin = STDIN;
|
||||
btree_delone(ast, &ast_free);
|
||||
/* btree_delone(ast, &ast_free); */
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_cleanup.c :+: :+: :+: */
|
||||
/* exec_reset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 14:42:42 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/09 21:50:38 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 14:45:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
extern char **environ;
|
||||
extern char PC;
|
||||
extern char *UP;
|
||||
extern char *BC;
|
||||
|
||||
void ft_cleanup(void)
|
||||
int exec_reset(void)
|
||||
{
|
||||
struct termios term;
|
||||
t_exec *exec;
|
||||
|
||||
DG("cleanup. char * UP at %p", UP);
|
||||
DG("cleanup. char * BC at %p", BC);
|
||||
if (tcgetattr(0, &term) == -1)
|
||||
return ;
|
||||
term.c_lflag |= ICANON | ISIG | ECHO;
|
||||
if (tcsetattr(0, TCSANOW, &term) == -1)
|
||||
return ;
|
||||
exec = &data_singleton()->exec;
|
||||
exec->fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC);
|
||||
exec->fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
||||
exec->fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
||||
exec->op_stack = NULL;
|
||||
exec->fdin = STDIN;
|
||||
exec->attrs = 0;
|
||||
exec->job.id = 0;
|
||||
exec->job.pgid = 0;
|
||||
exec->job.attrs = 0;
|
||||
exec->job.first_process = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,16 +6,20 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/12 18:00:21 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 16:41:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
int exec_semi(t_btree **ast)
|
||||
{
|
||||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_SEMI);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs &= ~EXEC_AOL_MASK;
|
||||
ft_exec(&(*ast)->right);
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
35
42sh/src/exec/exec_var.c
Normal file
35
42sh/src/exec/exec_var.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_var.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 18:37:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int set_var(char *stream, char **var, char **value)
|
||||
{
|
||||
*var = ft_strdupchr(stream, '=');
|
||||
stream += ft_strlenchr(stream, '=') + 1;
|
||||
*value = ft_strdup(stream);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int exec_var(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
char **av;
|
||||
char *var;
|
||||
char *value;
|
||||
|
||||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.token, 1);
|
||||
set_var(av[0], &var, &value);
|
||||
builtin_setenv("setenv", (char*[]){var, value, 0}, data_singleton()->local_var);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,13 +6,16 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 22:54:19 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 16:58:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int fd_is_valid(int fd)
|
||||
int fd_is_valid(int fd, int has_flag)
|
||||
{
|
||||
return (fcntl(fd, F_GETFD) != -1 || errno != EBADF);
|
||||
int flags;
|
||||
|
||||
flags = fcntl(fd, F_GETFD);
|
||||
return ((flags != -1 || errno != EBADF) && flags & has_flag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,21 +6,32 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 15:27:19 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/08 11:57:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
#include "minishell.h"
|
||||
|
||||
t_execmap g_execmap[] =
|
||||
t_itof g_execmap[] =
|
||||
{
|
||||
{TK_AND_IF, &exec_and_if},
|
||||
{TK_OR_IF, &exec_or_if},
|
||||
{TK_NEWLINE, &exec_semi},
|
||||
{TK_SEMI, &exec_semi},
|
||||
{TK_AMP, &exec_ampersand},
|
||||
{TK_AND_IF, &exec_and_if},
|
||||
{TK_OR_IF, &exec_or_if},
|
||||
{TK_PIPE, &exec_pipe},
|
||||
{TK_REDIR, &exec_redir},
|
||||
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
||||
{TK_WHILE, &exec_leaf},
|
||||
{TK_IF, &exec_leaf},
|
||||
{TK_ELIF, &exec_elif},
|
||||
{TK_ELSE, &exec_else},
|
||||
{TK_UNTIL, &exec_leaf},
|
||||
{TK_FOR, &exec_leaf},
|
||||
{TK_CASE, &exec_leaf},
|
||||
{TK_PAREN_OPEN, &exec_case_branch},
|
||||
{TK_ASSIGNEMENT_WORD, &exec_var},
|
||||
{MATH, &exec_math},
|
||||
{SUBSHELL, &exec_leaf},
|
||||
{CMD, &exec_leaf},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
|
|
@ -33,10 +44,10 @@ int ft_exec(t_btree **ast)
|
|||
if (!*ast)
|
||||
return (0);
|
||||
item = (*ast)->item;
|
||||
while (g_execmap[i].type)
|
||||
while (g_execmap[i].id)
|
||||
{
|
||||
if (item->type & g_execmap[i].type)
|
||||
(*g_execmap[i].f)(ast);
|
||||
if (item->type == g_execmap[i].id)
|
||||
return ((*g_execmap[i].f)(ast));
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
27
42sh/src/exec/is_function.c
Normal file
27
42sh/src/exec/is_function.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* is_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_btree *is_function(t_process *p)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = data_singleton()->lst_func;
|
||||
while (tmp)
|
||||
{
|
||||
if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0]))
|
||||
return (btree_map(p->data.subshell.content, node_copy));
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue