Merge remote-tracking branch 'refs/remotes/origin/master'

This commit is contained in:
Camille Chauvet 2023-04-17 10:45:10 +00:00
commit 9ab9c06593
13 changed files with 49 additions and 46 deletions

View File

@ -1,17 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* bozoshell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
# define MINISHELL_H
#ifndef BOZOSHELL_H
# define BOZOSHELL_H
# include "./env/env.h"
# include "./cmd/cmd.h"
# include "./parse/parse.h"

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/04/04 13:38:27 by erey-bet ### ########.fr */
/* Updated: 2023/04/14 19:12:10 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,6 +30,8 @@ void print_export(t_list **env, int fd)
current = *env;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)(current->content))->key, "_"))
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
@ -42,6 +44,7 @@ void print_export(t_list **env, int fd)
}
else
write(fd, "\n", 2);
}
current = current->next;
}
}

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);
}
if (key == NULL)
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (key);
}
@ -54,7 +54,7 @@ static char *ft_getvalue(t_data *data, char *key)
value = ft_strdup(value);
}
if (value == NULL)
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (value);
}

View File

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

10
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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/list.h"
#include "libftx/libftx.h"
#include "minishell.h"
#include "bozoshell.h"
#include "signal/signal.h"
#include <stdlib.h>
@ -32,7 +32,7 @@ static char *ft_get_user_input(void)
free(pwd);
if (prompt == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
line = readline(prompt);
@ -72,14 +72,14 @@ int ft_init_data(t_data *data, char **env)
data->cmds = malloc(sizeof(t_cmd *));
if (data->cmds == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
*data->cmds = NULL;
data->env = init_env(env);
if (data->env == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
free(data->cmds);
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);
if (cmd == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
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, "|");
if (tab == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (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])
&& 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);
}
str = ft_strdup(redirection);
if (str == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
ft_quote_remover(str);

View File

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

View File

@ -41,7 +41,7 @@ static int ft_heredoc3(char *stop, int fds[2])
}
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);
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]))
{
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 (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");
if (tab == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
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)))
{
ft_eprintf("minishell: Quote is not closed\n");
ft_eprintf("bozoshell: Quote is not closed\n");
return (1);
}
else
@ -47,7 +47,7 @@ static int ft_pipe_is_alone(const char *str)
}
}
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");
return (check == 0);
}
@ -70,7 +70,7 @@ static int ft_special_char_dub(const char *str)
if ((y > 2 && (str[i] == '>' || 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);
}
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);
if (exit_code_str == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (1);
}
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)
{
*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);
}
if (access(name, X_OK) != 0)
{
*data->exit_code = 126;
ft_eprintf("minishell: %s: permission denied\n", name);
ft_eprintf("bozoshell: %s: permission denied\n", name);
return (NULL);
}
path = ft_strdup(name);
if (path == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
return (path);
@ -47,13 +47,13 @@ static char **ft_get_paths(t_data *data, const char *name)
if (paths == NULL)
{
*data->exit_code = 127;
ft_eprintf("minishell: %s: command not found\n", name);
ft_eprintf("bozoshell: %s: command not found\n", name);
return (NULL);
}
tab = ft_split(paths, ':');
if (tab == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
return (NULL);
}
return (tab);
@ -66,7 +66,7 @@ static char *ft_file_is_executable(const char *path, const char *name)
out = ft_strmerger(3, path, "/", name);
if (out == NULL)
{
ft_eprintf("minishell: malloc failed\n");
ft_eprintf("bozoshell: malloc failed\n");
free(out);
return (NULL);
}
@ -98,7 +98,7 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
if (path == NULL)
{
*data->exit_code = 127;
ft_eprintf("minishell: %s: command not found\n", name);
ft_eprintf("bozoshell: %s: command not found\n", name);
}
return (path);
}