Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
cf10a76
Create README.md
Gregoirebrn Apr 16, 2024
75225d5
Update README.md
Gregoirebrn Apr 16, 2024
f06d8a8
Update README.md
Gregoirebrn Apr 16, 2024
d6efc5d
Update README.md
Gregoirebrn Apr 16, 2024
23d1c18
Update README.md
Gregoirebrn Apr 16, 2024
2a1ceaf
Update README.md
Gregoirebrn Apr 16, 2024
574031f
git learning
Gregoirebrn Apr 16, 2024
570f7e4
Update README.md
Gregoirebrn Apr 16, 2024
c471f01
add fork
Gregoirebrn Apr 16, 2024
68547c3
description de toutes les fonctions
Gregoirebrn Apr 16, 2024
9acbd04
added pipe function
Gregoirebrn Apr 16, 2024
ce33a54
retry
Jun 30, 2024
16e7018
del
Jun 30, 2024
9d59573
last version
Jun 30, 2024
873f255
value of name copy
Gregoirebrn Jul 1, 2024
c133590
leaks of readline
Gregoirebrn Jul 1, 2024
0558959
ctrl C remake
Gregoirebrn Jul 2, 2024
1710607
sig heredoc remake
Gregoirebrn Jul 2, 2024
9894239
exit if crash of malloc
Gregoirebrn Jul 2, 2024
45927cd
add free_malloc_fnp if crash of malloc
Gregoirebrn Jul 2, 2024
499069c
no leaks exit if crash
Gregoirebrn Jul 2, 2024
0836183
free_malloc_fnp
Gregoirebrn Jul 2, 2024
dacf9d3
return g_error
Gregoirebrn Jul 2, 2024
e760427
mod free_malloc_fnp
Gregoirebrn Jul 2, 2024
2f004c2
rem comments
Gregoirebrn Jul 2, 2024
6e80b14
value of exit of main procs
Gregoirebrn Jul 2, 2024
b15764e
cor of exit ""
Gregoirebrn Jul 2, 2024
7781988
exit all heredoc if ctrl C
Gregoirebrn Jul 2, 2024
c00f108
redir with fd exit proprely
Gregoirebrn Jul 2, 2024
0218768
wait for all deals with ctrl \
Gregoirebrn Jul 2, 2024
0b351e6
add exec_error file
Gregoirebrn Jul 2, 2024
43428d6
add exec_error
Gregoirebrn Jul 2, 2024
dfbf4cf
add exec_error
Gregoirebrn Jul 2, 2024
94c70c9
wait gere les signaux
Gregoirebrn Jul 2, 2024
533cc4e
norme
Gregoirebrn Jul 2, 2024
74695eb
norme
Gregoirebrn Jul 2, 2024
d894c68
write bash
Gregoirebrn Jul 2, 2024
8618f43
rename exec shell
Gregoirebrn Jul 2, 2024
b74249c
rework name, exit value, exec_shell
Gregoirebrn Jul 2, 2024
ec9872b
sig main value 1 to 0
Gregoirebrn Jul 2, 2024
4e428cb
parse all redir
Gregoirebrn Jul 2, 2024
0e1f610
print if first
Gregoirebrn Jul 2, 2024
0a46ef5
crash of fork updated
Gregoirebrn Jul 2, 2024
deb8475
mod open files proto
Gregoirebrn Jul 2, 2024
f6281e9
big rework of cd no leaks found
Gregoirebrn Jul 3, 2024
5e95134
last != -1
Gregoirebrn Jul 3, 2024
9bfa73c
rem of cd_rep_or_new
Gregoirebrn Jul 3, 2024
b3a6486
ft_strcat to cd_cat_backslash
Gregoirebrn Jul 3, 2024
77e15aa
move replace value
Gregoirebrn Jul 3, 2024
89a0281
normed
Gregoirebrn Jul 3, 2024
912cb20
TO DO
Gregoirebrn Jul 3, 2024
ffc39e1
none
Gregoirebrn Jul 3, 2024
d62e318
add
Jul 8, 2024
93a7194
push for final
Jul 8, 2024
fad3a3b
corr of cd absolute path
Jul 8, 2024
cc1a251
close fd in ctrl c heredoc
Jul 8, 2024
ff3b419
up
Jul 8, 2024
21df46f
corrected prev value
Jul 8, 2024
2f8e28e
unauthorized function
Jul 8, 2024
5a9e775
correction to do in file to_check
Jul 8, 2024
f0c6fb8
supp supp
Jul 8, 2024
b427d8b
supp supp
Jul 8, 2024
4c68218
find path env check exist
Gregoirebrn Jul 8, 2024
158f76b
return value
Gregoirebrn Jul 8, 2024
942a9c8
return value
Gregoirebrn Jul 8, 2024
af4151d
exit correctly
Gregoirebrn Jul 8, 2024
48917e2
envlen corrected
Gregoirebrn Jul 8, 2024
a1ed83a
str initialized
Gregoirebrn Jul 8, 2024
e1bbcd0
up if env empty & prev value
Gregoirebrn Jul 8, 2024
e2ceff8
cmdlen mod
Gregoirebrn Jul 8, 2024
a5d3f06
mod exec_error_exit
Gregoirebrn Jul 8, 2024
3b76c3c
mod exec_error_exit
Gregoirebrn Jul 8, 2024
3934a47
mod exec_error_exit
Gregoirebrn Jul 8, 2024
c34025a
mod exec_error_exit & protect of malloc
Gregoirebrn Jul 8, 2024
5fc4c8f
rework no_path_to_hapiness
Gregoirebrn Jul 8, 2024
04c272c
added
Gregoirebrn Jul 9, 2024
850f400
added
Gregoirebrn Jul 9, 2024
60d59c2
remove unused code
Jul 9, 2024
b5ec4d3
splitdestroy
Jul 9, 2024
5f6c0c2
protection
Jul 9, 2024
9445ecb
protection
Jul 9, 2024
8bc5197
unset to do
Jul 9, 2024
6a2080e
unset REWORK
Jul 9, 2024
1de08f5
underscore accepted
Jul 9, 2024
d95bfe8
remove free(str)
Jul 9, 2024
b2efe6f
push for push
Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 92 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,77 @@
# VARIABLE #
########################################################################################################################

SRCS := main.c
SRCS := backslash.c \
expand_var_utils.c \
expand_var_utils2.c \
init.c \
main.c \
parser_utils.c \
redir.c \
split.c \
utils.c \
expand_var.c \
format_redir.c \
init_utils.c \
init_utils2.c \
parser.c \
pre_check.c \
redir_utils.c \
trim.c \
trim_utils.c \
free_func.c \
header.c

EXEC := built_cd.c \
built_cd_back.c \
built_exit.c \
built_exit_free.c \
built_export.c \
built_export_add.c \
built_export_checker.c \
built_export_utils.c \
exec_main.c \
exec_error.c \
exec_utils.c \
built_echo.c \
built_pwd.c \
exec_redir.c \
exec_wait.c \
built_env.c \
built_export_no_arg.c \
built_unset.c \
exec_redir_utils.c \
heredoc.c \
signals_main.c


VALGRIND := valgrind --suppressions=valgrind_ignore_leaks.txt --leak-check=full --show-leak-kinds=all\
--track-fds=yes --show-mismatched-frees=yes --read-var-info=yes -s --trace-children=yes

IGN_LEAK := valgrind_ignore_leaks.txt

SRCS_D := srcs/

OBJS_D := objs/

OBJS := $(SRCS:%.c=$(OBJS_D)%.o)
EXEC_D := exec/

HEAD := includes/minishell.h
OBJS := $(SRCS:%.c=$(OBJS_D)%.o)\

OBJS_E := $(EXEC:%.c=$(OBJS_D)%.o)\

HEAD := includes/minishell.h \
includes/parser.h \
includes/builtins.h

HEAD_D := .

CFLAGS := -Wall -Wextra -Werror -g3
ifeq ($(shell uname), Darwin)
READLINE_DIR = $(shell brew --prefix readline)
endif
READLINE_LIB = -lreadline -lhistory -L $(READLINE_DIR)/lib

CFLAGS := -Wall -Wextra -Werror -g3 -I$(READLINE_DIR)/include

NAME := minishell

Expand All @@ -35,22 +93,46 @@ LIB_A := $(addprefix $(LIB_D), $(LIB))
########################################################################################################################
# RULES #
########################################################################################################################

all : lib
$(MAKE) $(NAME)

lib :
$(MAKE) -C $(LIB_D)

$(NAME) : $(OBJS_D) $(OBJS) $(LIB_A) $(HEAD)
$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LIB_A)
leaks : all $(IGN_LEAK)
$(VALGRIND) ./$(NAME)

$(NAME) : $(OBJS_D) $(OBJS) $(OBJS_E) $(LIB_A) $(HEAD)
$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OBJS_E) $(LIB_A) -lm ${READLINE_LIB}

$(OBJS) : $(OBJS_D)%.o: $(SRCS_D)%.c $(HEAD) $(LIB_H)
$(CC) $(CFLAGS) -I/usr/include -Isuper_libft -c $< -o $@
$(CC) $(CFLAGS) -Isuper_libft -c $< -o $@

$(OBJS_E) : $(OBJS_D)%.o: $(EXEC_D)%.c $(HEAD) $(LIB_H)
$(CC) $(CFLAGS) -Isuper_libft -c $< -o $@

$(OBJS_D) :
@mkdir -p $(OBJS_D)

$(IGN_LEAK) :
@echo "{" > $(IGN_LEAK)
@echo " leak readline" >> $(IGN_LEAK)
@echo " Memcheck:Leak" >> $(IGN_LEAK)
@echo " ..." >> $(IGN_LEAK)
@echo " fun:readline" >> $(IGN_LEAK)
@echo "}" >> $(IGN_LEAK)
@echo "{" >> $(IGN_LEAK)
@echo " leak add_history" >> $(IGN_LEAK)
@echo " Memcheck:Leak" >> $(IGN_LEAK)
@echo " ..." >> $(IGN_LEAK)
@echo " fun:add_history" >> $(IGN_LEAK)
@echo "}" >> $(IGN_LEAK)
@echo "{" >> $(IGN_LEAK)
@echo " leak readline_internal_char" >> $(IGN_LEAK)
@echo " Memcheck:Leak" >> $(IGN_LEAK)
@echo " ..." >> $(IGN_LEAK)
@echo " fun:readline_internal_char" >> $(IGN_LEAK)
@echo "}" >> $(IGN_LEAK)
########################################################################################################################
# COMMANDS #
########################################################################################################################
Expand All @@ -62,7 +144,8 @@ clean :
fclean : clean
$(RM) $(NAME) $(NAME_B)
$(MAKE) fclean -C super_libft
$(RM) $(IGN_LEAK)

re : fclean all

.PHONY: all clean fclean re lib
.PHONY: all clean fclean re lib
6 changes: 6 additions & 0 deletions data/header2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__ ____ _ _________
/ |/ (_)___ (_)___ ___ ____ ____ / __/ __( )
/ /|_/ / / __ \/ / __ `__ \/ __ \/ __ \/ /_/ /_ |/
/ / / / / / / / / / / / / / /_/ / / / / __/ __/
/_/ /_/_/_/ /_/_/_/ /_/ /_/\____/_/ /_/_/ /_/
by Grebrune & Beroy
Empty file added data/tmp
Empty file.
108 changes: 108 additions & 0 deletions exec/built_cd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* built_cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grebrune <grebrune@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/14 15:49:11 by grebrune #+# #+# */
/* Updated: 2024/07/08 20:13:12 by grebrune ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/minishell.h"

int cd_error(t_head *head)
{
if (head->cmd->next || (head->cmd->arg[1] && head->cmd->arg[1][0] == 0))
return (1);
if (head->cmd->arg[1] && head->cmd->arg[2])
return (write(2, "bash: cd: too many arguments\n", 29), g_error = 1, 1);
return (0);
}

void cd_rep_or_new(t_head *head, char *n_pwd, char *old_pwd)
{
if (replace_value(head, n_pwd, "PWD"))
{
new_pwd(head, n_pwd, "PWD");
free(n_pwd);
}
if (replace_value(head, old_pwd, "OLDPWD"))
{
new_pwd(head, old_pwd, "OLDPWD");
free(old_pwd);
}
}

int ft_cd(t_head *head)
{
int err;
char *new;
char *old;

old = NULL;
if (cd_error(head))
return (1);
new = cd_relative(head);
if (!new)
return (2);
err = get_path(&old);
if (err == 2)
return (2);
err = chdir(new);
if (err != 0)
return (cd_chdir_error(head, old, new), 1);
cd_rep_or_new(head, new, old);
return (0);
}

char *cd_relative(t_head *head)
{
char *new;

new = NULL;
if (!head->cmd->arg[1])
return (cd_find_var(head, "HOME"));
if (0 == ft_strcmp(head->cmd->arg[1], "../")
|| 0 == ft_strcmp(head->cmd->arg[1], ".."))
return (cd_back_trim());
if (0 == ft_strcmp(head->cmd->arg[1], "~/")
|| 0 == ft_strcmp(head->cmd->arg[1], "~"))
return (cd_tild_trim(head));
if (0 == ft_strcmp(head->cmd->arg[1], "-"))
return (cd_find_var(head, "OLDPWD"));
if (!ft_strncmp(head->cmd->arg[1], "~/", 2))
return (cat_of_tild(head, head->cmd->arg[1]));
if (!ft_strncmp(head->cmd->arg[1], "/home", 5))
return (ft_strdup(head->cmd->arg[1]));
if (get_path(&new) == 2)
return (NULL);
new = cd_cat_backslash(new, head->cmd->arg[1]);
if (!new)
return (write(2, "Crash of Malloc\n", 16), NULL);
return (new);
}

char *cd_find_var(t_head *head, char *name)
{
t_env *env;
char *str;

str = NULL;
env = head->env;
while (env)
{
if (ft_strcmp(env->name, name) == 0)
{
str = ft_strdup(env->value);
if (!str)
return (write(2, "Crash of Malloc\n", 16), NULL);
break ;
}
env = env->next;
}
if (!str)
return (cd_not_found(name), NULL);
return (str);
}
102 changes: 102 additions & 0 deletions exec/built_cd_back.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* built_cd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grebrune <grebrune@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 14:35:38 by grebrune #+# #+# */
/* Updated: 2024/07/08 20:13:12 by grebrune ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/minishell.h"

char *cd_tild_trim(t_head *head)
{
char *pwd;
char *new;

pwd = cd_find_var(head, "USER");
if (!pwd)
return (NULL);
new = ft_strjoin("/home/", pwd);
if (!new)
return (free(pwd), write(2, "Crash of Malloc\n", 16), NULL);
return (free(pwd), new);
}

char *cd_back_trim(void)
{
char *pwd;
char *new;
int i;
int x;

i = 0;
pwd = NULL;
if (get_path(&pwd) == 2)
return (NULL);
while (pwd && pwd[i])
i++;
while (pwd && pwd[i] != '/')
i--;
new = malloc(sizeof(char) * (i + 1));
if (!new)
return (free(pwd), write(2, "Crash of Malloc\n", 16), NULL);
x = 0;
while (x < i)
{
new[x] = pwd[x];
x++;
}
new[x] = 0;
return (free(pwd), new);
}

void cd_not_found(char *name)
{
write(2, "bash: cd: ", 10);
write(2, name, ft_strlen(name));
write(2, " not set\n", 9);
}

void cd_chdir_error(t_head *head, char *old_pwd, char *new_pwd)
{
DIR *ptr_dir;

g_error = 1;
ptr_dir = opendir(head->cmd->arg[1]);
perror("bash: cd");
closedir(ptr_dir);
free(old_pwd);
free(new_pwd);
}

char *cd_cat_backslash(char *path, char *dir)
{
char *dest;
size_t i;
size_t x;

dest = ft_calloc(sizeof (char), (ft_strlen(dir) + ft_strlen(path) + 2));
if (!dest)
return (NULL);
i = 0;
while (path && path[i])
{
dest[i] = path[i];
i++;
}
x = 0;
dest[i++] = '/';
while (dir && dir[x])
{
dest[i] = dir[x];
i++;
x++;
}
dest[i] = '\0';
free(path);
return (dest);
}
Loading