premier commit. working. . .

This commit is contained in:
wescande 2017-01-12 15:05:59 +01:00 committed by Jack Halford
parent 4b22633cab
commit 977238f69e
103 changed files with 1007 additions and 1 deletions

View file

@ -1,3 +1,4 @@
<<<<<<< HEAD
NAME = minishell NAME = minishell
CC = gcc CC = gcc
TAGFILE = .tags TAGFILE = .tags
@ -88,3 +89,185 @@ fclean: clean
@$(MAKE) fclean -C libft/ 2>/dev/null @$(MAKE) fclean -C libft/ 2>/dev/null
re: fclean all re: fclean all
=======
#* ************************************************************************** *#
#* *#
#* ::: :::::::: *#
#* 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 *#
#* *#
#* ************************************************************************** *#
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. . .

44
42sh/includes/glob.h Normal file
View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* glob.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,7 +6,11 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 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/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 "parser.h"
# include "ft_readline.h" # include "ft_readline.h"
# include "exec.h" # include "exec.h"
<<<<<<< HEAD
# include "builtin.h" # include "builtin.h"
# include "job_control.h" # include "job_control.h"
=======
# include "glob.h"
>>>>>>> premier commit. working. . .
# include <dirent.h> # include <dirent.h>
# include <sys/stat.h> # include <sys/stat.h>

@ -1 +1 @@
Subproject commit ab92f0e5d817c9d726a8ccf2f11c084ba446bbdf Subproject commit 4c4977452745481166749b813e8db51dcf0caf44

View file

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_redirect.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
}

65
42sh/srcs/exec/ft_cmd.c Normal file
View file

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

133
42sh/srcs/glob/glob.c Normal file
View file

@ -0,0 +1,133 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* glob.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* glob_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

View 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);
}

View 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);
}
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ld_del.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View 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);
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ld_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}

View 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/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);
}

View 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);
}

View 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);
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* interactive_sh.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cleanup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 14:42:42 by jhalford #+# #+# */
/* Updated: 2016/12/09 21:50:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#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 ;
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lib_expansion.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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++;
}
}

View file

@ -6,7 +6,11 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 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/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) while (1)
{ {
<<<<<<< HEAD:src/main/main.c
if (ft_readline()) 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); return (1);
if (shell_single_command(data_singleton()->line.input)) if (shell_single_command(data_singleton()->line.input))
return (1); return (1);

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sig_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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("");
}
}

Some files were not shown because too many files have changed in this diff Show more