diff --git a/42sh/Makefile b/42sh/Makefile index 8dcf5189..022c2fe2 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -1,3 +1,4 @@ +<<<<<<< HEAD NAME = minishell CC = gcc TAGFILE = .tags @@ -88,3 +89,185 @@ fclean: clean @$(MAKE) fclean -C libft/ 2>/dev/null re: fclean all +======= +#* ************************************************************************** *# +#* *# +#* ::: :::::::: *# +#* Makefile :+: :+: :+: *# +#* +:+ +:+ +:+ *# +#* By: wescande +#+ +:+ +#+ *# +#* +#+#+#+#+#+ +#+ *# +#* Created: 2016/08/29 21:32:58 by wescande #+# #+# *# +#* Updated: 2016/09/27 20:14:55 by wescande ### ########.fr *# +#* *# +#* ************************************************************************** *# + +NAME = 42sh + +CC = gcc +FLAGS = -Wall -Wextra -Werror +D_FLAGS = -g + +LEN_NAME = `printf "%s" $(NAME) |wc -c` +DELTA = $$(echo "$$(tput cols)-24-$(LEN_NAME)"|bc) + +LIBFT_DIR = libft/ +LIBFT_LIB = $(LIBFT_DIR)libft.a +LIBFT_INC = $(LIBFT_DIR)includes/ + +LIBS = -ltermcap + +SRC_DIR = srcs/ +INC_DIR = includes/ +OBJ_DIR = objs/ + +SRC_BASE = \ +builtin/builtin.c\ +builtin/builtin_cd.c\ +builtin/builtin_echo.c\ +builtin/builtin_env.c\ +builtin/builtin_exit.c\ +builtin/builtin_setenv.c\ +builtin/builtin_unsetenv.c\ +exec/ast_free.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/fd_redirect.c\ +exec/ft_cmd.c\ +exec/ft_exec.c\ +exec/ft_findexec.c\ +exec/set_exitstatus.c\ +glob/glob.c\ +glob/glob_print.c\ +glob/ld/ft_ld_back.c\ +glob/ld/ft_ld_clear.c\ +glob/ld/ft_ld_del.c\ +glob/ld/ft_ld_front.c\ +glob/ld/ft_ld_new.c\ +glob/ld/ft_ld_pushback.c\ +glob/ld/ft_ld_pushfront.c\ +glob/ld/ft_ld_reverse.c\ +glob/ld/ft_ld_size.c\ +glob/ld/ft_ld_swap.c\ +glob/ld/ft_ld_to_tab.c\ +lexer/ft_tokenize.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_word.c\ +lexer/token_append.c\ +lexer/token_cmp_type.c\ +lexer/token_free.c\ +lexer/token_init.c\ +lexer/token_print.c\ +line-editing/curs_ask.c\ +line-editing/curs_clear.c\ +line-editing/curs_goto.c\ +line-editing/curs_move.c\ +line-editing/curs_setup.c\ +line-editing/curs_single.c\ +line-editing/curs_term_setup.c\ +line-editing/curs_write.c\ +line-editing/ft_interactive_sh.c\ +line-editing/ft_readline.c\ +line-editing/rl_bitset.c\ +line-editing/rl_clear_function.c\ +line-editing/rl_clipboard_function.c\ +line-editing/rl_clipboard_utility.c\ +line-editing/rl_comp_function.c\ +line-editing/rl_default_function.c\ +line-editing/rl_display.c\ +line-editing/rl_dynamic_buffer.c\ +line-editing/rl_long_move_function.c\ +line-editing/rl_merge_line.c\ +line-editing/rl_page_move_function.c\ +line-editing/rl_prompt.c\ +line-editing/rl_quoting_function.c\ +line-editing/rl_remove_function.c\ +line-editing/rl_setup.c\ +line-editing/rl_short_move_function.c\ +line-editing/rl_stack_line.c\ +line-editing/rl_state_function.c\ +line-editing/rl_word_move_function.c\ +line-editing/rl_word_utility.c\ +main/data_exit.c\ +main/data_init.c\ +main/ft_cleanup.c\ +main/ft_putast.c\ +main/ft_putast2.c\ +main/lib_expansion.c\ +main/main.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_word.c + +SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) +OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) + +all : $(NAME) + +$(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" + +$(LIBFT_LIB): + @make -j -C $(LIBFT_DIR) + +$(OBJ_DIR) : + @mkdir -p $(OBJ_DIR) + @mkdir -p $(dir $(OBJS)) + +$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) + @$(CC) $(FLAGS) -MMD -c $< -o $@\ + -I $(INC_DIR)\ + -I $(LIBFT_INC) + @printf "\r\033[38;5;11m⌛ MAKE %s plz wait : %*s\033[0m\033[K" $(NAME) $(DELTA) "$@" + +clean: cleanlib + @rm -rf $(OBJ_DIR) + @echo "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K" + +cleanlib: + @make -C $(LIBFT_DIR) clean + +fclean: clean fcleanlib + @rm -f $(NAME) + @echo "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K" + +fcleanlib: cleanlib + @make -C $(LIBFT_DIR) fclean + +re: fclean all + +relib: fcleanlib $(LIBFT_LIB) + +.PHONY : fclean clean re relib cleanlib fcleanlib + +-include $(OBJS:.o=.d) +>>>>>>> premier commit. working. . . diff --git a/42sh/includes/glob.h b/42sh/includes/glob.h new file mode 100644 index 00000000..4df7b651 --- /dev/null +++ b/42sh/includes/glob.h @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* glob.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */ +/* Updated: 2017/01/05 16:20:32 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GLOB_H +# define GLOB_H + +# include "minishell.h" + +typedef struct s_ld +{ + void *content; + struct s_ld *next; + struct s_ld *prev; +} t_ld; + +char **glob(const char *str, char **env); +void glob_print(t_list *token, t_data *data); + +/* +** 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); + + +#endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 02b05202..108ea05b 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ +<<<<<<< HEAD /* Updated: 2017/01/11 17:17:16 by jhalford ### ########.fr */ +======= +/* Updated: 2017/01/05 14:24:14 by wescande ### ########.fr */ +>>>>>>> premier commit. working. . . /* */ /* ************************************************************************** */ @@ -21,8 +25,12 @@ # include "parser.h" # include "ft_readline.h" # include "exec.h" +<<<<<<< HEAD # include "builtin.h" # include "job_control.h" +======= +# include "glob.h" +>>>>>>> premier commit. working. . . # include # include diff --git a/42sh/libft b/42sh/libft index ab92f0e5..4c497745 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit ab92f0e5d817c9d726a8ccf2f11c084ba446bbdf +Subproject commit 4c4977452745481166749b813e8db51dcf0caf44 diff --git a/42sh/srcs/builtin/builtin.c b/42sh/srcs/builtin/builtin.c new file mode 100644 index 00000000..1966a63e --- /dev/null +++ b/42sh/srcs/builtin/builtin.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/28 14:21:34 by jhalford #+# #+# */ +/* Updated: 2016/12/03 15:17:21 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_stof g_builtin[] = { + {"echo", &builtin_echo}, + {"cd", &builtin_cd}, + {"setenv", &builtin_setenv}, + {"unsetenv", &builtin_unsetenv}, + {"env", &builtin_env}, + {"exit", &builtin_exit}, + {NULL, NULL}, +}; + +int ft_builtin(char **av, t_data *data) +{ + int i; + int ret; + + i = -1; + while (g_builtin[++i].name) + if (ft_strcmp(g_builtin[i].name, *av) == 0) + { + if (data->exec.fdout != STDOUT) + { + if (fork() == 0) + { + fd_redirect(data); + ret = (g_builtin[i].f)(av, data); + exit(ret); + } + } + else + { + ret = (g_builtin[i].f)(av, data); + set_exitstatus(data, ret); + } + return (1); + } + return (0); +} diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/srcs/builtin/builtin_cd.c similarity index 100% rename from 42sh/src/builtin/builtin_cd.c rename to 42sh/srcs/builtin/builtin_cd.c diff --git a/42sh/src/builtin/builtin_echo.c b/42sh/srcs/builtin/builtin_echo.c similarity index 100% rename from 42sh/src/builtin/builtin_echo.c rename to 42sh/srcs/builtin/builtin_echo.c diff --git a/42sh/src/builtin/builtin_env.c b/42sh/srcs/builtin/builtin_env.c similarity index 100% rename from 42sh/src/builtin/builtin_env.c rename to 42sh/srcs/builtin/builtin_env.c diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/srcs/builtin/builtin_exit.c similarity index 100% rename from 42sh/src/builtin/builtin_exit.c rename to 42sh/srcs/builtin/builtin_exit.c diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/srcs/builtin/builtin_setenv.c similarity index 100% rename from 42sh/src/builtin/builtin_setenv.c rename to 42sh/srcs/builtin/builtin_setenv.c diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/srcs/builtin/builtin_unsetenv.c similarity index 100% rename from 42sh/src/builtin/builtin_unsetenv.c rename to 42sh/srcs/builtin/builtin_unsetenv.c diff --git a/42sh/src/exec/ast_free.c b/42sh/srcs/exec/ast_free.c similarity index 100% rename from 42sh/src/exec/ast_free.c rename to 42sh/srcs/exec/ast_free.c diff --git a/42sh/src/exec/exec_and_if.c b/42sh/srcs/exec/exec_and_if.c similarity index 100% rename from 42sh/src/exec/exec_and_if.c rename to 42sh/srcs/exec/exec_and_if.c diff --git a/42sh/src/exec/exec_command.c b/42sh/srcs/exec/exec_command.c similarity index 100% rename from 42sh/src/exec/exec_command.c rename to 42sh/srcs/exec/exec_command.c diff --git a/42sh/src/exec/exec_dgreat.c b/42sh/srcs/exec/exec_dgreat.c similarity index 100% rename from 42sh/src/exec/exec_dgreat.c rename to 42sh/srcs/exec/exec_dgreat.c diff --git a/42sh/src/exec/exec_great.c b/42sh/srcs/exec/exec_great.c similarity index 100% rename from 42sh/src/exec/exec_great.c rename to 42sh/srcs/exec/exec_great.c diff --git a/42sh/src/exec/exec_less.c b/42sh/srcs/exec/exec_less.c similarity index 100% rename from 42sh/src/exec/exec_less.c rename to 42sh/srcs/exec/exec_less.c diff --git a/42sh/src/exec/exec_or_if.c b/42sh/srcs/exec/exec_or_if.c similarity index 100% rename from 42sh/src/exec/exec_or_if.c rename to 42sh/srcs/exec/exec_or_if.c diff --git a/42sh/src/exec/exec_pipe.c b/42sh/srcs/exec/exec_pipe.c similarity index 100% rename from 42sh/src/exec/exec_pipe.c rename to 42sh/srcs/exec/exec_pipe.c diff --git a/42sh/src/exec/exec_semi.c b/42sh/srcs/exec/exec_semi.c similarity index 100% rename from 42sh/src/exec/exec_semi.c rename to 42sh/srcs/exec/exec_semi.c diff --git a/42sh/srcs/exec/fd_redirect.c b/42sh/srcs/exec/fd_redirect.c new file mode 100644 index 00000000..6c1d8c47 --- /dev/null +++ b/42sh/srcs/exec/fd_redirect.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_redirect.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ +/* Updated: 2016/12/03 15:24:08 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void fd_redirect(t_data *data) +{ + if (data->exec.fdin != STDIN) + { + dup2(data->exec.fdin, STDIN); + close(data->exec.fdin); + } + if (data->exec.fdout != STDOUT) + { + dup2(data->exec.fdout, STDOUT); + close(data->exec.fdout); + } +} diff --git a/42sh/srcs/exec/ft_cmd.c b/42sh/srcs/exec/ft_cmd.c new file mode 100644 index 00000000..adb9d6db --- /dev/null +++ b/42sh/srcs/exec/ft_cmd.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */ +/* Updated: 2016/12/09 21:50:26 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +extern pid_t g_pid; + +int ft_cmd_process(char **argv, t_data *data) +{ + char *execpath; + + ft_expand_dollar(argv, data->env); + if (ft_builtin(argv, data)) + return (0); + else if (ft_strchr(argv[0], '/')) + execpath = argv[0]; + else if (!(execpath = ft_findexec(ft_getenv(data->env, "PATH"), argv[0]))) + { + ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, argv[0]); + set_exitstatus(data, 127); + return (-1); + } + return (ft_cmd_exec(execpath, argv, data)); +} + +int ft_cmd_exec(char *execpath, char **argv, t_data *data) +{ + pid_t pid; + int status; + + if (access(execpath, X_OK) == -1) + { + ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, argv[0]); + ft_strdel(&execpath); + return (-1); + } + if ((pid = fork()) == -1) + return (-1); + else if (pid == 0) + { + fd_redirect(data); + execve(execpath, argv, data->env); + } + else + { + ft_strdel(&execpath); + g_pid = pid; + if (data->exec.fdout == STDOUT) + { + waitpid(pid, &status, 0); + set_exitstatus(data, status); + } + g_pid = 0; + } + return (0); +} diff --git a/42sh/src/exec/ft_exec.c b/42sh/srcs/exec/ft_exec.c similarity index 100% rename from 42sh/src/exec/ft_exec.c rename to 42sh/srcs/exec/ft_exec.c diff --git a/42sh/src/exec/ft_findexec.c b/42sh/srcs/exec/ft_findexec.c similarity index 100% rename from 42sh/src/exec/ft_findexec.c rename to 42sh/srcs/exec/ft_findexec.c diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/srcs/exec/set_exitstatus.c similarity index 100% rename from 42sh/src/exec/set_exitstatus.c rename to 42sh/srcs/exec/set_exitstatus.c diff --git a/42sh/srcs/glob/glob.c b/42sh/srcs/glob/glob.c new file mode 100644 index 00000000..49f54440 --- /dev/null +++ b/42sh/srcs/glob/glob.c @@ -0,0 +1,133 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* glob.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ +/* Updated: 2017/01/05 20:09:14 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "glob.h" + +/* +** glob return expansion of a string. +** pattern searched are ~, *, ?, [a-z], [!a-z], [^a-z], {ab}. +** input parameters are : +** -char *pat -> pattern string to be looking for match +** -char **env -> env var. could be NULL + to just expanse in local directory and not in path +*/ + +static 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; +} + +static int match_bracket(const char **pat, char **str) +{ + return (1); +} + +static int match_star(const char *pat, char *str) +{ + char *fix; + + fix = str + ft_strlen(str); + return (1); +} + +static int match_pattern(const char *pat, char *str) +{ + while (*pat) + { + if (*pat == '?') + str++; + else if (*pat == '[') + { + if (!match_bracket(&pat, &str)) + return (0); + } + else if (*pat == '*') + return (match_star(pat, str)); + else if (*pat == '\\') + { + if (!*++pat || *str != *pat) + return (0); + } + else if (*pat != *str) + return (0); + ++str; + } + return (*str ? 0 : 1); +} + +static void dir_research(const char *pat, char *path, t_ld **match) +{ + DIR *dir; + struct dirent *inside; + + if (!(dir = opendir(path))) + return ; + while ((inside = readdir(dir))) + { + if (match_pattern(pat, inside->d_name)) + ft_ld_pushfront(match, ft_strdup(inside->d_name)); + } +} + +static void path_research(const char *pat, char **path, t_ld **match) +{ + int i; + int len; + char *good_path; + + i = -1; + good_path = NULL; + while (path[++i]) + { + good_path = ft_strjoin(path[i], "/"); + while ((len = ft_strlen(good_path)) && good_path[len - 1] == '/' + && good_path[len - 2] == '/') + good_path[ft_strlen(good_path) - 1] = '\0'; + dir_research(pat, good_path, match); + ft_strdel(&good_path); + } +} + +char **glob(const char *pat, char **env) +{ + t_ld *match; + char **gl; + char **path; + + match = NULL; + gl = NULL; + if (env && (path = ft_strsplit(ft_getenv(env, "PATH"), ':'))) + { + path_research(pat, path, &match); + ft_tabdel(&path); + } + dir_research(pat, "./", &match); + if (match) + { + gl = ft_ld_to_tab(match); + ft_ld_clear(&match, &ft_strdel); + } + return (gl); +} diff --git a/42sh/srcs/glob/glob_print.c b/42sh/srcs/glob/glob_print.c new file mode 100644 index 00000000..eba06727 --- /dev/null +++ b/42sh/srcs/glob/glob_print.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* glob_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/05 16:09:40 by wescande #+# #+# */ +/* Updated: 2017/01/05 16:31:36 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "glob.h" + +void ft_tabprint_fd(char **mytab, int fd) +{ + int i; + + if (!mytab || !*mytab) + return ; + i = 0; + while (mytab[i]) + { + ft_putendl_fd(mytab[i], fd); + ++i; + } +} + +void glob_print(t_list *lst, t_data *data) +{ + t_token *token; + int i; + t_type type; + char **glob_ret; + + while (lst) + { + i = 1; + token = lst->content; + type = token->type; + while (type >> (i++ + 2)) + ; + glob_ret = glob(token->data, data->env); + DG("%02i '%s'", i, token->data); + ft_tabprint_fd(glob_ret, 2); + lst = lst->next; + } +} diff --git a/42sh/srcs/glob/ld/ft_ld_back.c b/42sh/srcs/glob/ld/ft_ld_back.c new file mode 100644 index 00000000..d448f449 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_back.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/srcs/glob/ld/ft_ld_clear.c b/42sh/srcs/glob/ld/ft_ld_clear.c new file mode 100644 index 00000000..962d3c11 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_clear.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_clear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); + } +} diff --git a/42sh/srcs/glob/ld/ft_ld_del.c b/42sh/srcs/glob/ld/ft_ld_del.c new file mode 100644 index 00000000..69852e67 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_del.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_del.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/06 15:54:53 by wescande #+# #+# */ +/* Updated: 2017/01/05 14:17:18 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "glob.h" + +void ft_ld_del(t_ld **ld, void (*del)()) +{ + 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) + { + prev->next = next; + *ld = prev; + } + else + *ld = next; +} diff --git a/42sh/srcs/glob/ld/ft_ld_front.c b/42sh/srcs/glob/ld/ft_ld_front.c new file mode 100644 index 00000000..1599f49e --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_front.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/srcs/glob/ld/ft_ld_new.c b/42sh/srcs/glob/ld/ft_ld_new.c new file mode 100644 index 00000000..eece5e18 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_new.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/01 18:17:34 by wescande #+# #+# */ +/* Updated: 2017/01/05 14:17:34 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "glob.h" + +void ft_ld_new(t_ld **alst, void *content) +{ + t_ld *new; + + if ((new = (t_ld *)malloc(sizeof(t_ld)))) + { + new->content = content; + new->prev = NULL; + new->next = NULL; + *alst = new; + } +} diff --git a/42sh/srcs/glob/ld/ft_ld_pushback.c b/42sh/srcs/glob/ld/ft_ld_pushback.c new file mode 100644 index 00000000..25a1d019 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_pushback.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_pushback.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; + } +} diff --git a/42sh/srcs/glob/ld/ft_ld_pushfront.c b/42sh/srcs/glob/ld/ft_ld_pushfront.c new file mode 100644 index 00000000..5f830ee1 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_pushfront.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_pushfront.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; + } +} diff --git a/42sh/srcs/glob/ld/ft_ld_reverse.c b/42sh/srcs/glob/ld/ft_ld_reverse.c new file mode 100644 index 00000000..62ffe670 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_reverse.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_reverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/42sh/srcs/glob/ld/ft_ld_size.c b/42sh/srcs/glob/ld/ft_ld_size.c new file mode 100644 index 00000000..aab41b06 --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_size.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/01 18:33:48 by wescande #+# #+# */ +/* Updated: 2017/01/05 14:17:59 by wescande ### ########.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); +} diff --git a/42sh/srcs/glob/ld/ft_ld_swap.c b/42sh/srcs/glob/ld/ft_ld_swap.c new file mode 100644 index 00000000..6e6ff87b --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_swap.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/srcs/glob/ld/ft_ld_to_tab.c b/42sh/srcs/glob/ld/ft_ld_to_tab.c new file mode 100644 index 00000000..e6db262d --- /dev/null +++ b/42sh/srcs/glob/ld/ft_ld_to_tab.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ld_to_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/srcs/lexer/ft_tokenize.c similarity index 100% rename from 42sh/src/lexer/ft_tokenize.c rename to 42sh/srcs/lexer/ft_tokenize.c diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/srcs/lexer/lexer_backslash.c similarity index 100% rename from 42sh/src/lexer/lexer_backslash.c rename to 42sh/srcs/lexer/lexer_backslash.c diff --git a/42sh/src/lexer/lexer_default.c b/42sh/srcs/lexer/lexer_default.c similarity index 100% rename from 42sh/src/lexer/lexer_default.c rename to 42sh/srcs/lexer/lexer_default.c diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/srcs/lexer/lexer_delim.c similarity index 100% rename from 42sh/src/lexer/lexer_delim.c rename to 42sh/srcs/lexer/lexer_delim.c diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/srcs/lexer/lexer_dquote.c similarity index 100% rename from 42sh/src/lexer/lexer_dquote.c rename to 42sh/srcs/lexer/lexer_dquote.c diff --git a/42sh/src/lexer/lexer_great.c b/42sh/srcs/lexer/lexer_great.c similarity index 100% rename from 42sh/src/lexer/lexer_great.c rename to 42sh/srcs/lexer/lexer_great.c diff --git a/42sh/src/lexer/lexer_greatand.c b/42sh/srcs/lexer/lexer_greatand.c similarity index 100% rename from 42sh/src/lexer/lexer_greatand.c rename to 42sh/srcs/lexer/lexer_greatand.c diff --git a/42sh/src/lexer/lexer_less.c b/42sh/srcs/lexer/lexer_less.c similarity index 100% rename from 42sh/src/lexer/lexer_less.c rename to 42sh/srcs/lexer/lexer_less.c diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/srcs/lexer/lexer_lessand.c similarity index 100% rename from 42sh/src/lexer/lexer_lessand.c rename to 42sh/srcs/lexer/lexer_lessand.c diff --git a/42sh/src/lexer/lexer_number.c b/42sh/srcs/lexer/lexer_number.c similarity index 100% rename from 42sh/src/lexer/lexer_number.c rename to 42sh/srcs/lexer/lexer_number.c diff --git a/42sh/src/lexer/lexer_quote.c b/42sh/srcs/lexer/lexer_quote.c similarity index 100% rename from 42sh/src/lexer/lexer_quote.c rename to 42sh/srcs/lexer/lexer_quote.c diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/srcs/lexer/lexer_sep.c similarity index 100% rename from 42sh/src/lexer/lexer_sep.c rename to 42sh/srcs/lexer/lexer_sep.c diff --git a/42sh/src/lexer/lexer_word.c b/42sh/srcs/lexer/lexer_word.c similarity index 100% rename from 42sh/src/lexer/lexer_word.c rename to 42sh/srcs/lexer/lexer_word.c diff --git a/42sh/src/lexer/token_append.c b/42sh/srcs/lexer/token_append.c similarity index 100% rename from 42sh/src/lexer/token_append.c rename to 42sh/srcs/lexer/token_append.c diff --git a/42sh/src/lexer/token_cmp_type.c b/42sh/srcs/lexer/token_cmp_type.c similarity index 100% rename from 42sh/src/lexer/token_cmp_type.c rename to 42sh/srcs/lexer/token_cmp_type.c diff --git a/42sh/src/lexer/token_free.c b/42sh/srcs/lexer/token_free.c similarity index 100% rename from 42sh/src/lexer/token_free.c rename to 42sh/srcs/lexer/token_free.c diff --git a/42sh/src/lexer/token_init.c b/42sh/srcs/lexer/token_init.c similarity index 100% rename from 42sh/src/lexer/token_init.c rename to 42sh/srcs/lexer/token_init.c diff --git a/42sh/src/lexer/token_print.c b/42sh/srcs/lexer/token_print.c similarity index 100% rename from 42sh/src/lexer/token_print.c rename to 42sh/srcs/lexer/token_print.c diff --git a/42sh/src/line-editing/curs_ask.c b/42sh/srcs/line-editing/curs_ask.c similarity index 100% rename from 42sh/src/line-editing/curs_ask.c rename to 42sh/srcs/line-editing/curs_ask.c diff --git a/42sh/src/line-editing/curs_clear.c b/42sh/srcs/line-editing/curs_clear.c similarity index 100% rename from 42sh/src/line-editing/curs_clear.c rename to 42sh/srcs/line-editing/curs_clear.c diff --git a/42sh/src/line-editing/curs_goto.c b/42sh/srcs/line-editing/curs_goto.c similarity index 100% rename from 42sh/src/line-editing/curs_goto.c rename to 42sh/srcs/line-editing/curs_goto.c diff --git a/42sh/src/line-editing/curs_move.c b/42sh/srcs/line-editing/curs_move.c similarity index 100% rename from 42sh/src/line-editing/curs_move.c rename to 42sh/srcs/line-editing/curs_move.c diff --git a/42sh/src/line-editing/curs_setup.c b/42sh/srcs/line-editing/curs_setup.c similarity index 100% rename from 42sh/src/line-editing/curs_setup.c rename to 42sh/srcs/line-editing/curs_setup.c diff --git a/42sh/src/line-editing/curs_single.c b/42sh/srcs/line-editing/curs_single.c similarity index 100% rename from 42sh/src/line-editing/curs_single.c rename to 42sh/srcs/line-editing/curs_single.c diff --git a/42sh/src/line-editing/curs_term_setup.c b/42sh/srcs/line-editing/curs_term_setup.c similarity index 100% rename from 42sh/src/line-editing/curs_term_setup.c rename to 42sh/srcs/line-editing/curs_term_setup.c diff --git a/42sh/src/line-editing/curs_write.c b/42sh/srcs/line-editing/curs_write.c similarity index 100% rename from 42sh/src/line-editing/curs_write.c rename to 42sh/srcs/line-editing/curs_write.c diff --git a/42sh/srcs/line-editing/ft_interactive_sh.c b/42sh/srcs/line-editing/ft_interactive_sh.c new file mode 100644 index 00000000..5110f44b --- /dev/null +++ b/42sh/srcs/line-editing/ft_interactive_sh.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* interactive_sh.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: sbenning +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/10 09:44:43 by sbenning #+# #+# */ +/* Updated: 2016/12/10 10:24:12 by sbenning ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "line_editing.h" + +t_data **data_singleton(void) +{ + static t_data *data; + + return (&data); +} + +int ft_interactive_sh(t_data *data) +{ + *data_singleton() = data; + return (ft_readline(&data->line)); +} diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/srcs/line-editing/ft_readline.c similarity index 100% rename from 42sh/src/line-editing/ft_readline.c rename to 42sh/srcs/line-editing/ft_readline.c diff --git a/42sh/src/line-editing/rl_bitset.c b/42sh/srcs/line-editing/rl_bitset.c similarity index 100% rename from 42sh/src/line-editing/rl_bitset.c rename to 42sh/srcs/line-editing/rl_bitset.c diff --git a/42sh/src/line-editing/rl_clear_function.c b/42sh/srcs/line-editing/rl_clear_function.c similarity index 100% rename from 42sh/src/line-editing/rl_clear_function.c rename to 42sh/srcs/line-editing/rl_clear_function.c diff --git a/42sh/src/line-editing/rl_clipboard_function.c b/42sh/srcs/line-editing/rl_clipboard_function.c similarity index 100% rename from 42sh/src/line-editing/rl_clipboard_function.c rename to 42sh/srcs/line-editing/rl_clipboard_function.c diff --git a/42sh/src/line-editing/rl_clipboard_utility.c b/42sh/srcs/line-editing/rl_clipboard_utility.c similarity index 100% rename from 42sh/src/line-editing/rl_clipboard_utility.c rename to 42sh/srcs/line-editing/rl_clipboard_utility.c diff --git a/42sh/src/line-editing/rl_comp_function.c b/42sh/srcs/line-editing/rl_comp_function.c similarity index 100% rename from 42sh/src/line-editing/rl_comp_function.c rename to 42sh/srcs/line-editing/rl_comp_function.c diff --git a/42sh/src/line-editing/rl_default_function.c b/42sh/srcs/line-editing/rl_default_function.c similarity index 100% rename from 42sh/src/line-editing/rl_default_function.c rename to 42sh/srcs/line-editing/rl_default_function.c diff --git a/42sh/src/line-editing/rl_display.c b/42sh/srcs/line-editing/rl_display.c similarity index 100% rename from 42sh/src/line-editing/rl_display.c rename to 42sh/srcs/line-editing/rl_display.c diff --git a/42sh/src/line-editing/rl_dynamic_buffer.c b/42sh/srcs/line-editing/rl_dynamic_buffer.c similarity index 100% rename from 42sh/src/line-editing/rl_dynamic_buffer.c rename to 42sh/srcs/line-editing/rl_dynamic_buffer.c diff --git a/42sh/src/line-editing/rl_long_move_function.c b/42sh/srcs/line-editing/rl_long_move_function.c similarity index 100% rename from 42sh/src/line-editing/rl_long_move_function.c rename to 42sh/srcs/line-editing/rl_long_move_function.c diff --git a/42sh/src/line-editing/rl_merge_line.c b/42sh/srcs/line-editing/rl_merge_line.c similarity index 100% rename from 42sh/src/line-editing/rl_merge_line.c rename to 42sh/srcs/line-editing/rl_merge_line.c diff --git a/42sh/src/line-editing/rl_page_move_function.c b/42sh/srcs/line-editing/rl_page_move_function.c similarity index 100% rename from 42sh/src/line-editing/rl_page_move_function.c rename to 42sh/srcs/line-editing/rl_page_move_function.c diff --git a/42sh/src/line-editing/rl_prompt.c b/42sh/srcs/line-editing/rl_prompt.c similarity index 100% rename from 42sh/src/line-editing/rl_prompt.c rename to 42sh/srcs/line-editing/rl_prompt.c diff --git a/42sh/src/line-editing/rl_quoting_function.c b/42sh/srcs/line-editing/rl_quoting_function.c similarity index 100% rename from 42sh/src/line-editing/rl_quoting_function.c rename to 42sh/srcs/line-editing/rl_quoting_function.c diff --git a/42sh/src/line-editing/rl_remove_function.c b/42sh/srcs/line-editing/rl_remove_function.c similarity index 100% rename from 42sh/src/line-editing/rl_remove_function.c rename to 42sh/srcs/line-editing/rl_remove_function.c diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/srcs/line-editing/rl_setup.c similarity index 100% rename from 42sh/src/line-editing/rl_setup.c rename to 42sh/srcs/line-editing/rl_setup.c diff --git a/42sh/src/line-editing/rl_short_move_function.c b/42sh/srcs/line-editing/rl_short_move_function.c similarity index 100% rename from 42sh/src/line-editing/rl_short_move_function.c rename to 42sh/srcs/line-editing/rl_short_move_function.c diff --git a/42sh/src/line-editing/rl_stack_line.c b/42sh/srcs/line-editing/rl_stack_line.c similarity index 100% rename from 42sh/src/line-editing/rl_stack_line.c rename to 42sh/srcs/line-editing/rl_stack_line.c diff --git a/42sh/src/line-editing/rl_state_function.c b/42sh/srcs/line-editing/rl_state_function.c similarity index 100% rename from 42sh/src/line-editing/rl_state_function.c rename to 42sh/srcs/line-editing/rl_state_function.c diff --git a/42sh/src/line-editing/rl_word_move_function.c b/42sh/srcs/line-editing/rl_word_move_function.c similarity index 100% rename from 42sh/src/line-editing/rl_word_move_function.c rename to 42sh/srcs/line-editing/rl_word_move_function.c diff --git a/42sh/src/line-editing/rl_word_utility.c b/42sh/srcs/line-editing/rl_word_utility.c similarity index 100% rename from 42sh/src/line-editing/rl_word_utility.c rename to 42sh/srcs/line-editing/rl_word_utility.c diff --git a/42sh/src/main/data_exit.c b/42sh/srcs/main/data_exit.c similarity index 100% rename from 42sh/src/main/data_exit.c rename to 42sh/srcs/main/data_exit.c diff --git a/42sh/src/main/data_init.c b/42sh/srcs/main/data_init.c similarity index 100% rename from 42sh/src/main/data_init.c rename to 42sh/srcs/main/data_init.c diff --git a/42sh/srcs/main/ft_cleanup.c b/42sh/srcs/main/ft_cleanup.c new file mode 100644 index 00000000..7cf6aa3b --- /dev/null +++ b/42sh/srcs/main/ft_cleanup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_cleanup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/01 14:42:42 by jhalford #+# #+# */ +/* Updated: 2016/12/09 21:50:38 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +extern char **environ; +extern char PC; +extern char *UP; +extern char *BC; + +void ft_cleanup(void) +{ + struct termios term; + + DG("cleanup. char * UP at %p", UP); + DG("cleanup. char * BC at %p", BC); + if (tcgetattr(0, &term) == -1) + return ; + term.c_lflag |= ICANON | ISIG | ECHO; + if (tcsetattr(0, TCSANOW, &term) == -1) + return ; +} diff --git a/42sh/src/main/ft_putast.c b/42sh/srcs/main/ft_putast.c similarity index 100% rename from 42sh/src/main/ft_putast.c rename to 42sh/srcs/main/ft_putast.c diff --git a/42sh/src/main/ft_putast2.c b/42sh/srcs/main/ft_putast2.c similarity index 100% rename from 42sh/src/main/ft_putast2.c rename to 42sh/srcs/main/ft_putast2.c diff --git a/42sh/srcs/main/lib_expansion.c b/42sh/srcs/main/lib_expansion.c new file mode 100644 index 00000000..8905c284 --- /dev/null +++ b/42sh/srcs/main/lib_expansion.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lib_expansion.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 13:37:41 by jhalford #+# #+# */ +/* Updated: 2016/12/03 13:37:41 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_expand_dollar(char **av, char **env) +{ + char *dollar; + + while (*av) + { + if ((dollar = ft_strchr(*av, '$'))) + { + *dollar = '\0'; + *av = ft_strjoin(*av, ft_getenv(env, dollar + 1)); + } + av++; + } +} diff --git a/42sh/src/main/main.c b/42sh/srcs/main/main.c similarity index 78% rename from 42sh/src/main/main.c rename to 42sh/srcs/main/main.c index 27e00034..0228f689 100644 --- a/42sh/src/main/main.c +++ b/42sh/srcs/main/main.c @@ -6,7 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ +<<<<<<< HEAD:src/main/main.c /* Updated: 2017/01/12 14:02:30 by jhalford ### ########.fr */ +======= +/* Updated: 2017/01/05 16:07:09 by wescande ### ########.fr */ +>>>>>>> premier commit. working. . .:srcs/main/main.c /* */ /* ************************************************************************** */ @@ -52,7 +56,21 @@ int main(int ac, char **av) } while (1) { +<<<<<<< HEAD:src/main/main.c if (ft_readline()) +======= + if (ft_interactive_sh(&data)) + return (1); + DG("{inv}{mag}got command '%s'", data.line.input); + token = NULL; + if (ft_tokenize(&token, data.line.input, DEFAULT)) + return (1); + if (!token) + continue ; +// token_print(token); + glob_print(token, &data); + if (ft_parse(&ast, &token)) +>>>>>>> premier commit. working. . .:srcs/main/main.c return (1); if (shell_single_command(data_singleton()->line.input)) return (1); diff --git a/42sh/srcs/main/sig_handler.c b/42sh/srcs/main/sig_handler.c new file mode 100644 index 00000000..d56b03ee --- /dev/null +++ b/42sh/srcs/main/sig_handler.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sig_handler.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/01 12:43:22 by jhalford #+# #+# */ +/* Updated: 2016/12/03 13:31:33 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +pid_t g_pid; + +void sig_handler(int signo) +{ + (void)signo; + if (signo == SIGINT) + { + if (g_pid) + kill(g_pid, SIGINT); + if (kill(g_pid, 0) == 0) + ft_putendl(""); + } +} diff --git a/42sh/src/parser/ft_parse.c b/42sh/srcs/parser/ft_parse.c similarity index 100% rename from 42sh/src/parser/ft_parse.c rename to 42sh/srcs/parser/ft_parse.c diff --git a/42sh/src/parser/parse_dgreat.c b/42sh/srcs/parser/parse_dgreat.c similarity index 100% rename from 42sh/src/parser/parse_dgreat.c rename to 42sh/srcs/parser/parse_dgreat.c diff --git a/42sh/src/parser/parse_dless.c b/42sh/srcs/parser/parse_dless.c similarity index 100% rename from 42sh/src/parser/parse_dless.c rename to 42sh/srcs/parser/parse_dless.c diff --git a/42sh/src/parser/parse_great.c b/42sh/srcs/parser/parse_great.c similarity index 100% rename from 42sh/src/parser/parse_great.c rename to 42sh/srcs/parser/parse_great.c diff --git a/42sh/src/parser/parse_greatand.c b/42sh/srcs/parser/parse_greatand.c similarity index 100% rename from 42sh/src/parser/parse_greatand.c rename to 42sh/srcs/parser/parse_greatand.c diff --git a/42sh/src/parser/parse_less.c b/42sh/srcs/parser/parse_less.c similarity index 100% rename from 42sh/src/parser/parse_less.c rename to 42sh/srcs/parser/parse_less.c diff --git a/42sh/src/parser/parse_lessand.c b/42sh/srcs/parser/parse_lessand.c similarity index 100% rename from 42sh/src/parser/parse_lessand.c rename to 42sh/srcs/parser/parse_lessand.c diff --git a/42sh/src/parser/parse_separator.c b/42sh/srcs/parser/parse_separator.c similarity index 100% rename from 42sh/src/parser/parse_separator.c rename to 42sh/srcs/parser/parse_separator.c diff --git a/42sh/src/parser/parse_word.c b/42sh/srcs/parser/parse_word.c similarity index 100% rename from 42sh/src/parser/parse_word.c rename to 42sh/srcs/parser/parse_word.c