Compare commits
2 Commits
8a6a0012dc
...
2a0846fbf0
Author | SHA1 | Date | |
---|---|---|---|
|
2a0846fbf0 | ||
|
9787d71b85 |
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtins.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:41:31 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef BUILTINS_H
|
#ifndef BUILTINS_H
|
||||||
# define BUILTINS_H
|
# define BUILTINS_H
|
||||||
# include "../libftx/libft/list.h"
|
# include "../libftx/libft/list.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtins_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:41:44 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef BUILTINS_PRIVATE_H
|
#ifndef BUILTINS_PRIVATE_H
|
||||||
# define BUILTINS_PRIVATE_H
|
# define BUILTINS_PRIVATE_H
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/13 16:50:40 by erey-bet ### ########.fr */
|
/* Updated: 2023/03/28 15:53:52 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -46,7 +46,8 @@ int echo(int fd, char **strs)
|
|||||||
{
|
{
|
||||||
while (is_space(*strs[i]))
|
while (is_space(*strs[i]))
|
||||||
strs[i]++;
|
strs[i]++;
|
||||||
if (check_start_write == 1 || check_argument(strs[i], &check_backslash_n))
|
if (check_start_write == 1
|
||||||
|
|| check_argument(strs[i], &check_backslash_n))
|
||||||
{
|
{
|
||||||
check_start_write = 1;
|
check_start_write = 1;
|
||||||
ft_putstr_fd(strs[i], fd);
|
ft_putstr_fd(strs[i], fd);
|
||||||
@ -58,9 +59,3 @@ int echo(int fd, char **strs)
|
|||||||
write(fd, "\n", 1);
|
write(fd, "\n", 1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
echo(1, argv + 1);
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
||||||
|
12
cmd/cmd.h
12
cmd/cmd.h
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:47:02 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CMD_H
|
#ifndef CMD_H
|
||||||
# define CMD_H
|
# define CMD_H
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:50:24 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CMD_PRIVATE_H
|
#ifndef CMD_PRIVATE_H
|
||||||
# define CMD_PRIVATE_H
|
# define CMD_PRIVATE_H
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
14
data/data.c
14
data/data.c
@ -1,7 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* data.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:42:58 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./data_private.h"
|
#include "./data_private.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
t_data *ft_get_data()
|
t_data *ft_get_data(void)
|
||||||
{
|
{
|
||||||
static t_data data;
|
static t_data data;
|
||||||
|
|
||||||
|
12
data/data.h
12
data/data.h
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* data.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:43:40 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef DATA_H
|
#ifndef DATA_H
|
||||||
# define DATA_H
|
# define DATA_H
|
||||||
# include "../libftx/libft/list.h"
|
# include "../libftx/libft/list.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* data_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:42:21 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:42:23 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef DATA_PRIVATE_H
|
#ifndef DATA_PRIVATE_H
|
||||||
# define DATA_PRIVATE_H
|
# define DATA_PRIVATE_H
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
|
12
env/env.h
vendored
12
env/env.h
vendored
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* env.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:42:01 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:42:02 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef ENV_H
|
#ifndef ENV_H
|
||||||
# define ENV_H
|
# define ENV_H
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
7
env/env_fill.c
vendored
7
env/env_fill.c
vendored
@ -6,12 +6,11 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/20 15:39:28 by starnakin ### ########.fr */
|
/* Updated: 2023/03/27 16:42:27 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./env_private.h"
|
#include "./env_private.h"
|
||||||
#include "env.h"
|
|
||||||
|
|
||||||
static char *ft_getkey(const char *str)
|
static char *ft_getkey(const char *str)
|
||||||
{
|
{
|
||||||
@ -97,12 +96,12 @@ char *ft_env_filler(t_data *data, const char *str)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
temp = ft_strreplace(out, value, i, key_len + i);
|
temp = ft_strreplace(out, value, i, key_len + i);
|
||||||
i = i + ft_strlen(value);
|
i = i + ft_strlen(value);
|
||||||
free(out);
|
ft_freer_ultimate(2, value, out);
|
||||||
free(value);
|
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
out = temp;
|
out = temp;
|
||||||
}
|
}
|
||||||
|
if (out[i] != '\0')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (out);
|
return (out);
|
||||||
|
12
env/env_private.h
vendored
12
env/env_private.h
vendored
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* env_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:40:24 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:40:25 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef ENV_PRIVATE_H
|
#ifndef ENV_PRIVATE_H
|
||||||
# define ENV_PRIVATE_H
|
# define ENV_PRIVATE_H
|
||||||
# include "./env.h"
|
# include "./env.h"
|
||||||
|
@ -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/02/28 14:56:05 by erey-bet ### ########.fr */
|
/* Updated: 2023/03/28 15:46:43 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
|||||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||||
return_code = print_env(data->env, cmd->fd_out[0]);
|
return_code = print_env(data->env, cmd->fd_out[0]);
|
||||||
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, cmd->fd_out[0]));
|
||||||
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:46:52 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:46:53 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef EXECUTION_H
|
#ifndef EXECUTION_H
|
||||||
# define EXECUTION_H
|
# define EXECUTION_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:45:54 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef EXECUTION_PRIVATE_H
|
#ifndef EXECUTION_PRIVATE_H
|
||||||
# define EXECUTION_PRIVATE_H
|
# define EXECUTION_PRIVATE_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* spacer.c :+: :+: :+: */
|
/* format.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* format.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:44:56 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:44:57 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FORMAT_H
|
#ifndef FORMAT_H
|
||||||
# define FORMAT_H
|
# define FORMAT_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* format_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:44:59 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:45:00 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FORMAT_PRIVATE_H
|
#ifndef FORMAT_PRIVATE_H
|
||||||
# define FORMAT_PRIVATE_H
|
# define FORMAT_PRIVATE_H
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_swap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:43:25 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:43:26 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "extra.h"
|
#include "extra.h"
|
||||||
|
|
||||||
void ft_swap(void *a, void *b)
|
void ft_swap(void *a, void *b)
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* list.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:43:53 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:43:54 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef LIST_H
|
#ifndef LIST_H
|
||||||
# define LIST_H
|
# define LIST_H
|
||||||
|
|
||||||
|
6
main.c
6
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/03/28 14:35:13 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:39:53 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
static char *ft_get_user_input()
|
static char *ft_get_user_input(void)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
char *prompt;
|
char *prompt;
|
||||||
@ -62,7 +62,7 @@ static void ft_cmds_waiter(t_data *data)
|
|||||||
{
|
{
|
||||||
if (WTERMSIG(exit_status) == SIGKILL)
|
if (WTERMSIG(exit_status) == SIGKILL)
|
||||||
data->exit_code = 131;
|
data->exit_code = 131;
|
||||||
else //(WTERMSIG(exit_status) == SIGINT)
|
else
|
||||||
data->exit_code = 130;
|
data->exit_code = 130;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:42:37 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./parse_private.h"
|
#include "./parse_private.h"
|
||||||
|
|
||||||
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
||||||
@ -30,19 +42,11 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
|||||||
ft_closer(cmd->fd_in);
|
ft_closer(cmd->fd_in);
|
||||||
ft_closer(cmd->fd_out);
|
ft_closer(cmd->fd_out);
|
||||||
}
|
}
|
||||||
else if (ft_strcmp(cmd->args[0], "env") == 0)
|
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0],
|
||||||
own = 1;
|
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0)
|
||||||
else if (ft_strcmp(cmd->args[0], "export") == 0)
|
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0],
|
||||||
own = 1;
|
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0)
|
||||||
else if (ft_strcmp(cmd->args[0], "echo") == 0)
|
|| (ft_strcmp(cmd->args[0], "cd") == 0))
|
||||||
own = 1;
|
|
||||||
else if (ft_strcmp(cmd->args[0], "unset") == 0)
|
|
||||||
own = 1;
|
|
||||||
else if (ft_strcmp(cmd->args[0], "exit") == 0)
|
|
||||||
own = 1;
|
|
||||||
else if (ft_strcmp(cmd->args[0], "pwd") == 0)
|
|
||||||
own = 1;
|
|
||||||
else if (ft_strcmp(cmd->args[0], "cd") == 0)
|
|
||||||
own = 1;
|
own = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -55,10 +59,23 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_cmd_adder(t_data *data, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
t_list *element;
|
||||||
|
|
||||||
|
element = ft_lstnew(cmd);
|
||||||
|
if (element == NULL)
|
||||||
|
{
|
||||||
|
ft_cmddel(cmd);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_lstadd_back(data->cmds, element);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int ft_cmd_parser(t_data *data, char *cmd_str)
|
int ft_cmd_parser(t_data *data, char *cmd_str)
|
||||||
{
|
{
|
||||||
t_cmd *cmd;
|
t_cmd *cmd;
|
||||||
t_list *element;
|
|
||||||
|
|
||||||
cmd = ft_calloc(sizeof(t_cmd), 1);
|
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
@ -81,37 +98,28 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
|
|||||||
ft_cmddel(cmd);
|
ft_cmddel(cmd);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
element = ft_lstnew(cmd);
|
return (ft_cmd_adder(data, cmd));
|
||||||
if (element == NULL)
|
|
||||||
{
|
|
||||||
ft_cmddel(cmd);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
ft_lstadd_back(data->cmds, element);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_cmds_parser(t_data *data, const char *line)
|
int ft_cmds_parser(t_data *data, const char *line)
|
||||||
{
|
{
|
||||||
char **tab;
|
char **tab;
|
||||||
size_t i;
|
ssize_t i;
|
||||||
|
|
||||||
tab = ft_split_quoted(line, '|');
|
tab = ft_split_quoted(line, '|');
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
{
|
{
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
i = 0;
|
i = -1;
|
||||||
while (tab[i] != NULL)
|
while (tab[++i] != NULL)
|
||||||
{
|
{
|
||||||
if (ft_cmd_parser(data, tab[i]))
|
if (ft_cmd_parser(data, tab[i]))
|
||||||
{
|
{
|
||||||
ft_freer_tab_ultimate(1, tab);
|
ft_freer_tab_ultimate(1, tab);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
if (*data->cmds != NULL)
|
if (*data->cmds != NULL)
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parse.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:42:38 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:42:39 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef PARSE_H
|
#ifndef PARSE_H
|
||||||
# define PARSE_H
|
# define PARSE_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parse_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:42:44 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:42:45 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef PARSE_PRIVATE_H
|
#ifndef PARSE_PRIVATE_H
|
||||||
# define PARSE_PRIVATE_H
|
# define PARSE_PRIVATE_H
|
||||||
# include "../redirection/redirection.h"
|
# include "../redirection/redirection.h"
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
/* 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/02/17 16:21:02 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/28 15:47:25 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./redirection_private.h"
|
#include "./redirection_private.h"
|
||||||
|
|
||||||
int *ft_get_heredoc()
|
int *ft_get_heredoc(void)
|
||||||
{
|
{
|
||||||
static int heredoc = -1;
|
static int heredoc = -1;
|
||||||
|
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:49:58 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "redirection_private.h"
|
#include "redirection_private.h"
|
||||||
|
|
||||||
int ft_replace_file(t_data *data, char **tab)
|
int ft_replace_file(t_data *data, char **tab)
|
||||||
@ -44,7 +56,8 @@ void ft_remove_redirection(char *cmd_str)
|
|||||||
i++;
|
i++;
|
||||||
while (cmd_str[i] == ' ')
|
while (cmd_str[i] == ' ')
|
||||||
i++;
|
i++;
|
||||||
while (cmd_str[i] != '\0' && (cmd_str[i] != ' ' || ft_is_in_quote(cmd_str, i)))
|
while (cmd_str[i] != '\0' && (cmd_str[i] != ' '
|
||||||
|
|| ft_is_in_quote(cmd_str, i)))
|
||||||
i++;
|
i++;
|
||||||
stop = i - start;
|
stop = i - start;
|
||||||
if (start != -1)
|
if (start != -1)
|
||||||
@ -79,14 +92,16 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
|
|||||||
else if (ft_strcmp(tab[i], ">") == 0)
|
else if (ft_strcmp(tab[i], ">") == 0)
|
||||||
{
|
{
|
||||||
if (ft_file_is_writable(data, tab[i + 1]))
|
if (ft_file_is_writable(data, tab[i + 1]))
|
||||||
cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
cmd->fd_out[0] = open(tab[i + 1],
|
||||||
|
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if (ft_strcmp(tab[i], ">>") == 0)
|
else if (ft_strcmp(tab[i], ">>") == 0)
|
||||||
{
|
{
|
||||||
if (ft_file_is_appendable(data, tab[i + 1]))
|
if (ft_file_is_appendable(data, tab[i + 1]))
|
||||||
cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_APPEND | O_CREAT, 0644);
|
cmd->fd_out[0] = open(tab[i + 1],
|
||||||
|
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:19 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:44:20 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef REDIRECTION_H
|
#ifndef REDIRECTION_H
|
||||||
# define REDIRECTION_H
|
# define REDIRECTION_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
#ifndef REDIRECTIONS_PRIVATE
|
/* ************************************************************************** */
|
||||||
# define REDIRECTIONS_PRIVATE
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:44:38 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef REDIRECTION_PRIVATE_H
|
||||||
|
# define REDIRECTION_PRIVATE_H
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* syntax.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:42:54 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/28 15:42:55 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef SYNTAX_H
|
#ifndef SYNTAX_H
|
||||||
# define SYNTAX_H
|
# define SYNTAX_H
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
14
utils/fd.c
14
utils/fd.c
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 14:14:17 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./utils.h"
|
#include "./utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -5,12 +17,10 @@ void ft_closer(int fds[2])
|
|||||||
{
|
{
|
||||||
if (fds[0] > 2)
|
if (fds[0] > 2)
|
||||||
{
|
{
|
||||||
//dprintf(2, "close(%d)\n", fds[0]);
|
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
}
|
}
|
||||||
if (fds[1] > 2)
|
if (fds[1] > 2)
|
||||||
{
|
{
|
||||||
//dprintf(2, "close(%d)\n", fds[1]);
|
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_get_executable.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/27 13:39:50 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./utils.h"
|
#include "./utils.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -26,14 +38,11 @@ char *ft_get_executable_with_path(t_data *data, const char *name)
|
|||||||
return (path);
|
return (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_get_executable_without_path(t_data *data, const char *name)
|
static char **ft_get_paths(t_data *data, const char *name)
|
||||||
{
|
{
|
||||||
char **tab;
|
|
||||||
char *paths;
|
char *paths;
|
||||||
char *path;
|
char **tab;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
path = NULL;
|
|
||||||
paths = get_value_by_key("PATH", data->env);
|
paths = get_value_by_key("PATH", data->env);
|
||||||
if (paths == NULL)
|
if (paths == NULL)
|
||||||
{
|
{
|
||||||
@ -47,10 +56,23 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
|
|||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
i = 0;
|
return (tab);
|
||||||
while (tab[i] != NULL)
|
}
|
||||||
|
|
||||||
|
static char *ft_get_executable_without_path(t_data *data, const char *name)
|
||||||
{
|
{
|
||||||
path = ft_strmerger(3, tab[i], "/", name);
|
char **paths;
|
||||||
|
char *path;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
paths = ft_get_paths(data, name);
|
||||||
|
if (paths == NULL)
|
||||||
|
return (NULL);
|
||||||
|
path = NULL;
|
||||||
|
i = 0;
|
||||||
|
while (paths[i] != NULL)
|
||||||
|
{
|
||||||
|
path = ft_strmerger(3, paths[i], "/", name);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
@ -62,7 +84,7 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
|
|||||||
path = NULL;
|
path = NULL;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
ft_freer_tab_ultimate(1, tab);
|
ft_freer_tab_ultimate(1, paths);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
data->exit_code = 127;
|
data->exit_code = 127;
|
||||||
|
@ -6,40 +6,36 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
|
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/21 23:08:10 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
int ft_is_in_quote(const char *str, size_t n)
|
int ft_is_in_quote(const char *str, size_t n)
|
||||||
{
|
{
|
||||||
size_t i;
|
ssize_t i;
|
||||||
|
|
||||||
i = 0;
|
i = -1;
|
||||||
while (str[i] != '\0' && i < n)
|
while (str[++i] != '\0' && i < (ssize_t) n)
|
||||||
{
|
{
|
||||||
if (str[i] == '\'')
|
if (str[i] == '\'')
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
while (str[i] != '\'' && str[i] != '\0')
|
while (str[i] != '\'' && str[i] != '\0')
|
||||||
{
|
{
|
||||||
if (i == n)
|
if (i == (ssize_t) n)
|
||||||
return (1);
|
return (1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str[i] == '"')
|
if (str[i] == '"')
|
||||||
{
|
{
|
||||||
i++;
|
while (str[++i] != '"' && str[i] != '\0')
|
||||||
while (str[i] != '"' && str[i] != '\0')
|
if (i == (ssize_t) n)
|
||||||
{
|
|
||||||
if (i == n)
|
|
||||||
return (2);
|
return (2);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user