Compare commits
9 Commits
058c96849b
...
master
Author | SHA1 | Date | |
---|---|---|---|
bd5e1671fc | |||
62e887cfbd | |||
3e7dcd1ba9 | |||
9ab9c06593 | |||
2f6daa4ce5 | |||
b502364a67 | |||
0b56e95868 | |||
882a39fc94 | |||
59d9ed3514 |
@ -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"
|
BIN
builtins/.nfs000000000ab804b60000004a
Normal file
BIN
builtins/.nfs000000000ab804b60000004a
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
/* 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 echo(int fd, char **strs);
|
||||||
int pwd(int fd);
|
int pwd(int fd);
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(void);
|
||||||
int print_env(t_list **env, int fd);
|
int print_env(t_list **env, int fd);
|
||||||
int ft_export(t_list **env, char **args, 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 unset(t_list **env, char **args, int fd);
|
||||||
int ft_exit(char **args, int err);
|
int ft_exit(char **args, int err);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
/* 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 "../env/env.h"
|
||||||
# include "../utils/utils.h"
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,31 +6,37 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
/* 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"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int make_move(char *path, int fd)
|
int make_move(char *path, t_list **env)
|
||||||
{
|
{
|
||||||
char *join;
|
char *join;
|
||||||
|
char *old;
|
||||||
|
|
||||||
join = ft_strjoin("/", path);
|
join = ft_strjoin("/", path);
|
||||||
join = ft_strfjoin(get_pwd(fd), join);
|
join = ft_strfjoin(get_pwd(), join);
|
||||||
|
old = get_pwd();
|
||||||
if (chdir(join) == 0)
|
if (chdir(join) == 0)
|
||||||
{
|
{
|
||||||
|
set_value_by_key("OLDPWD", old, env);
|
||||||
|
set_value_by_key("PWD", get_pwd(), env);
|
||||||
free(join);
|
free(join);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
free(old);
|
||||||
free(join);
|
free(join);
|
||||||
write(2, "cd: No such file or directory\n", 30);
|
write(2, "cd: No such file or directory\n", 30);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int move_folder(char **args, int fd)
|
int move_folder(char **args, t_list **env)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
char *old;
|
||||||
|
|
||||||
if (args[0] == NULL || args[1] != NULL)
|
if (args[0] == NULL || args[1] != NULL)
|
||||||
{
|
{
|
||||||
@ -40,11 +46,17 @@ int move_folder(char **args, int fd)
|
|||||||
path = args[0];
|
path = args[0];
|
||||||
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
||||||
{
|
{
|
||||||
|
old = get_pwd();
|
||||||
if (chdir(path) == 0)
|
if (chdir(path) == 0)
|
||||||
|
{
|
||||||
|
set_value_by_key("OLDPWD", old, env);
|
||||||
|
set_value_by_key("PWD", get_pwd(), env);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
free(old);
|
||||||
write(2, "cd: No such file or directory\n", 30);
|
write(2, "cd: No such file or directory\n", 30);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (make_move(path, fd));
|
return (make_move(path, env));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
|
/* 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;
|
current = *env;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(((t_env *)(current->content))->key, "_"))
|
||||||
{
|
{
|
||||||
write(fd, "declare -x ", 11);
|
write(fd, "declare -x ", 11);
|
||||||
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
||||||
@ -42,6 +44,7 @@ void print_export(t_list **env, int fd)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
write(fd, "\n", 2);
|
write(fd, "\n", 2);
|
||||||
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
|
/* 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);
|
ft_putendl_fd(path, fd);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error getcwd", fd);
|
ft_putendl_fd("Error getcwd", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_pwd(int fd)
|
char *get_pwd(void)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ char *get_pwd(int fd)
|
|||||||
return (str);
|
return (str);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error getcwd", fd);
|
ft_putendl_fd("Error getcwd", 2);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
/* 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.h"
|
||||||
#include "cmd_private.h"
|
#include "cmd_private.h"
|
||||||
|
#include "../signal/signal.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
void ft_cmddel(void *ptr)
|
void ft_cmddel(void *ptr)
|
||||||
{
|
{
|
||||||
@ -56,13 +58,16 @@ void ft_cmdwaiter(void *ptr)
|
|||||||
{
|
{
|
||||||
if (exit_status == 131)
|
if (exit_status == 131)
|
||||||
{
|
{
|
||||||
ft_printf("Quit (core dumped)\n");
|
ft_printf("Quit (core dumped)");
|
||||||
*ft_get_exit_code() = 131;
|
*ft_get_exit_code() = 131;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*ft_get_exit_code() = 130;
|
*ft_get_exit_code() = 130;
|
||||||
|
ft_printf("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*ft_get_exit_code() = WEXITSTATUS(exit_status);
|
*ft_get_exit_code() = WEXITSTATUS(exit_status);
|
||||||
}
|
}
|
||||||
|
signal(SIGINT, ft_ctrlc);
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
}
|
}
|
||||||
|
14
env/env1.c
vendored
14
env/env1.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
|
/* 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)
|
if (current->next == NULL)
|
||||||
|
{
|
||||||
current->next = ft_calloc(1, sizeof(t_list));
|
current->next = ft_calloc(1, sizeof(t_list));
|
||||||
|
if (!current->next)
|
||||||
|
return ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_value_by_key(char *key, t_list **head)
|
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)
|
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
||||||
{
|
{
|
||||||
free(((t_env *)current->content)->value);
|
free(((t_env *)current->content)->value);
|
||||||
free(((t_env *)current->content)->key);
|
|
||||||
((t_env *)current->content)->value = value;
|
((t_env *)current->content)->value = value;
|
||||||
((t_env *)current->content)->key = key;
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
@ -76,7 +78,10 @@ int create_value_by_key(char *key, char *value, t_list **head)
|
|||||||
t_env *content;
|
t_env *content;
|
||||||
|
|
||||||
if (set_value_by_key(key, value, head) == 0)
|
if (set_value_by_key(key, value, head) == 0)
|
||||||
|
{
|
||||||
|
free(key);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
content = ft_calloc(1, sizeof(t_env));
|
content = ft_calloc(1, sizeof(t_env));
|
||||||
if (content == NULL)
|
if (content == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
@ -97,7 +102,10 @@ t_list **init_env(char **env)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
*head = ft_calloc(1, sizeof(t_list));
|
*head = ft_calloc(1, sizeof(t_list));
|
||||||
if (*head == NULL)
|
if (*head == NULL)
|
||||||
|
{
|
||||||
|
free(head);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
i = -1;
|
i = -1;
|
||||||
while (env[++i])
|
while (env[++i])
|
||||||
{
|
{
|
||||||
|
2
env/env2.c
vendored
2
env/env2.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
/* 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
4
env/env_fill.c
vendored
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
/* 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)
|
else if (ft_strcmp(cmd->executable, "export") == 0)
|
||||||
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
|
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
|
||||||
else if (ft_strcmp(cmd->executable, "cd") == 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)
|
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||||
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
||||||
else if (ft_strcmp(cmd->executable, "echo") == 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);
|
execve(cmd->executable, cmd->args, env);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
signal(SIGINT, SIG_IGN);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
12
main.c
12
main.c
@ -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/18 12:59:43 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>
|
||||||
|
|
||||||
@ -25,14 +25,14 @@ static char *ft_get_user_input(void)
|
|||||||
char *prompt;
|
char *prompt;
|
||||||
char *pwd;
|
char *pwd;
|
||||||
|
|
||||||
pwd = get_pwd(2);
|
pwd = get_pwd();
|
||||||
if (pwd == NULL)
|
if (pwd == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
prompt = ft_strmerger(2, pwd, "$ ");
|
prompt = ft_strmerger(2, pwd, "$ ");
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
/* 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 "./redirection_private.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "../signal/signal.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
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)
|
if (cmd->fd_in[0] == -2)
|
||||||
return (0);
|
return (0);
|
||||||
|
signal(SIGINT, ft_ctrlc_heredoc);
|
||||||
fd = ft_heredoc(data, redirection);
|
fd = ft_heredoc(data, redirection);
|
||||||
|
signal(SIGINT, ft_ctrlc);
|
||||||
if (fd == -2)
|
if (fd == -2)
|
||||||
return (1);
|
return (1);
|
||||||
else
|
else
|
||||||
@ -126,13 +130,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);
|
||||||
|
@ -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);
|
||||||
|
@ -6,17 +6,23 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
/* 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 "./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)
|
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);
|
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)
|
if (line == NULL)
|
||||||
{
|
{
|
||||||
ft_putchar_fd('\n', 1);
|
if (ft_fd_is_closed(0))
|
||||||
ft_closer(fds);
|
{
|
||||||
|
close(fds[0]);
|
||||||
|
fds[0] = -2;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: warning: here-document at line");
|
ft_eprintf("\nbozoshell: warning: here-document at line 1%s",
|
||||||
ft_eprintf("1 delimited by end-of-file (wanted `%s')\n", stop);
|
"delimited by end-of-file (wanted `adfsd')\n");
|
||||||
return (2);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
}
|
||||||
}
|
if (ft_strcmp(line, stop) == 0)
|
||||||
|
return (1);
|
||||||
static int ft_heredoc2(t_data *data, char *stop, int fds[2])
|
if (ft_format_and_write(data, line, fds[1]))
|
||||||
{
|
{
|
||||||
char *line;
|
close(fds[0]);
|
||||||
int out;
|
fds[0] = -2;
|
||||||
|
|
||||||
ft_printf("> ");
|
|
||||||
line = get_next_line(*ft_get_heredoc());
|
|
||||||
if (line == NULL)
|
|
||||||
{
|
|
||||||
out = ft_heredoc3(stop, fds);
|
|
||||||
if (out)
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
line[ft_strlen(line) - 1] = '\0';
|
|
||||||
if (ft_strcmp(line, stop) == 0)
|
|
||||||
{
|
|
||||||
free(line);
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
if (ft_format_and_write(data, line, fds[1]))
|
|
||||||
{
|
|
||||||
ft_closer(fds);
|
|
||||||
free(line);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
free(line);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_heredoc(t_data *data, char *stop)
|
int ft_heredoc(t_data *data, char *stop)
|
||||||
{
|
{
|
||||||
int fds[2];
|
int fds[2];
|
||||||
int return_code;
|
int stdin_bak;
|
||||||
|
char *line;
|
||||||
|
|
||||||
if (pipe(fds) == -1)
|
stdin_bak = dup(0);
|
||||||
return (-1);
|
if (stdin_bak == -1)
|
||||||
*ft_get_heredoc() = dup(0);
|
return (1);
|
||||||
while (true)
|
if (pipe(fds))
|
||||||
{
|
{
|
||||||
return_code = ft_heredoc2(data, stop, fds);
|
close(stdin_bak);
|
||||||
if (return_code == 2)
|
return (1);
|
||||||
break ;
|
}
|
||||||
else if (return_code == 1)
|
line = readline("> ");
|
||||||
|
while (ft_heredoc2(data, line, stop, fds) == 0)
|
||||||
{
|
{
|
||||||
if (*ft_get_heredoc() > 2)
|
free(line);
|
||||||
close(*ft_get_heredoc());
|
line = readline("> ");
|
||||||
*ft_get_heredoc() = -1;
|
|
||||||
return (-2);
|
|
||||||
}
|
}
|
||||||
}
|
free(line);
|
||||||
close(*ft_get_heredoc());
|
|
||||||
*ft_get_heredoc() = -1;
|
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
|
dup2(stdin_bak, 0);
|
||||||
|
close(stdin_bak);
|
||||||
return (fds[0]);
|
return (fds[0]);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -6,26 +6,25 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
/* 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"
|
#include "signal_private.h"
|
||||||
|
|
||||||
void ft_ctrlc(int num)
|
void ft_ctrlc_heredoc(int num)
|
||||||
{
|
{
|
||||||
if (*ft_get_heredoc() != -1)
|
close(0);
|
||||||
{
|
ft_putchar_fd('\n', 1);
|
||||||
close(*ft_get_heredoc());
|
(void) num;
|
||||||
*ft_get_heredoc() = -1;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
void ft_ctrlc(int num)
|
||||||
{
|
{
|
||||||
rl_replace_line("", 0);
|
rl_replace_line("", 0);
|
||||||
rl_on_new_line();
|
rl_on_new_line();
|
||||||
ft_putchar_fd('\n', 1);
|
ft_putchar_fd('\n', 1);
|
||||||
rl_redisplay();
|
rl_redisplay();
|
||||||
}
|
|
||||||
*ft_get_exit_code() = 130;
|
*ft_get_exit_code() = 130;
|
||||||
(void) num;
|
(void) num;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
|
/* 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_quit(int num);
|
||||||
void ft_ctrlc(int num);
|
void ft_ctrlc(int num);
|
||||||
|
void ft_ctrlc_heredoc(int num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
|
/* 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 j;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
int check;
|
||||||
|
|
||||||
x = -1;
|
x = -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
while (to_split[++x])
|
while (to_split[++x])
|
||||||
{
|
{
|
||||||
y = -1;
|
y = -1;
|
||||||
|
check = 1;
|
||||||
while (charset[++y])
|
while (charset[++y])
|
||||||
{
|
{
|
||||||
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
|
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
|
||||||
{
|
{
|
||||||
y = 0;
|
check = 0;
|
||||||
if (to_split[x + 1])
|
|
||||||
{
|
|
||||||
x++;
|
|
||||||
if (new_strs(strs, to_split, i, &j))
|
if (new_strs(strs, to_split, i, &j))
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (check)
|
||||||
(*strs)[(*i)][j++] = to_split[x];
|
(*strs)[(*i)][j++] = to_split[x];
|
||||||
}
|
}
|
||||||
return (0);
|
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 **ft_split_charset_quoted(const char *to_split, const char *charset)
|
||||||
{
|
{
|
||||||
char **strs;
|
char **strs;
|
||||||
@ -77,18 +85,6 @@ char **ft_split_charset_quoted(const char *to_split, const char *charset)
|
|||||||
free(strs);
|
free(strs);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
free_set_null(&strs, i);
|
||||||
return (strs);
|
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);
|
|
||||||
}*/
|
|
||||||
|
Reference in New Issue
Block a user