Compare commits

...

9 Commits

25 changed files with 178 additions and 160 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"

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
/* Updated: 2023/04/05 12:16:50 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 12:57:36 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,10 +16,10 @@
int echo(int fd, char **strs);
int pwd(int fd);
char *get_pwd(int fd);
char *get_pwd(void);
int print_env(t_list **env, int fd);
int ft_export(t_list **env, char **args, int fd);
int move_folder(char **args, int fd);
int move_folder(char **args, t_list **env, int fd);
int unset(t_list **env, char **args, int fd);
int ft_exit(char **args, int err);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
/* Updated: 2023/03/31 20:07:36 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 12:57:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,6 @@
# include "../env/env.h"
# include "../utils/utils.h"
char *get_pwd(int fd);
char *get_pwd(void);
#endif

View File

@ -6,31 +6,37 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
/* Updated: 2023/03/31 15:02:43 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 13:22:22 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
int make_move(char *path, int fd)
int make_move(char *path, t_list **env)
{
char *join;
char *old;
join = ft_strjoin("/", path);
join = ft_strfjoin(get_pwd(fd), join);
join = ft_strfjoin(get_pwd(), join);
old = get_pwd();
if (chdir(join) == 0)
{
set_value_by_key("OLDPWD", old, env);
set_value_by_key("PWD", get_pwd(), env);
free(join);
return (0);
}
free(old);
free(join);
write(2, "cd: No such file or directory\n", 30);
return (1);
}
int move_folder(char **args, int fd)
int move_folder(char **args, t_list **env)
{
char *path;
char *old;
if (args[0] == NULL || args[1] != NULL)
{
@ -40,11 +46,17 @@ int move_folder(char **args, int fd)
path = args[0];
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
{
old = get_pwd();
if (chdir(path) == 0)
{
set_value_by_key("OLDPWD", old, env);
set_value_by_key("PWD", get_pwd(), env);
return (0);
}
free(old);
write(2, "cd: No such file or directory\n", 30);
return (1);
}
else
return (make_move(path, fd));
return (make_move(path, env));
}

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 */
/* */
/* ************************************************************************** */
@ -31,17 +31,20 @@ void print_export(t_list **env, int fd)
current = *env;
while (current->next != NULL)
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
if (((t_env *)(current->content))->value != NULL)
if (ft_strcmp(((t_env *)(current->content))->key, "_"))
{
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
if (((t_env *)(current->content))->value != NULL)
{
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
}
else
write(fd, "\n", 2);
}
else
write(fd, "\n", 2);
current = current->next;
}
}

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
/* Updated: 2023/03/09 20:00:19 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,13 +20,13 @@ int pwd(int fd)
ft_putendl_fd(path, fd);
else
{
ft_putendl_fd("Error getcwd", fd);
ft_putendl_fd("Error getcwd", 2);
return (1);
}
return (0);
}
char *get_pwd(int fd)
char *get_pwd(void)
{
char *str;
@ -35,7 +35,7 @@ char *get_pwd(int fd)
return (str);
else
{
ft_putendl_fd("Error getcwd", fd);
ft_putendl_fd("Error getcwd", 2);
return (NULL);
}
}

View File

@ -6,12 +6,14 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
/* Updated: 2023/04/07 15:17:21 by alouis-j ### ########.fr */
/* Updated: 2023/04/17 11:57:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "cmd.h"
#include "cmd_private.h"
#include "../signal/signal.h"
#include <signal.h>
void ft_cmddel(void *ptr)
{
@ -56,13 +58,16 @@ void ft_cmdwaiter(void *ptr)
{
if (exit_status == 131)
{
ft_printf("Quit (core dumped)\n");
ft_printf("Quit (core dumped)");
*ft_get_exit_code() = 131;
}
else
*ft_get_exit_code() = 130;
ft_printf("\n");
}
else
*ft_get_exit_code() = WEXITSTATUS(exit_status);
}
signal(SIGINT, ft_ctrlc);
signal(SIGQUIT, SIG_IGN);
}

14
env/env1.c vendored
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/03/30 13:07:15 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 13:57:38 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,7 +34,11 @@ void add_sort(t_list **head, t_env *var)
}
}
if (current->next == NULL)
{
current->next = ft_calloc(1, sizeof(t_list));
if (!current->next)
return ;
}
}
char *get_value_by_key(char *key, t_list **head)
@ -61,9 +65,7 @@ int set_value_by_key(char *key, char *value, t_list **head)
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
{
free(((t_env *)current->content)->value);
free(((t_env *)current->content)->key);
((t_env *)current->content)->value = value;
((t_env *)current->content)->key = key;
return (0);
}
current = current->next;
@ -76,7 +78,10 @@ int create_value_by_key(char *key, char *value, t_list **head)
t_env *content;
if (set_value_by_key(key, value, head) == 0)
{
free(key);
return (0);
}
content = ft_calloc(1, sizeof(t_env));
if (content == NULL)
return (1);
@ -97,7 +102,10 @@ t_list **init_env(char **env)
return (NULL);
*head = ft_calloc(1, sizeof(t_list));
if (*head == NULL)
{
free(head);
return (NULL);
}
i = -1;
while (env[++i])
{

2
env/env2.c vendored
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
/* Updated: 2023/03/09 19:59:10 by erey-bet ### ########.fr */
/* Updated: 2023/04/18 13:26:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */

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

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
/* Updated: 2023/04/14 13:04:01 by cchauvet ### ########.fr */
/* Updated: 2023/04/18 13:00:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@ static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
else if (ft_strcmp(cmd->executable, "export") == 0)
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
else if (ft_strcmp(cmd->executable, "cd") == 0)
return_code = (move_folder(cmd->args + 1, cmd->fd_out[0]));
return_code = (move_folder(cmd->args + 1, data->env, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "unset") == 0)
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
else if (ft_strcmp(cmd->executable, "echo") == 0)
@ -58,6 +58,8 @@ static bool ft_executor(t_data *data, t_cmd *cmd, char **env)
execve(cmd->executable, cmd->args, env);
return (1);
}
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
return (0);
}

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;

12
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/18 12:59:43 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>
@ -25,14 +25,14 @@ static char *ft_get_user_input(void)
char *prompt;
char *pwd;
pwd = get_pwd(2);
pwd = get_pwd();
if (pwd == NULL)
return (NULL);
prompt = ft_strmerger(2, pwd, "$ ");
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

@ -6,12 +6,14 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
/* Updated: 2023/04/07 15:06:39 by alouis-j ### ########.fr */
/* Updated: 2023/04/17 11:15:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./redirection_private.h"
#include <stdbool.h>
#include "../signal/signal.h"
#include <signal.h>
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
char *redirection_identifier, char *redirection)
@ -22,7 +24,9 @@ static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
{
if (cmd->fd_in[0] == -2)
return (0);
signal(SIGINT, ft_ctrlc_heredoc);
fd = ft_heredoc(data, redirection);
signal(SIGINT, ft_ctrlc);
if (fd == -2)
return (1);
else
@ -126,13 +130,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

@ -6,17 +6,23 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
/* Updated: 2023/04/07 15:11:17 by alouis-j ### ########.fr */
/* Updated: 2023/04/17 12:14:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./redirection_private.h"
#include <readline/readline.h>
#include <unistd.h>
int *ft_get_heredoc(void)
static bool ft_fd_is_closed(int fd)
{
static int heredoc = -1;
int fd2;
return (&heredoc);
fd2 = dup(fd);
if (fd2 == -1)
return (1);
close(fd2);
return (0);
}
static int ft_format_and_write(t_data *data, const char *str, int fd)
@ -31,75 +37,57 @@ static int ft_format_and_write(t_data *data, const char *str, int fd)
return (0);
}
static int ft_heredoc3(char *stop, int fds[2])
int ft_heredoc2(t_data *data, char *line, char *stop, int fds[2])
{
if (*ft_get_heredoc() == -1)
{
ft_putchar_fd('\n', 1);
ft_closer(fds);
return (1);
}
else
{
ft_eprintf("minishell: warning: here-document at line");
ft_eprintf("1 delimited by end-of-file (wanted `%s')\n", stop);
return (2);
}
return (0);
}
static int ft_heredoc2(t_data *data, char *stop, int fds[2])
{
char *line;
int out;
ft_printf("> ");
line = get_next_line(*ft_get_heredoc());
if (line == NULL)
{
out = ft_heredoc3(stop, fds);
if (out)
return (out);
if (ft_fd_is_closed(0))
{
close(fds[0]);
fds[0] = -2;
return (1);
}
else
{
ft_eprintf("\nbozoshell: warning: here-document at line 1%s",
"delimited by end-of-file (wanted `adfsd')\n");
return (1);
}
}
line[ft_strlen(line) - 1] = '\0';
if (ft_strcmp(line, stop) == 0)
{
free(line);
return (2);
}
return (1);
if (ft_format_and_write(data, line, fds[1]))
{
ft_closer(fds);
free(line);
close(fds[0]);
fds[0] = -2;
return (1);
}
free(line);
return (0);
}
int ft_heredoc(t_data *data, char *stop)
{
int fds[2];
int return_code;
int stdin_bak;
char *line;
if (pipe(fds) == -1)
return (-1);
*ft_get_heredoc() = dup(0);
while (true)
stdin_bak = dup(0);
if (stdin_bak == -1)
return (1);
if (pipe(fds))
{
return_code = ft_heredoc2(data, stop, fds);
if (return_code == 2)
break ;
else if (return_code == 1)
{
if (*ft_get_heredoc() > 2)
close(*ft_get_heredoc());
*ft_get_heredoc() = -1;
return (-2);
}
close(stdin_bak);
return (1);
}
close(*ft_get_heredoc());
*ft_get_heredoc() = -1;
line = readline("> ");
while (ft_heredoc2(data, line, stop, fds) == 0)
{
free(line);
line = readline("> ");
}
free(line);
close(fds[1]);
dup2(stdin_bak, 0);
close(stdin_bak);
return (fds[0]);
}

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

@ -6,26 +6,25 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
/* Updated: 2023/04/11 13:02:34 by cchauvet ### ########.fr */
/* Updated: 2023/04/17 11:23:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "signal_private.h"
void ft_ctrlc_heredoc(int num)
{
close(0);
ft_putchar_fd('\n', 1);
(void) num;
}
void ft_ctrlc(int num)
{
if (*ft_get_heredoc() != -1)
{
close(*ft_get_heredoc());
*ft_get_heredoc() = -1;
}
else
{
rl_replace_line("", 0);
rl_on_new_line();
ft_putchar_fd('\n', 1);
rl_redisplay();
}
rl_replace_line("", 0);
rl_on_new_line();
ft_putchar_fd('\n', 1);
rl_redisplay();
*ft_get_exit_code() = 130;
(void) num;
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
/* Updated: 2023/03/28 16:03:11 by cchauvet ### ########.fr */
/* Updated: 2023/04/17 11:14:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,5 +15,6 @@
void ft_quit(int num);
void ft_ctrlc(int num);
void ft_ctrlc_heredoc(int num);
#endif

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

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
/* Updated: 2023/04/14 14:14:25 by erey-bet ### ########.fr */
/* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,30 +30,38 @@ int get_strs(const char *to_split, const char *charset, char ***strs, int *i)
int j;
int x;
int y;
int check;
x = -1;
j = 0;
while (to_split[++x])
{
y = -1;
check = 1;
while (charset[++y])
{
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
{
y = 0;
if (to_split[x + 1])
{
x++;
if (new_strs(strs, to_split, i, &j))
return (1);
}
check = 0;
if (new_strs(strs, to_split, i, &j))
return (1);
}
}
(*strs)[(*i)][j++] = to_split[x];
if (check)
(*strs)[(*i)][j++] = to_split[x];
}
return (0);
}
void free_set_null(char ***strs, int i)
{
if (ft_strlen((*strs)[i]) == 0)
{
free((*strs)[i]);
(*strs)[i] = NULL;
}
}
char **ft_split_charset_quoted(const char *to_split, const char *charset)
{
char **strs;
@ -77,18 +85,6 @@ char **ft_split_charset_quoted(const char *to_split, const char *charset)
free(strs);
return (NULL);
}
free_set_null(&strs, i);
return (strs);
}
/*#include <stdio.h>
int main(int argc, char **argv)
{
char **strs;
if (argc == 3)
strs = ft_split_charset_quoted(argv[1], argv[2]);
int i = -1;
while (strs[++i])
printf("%s\n", strs[i]);
return (0);
}*/