merge resolved
This commit is contained in:
commit
e708ce1e16
166 changed files with 5157 additions and 1690 deletions
1
42sh/.gitignore
vendored
1
42sh/.gitignore
vendored
|
|
@ -3,6 +3,7 @@ minishell
|
|||
42sh
|
||||
out
|
||||
debug
|
||||
.42sh_history
|
||||
*.dSYM
|
||||
.script.sh.swp
|
||||
*.swp
|
||||
|
|
|
|||
299
42sh/Makefile
299
42sh/Makefile
|
|
@ -1,90 +1,251 @@
|
|||
NAME = minishell
|
||||
CC = gcc
|
||||
TAGFILE = .tags
|
||||
#* ************************************************************************** *#
|
||||
#* *#
|
||||
#* ::: :::::::: *#
|
||||
#* Makefile :+: :+: :+: *#
|
||||
#* +:+ +:+ +:+ *#
|
||||
#* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ *#
|
||||
#* +#+#+#+#+#+ +#+ *#
|
||||
#* Created: 2016/08/29 21:32:58 by wescande #+# #+# *#
|
||||
#* Updated: 2016/09/27 20:14:55 by wescande ### ########.fr *#
|
||||
#* *#
|
||||
#* ************************************************************************** *#
|
||||
|
||||
D_SRC = src
|
||||
F_SRC := $(shell find $(D_SRC) -type f -regex ".*\.c$$")
|
||||
NAME = 42sh
|
||||
|
||||
D_OBJ = obj
|
||||
F_OBJ = $(notdir $(F_SRC:.c=.o))
|
||||
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
||||
CC = gcc
|
||||
FLAGS = -Wall -Wextra -Werror
|
||||
D_FLAGS = -g
|
||||
|
||||
D_INC = includes libft/includes
|
||||
F_INC := $(shell find $(D_INC) -type f -regex ".*\.h$$")
|
||||
O_INC = $(addprefix -I, $(D_INC))
|
||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||
|
||||
D_SER = libft/
|
||||
O_SER = $(addprefix -L, $(D_SER))
|
||||
LIBFT_DIR = libft/
|
||||
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
||||
LIBFT_INC = $(LIBFT_DIR)includes/
|
||||
|
||||
D_LIB = ft ncurses
|
||||
O_LIB = $(addprefix -l, $(D_LIB))
|
||||
LIBS = -ltermcap
|
||||
|
||||
W_FLAGS = -Wall -Wextra -Werror
|
||||
D_FLAGS = -g
|
||||
SRC_DIR = src/
|
||||
INC_DIR = includes/
|
||||
OBJ_DIR = objs/
|
||||
|
||||
MKDIR = mkdir -p
|
||||
RM = /bin/rm -rf
|
||||
SRC_BASE = \
|
||||
builtin/bt_read_get.c\
|
||||
builtin/bt_read_parse.c\
|
||||
builtin/bt_read_term.c\
|
||||
builtin/builtin_cd.c\
|
||||
builtin/builtin_echo.c\
|
||||
builtin/builtin_env.c\
|
||||
builtin/builtin_exit.c\
|
||||
builtin/builtin_read.c\
|
||||
builtin/builtin_setenv.c\
|
||||
builtin/builtin_unsetenv.c\
|
||||
builtin/is_builtin.c\
|
||||
exec/ast_free.c\
|
||||
exec/exec_ampersand.c\
|
||||
exec/exec_and_if.c\
|
||||
exec/exec_command.c\
|
||||
exec/exec_dgreat.c\
|
||||
exec/exec_great.c\
|
||||
exec/exec_less.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
exec/exec_semi.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
exec/launch_process.c\
|
||||
exec/process_redirect.c\
|
||||
exec/process_reset.c\
|
||||
exec/process_setexec.c\
|
||||
exec/process_setgroup.c\
|
||||
exec/process_setsig.c\
|
||||
exec/set_exitstatus.c\
|
||||
glob/dir_glob.c\
|
||||
glob/expand_brace.c\
|
||||
glob/expand_esc.c\
|
||||
glob/ft_strsplit_esc.c\
|
||||
glob/ft_strsplit_spe.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_del.c\
|
||||
glob/lib_perso/ft_ld_front.c\
|
||||
glob/lib_perso/ft_ld_new.c\
|
||||
glob/lib_perso/ft_ld_order.c\
|
||||
glob/lib_perso/ft_ld_pushback.c\
|
||||
glob/lib_perso/ft_ld_pushfront.c\
|
||||
glob/lib_perso/ft_ld_reverse.c\
|
||||
glob/lib_perso/ft_ld_size.c\
|
||||
glob/lib_perso/ft_ld_swap.c\
|
||||
glob/lib_perso/ft_ld_to_tab.c\
|
||||
glob/lib_perso/ft_strjoinf.c\
|
||||
glob/lib_perso/ft_tabdel.c\
|
||||
glob/lib_perso/ft_tablen.c\
|
||||
glob/match_pattern.c\
|
||||
job-control/builtin_bg.c\
|
||||
job-control/builtin_fg.c\
|
||||
job-control/builtin_jobs.c\
|
||||
job-control/do_job_notification.c\
|
||||
job-control/job_addprocess.c\
|
||||
job-control/job_cmp_id.c\
|
||||
job-control/job_format.c\
|
||||
job-control/job_format_head.c\
|
||||
job-control/job_free.c\
|
||||
job-control/job_getprocess.c\
|
||||
job-control/job_getrank.c\
|
||||
job-control/job_is_completed.c\
|
||||
job-control/job_is_stopped.c\
|
||||
job-control/job_kill_all.c\
|
||||
job-control/job_notify_change.c\
|
||||
job-control/job_notify_new.c\
|
||||
job-control/job_remove.c\
|
||||
job-control/job_run.c\
|
||||
job-control/job_update_id.c\
|
||||
job-control/job_update_status.c\
|
||||
job-control/job_wait.c\
|
||||
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/put_job_in_background.c\
|
||||
job-control/put_job_in_foreground.c\
|
||||
job-control/sigchld_handler.c\
|
||||
job-control/sigint_handler.c\
|
||||
job-control/sigtstp_handler.c\
|
||||
job-control/sigttin_handler.c\
|
||||
job-control/sigttou_handler.c\
|
||||
lexer/command_getoutput.c\
|
||||
lexer/ft_lexer.c\
|
||||
lexer/ft_post_tokenize.c\
|
||||
lexer/ft_tokenize.c\
|
||||
lexer/get_lexer_state.c\
|
||||
lexer/lexer_backslash.c\
|
||||
lexer/lexer_default.c\
|
||||
lexer/lexer_delim.c\
|
||||
lexer/lexer_dquote.c\
|
||||
lexer/lexer_great.c\
|
||||
lexer/lexer_greatand.c\
|
||||
lexer/lexer_less.c\
|
||||
lexer/lexer_lessand.c\
|
||||
lexer/lexer_number.c\
|
||||
lexer/lexer_quote.c\
|
||||
lexer/lexer_sep.c\
|
||||
lexer/lexer_special.c\
|
||||
lexer/lexer_var.c\
|
||||
lexer/lexer_word.c\
|
||||
lexer/reduce_bquotes.c\
|
||||
lexer/reduce_parens.c\
|
||||
lexer/token_append.c\
|
||||
lexer/token_cmp_type.c\
|
||||
lexer/token_expand_var.c\
|
||||
lexer/token_free.c\
|
||||
lexer/token_init.c\
|
||||
lexer/token_print.c\
|
||||
line-editing/builtin_history.c\
|
||||
line-editing/check_backslash.c\
|
||||
line-editing/control_c_and_d.c\
|
||||
line-editing/copy_cut_paste.c\
|
||||
line-editing/ft_split_whitespaces.c\
|
||||
line-editing/get_touch.c\
|
||||
line-editing/get_touch_toolz.c\
|
||||
line-editing/get_touch_toolz_2.c\
|
||||
line-editing/heredoc.c\
|
||||
line-editing/history.c\
|
||||
line-editing/history_parsing.c\
|
||||
line-editing/history_parsing_toolz.c\
|
||||
line-editing/history_parsing_toolz_2.c\
|
||||
line-editing/list_toolz.c\
|
||||
line-editing/move_to_line.c\
|
||||
line-editing/print_and_del.c\
|
||||
line-editing/prompt.c\
|
||||
line-editing/quotes_gest.c\
|
||||
line-editing/reader.c\
|
||||
line-editing/readline.c\
|
||||
line-editing/surch_in_history.c\
|
||||
line-editing/tool_line.c\
|
||||
line-editing/tool_line_2.c\
|
||||
line-editing/toolz.c\
|
||||
line-editing/toolz2.c\
|
||||
line-editing/toolz_parseur.c\
|
||||
line-editing/toolz_termcaps.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/main.c\
|
||||
main/shell_exit.c\
|
||||
main/shell_get_avdata.c\
|
||||
main/shell_get_opts.c\
|
||||
main/shell_init.c\
|
||||
main/sig_handler.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_separator.c\
|
||||
parser/parse_subshell.c\
|
||||
parser/parse_word.c
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||
NB = $(words $(SRC_BASE))
|
||||
INDEX = 0
|
||||
|
||||
all: $(NAME)
|
||||
all :
|
||||
@make -j $(NAME)
|
||||
|
||||
$(NAME): libft/libft.a $(DF_OBJ)
|
||||
$(CC) $(O_INC) $(O_SER) $(O_LIB) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
||||
@$(CC) $(FLAGS) $(D_FLAGS) \
|
||||
-I $(INC_DIR) \
|
||||
-I $(LIBFT_INC) \
|
||||
$(LIBS) \
|
||||
$(LIBFT_LIB) $(OBJS) \
|
||||
-o $(NAME)
|
||||
@echo "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K"
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/main/%.c includes/minishell.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
$(LIBFT_LIB):
|
||||
@make -j -C $(LIBFT_DIR)
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/builtin/%.c includes/minishell.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
$(OBJ_DIR) :
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
@mkdir -p $(dir $(OBJS))
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/minishell-exec/%.c includes/minishell.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||
@$(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\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) "$@"
|
||||
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||
-I $(INC_DIR)\
|
||||
-I $(LIBFT_INC)
|
||||
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/line-editing/%.c includes/ft_readline.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
clean: cleanlib
|
||||
@rm -rf $(OBJ_DIR)
|
||||
@echo "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K"
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/lexer/%.c includes/lexer.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
cleanlib:
|
||||
@make -C $(LIBFT_DIR) clean
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/parser/%.c includes/parser.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
fclean: clean fcleanlib
|
||||
@rm -f $(NAME)
|
||||
@echo "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K"
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/exec/%.c includes/exec.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
fcleanlib: cleanlib
|
||||
@make -C $(LIBFT_DIR) fclean
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/job-control/%.c includes/job_control.h
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
re: fclean all
|
||||
|
||||
libft/libft.a: libft/src/*/*.c
|
||||
@echo "libft/libft.a"
|
||||
@$(MAKE) -C libft 2>/dev/null
|
||||
relib: fcleanlib $(LIBFT_LIB)
|
||||
|
||||
libft:
|
||||
@echo "libft"
|
||||
@$(MAKE) -C libft 2>/dev/null
|
||||
.PHONY : fclean clean re relib cleanlib fcleanlib
|
||||
|
||||
clean:
|
||||
$(RM) $(D_OBJ)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
@$(MAKE) fclean -C libft/ 2>/dev/null
|
||||
|
||||
re: fclean all
|
||||
-include $(OBJS:.o=.d)
|
||||
|
|
|
|||
54
42sh/includes/btree.h
Normal file
54
42sh/includes/btree.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* btree.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/05 11:53:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BTREE_H
|
||||
# define BTREE_H
|
||||
|
||||
# include "libft.h"
|
||||
|
||||
struct s_btree
|
||||
{
|
||||
void *item;
|
||||
size_t content_size;
|
||||
struct s_btree *left;
|
||||
struct s_btree *right;
|
||||
};
|
||||
|
||||
struct s_printdata
|
||||
{
|
||||
int is_left;
|
||||
int offset;
|
||||
int depth;
|
||||
int left;
|
||||
int right;
|
||||
};
|
||||
|
||||
typedef struct s_btree t_btree;
|
||||
typedef struct s_printdata t_printdata;
|
||||
|
||||
t_btree *btree_create_node(void const *item, size_t content_size);
|
||||
void btree_insert_data(
|
||||
t_btree **root,
|
||||
void *item,
|
||||
size_t content_size,
|
||||
int (*cmpf)(void *, void *));
|
||||
void *btree_search_item(t_btree *root,
|
||||
void *data_ref, int (*cmpf)(void *, void *));
|
||||
int btree_level_count(t_btree *root);
|
||||
void btree_apply_prefix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_apply_infix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_apply_suffix(t_btree *root, void (*applyf)(void *));
|
||||
void btree_print(int fd, t_btree *tree, char *(*printer)(void *));
|
||||
void btree_del(t_btree **root, void (*del)(void *, size_t));
|
||||
void btree_delone(t_btree **root, void (*del)(void *, size_t));
|
||||
|
||||
#endif
|
||||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* builtin.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/25 15:49:26 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:44:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
# include "types.h"
|
||||
# include "libft.h"
|
||||
# include "builtin_read.h"
|
||||
|
||||
t_execf *is_builtin(t_process *p);
|
||||
int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
||||
|
|
@ -26,5 +27,6 @@ int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]);
|
|||
int builtin_jobs(const char *path, char *const av[], char *const envp[]);
|
||||
int builtin_fg(const char *path, char *const av[], char *const envp[]);
|
||||
int builtin_bg(const char *path, char *const av[], char *const envp[]);
|
||||
int builtin_history(const char *path, char *const av[], char *const envp[]);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
71
42sh/includes/builtin_read.h
Normal file
71
42sh/includes/builtin_read.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_read.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/27 18:56:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUILTIN_READ_H
|
||||
# define BUILTIN_READ_H
|
||||
|
||||
# include "types.h"
|
||||
# include "libft.h"
|
||||
# include "builtin.h"
|
||||
# include "minishell.h"
|
||||
|
||||
# define READ_OPT_LA (1 << 0)
|
||||
# define READ_OPT_LD (1 << 1)
|
||||
# define READ_OPT_LE (1 << 2)
|
||||
# define READ_OPT_LI (1 << 3)
|
||||
# define READ_OPT_LN (1 << 4)
|
||||
# define READ_OPT_UN (1 << 5)
|
||||
# define READ_OPT_LP (1 << 6)
|
||||
# define READ_OPT_LR (1 << 7)
|
||||
# define READ_OPT_LS (1 << 8)
|
||||
# define READ_OPT_LT (1 << 9)
|
||||
# define READ_OPT_LU (1 << 10)
|
||||
|
||||
typedef struct s_read t_read;
|
||||
typedef struct s_readopt t_readopt;
|
||||
|
||||
struct s_read
|
||||
{
|
||||
t_flag opts;
|
||||
char delim;
|
||||
int nchars;
|
||||
char *prompt;
|
||||
int timeout;
|
||||
int fd;
|
||||
char **names;
|
||||
char *input;
|
||||
};
|
||||
|
||||
struct s_readopt
|
||||
{
|
||||
char letter;
|
||||
t_flag flag;
|
||||
int (*get)(t_read *data, char *arg);
|
||||
};
|
||||
|
||||
extern t_readopt g_readtab[];
|
||||
|
||||
int builtin_read(const char *path, char *const av[], char *const envp[]);
|
||||
|
||||
int bt_read_init(t_read *data, char **av);
|
||||
|
||||
struct termios bt_read_term(int init);
|
||||
int bt_read_terminit(t_read *data);
|
||||
int bt_read_exit(t_read *data);
|
||||
|
||||
int bt_read_getdelim(t_read *data, char *arg);
|
||||
int bt_read_getnchars(t_read *data, char *arg);
|
||||
int bt_read_getprompt(t_read *data, char *arg);
|
||||
int bt_read_gettimeout(t_read *data, char *arg);
|
||||
int bt_read_getfd(t_read *data, char *arg);
|
||||
|
||||
#endif
|
||||
56
42sh/includes/color.h
Normal file
56
42sh/includes/color.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/09 22:09:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef COLOR_H
|
||||
# define COLOR_H
|
||||
# include "libft.h"
|
||||
|
||||
struct s_color
|
||||
{
|
||||
char fg[7];
|
||||
char bg[7];
|
||||
};
|
||||
|
||||
typedef struct s_color t_color;
|
||||
|
||||
# define FG_DEFAULT "\x1b[0m"
|
||||
# define ON_BOLD "\x1b[1m"
|
||||
|
||||
# define ON_UNDERLINED "\x1b[4m"
|
||||
# define ON_INVERTED "\x1b[7m"
|
||||
|
||||
# define FG_BLACK "\x1b[30m"
|
||||
# define FG_RED "\x1b[31m"
|
||||
# define FG_GREEN "\x1b[32m"
|
||||
# define FG_YELLOW "\x1b[33m"
|
||||
# define FG_BLUE "\x1b[34m"
|
||||
# define FG_MAGENTA "\x1b[35m"
|
||||
# define FG_CYAN "\x1b[36m"
|
||||
|
||||
# define BG_BLACK "\x1b[40m"
|
||||
# define BG_RED "\x1b[41m"
|
||||
# define BG_GREEN "\x1b[42m"
|
||||
# define BG_YELLOW "\x1b[43m"
|
||||
# define BG_BLUE "\x1b[44m"
|
||||
# define BG_MAGENTA "\x1b[45m"
|
||||
# define BG_CYAN "\x1b[46m"
|
||||
# define BG_DEFAULT "\x1b[49m"
|
||||
|
||||
# define FBG_DEFAULT "\x1b[49m\x1b[20m"
|
||||
|
||||
void ft_color_reset(void);
|
||||
void ft_color_set(t_color color);
|
||||
|
||||
void ft_color_mk(t_color *color, char fg[7], char bg[7]);
|
||||
void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]);
|
||||
|
||||
#endif
|
||||
35
42sh/includes/dlst.h
Normal file
35
42sh/includes/dlst.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dlst.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:21:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DLST_H
|
||||
# define DLST_H
|
||||
|
||||
struct s_dlist
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_dlist *next;
|
||||
struct s_dlist *prev;
|
||||
};
|
||||
|
||||
typedef struct s_dlist t_dlist;
|
||||
|
||||
void ft_dlstadd_after(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlstadd_before(t_dlist **alst, t_dlist *new);
|
||||
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t));
|
||||
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t));
|
||||
int ft_dlstsize(t_dlist *list);
|
||||
t_dlist *ft_dlstnew(void const *content, size_t content_size);
|
||||
t_dlist *ft_dlstlast(t_dlist *list);
|
||||
char *ft_dlsttostr(t_dlist *list);
|
||||
|
||||
#endif
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART)
|
||||
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND)
|
||||
# define IS_PIPESINGLE(a) (a & (PROCESS_PIPESTART | PROCESS_PIPEEND))
|
||||
|
||||
# define SCRIPT_LOOP (1 << 0)
|
||||
|
||||
|
|
@ -48,6 +49,7 @@ struct s_process
|
|||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int toclose;
|
||||
int status;
|
||||
t_flag attributes;
|
||||
t_flag script;
|
||||
|
|
@ -91,8 +93,9 @@ int exec_list(t_btree **ast);
|
|||
|
||||
int launch_process(t_process *p);
|
||||
int process_setexec(t_type type, t_process *p);
|
||||
int process_setgroup(t_process *p);
|
||||
int process_setgroup(t_process *p, pid_t pid);
|
||||
int process_redirect(t_process *p);
|
||||
void process_setsig(void);
|
||||
void process_free(void *content, size_t content_size);
|
||||
void process_reset(void);
|
||||
|
||||
|
|
@ -101,7 +104,7 @@ void fd_reset(void);
|
|||
|
||||
char *ft_findexec(char *path, char *file);
|
||||
|
||||
void set_exitstatus(int status);
|
||||
void set_exitstatus(int status, int override);
|
||||
|
||||
void ast_free(void *data, size_t content_size);
|
||||
|
||||
|
|
|
|||
81
42sh/includes/ft_printf.h
Normal file
81
42sh/includes/ft_printf.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ftprintf.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/15 15:29:22 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
# include "libft.h"
|
||||
# include <stdarg.h>
|
||||
# define ALL_FLAGS "#0- +"
|
||||
# define ALL_CONVERSIONS "sSpdDioOuUxXcCb"
|
||||
|
||||
typedef struct s_fmt t_fmt;
|
||||
typedef struct s_conv t_conv;
|
||||
typedef char *(t_converter)(t_fmt *fmt, va_list ap);
|
||||
typedef void (t_pad_func)(char *str, t_fmt *fmt);
|
||||
|
||||
struct s_conv
|
||||
{
|
||||
char id;
|
||||
char allowed_flags[6];
|
||||
char base[20];
|
||||
t_converter *converter;
|
||||
t_pad_func *sharp_func;
|
||||
};
|
||||
|
||||
struct s_fmt
|
||||
{
|
||||
char flags[6];
|
||||
int width;
|
||||
int precision;
|
||||
char modifier[3];
|
||||
char conversion;
|
||||
int valid;
|
||||
t_conv conv;
|
||||
};
|
||||
|
||||
int ft_vdprintf(int fd, const char *format, va_list ap);
|
||||
int ft_fmtcalc(char **final, char **str, va_list ap);
|
||||
|
||||
extern t_conv g_convs[];
|
||||
|
||||
t_fmt *ft_fmt_init(void);
|
||||
void ft_fmt_print(t_fmt *fmt);
|
||||
void ft_printf_color(int fd, char **final, char **str);
|
||||
|
||||
t_fmt *ft_printf_parse(char **format, va_list ap);
|
||||
void ft_printf_parse_flags(t_fmt *fmt, char **format);
|
||||
void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap);
|
||||
void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap);
|
||||
void ft_printf_parse_modifiers(t_fmt *fmt, char **format);
|
||||
|
||||
char *ft_transform(t_fmt *fmt, va_list ap);
|
||||
|
||||
void ft_fmt_error_conv(char conv);
|
||||
void ft_fmt_error_mod_conv(char *mod, char conv);
|
||||
void ft_fmt_error_flag_conv(char flag, char conv);
|
||||
void ft_fmt_error_flag_flag(char flag1, char flag2);
|
||||
|
||||
void ft_fmt_simplify(t_fmt *fmt);
|
||||
int ft_fmt_validate_conv(t_fmt *fmt);
|
||||
void ft_fmt_validate_flags(t_fmt *fmt);
|
||||
void ft_fmt_validate_mod(t_fmt *fmt);
|
||||
|
||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap);
|
||||
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap);
|
||||
char *ft_str_conversion(t_fmt *fmt, va_list ap);
|
||||
char *ft_char_conversion(t_fmt *fmt, va_list ap);
|
||||
|
||||
void ft_pad_sharp_o(char *str, t_fmt *fmt);
|
||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt);
|
||||
void ft_pad_left(char *str, t_fmt *fmt);
|
||||
void ft_pad_right(char *str, t_fmt *fmt);
|
||||
#endif
|
||||
|
|
@ -3,212 +3,145 @@
|
|||
/* ::: :::::::: */
|
||||
/* ft_readline.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 23:42:07 by ariard ### ########.fr */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/03 14:43:56 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_READLINE_H
|
||||
# define FT_READLINE_H
|
||||
|
||||
# include "libft.h"
|
||||
# include "ft_curs.h"
|
||||
# include <sys/ioctl.h>
|
||||
# include <termios.h>
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <term.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/xattr.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/types.h>
|
||||
# include <pwd.h>
|
||||
# include <grp.h>
|
||||
# include <uuid/uuid.h>
|
||||
# include <time.h>
|
||||
# include <dirent.h>
|
||||
# include <locale.h>
|
||||
|
||||
/*
|
||||
* Input-Key Mapping !!! LINUX Or MACOSX !!!
|
||||
*/
|
||||
# define FLECHE_HAUT 4283163
|
||||
# define FLECHE_BAS 4348699
|
||||
# define FLECHE_GAUCHE 4479771
|
||||
# define FLECHE_DROITE 4414235
|
||||
# define TOUCHE_DELETE 2117294875
|
||||
# define TOUCHE_CTRL_C 3
|
||||
# define TOUCHE_CTRL_D 4
|
||||
# define TOUCHE_CTRL_R 18
|
||||
# define TOUCHE_SUPPR 127
|
||||
# define TOUCHE_HOME 4741915
|
||||
# define TOUCHE_END 4610843
|
||||
# define TOUCHE_TAB 9
|
||||
# define TOUCHE_OPT_RIGHT 1130044187
|
||||
# define TOUCHE_OPT_LEFT 1146821403
|
||||
# define TOUCHE_OPT_UP 1096489755
|
||||
# define TOUCHE_OPT_DOWN 1113266971
|
||||
# define TOUCHE_OPT_V 10127586
|
||||
# define TOUCHE_OPT_C 42947
|
||||
# define TOUCHE_OPT_X 8948194
|
||||
# define TOUCHE_F5 892427035
|
||||
# define TOUCHE_F6 925981467
|
||||
|
||||
//# define LINUX
|
||||
# define MACOSX
|
||||
# include "ft_input.h"
|
||||
# define HIST 1
|
||||
|
||||
/*
|
||||
* Default offset for dynamic allocation
|
||||
*/
|
||||
# define ERROR_CNTL_R 1
|
||||
|
||||
# define RL_OFFSET 1024
|
||||
|
||||
/*
|
||||
* Readline possible prompt
|
||||
*/
|
||||
|
||||
# define RL_PROMPT_DEFAULT "$> "
|
||||
# define RL_PROMPT_ESC "> "
|
||||
# define RL_PROMPT_QUOTE "quote> "
|
||||
# define RL_PROMPT_DQUOTE "double quote> "
|
||||
|
||||
/*
|
||||
* Bitset manipulation : X is the bitset and Y is the bit to manipulate
|
||||
* IS : Is Y set in X
|
||||
* NOT : Is Y not set in X
|
||||
* SET : Set Y in X
|
||||
* UNSET : Unset Y from X
|
||||
*/
|
||||
|
||||
# define RL_IS(X, Y) (X & Y)
|
||||
# define RL_NOT(X, Y) (!RL_IS(X, Y))
|
||||
# define RL_SET(X, Y) (X |= Y)
|
||||
# define RL_UNSET(X, Y) (X &= ~Y)
|
||||
|
||||
/*
|
||||
* Possible bit for t_line.bitset
|
||||
*
|
||||
* FINISH : bit to terminate and flush the readline
|
||||
* STACK : bit to stack the current line and begin another one
|
||||
* INSERT : bit to toogle insert-mode/replace-mode
|
||||
* SELECT : bit to toogle extend-video-area-mode/clear-video-area-mode
|
||||
* ESC : bit to escape quoting and new line
|
||||
* QUOTE : bit to toogle quote-terminated-mode/quote-not-terminated-mode
|
||||
* DQUOTE : bit to toogle dquote-terminated-mode/dquote-not-terminated-mode
|
||||
* QUOTING : Regroup ESC, QUOTE and DQUOTE
|
||||
*/
|
||||
|
||||
# define RL_FINISH (1 << 0)
|
||||
# define RL_STACK (1 << 1)
|
||||
# define RL_INSERT (1 << 2)
|
||||
# define RL_SELECT (1 << 3)
|
||||
# define RL_ESC (1 << 4)
|
||||
# define RL_QUOTE (1 << 5)
|
||||
# define RL_DQUOTE (1 << 6)
|
||||
# define RL_QUOTING (RL_ESC | RL_QUOTE | RL_DQUOTE)
|
||||
|
||||
typedef struct s_data t_data;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_input t_input;
|
||||
typedef int (*t_input_function)(t_line *, long int);
|
||||
|
||||
/*
|
||||
* Interactive line data:
|
||||
*
|
||||
* bitset : global/local state and settings for readline
|
||||
* prompt : current prompt
|
||||
* input : destination buffer
|
||||
* pos : cursor position in the destination buffer
|
||||
* size : allocated size of the destination buffer
|
||||
* used : actual used size in the destination buffer
|
||||
* select : start position of the video (aka selected) area in the destination buffer
|
||||
* clipboard : duplication of the copied/cuted part of the destination buffer
|
||||
* stack : list of stacked line. (lines are stacked when a quoted (or escaped) new line appear)
|
||||
*/
|
||||
|
||||
struct s_line
|
||||
typedef struct s_list_history
|
||||
{
|
||||
char *str;
|
||||
struct s_list_history *prev;
|
||||
struct s_list_history *next;
|
||||
} t_list_history;
|
||||
|
||||
typedef struct s_line
|
||||
{
|
||||
int bitset;
|
||||
char *prompt;
|
||||
char *input;
|
||||
char *clipboard;
|
||||
int pos;
|
||||
int size;
|
||||
int used;
|
||||
int select;
|
||||
t_curs curs;
|
||||
t_list *stack;
|
||||
t_dlist *history;
|
||||
};
|
||||
char *copy_tmp;
|
||||
size_t pos;
|
||||
int prompt_size;
|
||||
int list_size;
|
||||
char opt;
|
||||
t_list_history *list_end;
|
||||
t_list_history *list_cur;
|
||||
t_list_history *list_beg;
|
||||
} t_line;
|
||||
|
||||
/*
|
||||
* Input data:
|
||||
* code : input identifier
|
||||
* function : input handler
|
||||
*/
|
||||
|
||||
struct s_input
|
||||
typedef struct s_key
|
||||
{
|
||||
long int code;
|
||||
t_input_function function;
|
||||
};
|
||||
int value;
|
||||
void (*f)(void);
|
||||
} t_key;
|
||||
|
||||
# include "minishell.h"
|
||||
extern t_key g_keys[];
|
||||
|
||||
/*
|
||||
* Readline setup/cleanup/teardown
|
||||
*/
|
||||
|
||||
int rl_setup(t_line *line);
|
||||
int rl_cleanup(t_line *line);
|
||||
void rl_teardown(t_line *line);
|
||||
int rl_set_termios(int input_mode);
|
||||
void ft_putnc(char c, int n);
|
||||
int ft_nbr_len(int nbr);
|
||||
void ft_puttermcaps(char *str);
|
||||
void ft_get_beggin_with_curs(char *str, size_t *pos);
|
||||
void ft_check_end_of_line(char *str, size_t pos);
|
||||
int ft_size_term(void);
|
||||
void ft_add_in_history_file(char *str);
|
||||
void ft_get_beggin(char *str, size_t *pos);
|
||||
void ft_get_next_str(char *str, size_t *pos);
|
||||
void ft_putall_current_str(char *str, size_t *pos);
|
||||
void ft_current_str(char *str, size_t pos);
|
||||
int ft_strlen_next(char *str, size_t pos);
|
||||
void ft_push_back_history(t_list_history **head, t_list_history *new);
|
||||
void ft_prompt(void);
|
||||
char *ft_remove_imput(char *str, size_t pos);
|
||||
char *ft_realloc_imput(char *str, int a, size_t pos);
|
||||
char *ft_strdupi(char const *s);
|
||||
char *ft_strndup(char const *s, int n);
|
||||
t_list_history *ft_create_history_list(char *str);
|
||||
char *ft_strdupi_w(char const *s);
|
||||
void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len);
|
||||
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||
long long ft_pow(int nbr, int power);
|
||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||
void ft_check_backslash(char **str);
|
||||
char *ft_strget_history(char *str);
|
||||
int ft_nb_last_line(char *str, size_t pos);
|
||||
int ft_put(int nb);
|
||||
|
||||
/*
|
||||
* Dynamic allocated buffer manipulation
|
||||
*/
|
||||
char *ft_read_stdin(void);
|
||||
void ft_end(void);
|
||||
void ft_home(void);
|
||||
void ft_move_right(void);
|
||||
void ft_move_left(void);
|
||||
void ft_up(void);
|
||||
void ft_down(void);
|
||||
void ft_buff_f6(void);
|
||||
void ft_control_d(void);
|
||||
void ft_control_c(void);
|
||||
void ft_del(void);
|
||||
void ft_suppr(void);
|
||||
void ft_print(int ret);
|
||||
void ft_surch_in_history(void);
|
||||
void ft_printall(void);
|
||||
void ft_history_down(void);
|
||||
void ft_history_up(void);
|
||||
void ft_found_next_word(void);
|
||||
void ft_found_prev_word(void);
|
||||
void ft_c(void);
|
||||
void ft_x(void);
|
||||
void ft_v(void);
|
||||
void ft_history_parsing(void);
|
||||
void ft_read_it(int input, size_t *pos, char **str);
|
||||
int ft_readline(void);
|
||||
|
||||
int input_maj(t_line *line, char *str, int size);
|
||||
int input_move(t_line *line, char *str, int size);
|
||||
void input_remove(t_line *line, int size);
|
||||
void ft_check_heredoc(char **str);
|
||||
void ft_check_quotes(char **s);
|
||||
|
||||
/*
|
||||
* Readline internal function
|
||||
*/
|
||||
|
||||
void rl_set_prompt(t_line *line);
|
||||
void rl_put_prompt(t_line *line);
|
||||
int rl_previous_word(t_line *line);
|
||||
int rl_next_word(t_line *line);
|
||||
int rl_clipboard_new(t_line *line);
|
||||
int rl_clipboard_new_cut(t_line *line);
|
||||
void rl_toogle_bitset(t_line *line, int set);
|
||||
int rl_finish(t_line *line);
|
||||
int rl_stack_line(t_line *line);
|
||||
int rl_merge_line(t_line *line);
|
||||
|
||||
/*
|
||||
* Realine display functions:
|
||||
*
|
||||
* reset_display : Redraw the interactive buffer and replace the cursor
|
||||
* based on t_line.input, t_line.pos and t_line.select .
|
||||
* reset_display_ante : Redraw before the cursor position.
|
||||
* reset_display_post : Redraw after the cursor position.
|
||||
*/
|
||||
|
||||
void rl_reset_display(t_line *line);
|
||||
void rl_reset_display_ante(t_line *line);
|
||||
void rl_reset_display_post(t_line *line);
|
||||
|
||||
/*
|
||||
* input handler functions
|
||||
*
|
||||
* An handler use curs_<utilities-function> to manipulate the cursor position
|
||||
* and recalc t_line.pos based on the cursor movement.
|
||||
*
|
||||
* An handler can also modify the content of the destination buffer.
|
||||
* If it do so, it must reset all display that appear
|
||||
* after the first index of that modification.
|
||||
* If t_line.pos is that index, rl_reset_display_post can simply do the work.
|
||||
*/
|
||||
|
||||
int rl_default_function(t_line *line, long int input); /* Not handled input */
|
||||
int rl_esc_function(t_line *line, long int input); /* Backslash */
|
||||
int rl_quote_function(t_line *line, long int input); /* Simple quote */
|
||||
int rl_dquote_function(t_line *line, long int input); /* Double quote */
|
||||
int rl_nl_function(t_line *line, long int input); /* New line */
|
||||
int rl_comp_function(t_line *line, long int input); /* Tabulation */
|
||||
int rl_left_function(t_line *line, long int input); /* Left move */
|
||||
int rl_right_function(t_line *line, long int input); /* Right move */
|
||||
int rl_wleft_function(t_line *line, long int input); /* Word left move */
|
||||
int rl_wright_function(t_line *line, long int input); /* Word right move */
|
||||
int rl_home_function(t_line *line, long int input); /* Home move */
|
||||
int rl_end_function(t_line *line, long int input); /* End move */
|
||||
int rl_pageup_function(t_line *line, long int input); /* Pageup move */
|
||||
int rl_pagedown_function(t_line *line, long int input); /* Pagedown move*/
|
||||
int rl_select_left_function(t_line *line, long int input); /* Left extend video area */
|
||||
int rl_select_right_function(t_line *line, long int input); /* Right extend video area */
|
||||
int rl_select_wleft_function(t_line *line, long int input); /* Word left extend video area */
|
||||
int rl_select_wright_function(t_line *line, long int input); /* Word right extend video area */
|
||||
int rl_select_home_function(t_line *line, long int input); /* Home extend video area */
|
||||
int rl_select_end_function(t_line *line, long int input); /* End extend video area */
|
||||
int rl_select_pageup_function(t_line *line, long int input); /* Pageup extend video area */
|
||||
int rl_select_pagedown_function(t_line *line, long int input); /* Pagedown extend video area */
|
||||
int rl_retarr_function(t_line *line, long int input); /* Remove before the cursor */
|
||||
int rl_suppr_function(t_line *line, long int input); /* Remove after the cursor */
|
||||
int rl_clear_function(t_line *line, long int input); /* Clear screen */
|
||||
int rl_copy_function(t_line *line, long int input); /* Copy selected area or current cursor line */
|
||||
int rl_cut_function(t_line *line, long int input); /* Cut selected area or current cursor line */
|
||||
int rl_paste_function(t_line *line, long int input); /* Paste copied/cuted area */
|
||||
int rl_insert_function(t_line *line, long int input); /* Toogle insert-mode/replacement-mode */
|
||||
|
||||
int ft_readline();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
21
42sh/includes/ft_xattr.h
Normal file
21
42sh/includes/ft_xattr.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ftxattr.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:24:05 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/07 13:24:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_XATTR_H
|
||||
# define FT_XATTR_H
|
||||
# define FT_XATTR_SIZE 10000
|
||||
# include <sys/types.h>
|
||||
# include <sys/xattr.h>
|
||||
|
||||
int ft_xattr_print(char *path);
|
||||
int ft_xattr_count(char *path);
|
||||
#endif
|
||||
|
|
@ -1,34 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* curs_clear.c :+: :+: :+: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 17:28:50 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 22:22:46 by ariard ### ########.fr */
|
||||
/* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/15 13:07:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_curs.h"
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
# define BUFF_SIZE 32
|
||||
|
||||
/*
|
||||
* Clear screen and keep track of cursoe's coordonate
|
||||
*/
|
||||
# include "libft.h"
|
||||
# include <sys/types.h>
|
||||
# include <sys/uio.h>
|
||||
|
||||
void curs_clear(t_curs *curs)
|
||||
typedef struct s_save t_save;
|
||||
|
||||
struct s_save
|
||||
{
|
||||
ft_putstr(tgetstr("cl", NULL));
|
||||
curs->li = 0;
|
||||
curs->co = 0;
|
||||
}
|
||||
int fd;
|
||||
char *str;
|
||||
};
|
||||
|
||||
/*
|
||||
* Clear screen after cursor position without moving cursor
|
||||
*/
|
||||
int get_next_line(int const fd, char **line);
|
||||
|
||||
void curs_clear_post(t_curs *curs)
|
||||
{
|
||||
ft_putstr(tgetstr("cd", NULL));
|
||||
(void)curs;
|
||||
}
|
||||
#endif
|
||||
101
42sh/includes/glob.h
Normal file
101
42sh/includes/glob.h
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* glob.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/01 19:50:07 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GLOB_H
|
||||
# define GLOB_H
|
||||
|
||||
# include "minishell.h"
|
||||
|
||||
# define CH(x) ((char **)(x)->content)
|
||||
# define UCH(x) ((unsigned char **)(x)->content)
|
||||
|
||||
typedef struct s_ld
|
||||
{
|
||||
void *content;
|
||||
struct s_ld *next;
|
||||
struct s_ld *prev;
|
||||
} t_ld;
|
||||
|
||||
typedef struct s_glob
|
||||
{
|
||||
const char *pat;
|
||||
const unsigned char *esc;
|
||||
t_ld *match;
|
||||
t_ld *m_pat;
|
||||
} t_glob;
|
||||
|
||||
typedef struct s_expand
|
||||
{
|
||||
t_ld **wk;
|
||||
char *str;
|
||||
unsigned char *esc;
|
||||
char **split;
|
||||
unsigned char **m_esc;
|
||||
char *s1;
|
||||
} t_expand;
|
||||
|
||||
/*
|
||||
** interface of glob.
|
||||
*/
|
||||
char **glob(const char *str, const unsigned char *esc);
|
||||
|
||||
/*
|
||||
** return TRUE if path file is a directory.
|
||||
*/
|
||||
|
||||
int is_directory(const char *path);
|
||||
/*
|
||||
** return TRUE if char at str_pos in ini_str is escape.
|
||||
*/
|
||||
int is_char_esc(const unsigned char *esc,
|
||||
const char *ini_str, const char *str_pos);
|
||||
|
||||
/*
|
||||
** Internal function.
|
||||
*/
|
||||
unsigned char *ft_sub_esc(const unsigned char *esc, int start, int len);
|
||||
unsigned char *calc_expand_esc(const unsigned char *esc,
|
||||
int nb_start, int nb_middle, int *nb_end);
|
||||
void modify_esc_split(unsigned char *esc_dest,
|
||||
unsigned char *esc_src, int start, int len);
|
||||
void expand_brace(t_glob *tglob);
|
||||
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||
int dir_research(t_glob *tglob, char *p, const char *pat, int rec);
|
||||
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);
|
||||
void ft_tabdel(char ***mytab);
|
||||
int ft_tablen(char **mytab);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/19 21:51:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:43:34 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ struct s_jobc
|
|||
|
||||
# include "exec.h"
|
||||
|
||||
t_process *job_getprocess(pid_t pid);
|
||||
t_list *job_getprocess(pid_t pid);
|
||||
int job_addprocess(t_process *p);
|
||||
void job_update_id(void);
|
||||
void job_update_rank(void);
|
||||
|
|
@ -53,8 +53,8 @@ void job_update_rank(void);
|
|||
int do_job_notification(void);
|
||||
void job_notify_new(t_job *job);
|
||||
void job_notify_change(int id);
|
||||
void job_format(t_job *j, int rank[2], int opts);
|
||||
void job_format_head(t_job *j, int rank[2]);
|
||||
void job_format(t_job *j, int opts);
|
||||
void job_format_head(t_job *j);
|
||||
|
||||
void job_update_status(void);
|
||||
void mark_job_as_running (t_job *j);
|
||||
|
|
@ -63,6 +63,7 @@ int job_is_stopped(int id);
|
|||
int job_is_completed(int id);
|
||||
|
||||
void job_new(char **av, pid_t pid);
|
||||
void job_run(t_job *job, int foreground);
|
||||
int job_wait(int id);
|
||||
void job_remove(int id);
|
||||
void job_free(void *content, size_t content_size);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 23:52:50 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:43:12 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -85,9 +85,10 @@ enum e_lexstate
|
|||
|
||||
struct s_token
|
||||
{
|
||||
t_type type;
|
||||
char *data;
|
||||
int size;
|
||||
t_type type;
|
||||
char *data;
|
||||
unsigned char *esc;
|
||||
int size;
|
||||
};
|
||||
|
||||
typedef struct s_data t_data;
|
||||
|
|
@ -96,10 +97,12 @@ typedef enum e_lexstate t_lexstate;
|
|||
|
||||
extern int (*g_lexer[])(t_list **alst, char *str);
|
||||
|
||||
t_token *token_init();
|
||||
int ft_lexer(t_list **alst, char **str);
|
||||
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
||||
int ft_post_tokenize(t_list **alst, char *str);
|
||||
int token_append(t_token *token, char c);
|
||||
int ft_post_tokenize(t_list **alst, char **str);
|
||||
|
||||
t_token *token_init();
|
||||
int token_append(t_token *token, char c, short int esc);
|
||||
void token_free(void *data, size_t size);
|
||||
int token_cmp_type(t_token *token, t_type *ref);
|
||||
void token_print(t_list *lst);
|
||||
|
|
|
|||
162
42sh/includes/libft.h
Normal file
162
42sh/includes/libft.h
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/19 16:13:05 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# define STDIN 0
|
||||
# define STDOUT 1
|
||||
# define STDERR 2
|
||||
# define STDBUG 3
|
||||
|
||||
# define DG_MSG0 "{inv}{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||
# define DG_MSG1 ft_path_notdir(__FILE__), __LINE__
|
||||
# define DG(f, ...) ft_dprintf(STDBUG, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__)
|
||||
|
||||
# include "get_next_line.h"
|
||||
# include "ft_xattr.h"
|
||||
# include "mytime.h"
|
||||
# include "lst.h"
|
||||
# include "dlst.h"
|
||||
# include "btree.h"
|
||||
# include "color.h"
|
||||
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <time.h>
|
||||
# include <sys/xattr.h>
|
||||
# include <sys/acl.h>
|
||||
|
||||
# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n')
|
||||
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
||||
# define FT_NEG(x) (((x) < 0) ? 1 : 0)
|
||||
# define FT_POS(x) (((x) > 0) ? 1 : 0)
|
||||
# define FT_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
# define FT_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
# define FT_DIST(a, b) (FT_ABS((a) - (b)))
|
||||
|
||||
typedef struct s_stof t_stof;
|
||||
typedef struct s_stos t_stos;
|
||||
|
||||
struct s_stos
|
||||
{
|
||||
char *key;
|
||||
char *val;
|
||||
};
|
||||
|
||||
struct s_stof
|
||||
{
|
||||
char *name;
|
||||
int (*f)();
|
||||
};
|
||||
|
||||
void ft_debug(void);
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
size_t ft_strlen(const char *s);
|
||||
char *ft_strdup(const char *s1);
|
||||
char *ft_strcpy(char *dst, const char *src);
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||
char *ft_strcat(char *s1, const char *s2);
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strstr(const char *big, const char *little);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
char *ft_strnew(size_t size);
|
||||
void ft_strdel(char **as);
|
||||
void ft_strclr(char *s);
|
||||
void ft_striter(char *s, void (*f)(char *));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||
char *ft_strmap(char const *s, char (*f)(char));
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
int ft_strequ(char const *s1, char const *s2);
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
int ft_putchar(int c);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putnbr(int n);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_putaddr(void *a);
|
||||
|
||||
char *ft_strrev(char *str);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_str3join(char const *s1, char const *s2, char const *s3);
|
||||
char *ft_strcut(char *str, char *cut);
|
||||
char **ft_split_whitespaces(char const *str);
|
||||
char *ft_convert_base(
|
||||
char *str, char *base_from, char *base_to, char *flags);
|
||||
char *ft_strcatf(char *s1, const char *s2);
|
||||
char *ft_strinsert(char *str, char c, int n);
|
||||
int ft_strappend(char **dst, char *src);
|
||||
char *ft_strbetween(char *start, char *end);
|
||||
char *ft_strreplace(char **str, char *start, char *end, char *new);
|
||||
|
||||
char *ft_itoa_base(int nbr, char *base, char *flags);
|
||||
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
||||
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
||||
char *ft_uitoa_base(unsigned int nbr, char *base);
|
||||
size_t ft_ilen(int n);
|
||||
size_t ft_ilen_base(int n, int base);
|
||||
size_t ft_uilen(unsigned int n);
|
||||
size_t ft_lllen(long long n);
|
||||
size_t ft_lllen_base(long long n, int base);
|
||||
int ft_addrcmp(void *a, void *b);
|
||||
|
||||
char **ft_sstradd(char **list, char *new);
|
||||
void ft_sstrsort(char **list, int (*cmp)());
|
||||
void ft_sstrprint(char **list, char sep);
|
||||
void ft_sstrprint_fd(int fd, char **list, char sep);
|
||||
char **ft_sstrdup(char **list);
|
||||
void ft_sstrdel(char **sstr, int index);
|
||||
void ft_sstrfree(char **sstr);
|
||||
char *ft_sstrcat(char **sstr, char sep);
|
||||
|
||||
char *ft_path_notdir(char *path);
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_dprintf(int fd, const char *format, ...);
|
||||
|
||||
char *ft_getenv(char **env, char *key);
|
||||
|
||||
void *ft_realloc(void *data, int size);
|
||||
#endif
|
||||
80
42sh/includes/lst.h
Normal file
80
42sh/includes/lst.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lst.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/12 14:59:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LST_H
|
||||
# define LST_H
|
||||
|
||||
# include "libft.h"
|
||||
|
||||
struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
};
|
||||
|
||||
typedef struct s_list t_list;
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||
|
||||
t_list *ft_lstnew_range(int a, int b);
|
||||
void ft_lsteadd(t_list **alst, t_list *new);
|
||||
void ft_lstnadd(t_list **alst, t_list *new, int n);
|
||||
void ft_lstsort(t_list **begin_list, int (*cmp)());
|
||||
void ft_lst_print(t_list *list, void (*printer)());
|
||||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
void ft_lst_sorted_merge(
|
||||
t_list **begin_list1,
|
||||
t_list *begin_list2,
|
||||
int (*cmp)());
|
||||
void ft_lst_sorted_insert(
|
||||
t_list **begin_list,
|
||||
t_list *insert,
|
||||
int (*cmp)());
|
||||
void ft_lst_delif(
|
||||
t_list **alist,
|
||||
void *data_ref,
|
||||
int (*cmp)(),
|
||||
void (*del)(void *, size_t));
|
||||
void ft_lst_delsub(
|
||||
t_list **alst,
|
||||
t_list *sub, int (*cmp)(),
|
||||
void (*del)(void *, size_t));
|
||||
void ft_lst_cfree(void *ptr, size_t size);
|
||||
void ft_lst_bfree(void *ptr, size_t size);
|
||||
t_list *ft_lst_filter(
|
||||
t_list *lst,
|
||||
void const *data_ref,
|
||||
t_list *(*f)(t_list *elem, void const *));
|
||||
t_list *ft_lst_removeif(
|
||||
t_list **alst,
|
||||
void *data_ref,
|
||||
int (*cmp)());
|
||||
t_list *ft_lst_find(
|
||||
t_list *begin_list,
|
||||
void *data_ref,
|
||||
int (*cmp)());
|
||||
t_list *ft_lstpop(t_list **lst);
|
||||
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
|
||||
void ft_lst_reverse(t_list **begin_list);
|
||||
|
||||
int ft_diff(void *a, void *b);
|
||||
t_list *ft_id(t_list *a);
|
||||
t_list *ft_lst_at(t_list *list, unsigned int nbr);
|
||||
|
||||
#endif
|
||||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* minishell.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 23:57:46 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:42:54 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
# include "exec.h"
|
||||
# include "builtin.h"
|
||||
# include "job_control.h"
|
||||
# include "glob.h"
|
||||
|
||||
# include <dirent.h>
|
||||
# include <sys/stat.h>
|
||||
|
|
|
|||
34
42sh/includes/mytime.h
Normal file
34
42sh/includes/mytime.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mytime.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/25 11:43:12 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 14:42:38 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MYTIME_H
|
||||
# define MYTIME_H
|
||||
# include "libft.h"
|
||||
|
||||
struct s_mytime
|
||||
{
|
||||
char *year;
|
||||
char *month;
|
||||
char *day;
|
||||
char *hour;
|
||||
char *min;
|
||||
char *sec;
|
||||
};
|
||||
|
||||
typedef struct s_mytime t_mytime;
|
||||
|
||||
int ft_time_isrecent(time_t event);
|
||||
|
||||
t_mytime *ft_mytime_get(time_t epoch);
|
||||
void ft_mytime_free(t_mytime **time);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 19:31:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:42:21 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "minishell.h"
|
||||
|
||||
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;
|
||||
|
|
@ -45,6 +46,7 @@ struct s_redir
|
|||
union u_astdata
|
||||
{
|
||||
t_redir redir;
|
||||
t_ld *token;
|
||||
char **sstr;
|
||||
char *str;
|
||||
};
|
||||
|
|
|
|||
43
42sh/src/builtin/bt_read_get.c
Normal file
43
42sh/src/builtin/bt_read_get.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bt_read_get.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/22 16:24:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
|
||||
int bt_read_getdelim(t_read *data, char *arg)
|
||||
{
|
||||
data->delim = *arg;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_getnchars(t_read *data, char *arg)
|
||||
{
|
||||
data->nchars = ft_atoi(arg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_getprompt(t_read *data, char *arg)
|
||||
{
|
||||
data->prompt = arg;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_gettimeout(t_read *data, char *arg)
|
||||
{
|
||||
data->timeout = ft_atoi(arg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_getfd(t_read *data, char *arg)
|
||||
{
|
||||
data->fd = ft_atoi(arg);
|
||||
return (0);
|
||||
}
|
||||
89
42sh/src/builtin/bt_read_parse.c
Normal file
89
42sh/src/builtin/bt_read_parse.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bt_read_parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/27 18:25:22 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/27 19:40:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
|
||||
static t_readopt *bt_read_getopt(char letter)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (g_readtab[i].letter)
|
||||
{
|
||||
if (g_readtab[i].letter == letter)
|
||||
return (&g_readtab[i]);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
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;
|
||||
if (av[i][j++] == '-')
|
||||
{
|
||||
if (av[i][j] == '-' && av[i][j + 1] == 0)
|
||||
{
|
||||
i++;
|
||||
break ;
|
||||
}
|
||||
while (av[i][j])
|
||||
{
|
||||
if (!(opt = bt_read_getopt(av[i][j])))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: bad option: %c{eoc}\n", SHELL_NAME, av[i][j]);
|
||||
return (2);
|
||||
}
|
||||
data->opts |= opt->flag;
|
||||
if (opt->get)
|
||||
{
|
||||
(*opt->get)(data, av[++i]);
|
||||
break ;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
data->names = av[i] ? av + i : NULL;
|
||||
DG("read_opts: %b", data->opts);
|
||||
DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i",
|
||||
data->delim, data->nchars, data->prompt, data->timeout, data->fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_init(t_read *data, char **av)
|
||||
{
|
||||
data->opts = 0;
|
||||
data->delim = '\n';
|
||||
data->nchars = -1;
|
||||
data->prompt = NULL;
|
||||
data->fd = 0;
|
||||
data->input = NULL;
|
||||
if ((bt_read_parse(data, av)))
|
||||
return (1);
|
||||
if (data->names)
|
||||
DG("%s,%s", data->names[0], data->names[1]);
|
||||
bt_read_terminit(data);
|
||||
return (0);
|
||||
}
|
||||
55
42sh/src/builtin/bt_read_term.c
Normal file
55
42sh/src/builtin/bt_read_term.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bt_read_term.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/27 19:00:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin.h"
|
||||
|
||||
struct termios bt_read_term(int init)
|
||||
{
|
||||
static struct termios term;
|
||||
|
||||
if (init)
|
||||
tcgetattr(0, &term);
|
||||
return (term);
|
||||
}
|
||||
|
||||
int bt_read_terminit(t_read *data)
|
||||
{
|
||||
struct termios term;
|
||||
|
||||
(void)data;
|
||||
term = bt_read_term(1);
|
||||
term.c_lflag &= ~(ECHO | ICANON);
|
||||
if (data->opts & READ_OPT_LT)
|
||||
{
|
||||
term.c_cc[VTIME] = data->timeout * 10;
|
||||
term.c_cc[VMIN] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
term.c_cc[VTIME] = 0;
|
||||
term.c_cc[VMIN] = 1;
|
||||
}
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_exit(t_read *data)
|
||||
{
|
||||
struct termios term;
|
||||
|
||||
ft_strdel(&data->input);
|
||||
term = bt_read_term(0);
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 16:25:06 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:04:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
106
42sh/src/builtin/builtin_read.c
Normal file
106
42sh/src/builtin/builtin_read.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_read.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/27 19:40:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
|
||||
t_readopt g_readtab[] =
|
||||
{
|
||||
/* {'a', READ_OPT_LA, NULL}, */
|
||||
{'d', READ_OPT_LD, bt_read_getdelim},
|
||||
/* {'e', READ_OPT_LE, NULL}, */
|
||||
/* {'i', READ_OPT_LI, NULL}, */
|
||||
{'n', READ_OPT_LN, bt_read_getnchars},
|
||||
/* {'N', READ_OPT_UN, bt_read_getnchars}, */
|
||||
{'p', READ_OPT_LP, bt_read_getprompt},
|
||||
{'r', READ_OPT_LR, NULL},
|
||||
{'s', READ_OPT_LS, NULL},
|
||||
{'t', READ_OPT_LT, bt_read_gettimeout},
|
||||
{'u', READ_OPT_LU, bt_read_getfd},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
int bt_read_loop(t_read *data)
|
||||
{
|
||||
int i;
|
||||
int esc;
|
||||
char buf[2];
|
||||
|
||||
i = 0;
|
||||
esc = 0;
|
||||
if (data->prompt)
|
||||
ft_printf(data->prompt);
|
||||
while (42)
|
||||
{
|
||||
if (read(data->fd, buf, 1) <= 0)
|
||||
return (1);
|
||||
buf[1] = 0;
|
||||
if (!esc && *buf == data->delim)
|
||||
break ;
|
||||
esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\');
|
||||
ft_strappend(&data->input, buf);
|
||||
if (!(data->opts & READ_OPT_LS))
|
||||
ft_putchar(*buf);
|
||||
if (*buf == '\n' && !(data->opts & READ_OPT_LR))
|
||||
ft_putstr("> ");
|
||||
if ((data->opts & READ_OPT_LN) && ++i >= data->nchars)
|
||||
break ;
|
||||
}
|
||||
ft_putchar('\n');
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_assign(t_read *data)
|
||||
{
|
||||
char *input;
|
||||
char **names;
|
||||
char *IFS;
|
||||
char *start;
|
||||
|
||||
input = data->input;
|
||||
names = data->names ? data->names : (char*[]){"REPLY", NULL};
|
||||
IFS = ft_getenv(data_singleton()->env, "IFS");
|
||||
start = input;
|
||||
while (*start && *names)
|
||||
{
|
||||
if (!(names[1]) || !IFS)
|
||||
{
|
||||
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
||||
break ;
|
||||
}
|
||||
while (*input && !ft_strchr(IFS, *input))
|
||||
input++;
|
||||
while (input && ft_strchr(IFS, *input))
|
||||
*(input++) = 0;
|
||||
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
|
||||
start = input;
|
||||
names++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int builtin_read(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
t_read data;
|
||||
int ret;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
ret = 0;
|
||||
if (bt_read_init(&data, (char **)av))
|
||||
ret = 2;
|
||||
else if (bt_read_loop(&data))
|
||||
ret = 1;
|
||||
else if (bt_read_assign(&data))
|
||||
ret = 1;
|
||||
bt_read_exit(&data);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 15:53:07 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/27 19:00:07 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,17 @@
|
|||
/* ::: :::::::: */
|
||||
/* is_builtin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 16:58:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/26 14:58:02 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_stof g_builtin[] = {
|
||||
t_stof g_builtin[] =
|
||||
{
|
||||
{"echo", &builtin_echo},
|
||||
{"cd", &builtin_cd},
|
||||
{"setenv", &builtin_setenv},
|
||||
|
|
@ -22,6 +23,8 @@ t_stof g_builtin[] = {
|
|||
{"jobs", &builtin_jobs},
|
||||
{"fg", &builtin_fg},
|
||||
{"bg", &builtin_bg},
|
||||
{"history", &builtin_history},
|
||||
{"read", &builtin_read},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 22:35:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:41:26 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,9 +19,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->data.sstr)
|
||||
ft_sstrfree(node->data.sstr);
|
||||
ft_sstrfree(node->data.sstr);
|
||||
node->data.sstr = NULL;
|
||||
}
|
||||
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,13 +6,42 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 17:25:52 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:40:45 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_command(t_btree **ast)
|
||||
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;
|
||||
expand = glob(content[0], (unsigned char *)content[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;
|
||||
|
|
@ -21,7 +50,7 @@ int exec_command(t_btree **ast)
|
|||
node = (*ast)->item;
|
||||
p = &data_singleton()->exec.process;
|
||||
job = &data_singleton()->exec.job;
|
||||
p->av = ft_sstrdup(node->data.sstr);
|
||||
p->av = token_to_argv(node);
|
||||
process_setexec(node->type, p);
|
||||
if (!(launch_process(p)))
|
||||
{
|
||||
|
|
@ -36,8 +65,7 @@ int exec_command(t_btree **ast)
|
|||
}
|
||||
p->av = NULL;
|
||||
p->pid = 0;
|
||||
p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
p->attributes &= ~(PROCESS_STATE_MASK | PROCESS_TYPE_MASK);
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@ int exec_pipe(t_btree **ast)
|
|||
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;
|
||||
ft_exec(&(*ast)->left);
|
||||
p->attributes &= ~PROCESS_PIPESTART;
|
||||
|
||||
p->toclose = STDIN;
|
||||
close(fds[PIPE_WRITE]);
|
||||
p->fdout = STDOUT;
|
||||
p->fdin = fds[PIPE_READ];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 20:00:23 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:40:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,6 +41,7 @@ int ft_exec(t_btree **ast)
|
|||
while (g_execmap[i].type)
|
||||
{
|
||||
if (item->type & g_execmap[i].type)
|
||||
|
||||
{
|
||||
/* return ((*g_execmap[i].f)(ast)); */
|
||||
(*g_execmap[i].f)(ast);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/30 19:36:21 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:39:16 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,40 +21,38 @@ int launch_process(t_process *p)
|
|||
if (p->attributes & PROCESS_UNKNOWN)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
set_exitstatus(127);
|
||||
return (1);
|
||||
set_exitstatus(127, 1);
|
||||
}
|
||||
else if (p->attributes & PROCESS_BUILTIN && p->fdout == STDOUT)
|
||||
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env));
|
||||
else if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(p->attributes))
|
||||
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
|
||||
else
|
||||
{
|
||||
p->attributes &= ~PROCESS_STATE_MASK;
|
||||
p->attributes |= PROCESS_RUNNING;
|
||||
DG("process is to be forked, %i->[]->%i, attr=%b", p->fdin, p->fdout, p->attributes);
|
||||
if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT)
|
||||
&& access(p->path, X_OK) == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
return (-1);
|
||||
set_exitstatus(126, 1);
|
||||
return (1);
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
process_setgroup(p);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGTSTP, SIG_DFL);
|
||||
signal(SIGTTIN, sigttin_handler);
|
||||
signal(SIGTTOU, sigttou_handler);
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
process_redirect(p);
|
||||
(*p->execf)(p->path, p->av, data_singleton()->env);
|
||||
exit(42);
|
||||
exit(43);
|
||||
}
|
||||
else if (pid > 0)
|
||||
{
|
||||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
return (0);
|
||||
}
|
||||
else if (pid == -1)
|
||||
perror("fork");
|
||||
ft_dprintf(2, "{red}internal fork error{eoc}\n");
|
||||
}
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@
|
|||
|
||||
int process_redirect(t_process *p)
|
||||
{
|
||||
if (p->toclose != STDIN)
|
||||
close(p->toclose);
|
||||
if (p->fdin != STDIN)
|
||||
{
|
||||
/* DG("redirect STDIN to %i", p->fdin); */
|
||||
dup2(p->fdin, STDIN);
|
||||
close(p->fdin);
|
||||
}
|
||||
if (p->fdout != STDOUT)
|
||||
{
|
||||
/* DG("redirect STDOUT to %i", p->fdout); */
|
||||
dup2(p->fdout, STDOUT);
|
||||
close(p->fdout);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,23 +13,18 @@
|
|||
#include "job_control.h"
|
||||
#include "exec.h"
|
||||
|
||||
int process_setgroup(t_process *p)
|
||||
int process_setgroup(t_process *p, pid_t pid)
|
||||
{
|
||||
t_job *job;
|
||||
int pid;
|
||||
t_job *j;
|
||||
|
||||
(void)p;
|
||||
job = &data_singleton()->exec.job;
|
||||
pid = getpid();
|
||||
if (job->pgid == 0)
|
||||
job->pgid = pid;
|
||||
if (setpgid(pid, job->pgid))
|
||||
DG("setpgid(%i, %i) failed", pid, job->pgid);
|
||||
if (JOB_IS_FG(job->attributes))
|
||||
{
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
tcsetpgrp(STDIN, job->pgid);
|
||||
signal(SIGTTOU, SIG_DFL);
|
||||
}
|
||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||
return (0);
|
||||
j = &data_singleton()->exec.job;
|
||||
if (!j->pgid)
|
||||
j->pgid = pid ? pid : getpid();
|
||||
setpgid(pid, j->pgid);
|
||||
if (pid == 0 && JOB_IS_FG(j->attributes))
|
||||
tcsetpgrp(STDIN, j->pgid);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
11
42sh/src/exec/process_setsig.c
Normal file
11
42sh/src/exec/process_setsig.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "exec.h"
|
||||
|
||||
void process_setsig(void)
|
||||
{
|
||||
/* signal(SIGINT, SIG_DFL); */
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGTSTP, SIG_DFL);
|
||||
signal(SIGTTIN, SIG_DFL);
|
||||
signal(SIGTTOU, SIG_DFL);
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
}
|
||||
|
|
@ -12,11 +12,27 @@
|
|||
|
||||
#include "minishell.h"
|
||||
|
||||
void set_exitstatus(int status)
|
||||
void set_exitstatus(int status, int override)
|
||||
{
|
||||
char *astatus;
|
||||
int exitval;
|
||||
|
||||
astatus = ft_itoa(status);
|
||||
builtin_setenv("setenv", (char*[3]){"?", astatus}, data_singleton()->env);
|
||||
if (override)
|
||||
exitval = status;
|
||||
else
|
||||
{
|
||||
if (WIFEXITED(status))
|
||||
exitval = WEXITSTATUS(status);
|
||||
else if (WIFSIGNALED(status))
|
||||
exitval = 128 + WTERMSIG(status);
|
||||
else
|
||||
{
|
||||
DG("fail: process was not exited nor signaled.");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
astatus = ft_itoa(exitval);
|
||||
builtin_setenv("setenv", (char*[]){"setenv", "?", astatus, 0},
|
||||
data_singleton()->env);
|
||||
ft_strdel(&astatus);
|
||||
}
|
||||
|
|
|
|||
64
42sh/src/glob/dir_glob.c
Normal file
64
42sh/src/glob/dir_glob.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dir_glob.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/01 19:49:44 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
int is_directory(const char *path)
|
||||
{
|
||||
struct stat path_stat;
|
||||
|
||||
stat(path, &path_stat);
|
||||
return (S_ISDIR(path_stat.st_mode));
|
||||
}
|
||||
|
||||
static int dir_list_content(t_glob *gl, char **str, const char *pat,
|
||||
int recursive)
|
||||
{
|
||||
int ret;
|
||||
char *path_tmp;
|
||||
|
||||
ret = 0;
|
||||
if (ft_strcmp(str[1], ".") && ft_strcmp(str[1], ".."))
|
||||
{
|
||||
if (*str[0] == '/' && !*(str[0] + 1))
|
||||
path_tmp = ft_strjoin(str[0], str[1]);
|
||||
else
|
||||
path_tmp = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
|
||||
if (recursive)
|
||||
dir_research(gl, path_tmp, pat, recursive);
|
||||
gl->pat = pat;
|
||||
if (match_pattern(gl, str[1], path_tmp) && ++ret)
|
||||
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 *
|
||||
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
||||
ft_strdel(&path_tmp);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int dir_research(t_glob *gl, char *p,
|
||||
const char *pat, int recursive)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *in;
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
||||
{
|
||||
dir = opendir(p);
|
||||
while ((in = readdir(dir)))
|
||||
ret += dir_list_content(gl,
|
||||
(char *[2]){p, in->d_name}, pat, recursive);
|
||||
closedir(dir);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
139
42sh/src/glob/expand_brace.c
Normal file
139
42sh/src/glob/expand_brace.c
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_brace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/12 19:00:29 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/31 23:20:38 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
/*
|
||||
** expand_brace return expansion of a string.
|
||||
** pattern searched are {ab, cd}.
|
||||
** return is t_ld which first param is ab and second is cd
|
||||
** input parameters are :
|
||||
** -char *pat -> pattern string to be looking for expand
|
||||
*/
|
||||
|
||||
static char **gen_tab(const char *pat,
|
||||
const unsigned char *esc, int dup)
|
||||
{
|
||||
char **my_tab;
|
||||
|
||||
if (!(my_tab = (char **)malloc(sizeof(char *) * 3)))
|
||||
return (NULL);
|
||||
if (dup)
|
||||
{
|
||||
my_tab[0] = ft_strdup(pat);
|
||||
my_tab[1] = ft_strdup((const char *)esc);
|
||||
}
|
||||
else
|
||||
{
|
||||
my_tab[0] = (char *)pat;
|
||||
my_tab[1] = (char *)esc;
|
||||
}
|
||||
my_tab[2] = NULL;
|
||||
return (my_tab);
|
||||
}
|
||||
|
||||
static void iter_on_each(t_expand *me)
|
||||
{
|
||||
int i;
|
||||
char **my_new;
|
||||
char *first;
|
||||
unsigned char *second;
|
||||
t_ld *wk_tmp;
|
||||
|
||||
i = -1;
|
||||
wk_tmp = *me->wk;
|
||||
while (me->split[++i])
|
||||
{
|
||||
first = ft_strjoinf(ft_strjoin(me->s1, me->split[i]), me->str + 1, 1);
|
||||
second = calc_expand_esc(me->esc,
|
||||
ft_strlen(me->s1),
|
||||
ft_strlen(me->split[i]),
|
||||
(int[2]){me->str - CH(*me->wk)[0], ft_strlen(me->str + 1)});
|
||||
modify_esc_split(second, me->m_esc[i],
|
||||
ft_strlen(me->s1), ft_strlen(me->split[i]));
|
||||
my_new = gen_tab(first, second, 0);
|
||||
ft_ld_pushfront(&wk_tmp, my_new);
|
||||
}
|
||||
me->wk = &wk_tmp;
|
||||
}
|
||||
|
||||
static void init_expand(t_expand *me, char *start)
|
||||
{
|
||||
unsigned char *esc;
|
||||
|
||||
me->s1 = ft_strsub(start, 1, me->str - start - 1);
|
||||
esc = ft_sub_esc(me->esc, start - CH(*me->wk)[0] + 1, me->str - start);
|
||||
me->split = ft_strsplit_spe(me->s1, esc, ',');
|
||||
me->m_esc = ft_strsplit_esc(me->s1, esc, ',');
|
||||
ft_strdel(&me->s1);
|
||||
ft_strdel((char **)&esc);
|
||||
me->s1 = ft_strsub(CH(*me->wk)[0], 0, start - CH(*me->wk)[0]);
|
||||
iter_on_each(me);
|
||||
ft_strdel(&me->s1);
|
||||
ft_tabdel(&me->split);
|
||||
ft_tabdel((char ***)&me->m_esc);
|
||||
}
|
||||
|
||||
static int search_brace(t_expand *me)
|
||||
{
|
||||
char *start;
|
||||
int nb;
|
||||
|
||||
start = NULL;
|
||||
nb = 0;
|
||||
while (*me->str)
|
||||
{
|
||||
start = *me->str == '{'
|
||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str)
|
||||
&& nb == 0 ? me->str : start;
|
||||
nb += *me->str == '{'
|
||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
||||
nb -= *me->str == '}'
|
||||
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str);
|
||||
if (!nb && start)
|
||||
{
|
||||
init_expand(me, start);
|
||||
return (1);
|
||||
}
|
||||
++me->str;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void expand_brace(t_glob *gl)
|
||||
{
|
||||
t_ld *tmp;
|
||||
int do_it;
|
||||
t_expand me;
|
||||
|
||||
ft_ld_pushfront(&gl->m_pat, gen_tab("", (const unsigned char *)"", 1));
|
||||
ft_ld_pushfront(&gl->m_pat, gen_tab(gl->pat, gl->esc, 1));
|
||||
me = (t_expand){NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
do_it = 1;
|
||||
while (do_it)
|
||||
{
|
||||
do_it = 0;
|
||||
while (gl->m_pat->next && !do_it)
|
||||
{
|
||||
me.wk = &gl->m_pat;
|
||||
me.esc = UCH(gl->m_pat)[1];
|
||||
me.str = CH(gl->m_pat)[0];
|
||||
if ((tmp = gl->m_pat) && search_brace(&me))
|
||||
{
|
||||
ft_ld_del(&tmp, &ft_tabdel);
|
||||
do_it = 1;
|
||||
}
|
||||
gl->m_pat = gl->m_pat->next;
|
||||
}
|
||||
gl->m_pat = ft_ld_front(gl->m_pat);
|
||||
}
|
||||
}
|
||||
76
42sh/src/glob/expand_esc.c
Normal file
76
42sh/src/glob/expand_esc.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_esc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/31 23:18:56 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/31 23:19:45 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
unsigned char *calc_expand_esc(const unsigned char *esc,
|
||||
int nb_start, int nb_middle, int *nb_end)
|
||||
{
|
||||
unsigned char *new_esc;
|
||||
int index;
|
||||
int pos;
|
||||
|
||||
if (!(new_esc = (unsigned char *)ft_strnew(((nb_start + nb_middle
|
||||
+ nb_end[1]) / 8) + 1)))
|
||||
return (NULL);
|
||||
index = -1;
|
||||
while (++index < nb_start)
|
||||
new_esc[index / 8] |=
|
||||
((esc[index / 8] >> (7 - index % 8)) & 1) << (7 - index % 8);
|
||||
pos = -1;
|
||||
while (++pos < nb_middle)
|
||||
{
|
||||
new_esc[index / 8] |= 0 << (7 - index % 8);
|
||||
++index;
|
||||
}
|
||||
pos = nb_end[0];
|
||||
while (++pos <= nb_end[0] + nb_end[1])
|
||||
{
|
||||
new_esc[index / 8] |=
|
||||
((esc[pos / 8] >> (7 - pos % 8)) & 1) << (7 - index % 8);
|
||||
++index;
|
||||
}
|
||||
return (new_esc);
|
||||
}
|
||||
|
||||
void modify_esc_split(unsigned char *esc_dest,
|
||||
unsigned char *esc_src, int start, int len)
|
||||
{
|
||||
int index;
|
||||
int wk;
|
||||
|
||||
index = -1;
|
||||
while (++index < len)
|
||||
{
|
||||
wk = index + start - 1;
|
||||
esc_dest[wk / 8] |=
|
||||
((esc_src[index / 8] >> (7 - index % 8)) & 1) << (7 - wk % 8);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char *ft_sub_esc(const unsigned char *esc,
|
||||
int start, int len)
|
||||
{
|
||||
unsigned char *new_esc;
|
||||
int index;
|
||||
|
||||
if (!(new_esc = (unsigned char *)ft_strnew(((len) / 8) + 1)))
|
||||
return (NULL);
|
||||
index = -1;
|
||||
while (++index < len)
|
||||
{
|
||||
new_esc[index / 8] |=
|
||||
((esc[start / 8] >> (7 - start % 8)) & 1) << (7 - index % 8);
|
||||
++start;
|
||||
}
|
||||
return (new_esc);
|
||||
}
|
||||
86
42sh/src/glob/ft_strsplit_esc.c
Normal file
86
42sh/src/glob/ft_strsplit_esc.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit_esc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/31 22:18:46 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/31 23:15:17 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
static int ft_strlen_c(const char *str, const char *fix,
|
||||
const unsigned char *esc, char c)
|
||||
{
|
||||
int len;
|
||||
int nb;
|
||||
|
||||
len = 0;
|
||||
nb = 0;
|
||||
while (*str && (*str != c || nb))
|
||||
{
|
||||
nb += *str == '{' && !is_char_esc(esc, fix, str);
|
||||
nb -= *str == '}' && !is_char_esc(esc, fix, str);
|
||||
++str;
|
||||
++len;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static int nb_c(const char *str, const unsigned char *esc, char c)
|
||||
{
|
||||
int len;
|
||||
int nb;
|
||||
const char *fix;
|
||||
|
||||
len = 0;
|
||||
nb = 0;
|
||||
fix = str;
|
||||
while (*str)
|
||||
{
|
||||
while (*str && *str == c)
|
||||
++str;
|
||||
if (*str)
|
||||
++len;
|
||||
while (*str && (*str != c || nb))
|
||||
{
|
||||
nb += *str == '{' && !is_char_esc(esc, fix, str);
|
||||
nb -= *str == '}' && !is_char_esc(esc, fix, str);
|
||||
++str;
|
||||
}
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
unsigned char **ft_strsplit_esc(const char *str,
|
||||
const unsigned char *esc, char c)
|
||||
{
|
||||
unsigned char **s1;
|
||||
int i;
|
||||
const char *fix;
|
||||
int len;
|
||||
int pos;
|
||||
|
||||
if ((pos = -1) && !str)
|
||||
return (NULL);
|
||||
if (!(s1 = (unsigned char **)malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1))))
|
||||
return (NULL);
|
||||
i = 0;
|
||||
fix = str;
|
||||
while (*str && *str == c && ++pos > -1)
|
||||
++str;
|
||||
while (*str && (len = ft_strlen_c(str, fix, esc, c)))
|
||||
{
|
||||
s1[i] = ft_sub_esc(esc, pos, len);
|
||||
str += len;
|
||||
pos += len;
|
||||
++i;
|
||||
while (*str && *str == c && ++pos)
|
||||
++str;
|
||||
}
|
||||
s1[i] = 0;
|
||||
return (s1);
|
||||
}
|
||||
86
42sh/src/glob/ft_strsplit_spe.c
Normal file
86
42sh/src/glob/ft_strsplit_spe.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit_spe.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/31 20:49:30 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/31 23:15:41 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
static int ft_strlen_c(const char *str, const char *fix,
|
||||
const unsigned char *esc, char c)
|
||||
{
|
||||
int len;
|
||||
int nb;
|
||||
|
||||
len = 0;
|
||||
nb = 0;
|
||||
while (*str && (*str != c || nb))
|
||||
{
|
||||
nb += *str == '{' && !is_char_esc(esc, fix, str);
|
||||
nb -= *str == '}' && !is_char_esc(esc, fix, str);
|
||||
++str;
|
||||
++len;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static int ft_nbstr_c(const char *str, const unsigned char *esc, char c)
|
||||
{
|
||||
int len;
|
||||
int nb;
|
||||
const char *fix;
|
||||
|
||||
len = 0;
|
||||
nb = 0;
|
||||
fix = str;
|
||||
while (*str)
|
||||
{
|
||||
while (*str && *str == c)
|
||||
++str;
|
||||
if (*str)
|
||||
++len;
|
||||
while (*str && (*str != c || nb))
|
||||
{
|
||||
nb += *str == '{' && !is_char_esc(esc, fix, str);
|
||||
nb -= *str == '}' && !is_char_esc(esc, fix, str);
|
||||
++str;
|
||||
}
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
char **ft_strsplit_spe(const char *str,
|
||||
const unsigned char *esc, char c)
|
||||
{
|
||||
char **s1;
|
||||
int i;
|
||||
const char *fix;
|
||||
int len;
|
||||
|
||||
if (!str)
|
||||
return (NULL);
|
||||
if (!(s1 = (char**)malloc(sizeof(*s1) * (ft_nbstr_c(str, esc, c) + 1))))
|
||||
return (NULL);
|
||||
i = 0;
|
||||
fix = str;
|
||||
while (*str && *str == c)
|
||||
++str;
|
||||
while (*str && (len = ft_strlen_c(str, fix, esc, c)))
|
||||
{
|
||||
if (!(s1[i] = (char*)malloc(sizeof(**s1) * (len + 1))))
|
||||
return (NULL);
|
||||
ft_strncpy(s1[i], str, len);
|
||||
str = str + len;
|
||||
++i;
|
||||
while (*str && *str == c)
|
||||
++str;
|
||||
}
|
||||
s1[i] = 0;
|
||||
return (s1);
|
||||
}
|
||||
58
42sh/src/glob/glob.c
Normal file
58
42sh/src/glob/glob.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* glob.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/01 19:46:22 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
/*
|
||||
** glob return expansion of a string.
|
||||
** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, **
|
||||
** input parameters are :
|
||||
** -char *pat -> pattern string to be looking for match
|
||||
** -char *esc -> escape binary sequence of *pat
|
||||
** -char **env -> env var. could be NULL
|
||||
** to just expanse in local directory and not in path dir
|
||||
*/
|
||||
|
||||
static char **treat_glob(t_ld **match)
|
||||
{
|
||||
char **gl;
|
||||
|
||||
gl = NULL;
|
||||
ft_ld_reverse(match);
|
||||
gl = ft_ld_to_tab(*match);
|
||||
ft_ld_clear(match, &ft_strdel);
|
||||
return (gl);
|
||||
}
|
||||
|
||||
char **glob(const char *pat, const unsigned char *esc)
|
||||
{
|
||||
t_glob gl;
|
||||
int ret;
|
||||
|
||||
gl = (t_glob){pat, esc, NULL, NULL};
|
||||
expand_brace(&gl);
|
||||
while (gl.m_pat->next)
|
||||
{
|
||||
gl.pat = ((char **)gl.m_pat->content)[0];
|
||||
gl.esc = ((unsigned char **)gl.m_pat->content)[1];
|
||||
if (gl.pat[0] != '/')
|
||||
ret = dir_research(&gl, ".", gl.pat, 0);
|
||||
else
|
||||
ret = dir_research(&gl, "/", gl.pat + 1, 0);
|
||||
if (!ret)
|
||||
ft_ld_pushfront(&gl.match,
|
||||
ft_strdup(((char **)gl.m_pat->content)[0]));
|
||||
gl.m_pat = gl.m_pat->next;
|
||||
}
|
||||
ft_ld_clear(&gl.m_pat, &ft_tabdel);
|
||||
return (treat_glob(&gl.match));
|
||||
}
|
||||
|
|
@ -1,32 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_clear_function.c :+: :+: :+: */
|
||||
/* is_char_esc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 13:34:29 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 22:36:01 by ariard ### ########.fr */
|
||||
/* Created: 2017/01/27 18:19:55 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/03 14:38:37 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
#include "glob.h"
|
||||
|
||||
int rl_clear_function(t_line *line, long int input)
|
||||
int is_char_esc(const unsigned char *esc,
|
||||
const char *ini_str, const char *str_pos)
|
||||
{
|
||||
int pos;
|
||||
int pos;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
curs_clear(&line->curs);
|
||||
rl_put_prompt(line);
|
||||
pos = line->pos;
|
||||
line->pos = 0;
|
||||
if (line->used)
|
||||
rl_reset_display_post(line);
|
||||
if (pos)
|
||||
curs_forward(&line->curs, pos);
|
||||
line->pos = pos;
|
||||
pos = str_pos - ini_str;
|
||||
if ((esc[pos / 8] >> (7 - pos % 8)) & 1)
|
||||
return (1);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
21
42sh/src/glob/lib_perso/ft_ld_back.c
Normal file
21
42sh/src/glob/lib_perso/ft_ld_back.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/16 16:23:26 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:16:53 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
t_ld *ft_ld_back(t_ld *ld)
|
||||
{
|
||||
if (ld)
|
||||
while (ld->next)
|
||||
ld = ld->next;
|
||||
return (ld);
|
||||
}
|
||||
24
42sh/src/glob/lib_perso/ft_ld_clear.c
Normal file
24
42sh/src/glob/lib_perso/ft_ld_clear.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_clear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 19:56:49 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:11 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void ft_ld_clear(t_ld **ld, void (*del)())
|
||||
{
|
||||
if (!ld || !*ld)
|
||||
return ;
|
||||
*ld = ft_ld_front(*ld);
|
||||
while (*ld)
|
||||
{
|
||||
ft_ld_del(ld, del);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* curs_goto.c :+: :+: :+: */
|
||||
/* ft_ld_del.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 17:10:22 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 22:22:56 by ariard ### ########.fr */
|
||||
/* Created: 2016/12/06 15:54:53 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:18 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_curs.h"
|
||||
#include "glob.h"
|
||||
|
||||
/*
|
||||
* Move the cursor to the given coordonate // scroll screen if line is unreachable
|
||||
*/
|
||||
|
||||
void curs_goto(t_curs *curs, int li, int co)
|
||||
void ft_ld_del(t_ld **ld, void (*del)())
|
||||
{
|
||||
if (co >= curs->win_co)
|
||||
co = curs->win_co - 1;
|
||||
if (li >= curs->win_li)
|
||||
t_ld *next;
|
||||
t_ld *prev;
|
||||
|
||||
if (!ld || !*ld)
|
||||
return ;
|
||||
next = (*ld)->next;
|
||||
prev = (*ld)->prev;
|
||||
if ((*ld)->content && del)
|
||||
del(&(*ld)->content);
|
||||
free(*ld);
|
||||
if (next)
|
||||
next->prev = prev;
|
||||
if (prev)
|
||||
{
|
||||
ft_putstr(tgetstr("sf", NULL));
|
||||
li = curs->win_li - 1;
|
||||
prev->next = next;
|
||||
*ld = prev;
|
||||
}
|
||||
ft_putstr(tgoto(tgetstr("cm", NULL), co, li));
|
||||
curs->li = li;
|
||||
curs->co = co;
|
||||
else
|
||||
*ld = next;
|
||||
}
|
||||
21
42sh/src/glob/lib_perso/ft_ld_front.c
Normal file
21
42sh/src/glob/lib_perso/ft_ld_front.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:26:11 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:27 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
t_ld *ft_ld_front(t_ld *ld)
|
||||
{
|
||||
if (ld)
|
||||
while (ld->prev)
|
||||
ld = ld->prev;
|
||||
return (ld);
|
||||
}
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* curs_single.c :+: :+: :+: */
|
||||
/* ft_ld_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 17:04:53 by sbenning #+# #+# */
|
||||
/* Updated: 2017/01/21 22:23:28 by ariard ### ########.fr */
|
||||
/* Created: 2016/12/01 18:17:34 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/03 14:38:19 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_curs.h"
|
||||
#include "glob.h"
|
||||
|
||||
/*
|
||||
* Save cursor reference or return a previous saved reference
|
||||
*/
|
||||
|
||||
t_curs *curs_single(t_curs *curs, int set)
|
||||
void ft_ld_new(t_ld **alst, void *content)
|
||||
{
|
||||
static t_curs *single;
|
||||
t_ld *new;
|
||||
|
||||
if (set)
|
||||
single = curs;
|
||||
return (single);
|
||||
if ((new = (t_ld *)malloc(sizeof(t_ld))))
|
||||
{
|
||||
new->content = content;
|
||||
new->prev = NULL;
|
||||
new->next = NULL;
|
||||
*alst = new;
|
||||
}
|
||||
}
|
||||
35
42sh/src/glob/lib_perso/ft_ld_order.c
Normal file
35
42sh/src/glob/lib_perso/ft_ld_order.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_order.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/24 19:20:45 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/24 19:40:54 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
t_ld *ft_ld_order(t_ld *ld, int (*f)(), void (*del)())
|
||||
{
|
||||
int swap;
|
||||
|
||||
swap = 1;
|
||||
ld = ft_ld_front(ld);
|
||||
while (swap)
|
||||
{
|
||||
swap = 0;
|
||||
while (ld && ld->next)
|
||||
{
|
||||
if (f(ld->content, ld->next->content) > 0 && (swap = 1))
|
||||
ld = ft_ld_swap(ld);
|
||||
else if (!f(ld->content, ld->next->content))
|
||||
ft_ld_del(&ld, del);
|
||||
ld = ld->next;
|
||||
}
|
||||
ld = ft_ld_front(ld);
|
||||
}
|
||||
return (ld);
|
||||
}
|
||||
30
42sh/src/glob/lib_perso/ft_ld_pushback.c
Normal file
30
42sh/src/glob/lib_perso/ft_ld_pushback.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_pushback.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/16 15:59:38 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:40 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void ft_ld_pushback(t_ld **alst, void *content)
|
||||
{
|
||||
t_ld *new;
|
||||
t_ld *back;
|
||||
|
||||
if (!alst || !*alst)
|
||||
return (ft_ld_new(alst, content));
|
||||
if ((new = (t_ld *)malloc(sizeof(t_ld))))
|
||||
{
|
||||
back = ft_ld_back(*alst);
|
||||
new->prev = back;
|
||||
new->next = NULL;
|
||||
new->content = content;
|
||||
back->next = new;
|
||||
}
|
||||
}
|
||||
31
42sh/src/glob/lib_perso/ft_ld_pushfront.c
Normal file
31
42sh/src/glob/lib_perso/ft_ld_pushfront.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_pushfront.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:32:40 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:46 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void ft_ld_pushfront(t_ld **alst, void *content)
|
||||
{
|
||||
t_ld *new;
|
||||
t_ld *front;
|
||||
|
||||
if (!alst || !*alst)
|
||||
return (ft_ld_new(alst, content));
|
||||
if ((new = (t_ld *)malloc(sizeof(t_ld))))
|
||||
{
|
||||
front = ft_ld_front(*alst);
|
||||
new->next = front;
|
||||
new->prev = NULL;
|
||||
new->content = content;
|
||||
front->prev = new;
|
||||
*alst = new;
|
||||
}
|
||||
}
|
||||
32
42sh/src/glob/lib_perso/ft_ld_reverse.c
Normal file
32
42sh/src/glob/lib_perso/ft_ld_reverse.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_reverse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 14:16:04 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:17:53 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void ft_ld_reverse(t_ld **lst)
|
||||
{
|
||||
t_ld *l_prev;
|
||||
t_ld *l_next;
|
||||
t_ld *l_cur;
|
||||
|
||||
l_cur = ft_ld_front(*lst);
|
||||
l_prev = NULL;
|
||||
while (l_cur)
|
||||
{
|
||||
l_next = l_cur->next;
|
||||
l_cur->next = l_prev;
|
||||
l_cur->prev = l_next;
|
||||
l_prev = l_cur;
|
||||
l_cur = l_next;
|
||||
}
|
||||
*lst = l_prev;
|
||||
}
|
||||
27
42sh/src/glob/lib_perso/ft_ld_size.c
Normal file
27
42sh/src/glob/lib_perso/ft_ld_size.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_size.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:33:48 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/03 14:38:07 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
size_t ft_ld_size(t_ld *ld)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
size = 0;
|
||||
ld = ft_ld_front(ld);
|
||||
while (ld)
|
||||
{
|
||||
++size;
|
||||
ld = ld->next;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
35
42sh/src/glob/lib_perso/ft_ld_swap.c
Normal file
35
42sh/src/glob/lib_perso/ft_ld_swap.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/24 21:12:53 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 14:18:06 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
t_ld *ft_ld_swap(t_ld *l_cur)
|
||||
{
|
||||
t_ld *l_next;
|
||||
t_ld *l_prev;
|
||||
|
||||
l_next = l_cur;
|
||||
if (l_cur && l_cur->next)
|
||||
{
|
||||
l_prev = l_cur->prev;
|
||||
l_next = l_cur->next;
|
||||
l_cur->next = l_next->next;
|
||||
if (l_cur->next)
|
||||
l_cur->next->prev = l_cur;
|
||||
l_cur->prev = l_next;
|
||||
l_next->next = l_cur;
|
||||
l_next->prev = l_prev;
|
||||
if (l_prev)
|
||||
l_prev->next = l_next;
|
||||
}
|
||||
return (l_next);
|
||||
}
|
||||
34
42sh/src/glob/lib_perso/ft_ld_to_tab.c
Normal file
34
42sh/src/glob/lib_perso/ft_ld_to_tab.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ld_to_tab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/05 16:17:00 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/05 16:22:12 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
char **ft_ld_to_tab(t_ld *ld)
|
||||
{
|
||||
char **my_tab;
|
||||
int nb_item;
|
||||
int index;
|
||||
|
||||
if (!ld)
|
||||
return (NULL);
|
||||
nb_item = ft_ld_size(ld);
|
||||
if (!(my_tab = (char **)malloc(sizeof(char *) * (nb_item + 1))))
|
||||
return (NULL);
|
||||
index = 0;
|
||||
while (ld)
|
||||
{
|
||||
my_tab[index++] = ft_strdup((char *)ld->content);
|
||||
ld = ld->next;
|
||||
}
|
||||
my_tab[index] = NULL;
|
||||
return (my_tab);
|
||||
}
|
||||
25
42sh/src/glob/lib_perso/ft_strjoinf.c
Normal file
25
42sh/src/glob/lib_perso/ft_strjoinf.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoinf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 13:33:24 by wescande #+# #+# */
|
||||
/* Updated: 2017/01/24 16:53:13 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
char *ft_strjoinf(char *s1, char *s2, int state)
|
||||
{
|
||||
char *ans;
|
||||
|
||||
ans = ft_strjoin((const char *)s1, (const char *)s2);
|
||||
if (state == 1 || state == 3)
|
||||
ft_strdel(&s1);
|
||||
if (state == 2 || state == 3)
|
||||
ft_strdel(&s2);
|
||||
return (ans);
|
||||
}
|
||||
31
42sh/src/glob/lib_perso/ft_tabdel.c
Normal file
31
42sh/src/glob/lib_perso/ft_tabdel.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* glob.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/02 14:22:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
void ft_tabdel(char ***mytab)
|
||||
{
|
||||
char **erase;
|
||||
int i;
|
||||
|
||||
if (!mytab || !*mytab)
|
||||
return ;
|
||||
erase = *mytab;
|
||||
i = 0;
|
||||
while (erase[i])
|
||||
{
|
||||
ft_strdel(&erase[i]);
|
||||
++i;
|
||||
}
|
||||
free(*mytab);
|
||||
*mytab = NULL;
|
||||
}
|
||||
27
42sh/src/glob/lib_perso/ft_tablen.c
Normal file
27
42sh/src/glob/lib_perso/ft_tablen.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tablen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/28 16:54:07 by wescande #+# #+# */
|
||||
/* Updated: 2016/12/28 16:55:46 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tablen(char **mytab)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!mytab || !*mytab)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (mytab[i])
|
||||
{
|
||||
++i;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
123
42sh/src/glob/match_pattern.c
Normal file
123
42sh/src/glob/match_pattern.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* match_pattern.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/01 19:46:43 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "glob.h"
|
||||
|
||||
static int match_bracket_char(char **cmp, const char *pat, char c, int neg)
|
||||
{
|
||||
int dir;
|
||||
char s;
|
||||
|
||||
if ((*cmp + 2) < pat && (*cmp)[1] == '-' && (s = (*cmp)[0]))
|
||||
{
|
||||
dir = s > (*cmp)[2];
|
||||
while ((dir && s >= (*cmp)[2]) || (!dir && s <= (*cmp)[2]))
|
||||
{
|
||||
if (!neg && s == c)
|
||||
return (1);
|
||||
else if (neg && s == c)
|
||||
return (0);
|
||||
s += (dir * -2 + 1);
|
||||
}
|
||||
*cmp += 2;
|
||||
}
|
||||
else if (!neg && **cmp == c)
|
||||
return (1);
|
||||
else if (neg && **cmp == c)
|
||||
return (0);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static int match_bracket(t_glob *gl, char c)
|
||||
{
|
||||
char *cmp;
|
||||
int neg;
|
||||
int ret;
|
||||
|
||||
cmp = (char *)gl->pat + 1;
|
||||
while (*gl->pat != ']'
|
||||
|| is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat))
|
||||
{
|
||||
if (!*gl->pat)
|
||||
return (0);
|
||||
++gl->pat;
|
||||
}
|
||||
neg = 0;
|
||||
if ((*cmp == '^' || *cmp == '!')
|
||||
&& !is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], cmp)
|
||||
&& ++neg)
|
||||
++cmp;
|
||||
while (cmp < gl->pat)
|
||||
{
|
||||
ret = match_bracket_char(&cmp, gl->pat, c, neg);
|
||||
if (ret != -1)
|
||||
return (ret);
|
||||
++cmp;
|
||||
}
|
||||
return (neg);
|
||||
}
|
||||
|
||||
static int match_star(t_glob *gl, char *str, char *full_word)
|
||||
{
|
||||
char *fix;
|
||||
|
||||
if (gl->pat[1] == '*' &&
|
||||
!is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1))
|
||||
dir_research(gl, full_word, gl->pat + 1, 1);
|
||||
if (!*++gl->pat)
|
||||
return (1);
|
||||
fix = str + ft_strlen(str);
|
||||
while (fix > str)
|
||||
{
|
||||
if (match_pattern(gl, fix, full_word))
|
||||
return (1);
|
||||
--fix;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
const char *manage_pat(const char *pat, char *str)
|
||||
{
|
||||
if (pat[0] == '.' && pat[1] == '/'
|
||||
&& ((str[0] == '.' && str[1] != '/') || str[0] != '.'))
|
||||
return (pat + 2);
|
||||
return (pat);
|
||||
}
|
||||
|
||||
int match_pattern(t_glob *gl, char *str, char *full_word)
|
||||
{
|
||||
gl->pat = manage_pat(gl->pat, str);
|
||||
while (*gl->pat)
|
||||
{
|
||||
if (is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat))
|
||||
{
|
||||
if (*str != *gl->pat)
|
||||
return (0);
|
||||
}
|
||||
else if (*gl->pat == '?')
|
||||
str++;
|
||||
else if (*gl->pat == '[')
|
||||
{
|
||||
if (!match_bracket(gl, *str))
|
||||
return (0);
|
||||
}
|
||||
else if (*gl->pat == '*')
|
||||
return (match_star(gl, str, full_word));
|
||||
else if (*gl->pat == '/' && !*str && is_directory(full_word))
|
||||
dir_research(gl, full_word, gl->pat + 1, 0);
|
||||
else if (*gl->pat != *str)
|
||||
return (0);
|
||||
++str;
|
||||
++gl->pat;
|
||||
}
|
||||
return (*str ? 0 : 1);
|
||||
}
|
||||
|
|
@ -15,14 +15,12 @@
|
|||
int builtin_bg(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_job *job;
|
||||
t_list *jlist;
|
||||
int rank[2];
|
||||
int id;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
(void)av;
|
||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||
{
|
||||
ft_dprintf(2, "{red}bg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||
|
|
@ -31,13 +29,9 @@ int builtin_bg(const char *path, char *const av[], char *const envp[])
|
|||
jobc = &data_singleton()->jobc;
|
||||
job_getrank(&rank);
|
||||
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
||||
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
|
||||
if (jlist)
|
||||
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
|
||||
{
|
||||
job = jlist->content;
|
||||
mark_job_as_running(job);
|
||||
job_format(job, rank, JOBS_OPTS_L);
|
||||
put_job_in_background(job, 1);
|
||||
job_run(jlist->content, 0);
|
||||
return (0);
|
||||
}
|
||||
else if (av[1])
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:42:04 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:05:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,14 +15,12 @@
|
|||
int builtin_fg(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_job *job;
|
||||
t_list *jlist;
|
||||
int rank[2];
|
||||
int id;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
(void)av;
|
||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||
{
|
||||
ft_dprintf(2, "{red}fg: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||
|
|
@ -31,12 +29,9 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
|
|||
jobc = &data_singleton()->jobc;
|
||||
job_getrank(&rank);
|
||||
id = av[1] ? ft_atoi(av[1]) : rank[0];
|
||||
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
|
||||
if (jlist)
|
||||
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
|
||||
{
|
||||
job = jlist->content;
|
||||
mark_job_as_running(job);
|
||||
put_job_in_foreground(job, 1);
|
||||
job_run(jlist->content, 1);
|
||||
return (0);
|
||||
}
|
||||
else if (av[1])
|
||||
|
|
|
|||
|
|
@ -6,43 +6,100 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:38:50 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:05:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
|
||||
int builtin_jobs(const char *path, char *const av[], char *const envp[])
|
||||
static int bt_jobs_parse(char **av, int *i)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_list *jlist;
|
||||
t_list *tmplist;
|
||||
int rank[2];
|
||||
int opts;
|
||||
int opts;
|
||||
int j;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
(void)av;
|
||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||
opts = 0;
|
||||
*i = 1;
|
||||
while (av[*i])
|
||||
{
|
||||
ft_dprintf(2, "{red}jobs: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||
return (-1);
|
||||
j = 0;
|
||||
if (av[*i][j++] != '-')
|
||||
break ;
|
||||
while (av[*i][j])
|
||||
{
|
||||
if (av[*i][j] == 'l')
|
||||
opts |= JOBS_OPTS_L;
|
||||
else
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: bad option: -%c{eoc}\n",
|
||||
SHELL_NAME, av[*i][j]);
|
||||
return (-1);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
(*i)++;
|
||||
}
|
||||
return (opts);
|
||||
}
|
||||
|
||||
static void bt_jobs_all(int opts)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_list *jlist;
|
||||
t_list *tmplist;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
jlist = jobc->first_job;
|
||||
job_getrank(&rank);
|
||||
opts = 0;
|
||||
if (ft_strcmp(av[1], "-l") == 0)
|
||||
opts |= JOBS_OPTS_L;
|
||||
tmplist = ft_lst_filter(jlist, NULL, NULL);
|
||||
ft_lstsort(&tmplist, job_cmp_id);
|
||||
jlist = tmplist;
|
||||
while (jlist)
|
||||
{
|
||||
job_format(jlist->content, rank, opts);
|
||||
job_format(jlist->content, opts);
|
||||
jlist = jlist->next;
|
||||
}
|
||||
ft_lstdel(&tmplist, ft_lst_cfree);
|
||||
}
|
||||
|
||||
static int bt_jobs_spec(char **av, int opts)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_list *jlist;
|
||||
t_list *lst;
|
||||
int id;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
jlist = jobc->first_job;
|
||||
while (*av)
|
||||
{
|
||||
id = ft_atoi(*av);
|
||||
if (!(lst = ft_lst_find(jlist, &id, job_cmp_id)))
|
||||
{
|
||||
ft_dprintf(2, "{red}jobs: %s: no such job{eoc}\n", *av);
|
||||
return (1);
|
||||
}
|
||||
job_format(lst->content, opts);
|
||||
av++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int builtin_jobs(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
int opts;
|
||||
int i;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
if (!SHELL_HAS_JOBC(data_singleton()->opts))
|
||||
{
|
||||
ft_dprintf(2, "{red}jobs: %s{eoc}\n", SHELL_MSG_NOJOBC);
|
||||
return (1);
|
||||
}
|
||||
if ((opts = bt_jobs_parse((char**)av, &i)) < 0)
|
||||
return (1);
|
||||
if (!av[i])
|
||||
bt_jobs_all(opts);
|
||||
else if (bt_jobs_spec((char **)av + i, opts))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 17:35:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:06:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,18 +26,15 @@ int do_job_notification(void)
|
|||
while (jlist)
|
||||
{
|
||||
j = jlist->content;
|
||||
DG("checking [%i]", j->id);
|
||||
if (job_is_completed(j->id))
|
||||
if (job_is_completed(j->id)
|
||||
|| (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED)))
|
||||
{
|
||||
ret = 1;
|
||||
job_notify_change(j->id);
|
||||
job_remove(j->id);
|
||||
}
|
||||
else if (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED))
|
||||
{
|
||||
ret = 1;
|
||||
job_notify_change(j->id);
|
||||
j->attributes |= JOB_NOTIFIED;
|
||||
if (job_is_completed(j->id))
|
||||
job_remove(j->id);
|
||||
else
|
||||
j->attributes |= JOB_NOTIFIED;
|
||||
}
|
||||
jlist = jlist->next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:40:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:07:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,15 +25,13 @@ int job_addprocess(t_process *p)
|
|||
job->id = jobc->current_id;
|
||||
job->pgid = p->pid;
|
||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||
/* DG("added new job [%i]", job->id); */
|
||||
}
|
||||
job = jobc->first_job->content;
|
||||
if (p->pid > 0)
|
||||
{
|
||||
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
||||
/* DG("added pid=%i to [%i]", p->pid, job->id); */
|
||||
}
|
||||
if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p->attributes))
|
||||
job_notify_new(job);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 13:38:13 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 11:08:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:06:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,4 +16,3 @@ int job_cmp_id(t_job *job, int *id)
|
|||
{
|
||||
return (job->id - *id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* job_format.c :+: :+: :+: */
|
||||
/* job_format.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 12:47:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 11:16:50 by jhalford ### ########.fr */
|
||||
/* Created: 2017/01/31 15:06:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 15:06:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
void job_format(t_job *j, int rank[2], int opts)
|
||||
void job_format(t_job *j, int opts)
|
||||
{
|
||||
t_list *plist;
|
||||
int firstp;
|
||||
|
||||
job_format_head(j, rank);
|
||||
job_format_head(j);
|
||||
plist = j->first_process;
|
||||
firstp = 1;
|
||||
while (plist)
|
||||
|
|
|
|||
|
|
@ -6,16 +6,18 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 13:10:38 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 13:53:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 14:53:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
void job_format_head(t_job *j, int rank[2])
|
||||
void job_format_head(t_job *j)
|
||||
{
|
||||
char crank;
|
||||
char crank;
|
||||
int rank[2];
|
||||
|
||||
job_getrank(&rank);
|
||||
if (j->id == rank[0])
|
||||
crank = '+';
|
||||
else if (j->id == rank[1])
|
||||
|
|
|
|||
|
|
@ -1,6 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* job_getprocess.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 15:07:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
t_process *job_getprocess(pid_t pid)
|
||||
t_list *job_getprocess(pid_t pid)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_job *j;
|
||||
|
|
@ -13,7 +25,7 @@ t_process *job_getprocess(pid_t pid)
|
|||
{
|
||||
j = jlist->content;
|
||||
if ((lst = ft_lst_find(j->first_process, &pid, &process_cmp_pid)))
|
||||
return (lst->content);
|
||||
return (lst);
|
||||
jlist = jlist->next;
|
||||
}
|
||||
return (NULL);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 10:30:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:04:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 15:15:21 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 13:52:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,12 +25,8 @@ int job_is_completed(int id)
|
|||
while (lst)
|
||||
{
|
||||
p = lst->content;
|
||||
DG("checking pid=%i", p->pid);
|
||||
if (!(p->attributes & PROCESS_COMPLETED))
|
||||
{
|
||||
DG("process %i is not completed", p->pid);
|
||||
return (0);
|
||||
}
|
||||
lst = lst->next;
|
||||
}
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 11:16:17 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 14:46:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,10 +16,8 @@ void job_notify_change(int id)
|
|||
{
|
||||
t_job *job;
|
||||
t_jobc *jobc;
|
||||
int rank[2];
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||
job_getrank(&rank);
|
||||
job_format(job, rank, JOBS_OPTS_L);
|
||||
job_format(job, JOBS_OPTS_L);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 15:16:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 13:44:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,16 +14,18 @@
|
|||
|
||||
void job_remove(int id)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_jobc *jobc;
|
||||
t_job *j;
|
||||
t_process *p;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||
if (job_is_completed(id))
|
||||
{
|
||||
DG("job_remove");
|
||||
p = ft_lstlast(j->first_process)->content;
|
||||
set_exitstatus(p->status, 0);
|
||||
if (id < data_singleton()->jobc.current_id)
|
||||
data_singleton()->jobc.current_id = id;
|
||||
ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free);
|
||||
}
|
||||
else
|
||||
DG("job_remove failed (not completed)");
|
||||
}
|
||||
|
|
|
|||
23
42sh/src/job-control/job_run.c
Normal file
23
42sh/src/job-control/job_run.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* job_run.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 14:47:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
void job_run(t_job *job, int foreground)
|
||||
{
|
||||
mark_job_as_running(job);
|
||||
job_format(job, JOBS_OPTS_L);
|
||||
if (foreground)
|
||||
put_job_in_foreground(job, 1);
|
||||
else
|
||||
put_job_in_background(job, 1);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 12:33:09 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:07:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ void job_update_status(void)
|
|||
int status;
|
||||
pid_t pid;
|
||||
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
while (!process_mark_status(pid, status))
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 15:14:38 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 13:44:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,19 +17,15 @@ int job_wait(int id)
|
|||
pid_t pid;
|
||||
int status;
|
||||
|
||||
DG("job wait");
|
||||
if (job_is_stopped(id) || job_is_completed(id))
|
||||
if (job_is_stopped(id))
|
||||
return (0);
|
||||
DG("waitpid now");
|
||||
job_update_status();
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||
DG("waitpid done");
|
||||
while (!process_mark_status(pid, status)
|
||||
&& !job_is_completed(id)
|
||||
&& !job_is_stopped(id))
|
||||
{
|
||||
DG("waitpid now");
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||
DG("waitpid done");
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 10:52:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:08:11 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
void mark_job_as_running (t_job *j)
|
||||
void mark_job_as_running(t_job *j)
|
||||
{
|
||||
t_list *plist;
|
||||
t_process *p;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 13:00:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/12 13:40:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:06:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,16 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 13:16:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:10:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
void process_format(t_list **plist, int firstp, int opts)
|
||||
static void process_format_state(t_process *p)
|
||||
{
|
||||
t_process *p;
|
||||
int state;
|
||||
|
||||
p = (*plist)->content;
|
||||
if (!firstp)
|
||||
ft_printf(" ");
|
||||
if (opts & JOBS_OPTS_L)
|
||||
ft_printf("%i ", p->pid);
|
||||
state = p->attributes & PROCESS_STATE_MASK;
|
||||
if (state == PROCESS_RUNNING)
|
||||
ft_putstr("running ");
|
||||
|
|
@ -41,8 +35,41 @@ void process_format(t_list **plist, int firstp, int opts)
|
|||
ft_printf("exit %i ", p->status);
|
||||
}
|
||||
ft_putchar('\t');
|
||||
if (opts & JOBS_OPTS_L)
|
||||
}
|
||||
|
||||
static void process_format_com_long(t_list **plist)
|
||||
{
|
||||
t_process *p;
|
||||
|
||||
p = (*plist)->content;
|
||||
if (p->attributes & PROCESS_SUBSHELL)
|
||||
{
|
||||
ft_putstr("( ");
|
||||
ft_putstr(p->av[2]);
|
||||
ft_putstr(" )");
|
||||
}
|
||||
else
|
||||
ft_sstrprint(p->av, ' ');
|
||||
if ((*plist)->next)
|
||||
ft_putstr(" |");
|
||||
(*plist) = (*plist)->next;
|
||||
}
|
||||
|
||||
static void process_format_com_short(t_list **plist, t_flag state)
|
||||
{
|
||||
t_process *p;
|
||||
|
||||
while (*plist)
|
||||
{
|
||||
p = (*plist)->content;
|
||||
if (!(p->attributes & state) ||
|
||||
(state == PROCESS_COMPLETED && p->status != 0))
|
||||
break ;
|
||||
if (p->attributes & PROCESS_CONTINUED)
|
||||
{
|
||||
p->attributes &= ~PROCESS_STATE_MASK;
|
||||
p->attributes &= ~PROCESS_RUNNING;
|
||||
}
|
||||
if (p->attributes & PROCESS_SUBSHELL)
|
||||
{
|
||||
ft_putstr("( ");
|
||||
|
|
@ -52,34 +79,26 @@ void process_format(t_list **plist, int firstp, int opts)
|
|||
else
|
||||
ft_sstrprint(p->av, ' ');
|
||||
if ((*plist)->next)
|
||||
ft_putstr(" |");
|
||||
ft_putstr(" | ");
|
||||
(*plist) = (*plist)->next;
|
||||
}
|
||||
}
|
||||
|
||||
void process_format(t_list **plist, int firstp, int opts)
|
||||
{
|
||||
t_process *p;
|
||||
t_flag state;
|
||||
|
||||
p = (*plist)->content;
|
||||
state = p->attributes & PROCESS_STATE_MASK;
|
||||
if (!firstp)
|
||||
ft_printf(" ");
|
||||
if (opts & JOBS_OPTS_L)
|
||||
ft_printf("%i ", p->pid);
|
||||
process_format_state(p);
|
||||
if (opts & JOBS_OPTS_L)
|
||||
process_format_com_long(plist);
|
||||
else
|
||||
{
|
||||
while (*plist)
|
||||
{
|
||||
p = (*plist)->content;
|
||||
if (!(p->attributes & state) ||
|
||||
(state == PROCESS_COMPLETED && p->status != 0))
|
||||
break;
|
||||
if (p->attributes & PROCESS_CONTINUED)
|
||||
{
|
||||
p->attributes &= ~PROCESS_STATE_MASK;
|
||||
p->attributes &= ~PROCESS_RUNNING;
|
||||
}
|
||||
if (p->attributes & PROCESS_SUBSHELL)
|
||||
{
|
||||
ft_putstr("( ");
|
||||
ft_putstr(p->av[2]);
|
||||
ft_putstr(" )");
|
||||
}
|
||||
else
|
||||
ft_sstrprint(p->av, ' ');
|
||||
if ((*plist)->next)
|
||||
ft_putstr(" | ");
|
||||
(*plist) = (*plist)->next;
|
||||
}
|
||||
}
|
||||
process_format_com_short(plist, state);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/02 19:11:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 15:45:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 15:14:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:10:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,32 +14,31 @@
|
|||
|
||||
int process_mark_status(pid_t pid, int status)
|
||||
{
|
||||
t_list *plist;
|
||||
t_process *p;
|
||||
|
||||
if (pid > 1)
|
||||
{
|
||||
if ((p = job_getprocess(pid)))
|
||||
if ((plist = job_getprocess(pid)))
|
||||
{
|
||||
p = plist->content;
|
||||
p->status = status;
|
||||
if (WIFSTOPPED(status))
|
||||
{
|
||||
DG("marking: pid=%i, status=%i (stopped sig %i)", pid, status, WTERMSIG(status));
|
||||
p->attributes &= ~PROCESS_STATE_MASK;
|
||||
p->attributes |= PROCESS_SUSPENDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
DG("marking: pid=%i, status=%i (completed sig %i)", pid, status, WTERMSIG(status));
|
||||
p->attributes &= ~PROCESS_STATE_MASK;
|
||||
p->attributes |= PROCESS_COMPLETED;
|
||||
if (WIFSIGNALED(status))
|
||||
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}",
|
||||
(int) pid, WTERMSIG(p->status));
|
||||
(int)pid, WTERMSIG(status));
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
ft_dprintf(2, "No child process %d.\n", pid);
|
||||
return(-1);
|
||||
}
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,16 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/08 13:24:53 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:09:06 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
int put_job_in_background(t_job *job, int cont)
|
||||
int put_job_in_background(t_job *j, int cont)
|
||||
{
|
||||
/* Send the job a continue signal, if necessary. */
|
||||
if (cont)
|
||||
if (kill (-job->pgid, SIGCONT) < 0)
|
||||
perror ("kill (SIGCONT)");
|
||||
if (kill(-j->pgid, SIGCONT) < 0)
|
||||
DG("kill(SIGCONT) failed");
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,41 +6,32 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 13:16:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:10:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
int put_job_in_foreground(t_job *job, int cont)
|
||||
int put_job_in_foreground(t_job *j, int cont)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
/* Send the job a continue signal, if necessary. */
|
||||
tcsetpgrp(STDIN, j->pgid);
|
||||
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
|
||||
|
||||
if (cont)
|
||||
{
|
||||
/* Put the job into the foreground. */
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
if (tcsetpgrp(STDIN, job->pgid) == -1)
|
||||
DG("couldn't put process in control. errno=%i, pgid=%i", errno, job->pgid);
|
||||
signal(SIGTTOU, sigttou_handler);
|
||||
tcsetattr (STDIN, TCSANOW, &job->tmodes);
|
||||
if (kill(-job->pgid, SIGCONT) < 0)
|
||||
perror("kill (SIGCONT)");
|
||||
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
|
||||
if (kill(-j->pgid, SIGCONT) < 0)
|
||||
DG("kill(SIGCONT) failed");
|
||||
}
|
||||
/* Wait for it to report. */
|
||||
DG("gonna wait for job id=%i", job->id);
|
||||
job_wait(job->id);
|
||||
job_remove(job->id);
|
||||
job_wait(j->id);
|
||||
job_remove(j->id);
|
||||
|
||||
/* Put the shell back in the foreground. */
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
tcsetpgrp(STDIN, jobc->shell_pgid);
|
||||
signal(SIGTTOU, sigttou_handler);
|
||||
|
||||
/* Restore the shell’s terminal modes. */
|
||||
tcgetattr(STDIN, &job->tmodes);
|
||||
tcgetattr(STDIN, &j->tmodes);
|
||||
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 17:59:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/31 15:09:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,9 +18,4 @@ void sigchld_handler(int signo)
|
|||
|
||||
(void)signo;
|
||||
data = data_singleton();
|
||||
/* DG("got SIGCHLD"); */
|
||||
/* if (do_job_notification()) */
|
||||
/* ft_putstr(SHELL_PROMPT); */
|
||||
/* if (data_singleton()->mode != MODE_EXEC) */
|
||||
/* job_update_status(); */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
void sigint_handler(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
DG("got SIGINT in process %i", getpid());
|
||||
DG("pid:%i got SIGINT", getpid());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
void sigttin_handler(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
DG("got SIGTTIN");
|
||||
DG("got SIGTTIN, pid=%i, pgid=%i", getpid(), getpgrp());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
void sigttou_handler(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
DG("got SIGTTOU");
|
||||
DG("got SIGTTOU, pid=%i, pgid=%i", getpid(), getpgid(getpid()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/20 00:31:42 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/02/02 15:16:25 by jhalford ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
28
42sh/src/lexer/ft_lexer.c
Normal file
28
42sh/src/lexer/ft_lexer.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lexer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:42:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int ft_lexer(t_list **alst, char **command)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if (!*command)
|
||||
ret = 1;
|
||||
else if (ft_tokenize(alst, *command, DEFAULT))
|
||||
ret = 1;
|
||||
else if (ft_post_tokenize(alst, command))
|
||||
ret = 1;
|
||||
ft_strdel(command);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,23 +6,44 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/02/02 17:50:45 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/02/02 15:29:57 by jhalford ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
int ft_post_tokenize(t_list **alst, char *str)
|
||||
int ft_post_tokenize(t_list **alst, char **str)
|
||||
{
|
||||
int ret;
|
||||
t_flag tk;
|
||||
|
||||
<<<<<<< HEAD
|
||||
// get_reserverd_words(alst, str);
|
||||
while ((ret = reduce_parens(alst, str)))
|
||||
=======
|
||||
while ((ret = reduce_parens(alst, *str)))
|
||||
>>>>>>> master
|
||||
if (ret == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near '('{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
while ((ret = reduce_bquotes(alst, &str)))
|
||||
}
|
||||
tk = TK_PAREN_CLOSE;
|
||||
if (ft_lst_find(*alst, &tk, token_cmp_type))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near ')'{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
}
|
||||
while ((ret = reduce_bquotes(alst, str)))
|
||||
if (ret == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: parse error near '`'{eoc}\n", SHELL_NAME);
|
||||
return (-1);
|
||||
DG("new command from bquotes: '%s'", str);
|
||||
}
|
||||
DG("new command from bquotes: '%s'", *str);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/02/02 17:50:28 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/02/02 15:34:45 by jhalford ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/02 17:50:17 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:27:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/23 23:24:40 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/30 13:07:52 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,6 +22,6 @@ int lexer_backslash(t_list **alst, char *str)
|
|||
|
||||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
token_append(token, str[1]);
|
||||
token_append(token, str[1], 1);
|
||||
return (ft_tokenize(alst, str + 2, WORD));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/26 18:16:02 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/27 15:53:10 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +34,10 @@ int lexer_default(t_list **alst, char *str)
|
|||
else
|
||||
state = WORD;
|
||||
token = (*alst)->content;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
token_append(token, *str, 0);
|
||||
>>>>>>> master
|
||||
token->type = TK_N_WORD;
|
||||
return (ft_tokenize(alst, str, state));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/26 23:37:49 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/26 16:30:43 by jhalford ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/25 22:52:47 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/27 15:53:31 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,9 +27,9 @@ int lexer_dquote(t_list **alst, char *str)
|
|||
return (ft_tokenize(alst, str + 1, DEFAULT));
|
||||
if (*str == '\\')
|
||||
{
|
||||
token_append(token, *(str + 1));
|
||||
token_append(token, *(str + 1), 1);
|
||||
return (lexer_dquote(alst, str + 1));
|
||||
}
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 1);
|
||||
return (lexer_dquote(alst, str));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/24 19:06:00 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/27 15:54:53 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,17 +21,17 @@ int lexer_great(t_list **alst, char *str)
|
|||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
token_append(token, str[0]);
|
||||
token_append(token, str[0], 0);
|
||||
if (*(str + 1) == '&')
|
||||
{
|
||||
token->type = TK_GREATAND;
|
||||
token_append(token, str[1]);
|
||||
token_append(token, str[1], 0);
|
||||
return (lexer_greatand(alst, str + 2));
|
||||
}
|
||||
else if (*(str + 1) == '>')
|
||||
{
|
||||
token->type = TK_DGREAT;
|
||||
token_append(token, str[1]);
|
||||
token_append(token, str[1], 0);
|
||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/25 22:52:39 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/27 15:55:04 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,12 +24,12 @@ int lexer_greatand(t_list **alst, char *str)
|
|||
token->type = TK_GREATAND;
|
||||
if (ft_isdigit(*str))
|
||||
{
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 0);
|
||||
return (lexer_greatand(alst, str + 1));
|
||||
}
|
||||
else if (*str == '-')
|
||||
{
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 0);
|
||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
||||
}
|
||||
return (ft_tokenize(alst, str, DEFAULT));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/26 18:26:28 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/27 15:55:16 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,17 +21,17 @@ int lexer_less(t_list **alst, char *str)
|
|||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
token_append(token, str[0]);
|
||||
token_append(token, str[0], 0);
|
||||
if (*(str + 1) == '&')
|
||||
{
|
||||
token->type = TK_LESSAND;
|
||||
token_append(token, str[1]);
|
||||
token_append(token, str[1], 0);
|
||||
return (lexer_lessand(alst, str + 2));
|
||||
}
|
||||
else if (*(str + 1) == '<')
|
||||
{
|
||||
token->type = TK_DLESS;
|
||||
token_append(token, str[1]);
|
||||
token_append(token, str[1], 0);
|
||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/03 11:58:52 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/27 15:55:27 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,12 +20,12 @@ int lexer_lessand(t_list **alst, char *str)
|
|||
token->type = TK_LESSAND;
|
||||
if (ft_isdigit(*str))
|
||||
{
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 0);
|
||||
return (lexer_lessand(alst, str + 1));
|
||||
}
|
||||
else if (*str == '-')
|
||||
{
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 0);
|
||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
||||
}
|
||||
return (ft_tokenize(alst, str, DEFAULT));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2017/01/25 23:05:08 by ariard ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2017/01/30 13:08:05 by wescande ### ########.fr */
|
||||
>>>>>>> master
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +22,6 @@ int lexer_number(t_list **alst, char *str)
|
|||
t_lexstate state;
|
||||
|
||||
token = (*alst)->content;
|
||||
DG("*str=%c", *str);
|
||||
if ((state = get_lexer_state(str)))
|
||||
return (ft_tokenize(alst, str, state));
|
||||
if (*str == '>')
|
||||
|
|
@ -27,7 +30,7 @@ int lexer_number(t_list **alst, char *str)
|
|||
return (ft_tokenize(alst, str, LESS));
|
||||
else if (ft_isdigit(*str))
|
||||
{
|
||||
token_append(token, *str);
|
||||
token_append(token, *str, 0);
|
||||
return (lexer_number(alst, str + 1));
|
||||
}
|
||||
return (ft_tokenize(alst, str, DEFAULT));
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue