This commit is contained in:
Etienne Rey-bethbeder 2023-04-14 16:17:35 +02:00
parent 882a39fc94
commit 0b56e95868
12 changed files with 36 additions and 36 deletions

View File

@ -1,17 +1,17 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* minishell.h :+: :+: :+: */ /* bozoshell.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */ /* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/04/05 14:46:56 by alouis-j ### ########.fr */ /* Updated: 2023/04/14 16:16:31 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef MINISHELL_H #ifndef BOZOSHELL_H
# define MINISHELL_H # define BOZOSHELL_H
# include "./env/env.h" # include "./env/env.h"
# include "./cmd/cmd.h" # include "./cmd/cmd.h"
# include "./parse/parse.h" # include "./parse/parse.h"

4
env/env_fill.c vendored
View File

@ -31,7 +31,7 @@ static char *ft_getkey(const char *str)
key = ft_strndup(str + 1, i - 1); key = ft_strndup(str + 1, i - 1);
} }
if (key == NULL) if (key == NULL)
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (key); return (key);
} }
@ -54,7 +54,7 @@ static char *ft_getvalue(t_data *data, char *key)
value = ft_strdup(value); value = ft_strdup(value);
} }
if (value == NULL) if (value == NULL)
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (value); return (value);
} }

View File

@ -20,7 +20,7 @@ static int ft_replace(char **str, size_t i)
free(*str); free(*str);
if (temp == NULL) if (temp == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
*str = temp; *str = temp;

10
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */ /* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/04/07 15:04:12 by alouis-j ### ########.fr */ /* Updated: 2023/04/14 16:10:20 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,7 @@
#include "libftx/libft/libft.h" #include "libftx/libft/libft.h"
#include "libftx/libft/list.h" #include "libftx/libft/list.h"
#include "libftx/libftx.h" #include "libftx/libftx.h"
#include "minishell.h" #include "bozoshell.h"
#include "signal/signal.h" #include "signal/signal.h"
#include <stdlib.h> #include <stdlib.h>
@ -32,7 +32,7 @@ static char *ft_get_user_input(void)
free(pwd); free(pwd);
if (prompt == NULL) if (prompt == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (NULL); return (NULL);
} }
line = readline(prompt); line = readline(prompt);
@ -72,14 +72,14 @@ int ft_init_data(t_data *data, char **env)
data->cmds = malloc(sizeof(t_cmd *)); data->cmds = malloc(sizeof(t_cmd *));
if (data->cmds == NULL) if (data->cmds == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
*data->cmds = NULL; *data->cmds = NULL;
data->env = init_env(env); data->env = init_env(env);
if (data->env == NULL) if (data->env == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
free(data->cmds); free(data->cmds);
return (1); return (1);
} }

View File

@ -80,7 +80,7 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
cmd = ft_calloc(sizeof(t_cmd), 1); cmd = ft_calloc(sizeof(t_cmd), 1);
if (cmd == NULL) if (cmd == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
if (ft_redirection(data, cmd, cmd_str)) if (ft_redirection(data, cmd, cmd_str))
@ -105,7 +105,7 @@ int ft_cmds_parser(t_data *data, const char *line)
tab = ft_split_charset_quoted(line, "|"); tab = ft_split_charset_quoted(line, "|");
if (tab == NULL) if (tab == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
i = -1; i = -1;

View File

@ -126,13 +126,13 @@ bool ft_check_redirection(t_data *data, t_cmd *cmd,
if (ft_is_in("<>", redirection_identifier[0]) if (ft_is_in("<>", redirection_identifier[0])
&& ft_is_in("<>", redirection[0])) && ft_is_in("<>", redirection[0]))
{ {
ft_eprintf("minishell: %s: invalid redirection file\n", redirection); ft_eprintf("bozoshell: %s: invalid redirection file\n", redirection);
return (1); return (1);
} }
str = ft_strdup(redirection); str = ft_strdup(redirection);
if (str == NULL) if (str == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
ft_quote_remover(str); ft_quote_remover(str);

View File

@ -21,14 +21,14 @@ int ft_file_is_readable(t_data *data, const char *path)
if (fd == -1) if (fd == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: No such file or directory\n", path); ft_eprintf("bozoshell: %s: No such file or directory\n", path);
return (0); return (0);
} }
readable = read(fd, "", 0); readable = read(fd, "", 0);
if (readable == -1) if (readable == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: Permission denied\n", path); ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0); return (0);
} }
close(fd); close(fd);
@ -44,14 +44,14 @@ int ft_file_is_writable(t_data *data, const char *path)
if (fd == -1) if (fd == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: Permission denied\n", path); ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0); return (0);
} }
writeable = write(fd, "", 0); writeable = write(fd, "", 0);
if (writeable == -1) if (writeable == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: Permission denied\n", path); ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0); return (0);
} }
close(fd); close(fd);
@ -67,14 +67,14 @@ int ft_file_is_appendable(t_data *data, const char *path)
if (fd == -1) if (fd == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: Permission denied\n", path); ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0); return (0);
} }
writeable = write(fd, "", 0); writeable = write(fd, "", 0);
if (writeable == -1) if (writeable == -1)
{ {
*data->exit_code = 1; *data->exit_code = 1;
ft_eprintf("minishell: %s: Permission denied\n", path); ft_eprintf("bozoshell: %s: Permission denied\n", path);
return (0); return (0);
} }
close(fd); close(fd);

View File

@ -41,7 +41,7 @@ static int ft_heredoc3(char *stop, int fds[2])
} }
else else
{ {
ft_eprintf("minishell: warning: here-document at line"); ft_eprintf("bozoshell: warning: here-document at line");
ft_eprintf("1 delimited by end-of-file (wanted `%s')\n", stop); ft_eprintf("1 delimited by end-of-file (wanted `%s')\n", stop);
return (2); return (2);
} }

View File

@ -84,7 +84,7 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
} }
if (ft_is_in("<>", tab[i][0])) if (ft_is_in("<>", tab[i][0]))
{ {
ft_eprintf("minishell: %s: must be followed by a file\n", tab[i]); ft_eprintf("bozoshell: %s: must be followed by a file\n", tab[i]);
return (1); return (1);
} }
return (0); return (0);
@ -101,7 +101,7 @@ int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str)
tab = ft_split_charset_quoted(cmd_str, " \t"); tab = ft_split_charset_quoted(cmd_str, " \t");
if (tab == NULL) if (tab == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
ft_remove_redirection(cmd_str); ft_remove_redirection(cmd_str);

View File

@ -17,7 +17,7 @@ static int ft_quote_verif(const char *str)
{ {
if (ft_is_in_quote(str, ft_strlen(str))) if (ft_is_in_quote(str, ft_strlen(str)))
{ {
ft_eprintf("minishell: Quote is not closed\n"); ft_eprintf("bozoshell: Quote is not closed\n");
return (1); return (1);
} }
else else
@ -47,7 +47,7 @@ static int ft_pipe_is_alone(const char *str)
} }
} }
if (check == 0) if (check == 0)
ft_eprintf("minishell: Pipe must be followed and %s", ft_eprintf("bozoshell: Pipe must be followed and %s",
"preced by a command or redirection\n"); "preced by a command or redirection\n");
return (check == 0); return (check == 0);
} }
@ -70,7 +70,7 @@ static int ft_special_char_dub(const char *str)
if ((y > 2 && (str[i] == '>' || str[i] == '<')) if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|| (y > 1 && str[i] == '|')) || (y > 1 && str[i] == '|'))
{ {
ft_eprintf("minishell: too many %s in a row\n", str); ft_eprintf("bozoshell: too many %s in a row\n", str);
return (1); return (1);
} }
i = i + y; i = i + y;

View File

@ -20,7 +20,7 @@ int ft_change_exit_code(t_data *data, int new_value)
exit_code_str = ft_itoa(new_value); exit_code_str = ft_itoa(new_value);
if (exit_code_str == NULL) if (exit_code_str == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (1); return (1);
} }
return (0); return (0);

View File

@ -20,19 +20,19 @@ char *ft_get_executable_with_path(t_data *data, const char *name)
if (access(name, F_OK) != 0) if (access(name, F_OK) != 0)
{ {
*data->exit_code = 127; *data->exit_code = 127;
ft_eprintf("minishell: %s: No such file or directery\n", name); ft_eprintf("bozoshell: %s: No such file or directery\n", name);
return (NULL); return (NULL);
} }
if (access(name, X_OK) != 0) if (access(name, X_OK) != 0)
{ {
*data->exit_code = 126; *data->exit_code = 126;
ft_eprintf("minishell: %s: permission denied\n", name); ft_eprintf("bozoshell: %s: permission denied\n", name);
return (NULL); return (NULL);
} }
path = ft_strdup(name); path = ft_strdup(name);
if (path == NULL) if (path == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (NULL); return (NULL);
} }
return (path); return (path);
@ -47,13 +47,13 @@ static char **ft_get_paths(t_data *data, const char *name)
if (paths == NULL) if (paths == NULL)
{ {
*data->exit_code = 127; *data->exit_code = 127;
ft_eprintf("minishell: %s: command not found\n", name); ft_eprintf("bozoshell: %s: command not found\n", name);
return (NULL); return (NULL);
} }
tab = ft_split(paths, ':'); tab = ft_split(paths, ':');
if (tab == NULL) if (tab == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
return (NULL); return (NULL);
} }
return (tab); return (tab);
@ -66,7 +66,7 @@ static char *ft_file_is_executable(const char *path, const char *name)
out = ft_strmerger(3, path, "/", name); out = ft_strmerger(3, path, "/", name);
if (out == NULL) if (out == NULL)
{ {
ft_eprintf("minishell: malloc failed\n"); ft_eprintf("bozoshell: malloc failed\n");
free(out); free(out);
return (NULL); return (NULL);
} }
@ -98,7 +98,7 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
if (path == NULL) if (path == NULL)
{ {
*data->exit_code = 127; *data->exit_code = 127;
ft_eprintf("minishell: %s: command not found\n", name); ft_eprintf("bozoshell: %s: command not found\n", name);
} }
return (path); return (path);
} }