Compare commits
149 Commits
8ea2e6c620
...
master
Author | SHA1 | Date | |
---|---|---|---|
bd5e1671fc | |||
62e887cfbd | |||
3e7dcd1ba9 | |||
9ab9c06593 | |||
2f6daa4ce5 | |||
b502364a67 | |||
0b56e95868 | |||
882a39fc94 | |||
59d9ed3514 | |||
058c96849b | |||
37bd3efc98 | |||
425fbd15cd | |||
d3fa573054 | |||
227d16ca53 | |||
91ef62d8f9 | |||
d06eb570fc | |||
1ef3fa115e | |||
10db23e4ef | |||
a6a0293095 | |||
a48da783dd | |||
be1f7ebf8c | |||
e65a9f32c0 | |||
8a2eb85dc6 | |||
5d482fc65a | |||
e0fb7f1fd0 | |||
404fcaa15f | |||
fe535a21f0 | |||
8a245f0dd8 | |||
f93fed5cdd | |||
d99aa39070 | |||
f0afd69bf6 | |||
5cbb6f078d | |||
b3e9a23f32 | |||
b1805834ec | |||
0d231a062d | |||
10413e500b | |||
760b8b644e | |||
fdfe1c8b95 | |||
0bf045d4ab | |||
7e0bbd1203 | |||
b96b617e09 | |||
f6617e07c7 | |||
a7e75bb163 | |||
d9ae113b94 | |||
88d955fddc | |||
68c945ae05 | |||
8af6b42642 | |||
46fe9caded | |||
1e00fee53c | |||
4dc8793eec | |||
f66ab7790e | |||
41bbe2bc0b | |||
3374d21cad | |||
94f55af0be | |||
6f3b1ab918 | |||
6a81705b98 | |||
27b8874f75 | |||
cdfa81328b | |||
bb00de527a | |||
7e77c4fe48 | |||
13e455cbf4 | |||
471845b565 | |||
1c43d89fa1 | |||
a941a0138f | |||
011c801f1d | |||
f874ed9f7b | |||
dd49432d0d | |||
1c8892983e | |||
c1e61780e0 | |||
6498031d59 | |||
3e656abf5d | |||
a9df160295 | |||
2a0846fbf0 | |||
9787d71b85 | |||
8a6a0012dc | |||
4acefd9208 | |||
c8c4297f8b | |||
d05edefa0f | |||
392c2d94d0 | |||
94fa4de0a2 | |||
d54cd98197 | |||
147af02c6e | |||
67e8a60423 | |||
96a5856592 | |||
57dd5c9962 | |||
689a4e4eb6 | |||
db51c3c85b | |||
c5ddcdc892 | |||
45fc051e9d | |||
e195fe2c6d | |||
215b0dbb7e | |||
22dc9776d6 | |||
b3d060874d | |||
72ff3ba134 | |||
086fd3bcbe | |||
0fa822f6db | |||
a58f9a0c76 | |||
d56aac4b25 | |||
96696243d0 | |||
f5940ee99e | |||
ee3d535393 | |||
08261b1921 | |||
7ea602b12c | |||
7ffe556cd4 | |||
6ce54ea6fe | |||
74bbbd899a | |||
b1d827e106 | |||
bf15a86c2e | |||
1b17df6170 | |||
51d7e60790 | |||
4d3c25547e | |||
c43331dca3 | |||
ec752adbfa | |||
dbb39712ea | |||
e2c43eb973 | |||
3d68490320 | |||
0694b36a72 | |||
3d62d3dde9 | |||
69fc4c573a | |||
087a96e54b | |||
1a4ed128e7 | |||
d36d9c92f5 | |||
6c8e161a32 | |||
f20eab31dd | |||
86f01779cc | |||
c6d683a1fc | |||
f956986789 | |||
a18c4cae82 | |||
5c9be2d56b | |||
15c95b45b1 | |||
876c75bb92 | |||
8093b250ce | |||
2930755dd3 | |||
3540743135 | |||
5bfc613126 | |||
686ea5d0db | |||
e7f8373b4a | |||
9cbb1e139a | |||
06f6308bc4 | |||
b2c7013cf9 | |||
7f4fd9d421 | |||
af7336fbf3 | |||
4342d9a015 | |||
e0e329a355 | |||
5541a1f3fe | |||
b914753c47 | |||
9a5cca3e2d | |||
77620211da | |||
07bc37cc71 |
32
Makefile
32
Makefile
@ -1,5 +1,31 @@
|
|||||||
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c
|
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_charset_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c ./utils/ft_get_executable.c ./utils/fd.c
|
||||||
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c builtins/exit.c builtins/unset.c
|
|
||||||
|
BUILTINS_SRC = builtins/pwd.c \
|
||||||
|
builtins/export.c \
|
||||||
|
builtins/env.c \
|
||||||
|
builtins/cd.c \
|
||||||
|
builtins/exit.c \
|
||||||
|
builtins/unset.c \
|
||||||
|
builtins/echo.c
|
||||||
|
|
||||||
|
SRCS = ${BUILTINS_SRC} \
|
||||||
|
${UTILS_SRC} \
|
||||||
|
main.c \
|
||||||
|
./cmd/cmd.c \
|
||||||
|
./env/env1.c \
|
||||||
|
./env/env2.c \
|
||||||
|
./env/env3.c \
|
||||||
|
./env/env_fill.c \
|
||||||
|
./data/data.c \
|
||||||
|
./execution/execution.c \
|
||||||
|
./syntax/syntax.c \
|
||||||
|
./format/format.c \
|
||||||
|
./redirection/heredoc.c \
|
||||||
|
./redirection/file.c \
|
||||||
|
./redirection/redirection.c \
|
||||||
|
./redirection/check.c \
|
||||||
|
./parse/parse.c \
|
||||||
|
./signal/signal.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
@ -7,7 +33,7 @@ NAME = minishell
|
|||||||
|
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|
||||||
CFLAGS = -Werror -Wextra -g
|
CFLAGS = -Werror -Wextra -Wall -g
|
||||||
|
|
||||||
LIBS = libftx/libftx.a
|
LIBS = libftx/libftx.a
|
||||||
|
|
||||||
|
34
bozoshell.h
Normal file
34
bozoshell.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* bozoshell.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/14 16:16:31 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BOZOSHELL_H
|
||||||
|
# define BOZOSHELL_H
|
||||||
|
# include "./env/env.h"
|
||||||
|
# include "./cmd/cmd.h"
|
||||||
|
# include "./parse/parse.h"
|
||||||
|
# include "./syntax/syntax.h"
|
||||||
|
# include "./execution/execution.h"
|
||||||
|
# include "./builtins/builtins.h"
|
||||||
|
# include "./format/format.h"
|
||||||
|
# include "./redirection/redirection.h"
|
||||||
|
# include "./libftx/libftx.h"
|
||||||
|
# include "./utils/utils.h"
|
||||||
|
# include "./data/data.h"
|
||||||
|
# include "./signal/signal.h"
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <readline/readline.h>
|
||||||
|
# include <readline/history.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/wait.h>
|
||||||
|
|
||||||
|
#endif
|
Binary file not shown.
26
builtins/builtins.h
Normal file
26
builtins/builtins.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtins.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/18 12:57:36 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BUILTINS_H
|
||||||
|
# define BUILTINS_H
|
||||||
|
# include "../libftx/libft/list.h"
|
||||||
|
|
||||||
|
int echo(int fd, char **strs);
|
||||||
|
int 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, t_list **env, int fd);
|
||||||
|
int unset(t_list **env, char **args, int fd);
|
||||||
|
int ft_exit(char **args, int err);
|
||||||
|
|
||||||
|
#endif
|
22
builtins/builtins_private.h
Normal file
22
builtins/builtins_private.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtins_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/18 12:57:25 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BUILTINS_PRIVATE_H
|
||||||
|
# define BUILTINS_PRIVATE_H
|
||||||
|
# include <limits.h>
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../env/env.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
|
char *get_pwd(void);
|
||||||
|
|
||||||
|
#endif
|
@ -6,59 +6,57 @@
|
|||||||
/* 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/02/28 13:37:18 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:22:22 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int move_folder(char **args, int fd)
|
int make_move(char *path, t_list **env)
|
||||||
{
|
{
|
||||||
char *join;
|
char *join;
|
||||||
char *path;
|
char *old;
|
||||||
|
|
||||||
if (args[1] != NULL)
|
join = ft_strjoin("/", path);
|
||||||
|
join = ft_strfjoin(get_pwd(), join);
|
||||||
|
old = get_pwd();
|
||||||
|
if (chdir(join) == 0)
|
||||||
{
|
{
|
||||||
write(2, "cd: too many argument", 22);
|
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, t_list **env)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
char *old;
|
||||||
|
|
||||||
|
if (args[0] == NULL || args[1] != NULL)
|
||||||
|
{
|
||||||
|
write(2, "cd: Wrong number's argument\n", 28);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
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);
|
||||||
write(2, "No suck file or directory", 25);
|
}
|
||||||
|
free(old);
|
||||||
|
write(2, "cd: No such file or directory\n", 30);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
return (make_move(path, env));
|
||||||
join = ft_strjoin("/", path);
|
|
||||||
join = ft_strfjoin(get_pwd(fd), join);
|
|
||||||
if (chdir(join) == 0)
|
|
||||||
{
|
|
||||||
free(join);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
free(join);
|
|
||||||
write(2, "No suck file or directory", 25);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int main(int argc, char *argv[]) {
|
|
||||||
char cwd[PATH_MAX];
|
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
|
||||||
printf("%s\n", cwd);
|
|
||||||
} else {
|
|
||||||
perror("getcwd() error");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
move_folder(argv[1], 1);
|
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
|
||||||
printf("%s\n", cwd);
|
|
||||||
} else {
|
|
||||||
perror("getcwd() error");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
/* 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/02/22 13:23:16 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/11 14:57:00 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int is_space(char c)
|
int is_space(char c)
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ int is_space(char c)
|
|||||||
|| c == '\r' || c == '\n');
|
|| c == '\r' || c == '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_argument(char *str, int *check)
|
int check_argument(char *str, int *check_backslash_n)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -26,36 +26,38 @@ int check_argument(char *str, int *check)
|
|||||||
while (str[++i])
|
while (str[++i])
|
||||||
if (str[i] != '-' && str[i] != 'n')
|
if (str[i] != '-' && str[i] != 'n')
|
||||||
return (1);
|
return (1);
|
||||||
if (ft_strnstr(str, "n", ft_strlen(str)))
|
if (ft_strnstr(str, "n", ft_strlen(str)) && str[0] == '-')
|
||||||
*check = 1;
|
*check_backslash_n = 1;
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int echo(int fd, char **strs)
|
int echo(int fd, char **strs)
|
||||||
{
|
{
|
||||||
int check;
|
int check_backslash_n;
|
||||||
|
int check_start_write;
|
||||||
int i;
|
int i;
|
||||||
|
int y;
|
||||||
|
|
||||||
check = 0;
|
check_backslash_n = 0;
|
||||||
|
check_start_write = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (strs[++i])
|
while (strs[++i])
|
||||||
{
|
{
|
||||||
while (is_space(*strs[i]))
|
y = -1;
|
||||||
strs[i]++;
|
while (is_space(strs[i][++y]))
|
||||||
if (check == 1 || check_argument(strs[i], &check))
|
;
|
||||||
|
if (check_start_write == 1
|
||||||
|
|| check_argument(strs[i], &check_backslash_n))
|
||||||
{
|
{
|
||||||
|
check_start_write = 1;
|
||||||
ft_putstr_fd(strs[i], fd);
|
ft_putstr_fd(strs[i], fd);
|
||||||
if (strs[i + 1] != NULL)
|
if (strs[i + 1] != NULL)
|
||||||
write(fd, " ", 1);
|
write(fd, " ", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!check)
|
if (!check_backslash_n)
|
||||||
write(fd, "\n", 1);
|
write(fd, "\n", 1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
echo(1, argv + 1);
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/23 16:50:01 by erey-bet ### ########.fr */
|
/* Updated: 2023/03/30 15:15:04 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int print_env(t_list **env, int fd)
|
int print_env(t_list **env, int fd)
|
||||||
{
|
{
|
||||||
@ -18,21 +18,15 @@ int print_env(t_list **env, int fd)
|
|||||||
|
|
||||||
current = *env;
|
current = *env;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
|
{
|
||||||
|
if (((t_env *)(current->content))->value)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
||||||
ft_putstr_fd("=", fd);
|
ft_putstr_fd("=", fd);
|
||||||
ft_putstr_fd(((t_env *)(current->content))->value, fd);
|
ft_putstr_fd(((t_env *)(current->content))->value, fd);
|
||||||
write(fd, "\n", 1);
|
write(fd, "\n", 1);
|
||||||
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[], char **env)
|
|
||||||
{
|
|
||||||
t_list **be;
|
|
||||||
|
|
||||||
be = init_env(env);
|
|
||||||
print_env(be, 1);
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
||||||
|
@ -6,15 +6,15 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/28 14:55:39 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/05 12:30:46 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
static int error(int err, char *reason, char *problem)
|
static int error(int err, char *reason, char *problem)
|
||||||
{
|
{
|
||||||
ft_putstr_fd("minishell: exit ", 2);
|
ft_putstr_fd("bozoshell: bozo_exit ", 2);
|
||||||
if (problem != NULL)
|
if (problem != NULL)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(problem, 2);
|
ft_putstr_fd(problem, 2);
|
||||||
@ -24,24 +24,20 @@ static int error(int err, char *reason, char *problem)
|
|||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_exit(char **args)
|
int ft_exit(char **args, int err)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
|
|
||||||
if (args[0] == NULL)
|
if (args[0] == NULL)
|
||||||
return (0);
|
{
|
||||||
|
write(1, "bozo_exit\n", 10);
|
||||||
|
return (err);
|
||||||
|
}
|
||||||
err = ft_atoi_check(args[0]);
|
err = ft_atoi_check(args[0]);
|
||||||
if (err == 1)
|
if (err == 1)
|
||||||
return (error(err, "numeric argument required", args[0]));
|
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
|
||||||
if (args[1] != NULL)
|
if (args[1] != NULL)
|
||||||
return (error(-1, "too many arguments", NULL));
|
return (error(-1, "bozo_exit: too many arguments\n", NULL));
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
return(error(err, "numeric argument required", args[0]));
|
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
|
||||||
|
write(1, "exit\n", 6);
|
||||||
return ((ft_atoi(args[0]) % 256 + 256) % 256);
|
return ((ft_atoi(args[0]) % 256 + 256) % 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
(void)argc;
|
|
||||||
return(ft_exit(argv + 1, 1));
|
|
||||||
}*/
|
|
||||||
|
@ -6,17 +6,21 @@
|
|||||||
/* 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/02/28 14:37:38 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/14 19:12:10 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
static int error(char *str, int fd)
|
static int error(char *str, char *to_free1, char *to_free2)
|
||||||
{
|
{
|
||||||
write(fd, "bash: export: `", 15);
|
write(2, "bozoshell: export: `", 20);
|
||||||
write(fd, str, ft_strlen(str));
|
write(2, str, ft_strlen(str));
|
||||||
write(fd, "': not a valid identifier\n", 26);
|
write(2, "': not a valid identifier\n", 26);
|
||||||
|
if (to_free1 != NULL)
|
||||||
|
free(to_free1);
|
||||||
|
if (to_free2 != NULL)
|
||||||
|
free(to_free2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,46 +30,72 @@ 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);
|
||||||
|
if (((t_env *)(current->content))->value != NULL)
|
||||||
|
{
|
||||||
ft_putstr_fd("=", fd);
|
ft_putstr_fd("=", fd);
|
||||||
write(fd, "\"", 1);
|
write(fd, "\"", 1);
|
||||||
ft_putstr_fd(((t_env *)(current->content))->value, fd);
|
ft_putstr_fd(((t_env *)(current->content))->value, fd);
|
||||||
write(fd, "\"\n", 2);
|
write(fd, "\"\n", 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
write(fd, "\n", 2);
|
||||||
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_export(t_list **env, char *args, int fd, int *err)
|
int set_key_value_export(t_list **env, char *args, char **key, char **value)
|
||||||
|
{
|
||||||
|
*key = ft_strndup(args, ft_strnchr(args, '='));
|
||||||
|
if (*key == NULL)
|
||||||
|
return (1);
|
||||||
|
if (ft_strlen(*key) == 0)
|
||||||
|
return (1);
|
||||||
|
if (possible_key(*key) == 2)
|
||||||
|
{
|
||||||
|
(*key)[ft_strlen(*key) - 1] = '\0';
|
||||||
|
if (get_value_by_key(*key, env) == NULL)
|
||||||
|
*value = ft_strdup(ft_strchr(args, '=') + 1);
|
||||||
|
else
|
||||||
|
*value = ft_strjoin(get_value_by_key(*key, env),
|
||||||
|
ft_strchr(args, '=') + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*value = ft_strdup(ft_strchr(args, '=') + 1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_export(t_list **env, char *args)
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
key = args;
|
|
||||||
value = "";
|
|
||||||
if (ft_strchr(args, '=') != NULL)
|
if (ft_strchr(args, '=') != NULL)
|
||||||
{
|
{
|
||||||
key = ft_strndup(args, ft_strnchr(args, '='));
|
if (set_key_value_export(env, args, &key, &value))
|
||||||
if (key == NULL)
|
return (error(args, key, NULL));
|
||||||
return (1);
|
|
||||||
if (ft_strlen(key) == 0)
|
|
||||||
{
|
|
||||||
error(args, fd);
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
value = ft_strchr(args, '=') + 1;
|
else
|
||||||
|
{
|
||||||
|
key = ft_strdup(args);
|
||||||
|
value = get_value_by_key(key, env);
|
||||||
|
if (value != NULL)
|
||||||
|
value = ft_strdup(value);
|
||||||
|
if (possible_key(key) == 2)
|
||||||
|
return (error(key, key, value));
|
||||||
}
|
}
|
||||||
if (!possible_key(key))
|
if (!possible_key(key))
|
||||||
{
|
return (error(args, key, value));
|
||||||
*err = error(key, fd);
|
create_value_by_key(key, value, env);
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
create_value_by_key_dup(key, value, env);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int export(t_list **env, char **args, int fd)
|
int ft_export(t_list **env, char **args, int fd)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int i;
|
int i;
|
||||||
@ -77,18 +107,8 @@ int export(t_list **env, char **args, int fd)
|
|||||||
{
|
{
|
||||||
i = -1;
|
i = -1;
|
||||||
while (args[++i])
|
while (args[++i])
|
||||||
if (add_export(env, args[i], fd, &err) == 1)
|
if (add_export(env, args[i]) == 1)
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
int main(int argc, char *argv[], char **env)
|
|
||||||
{
|
|
||||||
t_list **n_env;
|
|
||||||
|
|
||||||
(void)argc;
|
|
||||||
n_env = init_env(env);
|
|
||||||
export(n_env, argv + 1, 1);
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
/* 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/02/21 15:11:38 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int pwd(int fd)
|
int pwd(int fd)
|
||||||
{
|
{
|
||||||
@ -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,17 +6,17 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
|
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/07 12:46:28 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int error(char *str, int fd)
|
int error(char *str, int fd)
|
||||||
{
|
{
|
||||||
write(fd, "bash: unset: `", 14);
|
write(fd, "bozoshell: unset: `", 19);
|
||||||
write(fd, str, ft_strlen(str));
|
write(fd, str, ft_strlen(str));
|
||||||
write(fd, "': not a valid identifier", 25);
|
write(fd, "': not a valid identifier\n", 26);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
55
cmd.c
55
cmd.c
@ -1,55 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* cmd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
void ft_cmddel(void *ptr)
|
|
||||||
{
|
|
||||||
t_cmd *content;
|
|
||||||
|
|
||||||
content = (t_cmd *) ptr;
|
|
||||||
if (content->args != NULL)
|
|
||||||
ft_freer_tab_ultimate(1, content->args);
|
|
||||||
if (content->executable != NULL)
|
|
||||||
free(content->executable);
|
|
||||||
if (content->fd_in > 2)
|
|
||||||
close(content->fd_out);
|
|
||||||
if (content->fd_in > 2)
|
|
||||||
close(content->fd_out);
|
|
||||||
free(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_cmd_filler(t_data *data, t_list *element, char **args)
|
|
||||||
{
|
|
||||||
t_cmd *content;
|
|
||||||
char *temp;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (args == NULL)
|
|
||||||
return (1);
|
|
||||||
content = (t_cmd *)element->content;
|
|
||||||
i = 0;
|
|
||||||
while (args[i] != NULL)
|
|
||||||
{
|
|
||||||
temp = ft_env_filler(data, args[i]);
|
|
||||||
if (temp == NULL)
|
|
||||||
return (1);
|
|
||||||
free(args[i]);
|
|
||||||
args[i] = temp;
|
|
||||||
ft_quote_remover(temp);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
content->args = args;
|
|
||||||
content->executable = args[0];
|
|
||||||
return (0);
|
|
||||||
}
|
|
73
cmd/cmd.c
Normal file
73
cmd/cmd.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
t_cmd *content;
|
||||||
|
|
||||||
|
content = (t_cmd *) ptr;
|
||||||
|
if (content->args != NULL)
|
||||||
|
ft_freer_tab_ultimate(1, content->args);
|
||||||
|
if (content->own_cmd == false && content->executable != NULL)
|
||||||
|
free(content->executable);
|
||||||
|
if (content->fd_in[0] > 2)
|
||||||
|
close(content->fd_in[0]);
|
||||||
|
if (content->fd_out[0] > 2)
|
||||||
|
close(content->fd_out[0]);
|
||||||
|
if (content->fd_in[1] > 2)
|
||||||
|
close(content->fd_in[1]);
|
||||||
|
if (content->fd_out[1] > 2)
|
||||||
|
close(content->fd_out[1]);
|
||||||
|
free(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_cmdcloser(void *ptr)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
|
||||||
|
cmd = ptr;
|
||||||
|
ft_closer(cmd->fd_in);
|
||||||
|
ft_closer(cmd->fd_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_cmdwaiter(void *ptr)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
int exit_status;
|
||||||
|
|
||||||
|
cmd = ptr;
|
||||||
|
if (cmd->executable != NULL && cmd->own_cmd == 0
|
||||||
|
&& cmd->pid != -1 && cmd->fd_in[0] != -2 && cmd->fd_out[0] != -2)
|
||||||
|
{
|
||||||
|
waitpid(cmd->pid, &exit_status, 0);
|
||||||
|
if (WIFSIGNALED(exit_status))
|
||||||
|
{
|
||||||
|
if (exit_status == 131)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
32
cmd/cmd.h
Normal file
32
cmd/cmd.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/07 15:03:53 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CMD_H
|
||||||
|
# define CMD_H
|
||||||
|
# include <stdbool.h>
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
typedef struct s_cmd
|
||||||
|
{
|
||||||
|
int fd_in[2];
|
||||||
|
int fd_out[2];
|
||||||
|
int pid;
|
||||||
|
char *executable;
|
||||||
|
char **args;
|
||||||
|
bool own_cmd;
|
||||||
|
} t_cmd;
|
||||||
|
|
||||||
|
void ft_cmddel(void *content);
|
||||||
|
void ft_cmdwaiter(void *content);
|
||||||
|
void ft_cmdcloser(void *ptr);
|
||||||
|
|
||||||
|
#endif
|
21
cmd/cmd_private.h
Normal file
21
cmd/cmd_private.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/31 16:33:24 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CMD_PRIVATE_H
|
||||||
|
# define CMD_PRIVATE_H
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/wait.h>
|
||||||
|
# include "./cmd.h"
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
#endif
|
114
cmds.c
114
cmds.c
@ -1,114 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* cmds.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 14:17:26 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/17 15:20:29 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
static int ft_cmds_init(t_list **cmds, size_t len)
|
|
||||||
{
|
|
||||||
t_cmd *content;
|
|
||||||
t_list *current;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
*cmds = NULL;
|
|
||||||
if (len > 0)
|
|
||||||
*cmds = malloc(sizeof(t_list));
|
|
||||||
current = *cmds;
|
|
||||||
i = 0;
|
|
||||||
while (i < len)
|
|
||||||
{
|
|
||||||
content = malloc(sizeof(t_cmd));
|
|
||||||
if (content == NULL)
|
|
||||||
{
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
content->args = NULL;
|
|
||||||
content->executable = NULL;
|
|
||||||
content->fd_in = -1;
|
|
||||||
content->fd_out = -1;
|
|
||||||
current->content = content;
|
|
||||||
if (!((i + 1) < len))
|
|
||||||
{
|
|
||||||
current->next = NULL;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
current->next = malloc(sizeof(t_list));
|
|
||||||
if (current->next == NULL)
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
current = current->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile)
|
|
||||||
{
|
|
||||||
t_cmd *cmd;
|
|
||||||
t_list *current;
|
|
||||||
|
|
||||||
if (ft_cmds_init(cmds, ft_seglen_quoted(line, '|')))
|
|
||||||
{
|
|
||||||
free(cmds);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (*cmds == NULL)
|
|
||||||
return (0);
|
|
||||||
current = *cmds;
|
|
||||||
cmd = current->content;
|
|
||||||
cmd->fd_in = infile;
|
|
||||||
while (current->next != NULL)
|
|
||||||
current = current->next;
|
|
||||||
cmd = current->content;
|
|
||||||
cmd->fd_out = outfile;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_cmds_fill(t_data *data, t_list **cmds, const char *line)
|
|
||||||
{
|
|
||||||
char **tab;
|
|
||||||
char **args;
|
|
||||||
t_list *current;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, '|');
|
|
||||||
if (tab == NULL)
|
|
||||||
return (1);
|
|
||||||
i = 0;
|
|
||||||
current = *cmds;
|
|
||||||
while (tab[i] != NULL)
|
|
||||||
{
|
|
||||||
args = ft_split_quoted(tab[i], ' ');
|
|
||||||
if (ft_cmd_filler(data, current, args) == 1)
|
|
||||||
{
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
ft_freer_tab_ultimate(2, args, tab);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
current = current->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_list **ft_parse_cmds(t_data *data, char *line, int infile, int outfile)
|
|
||||||
{
|
|
||||||
t_list **cmds;
|
|
||||||
|
|
||||||
cmds = malloc(sizeof(t_list *));
|
|
||||||
if (ft_cmds_prep(cmds, line, infile, outfile) == 1)
|
|
||||||
return (NULL);
|
|
||||||
if (ft_cmds_fill(data, cmds, line) == 1)
|
|
||||||
return (NULL);
|
|
||||||
return (cmds);
|
|
||||||
}
|
|
21
data/data.c
Normal file
21
data/data.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* data.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/05 14:48:30 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "./data_private.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
int *ft_get_exit_code(void)
|
||||||
|
{
|
||||||
|
static int exit_code;
|
||||||
|
|
||||||
|
return (&exit_code);
|
||||||
|
}
|
26
data/data.h
Normal file
26
data/data.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* data.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/05 14:45:23 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef DATA_H
|
||||||
|
# define DATA_H
|
||||||
|
# include "../libftx/libft/list.h"
|
||||||
|
|
||||||
|
typedef struct s_data
|
||||||
|
{
|
||||||
|
t_list **env;
|
||||||
|
t_list **cmds;
|
||||||
|
int *exit_code;
|
||||||
|
} t_data;
|
||||||
|
|
||||||
|
int *ft_get_exit_code(void);
|
||||||
|
|
||||||
|
#endif
|
18
data/data_private.h
Normal file
18
data/data_private.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define DATA_PRIVATE_H
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "./data.h"
|
||||||
|
|
||||||
|
#endif
|
37
env/env.h
vendored
Normal file
37
env/env.h
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define ENV_H
|
||||||
|
# include <stdbool.h>
|
||||||
|
# include "../libftx/libft/list.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
typedef struct s_env
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *value;
|
||||||
|
} t_env;
|
||||||
|
|
||||||
|
char *ft_env_filler(t_data *data, const char *str);
|
||||||
|
void env_del(void *content);
|
||||||
|
t_list **init_env(char **env);
|
||||||
|
char **env_to_strs(t_list **head);
|
||||||
|
int create_value_by_key(char *key, char *value, t_list **head);
|
||||||
|
int create_value_by_key_dup(char *key, char *value, t_list **head);
|
||||||
|
int set_value_by_key(char *key, char *value, t_list **head);
|
||||||
|
char *get_value_by_key(char *key, t_list **head);
|
||||||
|
void env_del(void *ptr);
|
||||||
|
int delete_by_key(char *key, t_list **head);
|
||||||
|
int possible_key(char *key);
|
||||||
|
|
||||||
|
#endif
|
29
env.c → env/env1.c
vendored
29
env.c → env/env1.c
vendored
@ -1,16 +1,16 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* env.c :+: :+: :+: */
|
/* env1.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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/02/23 13:34:41 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:57:38 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "env_private.h"
|
||||||
|
|
||||||
void add_sort(t_list **head, t_env *var)
|
void add_sort(t_list **head, t_env *var)
|
||||||
{
|
{
|
||||||
@ -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)
|
||||||
@ -48,7 +52,7 @@ char *get_value_by_key(char *key, t_list **head)
|
|||||||
return (((t_env *)current->content)->value);
|
return (((t_env *)current->content)->value);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
return ("");
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_value_by_key(char *key, char *value, t_list **head)
|
int set_value_by_key(char *key, char *value, t_list **head)
|
||||||
@ -74,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);
|
||||||
@ -95,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])
|
||||||
{
|
{
|
||||||
@ -108,14 +118,3 @@ t_list **init_env(char **env)
|
|||||||
}
|
}
|
||||||
return (head);
|
return (head);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[], char **env)
|
|
||||||
{
|
|
||||||
t_list **n_env;
|
|
||||||
|
|
||||||
n_env = init_env(env);
|
|
||||||
delete_by_key("SSH_AUTH_SOCK", n_env);
|
|
||||||
print_env(n_env, 1);
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
8
env2.c → env/env2.c
vendored
8
env2.c → env/env2.c
vendored
@ -1,16 +1,16 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* env2.c :+: :+: :+: */
|
/* env2.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 17:22:01 by erey-bet #+# #+# */
|
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/17 17:24:57 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:26:31 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "env_private.h"
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int get_index(char *s, char c)
|
int get_index(char *s, char c)
|
||||||
{
|
{
|
29
env3.c → env/env3.c
vendored
29
env3.c → env/env3.c
vendored
@ -6,12 +6,11 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/28 12:46:33 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/07 13:21:54 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "env_private.h"
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
char *get_value(char *str)
|
char *get_value(char *str)
|
||||||
{
|
{
|
||||||
@ -44,19 +43,22 @@ int create_value_by_key_dup(char *key, char *value, t_list **env)
|
|||||||
char *key_dup;
|
char *key_dup;
|
||||||
char *value_dup;
|
char *value_dup;
|
||||||
|
|
||||||
|
if (set_value_by_key(key, value, env) == 0)
|
||||||
|
return (0);
|
||||||
key_dup = ft_strdup(key);
|
key_dup = ft_strdup(key);
|
||||||
if (key_dup == NULL)
|
if (key_dup == NULL)
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
if (value != NULL)
|
||||||
|
{
|
||||||
value_dup = ft_strdup(value);
|
value_dup = ft_strdup(value);
|
||||||
if (value_dup == NULL)
|
if (value_dup == NULL)
|
||||||
{
|
{
|
||||||
free(key);
|
free(key);
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
value_dup = value;
|
||||||
if (create_value_by_key(key_dup, value_dup, env))
|
if (create_value_by_key(key_dup, value_dup, env))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
@ -68,14 +70,19 @@ int delete_by_key(char *key, t_list **head)
|
|||||||
t_list *current;
|
t_list *current;
|
||||||
|
|
||||||
current = *head;
|
current = *head;
|
||||||
|
last = NULL;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
||||||
{
|
{
|
||||||
if (last->next != NULL)
|
free(((t_env *)current->content)->key);
|
||||||
|
free(((t_env *)current->content)->value);
|
||||||
|
free(current->content);
|
||||||
|
if (last && last->next)
|
||||||
last->next = current->next;
|
last->next = current->next;
|
||||||
else
|
else
|
||||||
*head = current->next;
|
*head = current->next;
|
||||||
|
free(current);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
last = current;
|
last = current;
|
||||||
@ -91,8 +98,12 @@ int possible_key(char *key)
|
|||||||
i = -1;
|
i = -1;
|
||||||
if (ft_isdigit(key[i + 1]))
|
if (ft_isdigit(key[i + 1]))
|
||||||
return (0);
|
return (0);
|
||||||
while (key[++i])
|
while (key[++i + 1])
|
||||||
if (!ft_isalnum(key[i]) && key[i] != '_')
|
if (!ft_isalnum(key[i]) && key[i] != '_')
|
||||||
return (0);
|
return (0);
|
||||||
|
if (key[i] == '+')
|
||||||
|
return (2);
|
||||||
|
else if (!ft_isalnum(key[i]) && key[i] != '_')
|
||||||
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
130
env_fill.c → env/env_fill.c
vendored
130
env_fill.c → env/env_fill.c
vendored
@ -6,91 +6,97 @@
|
|||||||
/* 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/04/05 15:09:46 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "./env_private.h"
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int ft_gen_exit_code_var(t_data *data)
|
static char *ft_getkey(const char *str)
|
||||||
{
|
{
|
||||||
char *str;
|
size_t i;
|
||||||
|
char *key;
|
||||||
|
|
||||||
str = ft_itoa(data->exit_code);
|
if (ft_strncmp(str, "$$", 2) == 0)
|
||||||
if (str == NULL)
|
key = ft_strdup("$");
|
||||||
|
else if (ft_strncmp(str, "$?", 2) == 0)
|
||||||
|
key = ft_strdup("?");
|
||||||
|
else if (str[1] == '\0')
|
||||||
|
key = ft_strdup("");
|
||||||
|
else
|
||||||
{
|
{
|
||||||
ft_printf("minishell: malloc failed");
|
i = 1;
|
||||||
return (1);
|
while (str[i] != '\0' && !ft_is_in("$?\'\" ", str[i]))
|
||||||
|
i++;
|
||||||
|
key = ft_strndup(str + 1, i - 1);
|
||||||
}
|
}
|
||||||
data->exit_code_str = str;
|
if (key == NULL)
|
||||||
return (0);
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *ft_get_value(t_data *data, char *key)
|
static char *ft_getvalue(t_data *data, char *key)
|
||||||
{
|
{
|
||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
if (key[0] == '\0')
|
if (ft_strcmp(key, "?") == 0)
|
||||||
return ("$");
|
value = ft_itoa(*data->exit_code);
|
||||||
if (ft_strcmp("?", key) == 0)
|
else if (ft_strcmp(key, "$") == 0)
|
||||||
return (data->exit_code_str);
|
value = ft_strdup("PID");
|
||||||
|
else if (key[0] == '\0')
|
||||||
|
value = ft_strdup("$");
|
||||||
|
else
|
||||||
|
{
|
||||||
value = get_value_by_key(key, data->env);
|
value = get_value_by_key(key, data->env);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
value = "";
|
value = ft_strdup("");
|
||||||
|
else
|
||||||
|
value = ft_strdup(value);
|
||||||
|
}
|
||||||
|
if (value == NULL)
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (value);
|
return (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *ft_get_key(char *str)
|
static char *ft_getvalue_by_str(t_data *data, const char *str,
|
||||||
|
size_t *key_len)
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
size_t i;
|
char *value;
|
||||||
|
|
||||||
i = 1;
|
key = ft_getkey(str);
|
||||||
if (ft_strncmp(str, "$$", 2) == 0)
|
|
||||||
{
|
|
||||||
key = ft_strdup("$");
|
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
return (NULL);
|
||||||
return (key);
|
*key_len = ft_strlen(key) + 1;
|
||||||
|
value = ft_getvalue(data, key);
|
||||||
|
free(key);
|
||||||
|
return (value);
|
||||||
}
|
}
|
||||||
if (str[i] == ' ' || str[i] == '\0')
|
|
||||||
|
char *ft_str_formator(t_data *data, char *str, size_t *i)
|
||||||
{
|
{
|
||||||
key = ft_strdup("");
|
char *value;
|
||||||
if (key == NULL)
|
size_t key_len;
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
char *out;
|
||||||
return (key);
|
|
||||||
}
|
value = ft_getvalue_by_str(data, str + *i, &key_len);
|
||||||
if (str[i] == '?')
|
if (value == NULL)
|
||||||
{
|
return (NULL);
|
||||||
key = ft_strdup("?");
|
out = ft_strreplace(str, value, *i, key_len + *i);
|
||||||
if (key == NULL)
|
*i = *i + ft_strlen(value);
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
free(value);
|
||||||
return (key);
|
return (out);
|
||||||
}
|
|
||||||
while (str[i] != '\0' && str[i] != '$' && str[i] != ' '
|
|
||||||
&& str[i] != '"')
|
|
||||||
i++;
|
|
||||||
key = ft_strndup(str + 1, i - 1);
|
|
||||||
if (key == NULL)
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_env_filler(t_data *data, const char *str)
|
char *ft_env_filler(t_data *data, const char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
char *key;
|
|
||||||
char *out;
|
char *out;
|
||||||
char *temp;
|
char *temp;
|
||||||
char *value;
|
size_t i;
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (out[i] != '\0')
|
while (out[i] != '\0')
|
||||||
{
|
{
|
||||||
@ -98,28 +104,10 @@ char *ft_env_filler(t_data *data, const char *str)
|
|||||||
i++;
|
i++;
|
||||||
while (out[i] == '$')
|
while (out[i] == '$')
|
||||||
{
|
{
|
||||||
key = ft_get_key(out + i);
|
temp = ft_str_formator(data, out, &i);
|
||||||
if (key == NULL)
|
|
||||||
{
|
|
||||||
free(out);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
value = ft_get_value(data, key);
|
|
||||||
if (value == NULL)
|
|
||||||
{
|
|
||||||
free(key);
|
|
||||||
free(out);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
temp = ft_strreplace(out, value, i, ft_strlen(key) + 1 + i);
|
|
||||||
free(key);
|
|
||||||
i = i + ft_strlen(value);
|
|
||||||
free(out);
|
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
free(out);
|
||||||
out = temp;
|
out = temp;
|
||||||
}
|
}
|
||||||
if (out[i] != '\0')
|
if (out[i] != '\0')
|
26
env/env_private.h
vendored
Normal file
26
env/env_private.h
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define ENV_PRIVATE_H
|
||||||
|
# include "./env.h"
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
|
void swap_env_3(void **a, void **b, void **c);
|
||||||
|
void swap_env(void **a, void **b);
|
||||||
|
char *get_value(char *str);
|
||||||
|
char *get_key(char *str);
|
||||||
|
int get_index(char *str, char c);
|
||||||
|
char *ft_env_filler(t_data *data, const char *str);
|
||||||
|
|
||||||
|
#endif
|
175
execution.c
175
execution.c
@ -1,175 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* execution.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/28 14:56:05 by erey-bet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
static char *ft_get_executable_path(t_data *data, char *executable_name)
|
|
||||||
{
|
|
||||||
char *path;
|
|
||||||
char *temp;
|
|
||||||
char **tab;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (executable_name == NULL)
|
|
||||||
return (NULL);
|
|
||||||
path = NULL;
|
|
||||||
if (executable_name[0] == '.' || executable_name[0] == '/')
|
|
||||||
{
|
|
||||||
path = ft_strdup(executable_name);
|
|
||||||
if (path == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
if (access(path, X_OK) == 0)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: %s: permission denied\n", path);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tab = ft_split(get_value_by_key("PATH", data->env), ':');
|
|
||||||
if (tab == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (tab[i] != NULL)
|
|
||||||
{
|
|
||||||
temp = ft_strmerger(3, tab[i], "/", executable_name);
|
|
||||||
if (temp == NULL)
|
|
||||||
{
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
free(executable_name);
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
}
|
|
||||||
if (access(temp, X_OK) == 0)
|
|
||||||
{
|
|
||||||
path = temp;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
free(temp);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (path == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("%s: command not found\n", executable_name);
|
|
||||||
data->exit_code = 127;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
}
|
|
||||||
return (path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_executor(t_data *data, t_cmd *cmd)
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
int return_value;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
if (cmd->fd_in == -1 || cmd->fd_out == -1)
|
|
||||||
return (1);
|
|
||||||
pid = fork();
|
|
||||||
if (pid == -1)
|
|
||||||
return (1);
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
tab = env_to_strs(data->env);
|
|
||||||
if (tab == NULL)
|
|
||||||
return (1);
|
|
||||||
dup2(cmd->fd_out, 1);
|
|
||||||
dup2(cmd->fd_in, 0);
|
|
||||||
execve(cmd->executable, cmd->args, tab);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
waitpid(pid, &return_value, 0);
|
|
||||||
data->exit_code = return_value;
|
|
||||||
return (return_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
|
||||||
{
|
|
||||||
int return_code;
|
|
||||||
int exit_code;
|
|
||||||
|
|
||||||
return_code = -1;
|
|
||||||
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
|
||||||
return_code = pwd(cmd->fd_out);
|
|
||||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
|
||||||
return_code = print_env(data->env, cmd->fd_out);
|
|
||||||
else if (ft_strcmp(cmd->executable, "export") == 0)
|
|
||||||
return_code = (export(data->env,cmd->args + 1, cmd->fd_out));
|
|
||||||
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
|
||||||
return_code = (move_folder(cmd->args + 1, cmd->fd_out));
|
|
||||||
if (ft_strcmp(cmd->executable, "unset") == 0)
|
|
||||||
return_code = (unset(data->env, cmd->args, cmd->fd_out));
|
|
||||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
|
||||||
return_code = (echo(cmd->fd_out, cmd->args + 1));
|
|
||||||
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
|
||||||
{
|
|
||||||
exit_code = ft_exit(cmd->args + 1);
|
|
||||||
if (exit_code != -1)
|
|
||||||
{
|
|
||||||
data->exit_code = exit_code;
|
|
||||||
return_code = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (return_code != -1)
|
|
||||||
{
|
|
||||||
cmd->executable = NULL;
|
|
||||||
data->exit_code = return_code;
|
|
||||||
}
|
|
||||||
return (return_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_cmds_executor(t_data *data, t_list **cmds)
|
|
||||||
{
|
|
||||||
t_cmd *content;
|
|
||||||
t_list *current;
|
|
||||||
int exit_code;
|
|
||||||
int fds[2];
|
|
||||||
|
|
||||||
current = *cmds;
|
|
||||||
while (current != NULL)
|
|
||||||
{
|
|
||||||
content = current->content;
|
|
||||||
if (current->next != NULL)
|
|
||||||
{
|
|
||||||
if (pipe(fds) == -1)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: pipe failed\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
content->fd_out = fds[1];
|
|
||||||
((t_cmd *) current->next->content)->fd_in = fds[0];
|
|
||||||
}
|
|
||||||
exit_code = ft_own_cmd(data, content);
|
|
||||||
if (exit_code == -1)
|
|
||||||
{
|
|
||||||
content->executable = ft_get_executable_path(data,
|
|
||||||
content->executable);
|
|
||||||
if (content->executable != NULL)
|
|
||||||
exit_code = ft_executor(data, content);
|
|
||||||
}
|
|
||||||
else if (exit_code == -2)
|
|
||||||
return (1);
|
|
||||||
if (ft_gen_exit_code_var(data))
|
|
||||||
return (1);
|
|
||||||
if (content->fd_in > 2)
|
|
||||||
close(content->fd_in);
|
|
||||||
if (content->fd_out > 2)
|
|
||||||
close(content->fd_out);
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
119
execution/execution.c
Normal file
119
execution/execution.c
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/18 13:00:08 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "execution_private.h"
|
||||||
|
|
||||||
|
static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
int return_code;
|
||||||
|
|
||||||
|
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
||||||
|
return_code = pwd(cmd->fd_out[0]);
|
||||||
|
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||||
|
return_code = print_env(data->env, cmd->fd_out[0]);
|
||||||
|
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, 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)
|
||||||
|
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return_code = ft_exit(cmd->args + 1, *data->exit_code);
|
||||||
|
if (return_code >= 0)
|
||||||
|
{
|
||||||
|
*data->exit_code = return_code;
|
||||||
|
return (-2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*data->exit_code = return_code;
|
||||||
|
return (return_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ft_executor(t_data *data, t_cmd *cmd, char **env)
|
||||||
|
{
|
||||||
|
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
|
||||||
|
return (0);
|
||||||
|
cmd->pid = fork();
|
||||||
|
if (cmd->pid == -1)
|
||||||
|
return (1);
|
||||||
|
if (cmd->pid == 0)
|
||||||
|
{
|
||||||
|
signal(SIGQUIT, SIG_DFL);
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
dup2(cmd->fd_in[0], 0);
|
||||||
|
dup2(cmd->fd_out[0], 1);
|
||||||
|
ft_lstiter(*data->cmds, ft_cmdcloser);
|
||||||
|
execve(cmd->executable, cmd->args, env);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
signal(SIGINT, SIG_IGN);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_cmd_executor(t_data *data, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
int exit_code;
|
||||||
|
char **env;
|
||||||
|
|
||||||
|
if (cmd->own_cmd == 1)
|
||||||
|
{
|
||||||
|
exit_code = ft_execute_own_cmd(data, cmd);
|
||||||
|
ft_closer(cmd->fd_in);
|
||||||
|
ft_closer(cmd->fd_out);
|
||||||
|
if (exit_code == -2)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
env = env_to_strs(data->env);
|
||||||
|
if (env == NULL)
|
||||||
|
return (1);
|
||||||
|
exit_code = ft_executor(data, cmd, env);
|
||||||
|
ft_closer(cmd->fd_in);
|
||||||
|
ft_closer(cmd->fd_out);
|
||||||
|
ft_freer_tab_ultimate(1, env);
|
||||||
|
if (exit_code == 1)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_cmds_executor(t_data *data)
|
||||||
|
{
|
||||||
|
int fds[2];
|
||||||
|
t_list *current;
|
||||||
|
t_cmd *content;
|
||||||
|
|
||||||
|
current = *data->cmds;
|
||||||
|
while (current != NULL)
|
||||||
|
{
|
||||||
|
content = current->content;
|
||||||
|
fds[0] = -1;
|
||||||
|
if (current->next != NULL)
|
||||||
|
{
|
||||||
|
if (pipe(fds) == -1)
|
||||||
|
return (1);
|
||||||
|
ft_add_fd(content->fd_out, fds[1]);
|
||||||
|
ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]);
|
||||||
|
}
|
||||||
|
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
|
||||||
|
ft_mega_closer(content->fd_in, content->fd_out);
|
||||||
|
else if (ft_cmd_executor(data, content))
|
||||||
|
return (1);
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
19
execution/execution.h
Normal file
19
execution/execution.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define EXECUTION_H
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
int ft_cmds_executor(t_data *data);
|
||||||
|
|
||||||
|
#endif
|
24
execution/execution_private.h
Normal file
24
execution/execution_private.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/05 15:15:56 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef EXECUTION_PRIVATE_H
|
||||||
|
# define EXECUTION_PRIVATE_H
|
||||||
|
# include <signal.h>
|
||||||
|
# include "../signal/signal.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../cmd/cmd.h"
|
||||||
|
# include "../env/env.h"
|
||||||
|
# include "../builtins/builtins.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
|
#endif
|
@ -1,23 +1,35 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* spacer.c :+: :+: :+: */
|
/* format.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/16 16:26:15 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/31 15:22:21 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "./format_private.h"
|
||||||
#include "minishell.h"
|
|
||||||
#include "utils/utils.h"
|
static int ft_replace(char **str, size_t i)
|
||||||
|
{
|
||||||
|
char *temp;
|
||||||
|
|
||||||
|
temp = ft_strreplace(*str, " ", i, i);
|
||||||
|
free(*str);
|
||||||
|
if (temp == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
*str = temp;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
static char *ft_spacer_after(const char *str)
|
static char *ft_spacer_after(const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
char *temp;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
@ -26,18 +38,18 @@ static char *ft_spacer_after(const char *str)
|
|||||||
i = 1;
|
i = 1;
|
||||||
while (out[i] != '\0')
|
while (out[i] != '\0')
|
||||||
{
|
{
|
||||||
while (ft_is_in_quote(out, i))
|
while (ft_is_in_quote(out, i - 1))
|
||||||
i++;
|
i++;
|
||||||
|
if (out[i - 1] == '\0' || out[i] == '\0')
|
||||||
|
break ;
|
||||||
if (ft_is_in("><|", out[i - 1]))
|
if (ft_is_in("><|", out[i - 1]))
|
||||||
{
|
{
|
||||||
while (out[i] == out[i - 1])
|
while (out[i] == out[i - 1])
|
||||||
i++;
|
i++;
|
||||||
temp = ft_strreplace(out, " ", i, i);
|
if (ft_replace(&out, i))
|
||||||
free(out);
|
|
||||||
out = temp;
|
|
||||||
if (out == NULL)
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
if (out[i] != '\0')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (out);
|
return (out);
|
||||||
@ -46,30 +58,27 @@ static char *ft_spacer_after(const char *str)
|
|||||||
static char *ft_spacer_before(const char *str)
|
static char *ft_spacer_before(const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
char *temp;
|
ssize_t i;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
out = ft_strdup(str);
|
out = ft_strdup(str);
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i = 0;
|
i = -1;
|
||||||
while (out[i + 1] != '\0')
|
while (out[++i] != '\0')
|
||||||
{
|
{
|
||||||
while (ft_is_in_quote(out, i))
|
while (ft_is_in_quote(out, i + 1))
|
||||||
i++;
|
i++;
|
||||||
|
if (out[i] == '\0')
|
||||||
|
break ;
|
||||||
if (ft_is_in("><|", out[i + 1]))
|
if (ft_is_in("><|", out[i + 1]))
|
||||||
{
|
{
|
||||||
while (out[i] == ' ')
|
while (out[i] == ' ')
|
||||||
i++;
|
i++;
|
||||||
while (out[i] == out[i + 1])
|
while (out[i] == out[i + 1])
|
||||||
i++;
|
i++;
|
||||||
temp = ft_strreplace(out, " ", i + 1, i + 1);
|
if (ft_replace(&out, i + 1))
|
||||||
free(out);
|
|
||||||
out = temp;
|
|
||||||
if (out == NULL)
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
@ -84,6 +93,8 @@ static void ft_space_simplifier(char *str)
|
|||||||
{
|
{
|
||||||
if (ft_is_in_quote(str, i))
|
if (ft_is_in_quote(str, i))
|
||||||
i++;
|
i++;
|
||||||
|
if (str[i] != '\0')
|
||||||
|
break ;
|
||||||
y = 0;
|
y = 0;
|
||||||
while (str[y + i] == ' ')
|
while (str[y + i] == ' ')
|
||||||
y++;
|
y++;
|
||||||
@ -96,7 +107,7 @@ static void ft_space_simplifier(char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_normalizer(char *str)
|
char *ft_formater(t_data *data, const char *str)
|
||||||
{
|
{
|
||||||
char *out;
|
char *out;
|
||||||
char *temp;
|
char *temp;
|
||||||
@ -113,5 +124,7 @@ char *ft_normalizer(char *str)
|
|||||||
ft_space_simplifier(out);
|
ft_space_simplifier(out);
|
||||||
if (out[ft_strlen(out) - 1] == ' ')
|
if (out[ft_strlen(out) - 1] == ' ')
|
||||||
out[ft_strlen(out) - 1] = '\0';
|
out[ft_strlen(out) - 1] = '\0';
|
||||||
return (out);
|
temp = ft_env_filler(data, out);
|
||||||
|
free(out);
|
||||||
|
return (temp);
|
||||||
}
|
}
|
19
format/format.h
Normal file
19
format/format.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define FORMAT_H
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
char *ft_formater(t_data *data, const char *str);
|
||||||
|
|
||||||
|
#endif
|
18
format/format_private.h
Normal file
18
format/format_private.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define FORMAT_PRIVATE_H
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
|
#endif
|
66
heredoc.c
66
heredoc.c
@ -1,66 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* heredoc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/17 16:21:02 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int *ft_get_heredoc()
|
|
||||||
{
|
|
||||||
static int heredoc;
|
|
||||||
|
|
||||||
return (&heredoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_heredoc_creator(char *stop, int fd)
|
|
||||||
{
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
line = readline("> ");
|
|
||||||
while (line != NULL)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(line, stop) == 0)
|
|
||||||
break ;
|
|
||||||
ft_putendl_fd(line, fd);
|
|
||||||
free(line);
|
|
||||||
line = readline("> ");
|
|
||||||
if (line == NULL)
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_heredoc(char *stop)
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
int fds[2];
|
|
||||||
int exit_code;
|
|
||||||
|
|
||||||
if (pipe(fds) == -1)
|
|
||||||
return (-1);
|
|
||||||
pid = fork();
|
|
||||||
if (pid == -1)
|
|
||||||
return (-1);
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
exit_code = ft_heredoc_creator(stop, fds[1]);
|
|
||||||
exit (exit_code + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*ft_get_heredoc() = pid;
|
|
||||||
waitpid(pid, &exit_code, 0);
|
|
||||||
*ft_get_heredoc() = 0;
|
|
||||||
close(fds[1]);
|
|
||||||
return (fds[0]);
|
|
||||||
}
|
|
||||||
}
|
|
113
infile.c
113
infile.c
@ -1,113 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* infile.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 17:52:10 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 13:05:43 by starnakin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
#include "utils/utils.h"
|
|
||||||
|
|
||||||
static int ft_infile_is_valid(const char *line)
|
|
||||||
{
|
|
||||||
char **tab;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
if (tab[0] == NULL)
|
|
||||||
return (1);
|
|
||||||
i = 0;
|
|
||||||
while (tab[i + 1] != NULL)
|
|
||||||
i++;
|
|
||||||
if (tab[i][0] == '<')
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]);
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_get_infile(const char *line)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int fd;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (-2);
|
|
||||||
}
|
|
||||||
fd = 0;
|
|
||||||
i = 0;
|
|
||||||
while (tab[i + 1] != NULL)
|
|
||||||
{
|
|
||||||
if (tab[i][0] == '<')
|
|
||||||
if (fd != 0)
|
|
||||||
close(fd);
|
|
||||||
if (ft_strcmp("<", tab[i]) == 0)
|
|
||||||
fd = ft_file_is_readable(ft_quote_remover(tab[i + 1]));
|
|
||||||
else if (ft_strcmp("<<", tab[i]) == 0)
|
|
||||||
fd = ft_heredoc(tab[i + 1]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_remove_infile(char *line)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t y;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
y = 0;
|
|
||||||
while (tab[i] != NULL)
|
|
||||||
{
|
|
||||||
if (tab[i][0] == '<')
|
|
||||||
ft_strshift(line + y,
|
|
||||||
(-1) * (ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1 + (line[ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1] != '\0')));
|
|
||||||
else
|
|
||||||
y = y + ft_strlen(tab[i]) + (y != 0);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_infile(t_data *data, char *line)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (ft_infile_is_valid(line) == 0)
|
|
||||||
{
|
|
||||||
data->exit_code = 2;
|
|
||||||
return (-2);
|
|
||||||
}
|
|
||||||
fd = ft_get_infile(line);
|
|
||||||
if (fd == -2)
|
|
||||||
return (-2);
|
|
||||||
ft_remove_infile(line);
|
|
||||||
return (fd);
|
|
||||||
}
|
|
@ -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)
|
||||||
|
Binary file not shown.
@ -14,6 +14,7 @@
|
|||||||
# define LIBFT_H
|
# define LIBFT_H
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# include "./list.h"
|
||||||
|
|
||||||
void *ft_cancel(void **tab, size_t len);
|
void *ft_cancel(void **tab, size_t len);
|
||||||
int ft_atoi(const char *nptr);
|
int ft_atoi(const char *nptr);
|
||||||
@ -52,20 +53,4 @@ void ft_putstr_fd(char *s, int fd);
|
|||||||
void ft_putendl_fd(char *s, int fd);
|
void ft_putendl_fd(char *s, int fd);
|
||||||
void ft_putnbr_fd(int n, int fd);
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *nouveau);
|
|
||||||
int ft_lstsize(t_list *lst);
|
|
||||||
t_list *ft_lstlast(t_list *lst);
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *nouveau);
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
32
libftx/libft/list.h
Normal file
32
libftx/libft/list.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define LIST_H
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content);
|
||||||
|
void ft_lstadd_front(t_list **lst, t_list *nouveau);
|
||||||
|
int ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
void ft_lstadd_back(t_list **lst, t_list *nouveau);
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
|
|
||||||
|
#endif
|
@ -15,6 +15,7 @@
|
|||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
# include "./libft/libft.h"
|
||||||
|
|
||||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||||
int ft_printf(const char *format, ...);
|
int ft_printf(const char *format, ...);
|
||||||
@ -39,57 +40,41 @@ void ft_swap(void *a, void *b);
|
|||||||
void ft_swap_int(int *a, int *b);
|
void ft_swap_int(int *a, int *b);
|
||||||
void ft_swap_char(char *a, char *b);
|
void ft_swap_char(char *a, char *b);
|
||||||
|
|
||||||
void *ft_cancel(void **tab, size_t len);
|
/* void *ft_cancel(void **tab, size_t len); */
|
||||||
int ft_atoi(const char *nptr);
|
/* int ft_atoi(const char *nptr); */
|
||||||
void ft_bzero(void *s, size_t n);
|
/* void ft_bzero(void *s, size_t n); */
|
||||||
void *ft_calloc(size_t nmemb, size_t size);
|
/* void *ft_calloc(size_t nmemb, size_t size); */
|
||||||
int ft_isalnum(int c);
|
/* int ft_isalnum(int c); */
|
||||||
int ft_isalpha(int c);
|
/* int ft_isalpha(int c); */
|
||||||
int ft_isascii(int c);
|
/* int ft_isascii(int c); */
|
||||||
int ft_isdigit(int c);
|
/* int ft_isdigit(int c); */
|
||||||
int ft_isprint(int c);
|
/* int ft_isprint(int c); */
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
/* void *ft_memchr(const void *s, int c, size_t n); */
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
/* int ft_memcmp(const void *s1, const void *s2, size_t n); */
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
/* void *ft_memcpy(void *dest, const void *src, size_t n); */
|
||||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
/* void *ft_memmove(void *dest, const void *src, size_t n); */
|
||||||
void *ft_memset(void *s, int c, size_t n);
|
/* void *ft_memset(void *s, int c, size_t n); */
|
||||||
char *ft_strchr(const char *s, int c);
|
/* char *ft_strchr(const char *s, int c); */
|
||||||
char *ft_strdup(const char *s);
|
/* char *ft_strdup(const char *s); */
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
/* size_t ft_strlcat(char *dst, const char *src, size_t size); */
|
||||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
/* size_t ft_strlcpy(char *dst, const char *src, size_t size); */
|
||||||
size_t ft_strlen(const char *s);
|
/* size_t ft_strlen(const char *s); */
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
/* int ft_strncmp(const char *s1, const char *s2, size_t n); */
|
||||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
/* char *ft_strnstr(const char *big, const char *little, size_t len); */
|
||||||
char *ft_strrchr(const char *s, int c);
|
/* char *ft_strrchr(const char *s, int c); */
|
||||||
int ft_tolower(int c);
|
/* int ft_tolower(int c); */
|
||||||
int ft_toupper(int c);
|
/* int ft_toupper(int c); */
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
/* char *ft_substr(char const *s, unsigned int start, size_t len); */
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
/* char *ft_strjoin(char const *s1, char const *s2); */
|
||||||
char *ft_strtrim(char const *s1, char const *set);
|
/* char *ft_strtrim(char const *s1, char const *set); */
|
||||||
char **ft_split(char const *s, char c);
|
/* char **ft_split(char const *s, char c); */
|
||||||
char *ft_itoa(int n);
|
/* char *ft_itoa(int n); */
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
/* char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); */
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
/* void ft_striteri(char *s, void (*f)(unsigned int, char*)); */
|
||||||
void ft_putchar_fd(char c, int fd);
|
/* void ft_putchar_fd(char c, int fd); */
|
||||||
void ft_putstr_fd(char *s, int fd);
|
/* void ft_putstr_fd(char *s, int fd); */
|
||||||
void ft_putendl_fd(char *s, int fd);
|
/* void ft_putendl_fd(char *s, int fd); */
|
||||||
void ft_putnbr_fd(int n, int fd);
|
/* void ft_putnbr_fd(int n, int fd); */
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *nouveau);
|
|
||||||
int ft_lstsize(t_list *lst);
|
|
||||||
t_list *ft_lstlast(t_list *lst);
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *nouveau);
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Binary file not shown.
126
main.c
126
main.c
@ -6,118 +6,84 @@
|
|||||||
/* 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/02/24 11:04:40 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 12:59:43 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "data/data.h"
|
||||||
|
#include "env/env.h"
|
||||||
|
#include "libftx/libft/libft.h"
|
||||||
|
#include "libftx/libft/list.h"
|
||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "bozoshell.h"
|
||||||
#include <readline/readline.h>
|
#include "signal/signal.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static char *ft_get_user_input()
|
static char *ft_get_user_input(void)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
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);
|
||||||
if (line != NULL && ft_strcmp(line, "") != 0)
|
if (line != NULL && ft_strcmp(line, "") != 0)
|
||||||
add_history(line);
|
add_history(line);
|
||||||
free(prompt);
|
free(prompt);
|
||||||
|
if (line == NULL)
|
||||||
|
ft_printf("exit\n");
|
||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_minishell(t_data *data, char *line)
|
static int ft_minishell(t_data *data, char *line)
|
||||||
{
|
{
|
||||||
t_list **cmds;
|
|
||||||
char *line_clean;
|
char *line_clean;
|
||||||
int infile;
|
|
||||||
int outfile;
|
|
||||||
|
|
||||||
if (ft_syntatic_verif(data, line))
|
if (ft_syntax_verif(data, line))
|
||||||
return (1);
|
return (0);
|
||||||
line_clean = ft_normalizer(line);
|
line_clean = ft_formater(data, line);
|
||||||
if (line_clean == NULL)
|
if (line_clean == NULL || line_clean[0] == '\0')
|
||||||
return (1);
|
return (0);
|
||||||
outfile = ft_outfile(data, line_clean);
|
if (ft_cmds_parser(data, line_clean))
|
||||||
if (outfile == -2)
|
|
||||||
{
|
{
|
||||||
free(line_clean);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
infile = ft_infile(data, line_clean);
|
|
||||||
if (infile == -2)
|
|
||||||
{
|
|
||||||
if (outfile > 2)
|
|
||||||
close(outfile);
|
|
||||||
free(line_clean);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (ft_gen_exit_code_var(data))
|
|
||||||
{
|
|
||||||
if (outfile > 2)
|
|
||||||
close(outfile);
|
|
||||||
if (infile > 2)
|
|
||||||
close(infile);
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
free(cmds);
|
|
||||||
free(line_clean);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
cmds = ft_parse_cmds(data, line_clean, infile, outfile);
|
|
||||||
if (cmds == NULL)
|
|
||||||
{
|
|
||||||
if (outfile > 2)
|
|
||||||
close(outfile);
|
|
||||||
if (infile > 2)
|
|
||||||
close(infile);
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
free(cmds);
|
|
||||||
free(line_clean);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
ft_cmds_executor(data, cmds);
|
|
||||||
ft_lstclear(cmds, ft_cmddel);
|
|
||||||
free(cmds);
|
|
||||||
free(line_clean);
|
free(line_clean);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
free(line_clean);
|
||||||
void ft_ctrlc(int num)
|
if (ft_cmds_executor(data) == 1)
|
||||||
{
|
return (1);
|
||||||
(void) num;
|
ft_lstiter(*data->cmds, ft_cmdwaiter);
|
||||||
if (*ft_get_heredoc())
|
ft_lstclear(data->cmds, ft_cmddel);
|
||||||
{
|
return (0);
|
||||||
kill(*ft_get_heredoc(), SIGQUIT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rl_replace_line("", 0);
|
|
||||||
rl_on_new_line();
|
|
||||||
ft_putchar_fd('\n', 1);
|
|
||||||
rl_redisplay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_quit(int num)
|
int ft_init_data(t_data *data, char **env)
|
||||||
{
|
{
|
||||||
(void) num;
|
data->exit_code = ft_get_exit_code();
|
||||||
if (*ft_get_heredoc())
|
data->cmds = malloc(sizeof(t_cmd *));
|
||||||
|
if (data->cmds == NULL)
|
||||||
{
|
{
|
||||||
ft_printf("pb");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
*data->cmds = NULL;
|
||||||
ft_printf("bozoman");
|
data->env = init_env(env);
|
||||||
|
if (data->env == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
free(data->cmds);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av, char **env)
|
int main(int ac, char **av, char **env)
|
||||||
@ -128,22 +94,22 @@ int main(int ac, char **av, char **env)
|
|||||||
(void) ac;
|
(void) ac;
|
||||||
(void) av;
|
(void) av;
|
||||||
signal(SIGINT, ft_ctrlc);
|
signal(SIGINT, ft_ctrlc);
|
||||||
signal(SIGQUIT, ft_quit);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
data.exit_code = 0;
|
if (ft_init_data(&data, env))
|
||||||
data.env = init_env(env);
|
|
||||||
if (data.env == NULL)
|
|
||||||
return (1);
|
return (1);
|
||||||
line = ft_get_user_input();
|
line = ft_get_user_input();
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
if (ft_minishell(&data, line) == -1)
|
if (ft_minishell(&data, line) == 1)
|
||||||
break ;
|
break ;
|
||||||
free(line);
|
free(line);
|
||||||
line = ft_get_user_input();
|
line = ft_get_user_input();
|
||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
ft_lstclear(data.cmds, ft_cmddel);
|
||||||
|
free(data.cmds);
|
||||||
ft_lstclear(data.env, env_del);
|
ft_lstclear(data.env, env_del);
|
||||||
free(data.env);
|
free(data.env);
|
||||||
return (data.exit_code);
|
return (*data.exit_code);
|
||||||
}
|
}
|
||||||
|
104
minishell.h
104
minishell.h
@ -1,104 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* minishell.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/28 14:55:52 by erey-bet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef MINISHELL_H
|
|
||||||
# define MINISHELL_H
|
|
||||||
# include "libftx/libftx.h"
|
|
||||||
# include "utils/utils.h"
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <sys/stat.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
# include <sys/wait.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <limits.h>
|
|
||||||
# include <string.h>
|
|
||||||
# include <readline/readline.h>
|
|
||||||
# include <readline/history.h>
|
|
||||||
# define DEBUG 0
|
|
||||||
|
|
||||||
typedef struct s_data
|
|
||||||
{
|
|
||||||
t_list **env;
|
|
||||||
int exit_code;
|
|
||||||
char *exit_code_str;
|
|
||||||
} t_data;
|
|
||||||
|
|
||||||
int ft_syntatic_verif(t_data *data, const char *str);
|
|
||||||
int ft_file_is_readable(const char *path);
|
|
||||||
int ft_file_is_writable(const char *path);
|
|
||||||
int ft_file_is_appendable(const char *path);
|
|
||||||
char *ft_get_file_path(const char *infile);
|
|
||||||
int ft_infile(t_data *data, char *line);
|
|
||||||
int ft_outfile(t_data *data, char *line);
|
|
||||||
int ft_heredoc(char *stop);
|
|
||||||
int *ft_get_heredoc();
|
|
||||||
size_t ft_seglen_quoted(const char *str, char c);
|
|
||||||
int ft_cmds_executor(t_data *data, t_list **cmds);
|
|
||||||
char **ft_split_quoted(const char *s, char c);
|
|
||||||
void ft_cmddel(void *content);
|
|
||||||
void env_del(void *content);
|
|
||||||
t_list **ft_parse_cmds(t_data *data, char *line, int infile, int outfile);
|
|
||||||
int ft_gen_exit_code_var(t_data *data);
|
|
||||||
int ft_cmd_filler(t_data *data, t_list *current, char **args);
|
|
||||||
char *ft_normalizer(char *str);
|
|
||||||
char *ft_env_filler(t_data *data, const char *str);
|
|
||||||
char **env_to_strs(t_list **head);
|
|
||||||
|
|
||||||
/* Environnement */
|
|
||||||
t_list **init_env(char **env);
|
|
||||||
char **env_to_strs(t_list **head);
|
|
||||||
int create_value_by_key(char *key, char *value, t_list **head);
|
|
||||||
int create_value_by_key_dup(char *key, char *value, t_list **head);
|
|
||||||
int set_value_by_key(char *key, char *value, t_list **head);
|
|
||||||
char *get_value_by_key(char *key, t_list **head);
|
|
||||||
int get_index(char *s, char c);
|
|
||||||
void swap_env_3(void **a, void **b, void **c);
|
|
||||||
void swap_env(void **a, void **b);
|
|
||||||
void env_del(void *ptr);
|
|
||||||
char **env_to_strs(t_list **head);
|
|
||||||
char *get_value(char *str);
|
|
||||||
char *get_key(char *str);
|
|
||||||
int delete_by_key(char *key, t_list **head);
|
|
||||||
int possible_key(char *key);
|
|
||||||
|
|
||||||
/* Echo */
|
|
||||||
int echo(int fd, char **strs);
|
|
||||||
/* PWD */
|
|
||||||
int pwd(int fd);
|
|
||||||
char *get_pwd(int fd);
|
|
||||||
/* Env */
|
|
||||||
int print_env(t_list **env, int fd);
|
|
||||||
/* Export */
|
|
||||||
int export(t_list **env, char **args, int fd);
|
|
||||||
/* CD */
|
|
||||||
int move_folder(char **args, int fd);
|
|
||||||
/* Unset */
|
|
||||||
int unset(t_list **env, char **args, int fd);
|
|
||||||
/* Exit */
|
|
||||||
int ft_exit(char **args);
|
|
||||||
|
|
||||||
typedef struct s_cmd
|
|
||||||
{
|
|
||||||
int fd_in;
|
|
||||||
int fd_out;
|
|
||||||
char *executable;
|
|
||||||
char **args;
|
|
||||||
} t_cmd;
|
|
||||||
|
|
||||||
typedef struct s_env
|
|
||||||
{
|
|
||||||
char *key;
|
|
||||||
char *value;
|
|
||||||
} t_env;
|
|
||||||
|
|
||||||
#endif
|
|
Submodule minishell_tester deleted from 1c6111b2fd
114
outfile.c
114
outfile.c
@ -1,114 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* outfile.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 18:01:07 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/17 19:03:00 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
static int ft_outfile_is_valid(const char *line)
|
|
||||||
{
|
|
||||||
char **tab;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
if (tab[0] == NULL)
|
|
||||||
return (1);
|
|
||||||
i = 0;
|
|
||||||
while (tab[i + 1] != NULL)
|
|
||||||
i++;
|
|
||||||
if (tab[i][0] == '>')
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]);
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_get_outfile(const char *line)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int fd;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (-2);
|
|
||||||
}
|
|
||||||
fd = 1;
|
|
||||||
i = 0;
|
|
||||||
while (tab[i + 1] != NULL)
|
|
||||||
{
|
|
||||||
if (tab[i][0] == '>')
|
|
||||||
if (fd != 1)
|
|
||||||
close(fd);
|
|
||||||
if (ft_strcmp(">", tab[i]) == 0)
|
|
||||||
fd = ft_file_is_writable(ft_quote_remover(tab[i + 1]));
|
|
||||||
else if (ft_strcmp(">>", tab[i]) == 0)
|
|
||||||
fd = ft_file_is_appendable(ft_quote_remover(tab[i + 1]));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_remove_outfile(char *line)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t y;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
tab = ft_split_quoted(line, ' ');
|
|
||||||
if (tab == NULL)
|
|
||||||
{
|
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
y = 0;
|
|
||||||
while (tab[i] != NULL)
|
|
||||||
{
|
|
||||||
if (tab[i][0] == '>')
|
|
||||||
{
|
|
||||||
ft_strshift(line + y,
|
|
||||||
(-1) * (ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1 + (line[ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1] != '\0')));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
y = y + ft_strlen(tab[i]) + (y != 0);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_outfile(t_data *data, char *line)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (ft_outfile_is_valid(line) == 0)
|
|
||||||
{
|
|
||||||
data->exit_code = 2;
|
|
||||||
return (-2);
|
|
||||||
}
|
|
||||||
fd = ft_get_outfile(line);
|
|
||||||
if (fd == -2)
|
|
||||||
return (-2);
|
|
||||||
ft_remove_outfile(line);
|
|
||||||
return (fd);
|
|
||||||
}
|
|
127
parse/parse.c
Normal file
127
parse/parse.c
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/11 16:17:19 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "./parse_private.h"
|
||||||
|
|
||||||
|
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
tab = ft_split_charset_quoted(cmd_str, "\t ");
|
||||||
|
if (tab == NULL)
|
||||||
|
return (1);
|
||||||
|
i = 0;
|
||||||
|
while (tab[i] != NULL)
|
||||||
|
{
|
||||||
|
ft_quote_remover(tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
cmd->args = tab;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
bool own;
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
path = cmd->args[0];
|
||||||
|
own = 0;
|
||||||
|
if (cmd->args[0] == NULL)
|
||||||
|
{
|
||||||
|
ft_closer(cmd->fd_in);
|
||||||
|
ft_closer(cmd->fd_out);
|
||||||
|
}
|
||||||
|
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0],
|
||||||
|
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0)
|
||||||
|
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0],
|
||||||
|
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0)
|
||||||
|
|| (ft_strcmp(cmd->args[0], "cd") == 0))
|
||||||
|
own = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = ft_get_executable(data, cmd->args[0]);
|
||||||
|
if (path == NULL)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
cmd->own_cmd = own;
|
||||||
|
cmd->executable = path;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
|
||||||
|
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||||
|
if (cmd == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (ft_redirection(data, cmd, cmd_str))
|
||||||
|
{
|
||||||
|
ft_cmddel(cmd);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (ft_args_parse(cmd_str, cmd))
|
||||||
|
{
|
||||||
|
ft_cmddel(cmd);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_executable_parse(data, cmd);
|
||||||
|
return (ft_cmd_adder(data, cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_cmds_parser(t_data *data, const char *line)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
ssize_t i;
|
||||||
|
|
||||||
|
tab = ft_split_charset_quoted(line, "|");
|
||||||
|
if (tab == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
i = -1;
|
||||||
|
while (tab[++i] != NULL)
|
||||||
|
{
|
||||||
|
if (ft_cmd_parser(data, tab[i]))
|
||||||
|
{
|
||||||
|
ft_freer_tab_ultimate(1, tab);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*data->cmds != NULL)
|
||||||
|
{
|
||||||
|
ft_add_fd(((t_cmd *)(*data->cmds)->content)->fd_in, 0);
|
||||||
|
ft_add_fd(((t_cmd *)(ft_lstlast(*data->cmds))->content)->fd_out, 1);
|
||||||
|
}
|
||||||
|
ft_freer_tab_ultimate(1, tab);
|
||||||
|
return (0);
|
||||||
|
}
|
19
parse/parse.h
Normal file
19
parse/parse.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define PARSE_H
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
int ft_cmds_parser(t_data *data, const char *line);
|
||||||
|
|
||||||
|
#endif
|
21
parse/parse_private.h
Normal file
21
parse/parse_private.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define PARSE_PRIVATE_H
|
||||||
|
# include "../redirection/redirection.h"
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
# include "../env/env.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../cmd/cmd.h"
|
||||||
|
#endif
|
151
redirection/check.c
Normal file
151
redirection/check.c
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* check.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (ft_strcmp(redirection_identifier, "<<") == 0)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
|
cmd->fd_in[0] = fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ft_check_infile(t_data *data, t_cmd *cmd,
|
||||||
|
char *redirection_identifier, char *redirection)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (ft_strcmp(redirection_identifier, "<") == 0)
|
||||||
|
{
|
||||||
|
if (cmd->fd_in[0] == -2)
|
||||||
|
return (0);
|
||||||
|
if (ft_file_is_readable(data, redirection))
|
||||||
|
{
|
||||||
|
fd = open(redirection, O_RDONLY);
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
|
cmd->fd_in[0] = fd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
|
cmd->fd_in[0] = -2;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ft_check_outfile(t_data *data, t_cmd *cmd,
|
||||||
|
char *redirection_identifier, char *redirection)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (ft_strcmp(redirection_identifier, ">") == 0)
|
||||||
|
{
|
||||||
|
if (cmd->fd_out[0] == -2)
|
||||||
|
return (0);
|
||||||
|
if (ft_file_is_writable(data, redirection))
|
||||||
|
{
|
||||||
|
fd = open(redirection,
|
||||||
|
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = fd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = -2;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ft_check_outfile_append(t_data *data, t_cmd *cmd,
|
||||||
|
char *redirection_identifier, char *redirection)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (ft_strcmp(redirection_identifier, ">>") == 0)
|
||||||
|
{
|
||||||
|
if (cmd->fd_out[0] == -2)
|
||||||
|
return (0);
|
||||||
|
if (ft_file_is_appendable(data, redirection))
|
||||||
|
{
|
||||||
|
fd = open(redirection,
|
||||||
|
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = fd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
||||||
|
char *redirection_identifier, char *redirection)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
bool out;
|
||||||
|
|
||||||
|
if (ft_is_in("<>", redirection_identifier[0])
|
||||||
|
&& ft_is_in("<>", redirection[0]))
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: %s: invalid redirection file\n", redirection);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
str = ft_strdup(redirection);
|
||||||
|
if (str == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_quote_remover(str);
|
||||||
|
out = 0;
|
||||||
|
if (ft_check_heredoc(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_infile(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_outfile(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_outfile_append(data, cmd, redirection_identifier, str))
|
||||||
|
out = 1;
|
||||||
|
free(str);
|
||||||
|
return (out);
|
||||||
|
}
|
@ -6,14 +6,13 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 17:36:11 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 17:36:11 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/15 17:41:13 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:12:41 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "./redirection_private.h"
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int ft_file_is_readable(const char *path)
|
int ft_file_is_readable(t_data *data, const char *path)
|
||||||
{
|
{
|
||||||
int readable;
|
int readable;
|
||||||
int fd;
|
int fd;
|
||||||
@ -21,59 +20,63 @@ int ft_file_is_readable(const char *path)
|
|||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: No such file or directory\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: No such file or directory\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
readable = read(fd, "", 0);
|
readable = read(fd, "", 0);
|
||||||
if (readable == -1)
|
if (readable == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
return (fd);
|
close(fd);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_file_is_writable(const char *path)
|
int ft_file_is_writable(t_data *data, const char *path)
|
||||||
{
|
{
|
||||||
int writeable;
|
int writeable;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
writeable = write(fd, "", 0);
|
writeable = write(fd, "", 0);
|
||||||
if (writeable == -1)
|
if (writeable == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
return (fd);
|
close(fd);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_file_is_appendable(const char *path)
|
int ft_file_is_appendable(t_data *data, const char *path)
|
||||||
{
|
{
|
||||||
int writeable;
|
int writeable;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
|
fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
writeable = write(fd, "", 0);
|
writeable = write(fd, "", 0);
|
||||||
if (writeable == -1)
|
if (writeable == -1)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
*data->exit_code = 1;
|
||||||
return (-1);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
return (fd);
|
close(fd);
|
||||||
}
|
return (1);
|
||||||
|
|
||||||
int ft_file_is_executable(const char *path)
|
|
||||||
{
|
|
||||||
return (access(path, X_OK) == 0);
|
|
||||||
}
|
}
|
93
redirection/heredoc.c
Normal file
93
redirection/heredoc.c
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* heredoc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/17 12:14:11 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "./redirection_private.h"
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static bool ft_fd_is_closed(int fd)
|
||||||
|
{
|
||||||
|
int fd2;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
char *line_clean;
|
||||||
|
|
||||||
|
line_clean = ft_env_filler(data, str);
|
||||||
|
if (line_clean == NULL)
|
||||||
|
return (1);
|
||||||
|
ft_putendl_fd(line_clean, fd);
|
||||||
|
free(line_clean);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_heredoc2(t_data *data, char *line, char *stop, int fds[2])
|
||||||
|
{
|
||||||
|
if (line == NULL)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ft_strcmp(line, stop) == 0)
|
||||||
|
return (1);
|
||||||
|
if (ft_format_and_write(data, line, fds[1]))
|
||||||
|
{
|
||||||
|
close(fds[0]);
|
||||||
|
fds[0] = -2;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_heredoc(t_data *data, char *stop)
|
||||||
|
{
|
||||||
|
int fds[2];
|
||||||
|
int stdin_bak;
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
stdin_bak = dup(0);
|
||||||
|
if (stdin_bak == -1)
|
||||||
|
return (1);
|
||||||
|
if (pipe(fds))
|
||||||
|
{
|
||||||
|
close(stdin_bak);
|
||||||
|
return (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]);
|
||||||
|
}
|
115
redirection/redirection.c
Normal file
115
redirection/redirection.c
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/13 13:26:06 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "redirection_private.h"
|
||||||
|
|
||||||
|
int ft_replace_file(t_data *data, char **tab)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *redirection;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (tab[i] != NULL)
|
||||||
|
{
|
||||||
|
if (ft_is_in("<>", tab[i][0]))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
redirection = ft_env_filler(data, tab[i]);
|
||||||
|
if (redirection == NULL)
|
||||||
|
return (1);
|
||||||
|
free(tab[i]);
|
||||||
|
tab[i] = redirection;
|
||||||
|
ft_quote_remover(tab[i]);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_skip(char *str, size_t *i, ssize_t *start)
|
||||||
|
{
|
||||||
|
while (str[*i] == str[*start])
|
||||||
|
(*i)++;
|
||||||
|
while (str[*i] == ' ')
|
||||||
|
(*i)++;
|
||||||
|
while (str[*i] != '\0' && (str[*i] != ' '
|
||||||
|
|| ft_is_in_quote(str, *i)))
|
||||||
|
(*i)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_remove_redirection(char *cmd_str)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
ssize_t start;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (cmd_str[i] != '\0')
|
||||||
|
{
|
||||||
|
start = -1;
|
||||||
|
while ((ft_is_in_quote(cmd_str, i) || !ft_is_in("<>", cmd_str[i]))
|
||||||
|
&& cmd_str[i] != '\0')
|
||||||
|
i++;
|
||||||
|
if (ft_is_in("<>", cmd_str[i]))
|
||||||
|
start = i;
|
||||||
|
else
|
||||||
|
continue ;
|
||||||
|
ft_skip(cmd_str, &i, &start);
|
||||||
|
if (start != -1)
|
||||||
|
{
|
||||||
|
ft_strshift(cmd_str + start, -1 * (i - start));
|
||||||
|
i = start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (tab[i + 1] != NULL)
|
||||||
|
{
|
||||||
|
if (ft_check_redirection(data, cmd, tab[i], tab[i + 1]))
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (ft_is_in("<>", tab[i][0]))
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: %s: must be followed by a file\n", tab[i]);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
cmd->fd_in[0] = -1;
|
||||||
|
cmd->fd_in[1] = -1;
|
||||||
|
cmd->fd_out[0] = -1;
|
||||||
|
cmd->fd_out[1] = -1;
|
||||||
|
tab = ft_split_charset_quoted(cmd_str, " \t");
|
||||||
|
if (tab == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_remove_redirection(cmd_str);
|
||||||
|
if (ft_set_redirection(data, cmd, tab))
|
||||||
|
{
|
||||||
|
ft_freer_tab_ultimate(1, tab);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_freer_tab_ultimate(1, tab);
|
||||||
|
return (0);
|
||||||
|
}
|
21
redirection/redirection.h
Normal file
21
redirection/redirection.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define REDIRECTION_H
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../cmd/cmd.h"
|
||||||
|
|
||||||
|
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str);
|
||||||
|
int *ft_get_heredoc(void);
|
||||||
|
|
||||||
|
#endif
|
32
redirection/redirection_private.h
Normal file
32
redirection/redirection_private.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:44:31 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/29 19:19:21 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef REDIRECTION_PRIVATE_H
|
||||||
|
# define REDIRECTION_PRIVATE_H
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../env/env.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
|
# include "../cmd/cmd.h"
|
||||||
|
|
||||||
|
int ft_file_is_readable(t_data *data, const char *path);
|
||||||
|
int ft_file_is_writable(t_data *data, const char *path);
|
||||||
|
bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
||||||
|
char *redirection_identifier, char *redirection);
|
||||||
|
int ft_file_is_appendable(t_data *data, const char *path);
|
||||||
|
int ft_heredoc(t_data *data, char *stop);
|
||||||
|
|
||||||
|
#endif
|
36
signal/signal.c
Normal file
36
signal/signal.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* signal.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
rl_replace_line("", 0);
|
||||||
|
rl_on_new_line();
|
||||||
|
ft_putchar_fd('\n', 1);
|
||||||
|
rl_redisplay();
|
||||||
|
*ft_get_exit_code() = 130;
|
||||||
|
(void) num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_quit(int num)
|
||||||
|
{
|
||||||
|
(void) num;
|
||||||
|
ft_printf("Quit (core dumped)\n");
|
||||||
|
}
|
20
signal/signal.h
Normal file
20
signal/signal.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* signal.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/17 11:14:28 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SIGNAL_H
|
||||||
|
# define SIGNAL_H
|
||||||
|
|
||||||
|
void ft_quit(int num);
|
||||||
|
void ft_ctrlc(int num);
|
||||||
|
void ft_ctrlc_heredoc(int num);
|
||||||
|
|
||||||
|
#endif
|
22
signal/signal_private.h
Normal file
22
signal/signal_private.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* signal_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/28 15:59:42 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/05 15:05:00 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef SIGNAL_PRIVATE_H
|
||||||
|
# define SIGNAL_PRIVATE_H
|
||||||
|
# include <signal.h>
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <readline/readline.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../redirection/redirection.h"
|
||||||
|
#endif
|
@ -1,24 +1,23 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* syntatics.c :+: :+: :+: */
|
/* syntax.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
|
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/21 23:40:20 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/07 11:07:52 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "../libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "../utils/utils.h"
|
||||||
#include "utils/utils.h"
|
|
||||||
|
|
||||||
static int ft_quote_verif(const char *str)
|
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
|
||||||
@ -27,16 +26,14 @@ static int ft_quote_verif(const char *str)
|
|||||||
|
|
||||||
static int ft_pipe_is_alone(const char *str)
|
static int ft_pipe_is_alone(const char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
ssize_t i;
|
||||||
int check;
|
int check;
|
||||||
|
|
||||||
check = 0;
|
check = 0;
|
||||||
i = 0;
|
i = -1;
|
||||||
while (str[i] != '\0')
|
while (str[++i] != '\0')
|
||||||
{
|
{
|
||||||
while (str[i] == ' ')
|
while (str[i] == ' ' || ft_is_in_quote(str, i))
|
||||||
i++;
|
|
||||||
while (ft_is_in_quote(str, i))
|
|
||||||
i++;
|
i++;
|
||||||
if (str[i] == '\0')
|
if (str[i] == '\0')
|
||||||
break ;
|
break ;
|
||||||
@ -45,20 +42,13 @@ static int ft_pipe_is_alone(const char *str)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (check == 0)
|
if (check == 0)
|
||||||
{
|
break ;
|
||||||
ft_eprintf("minishell: Pipe must be followed and ");
|
|
||||||
ft_eprintf("preced by a command or redirection\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
check = 0;
|
check = 0;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
if (check == 0)
|
if (check == 0)
|
||||||
{
|
ft_eprintf("bozoshell: Pipe must be followed and %s",
|
||||||
ft_eprintf("minishell: Pipe must be followed and ");
|
"preced by a command or redirection\n");
|
||||||
ft_eprintf("preced by a command or redirection\n");
|
|
||||||
}
|
|
||||||
return (check == 0);
|
return (check == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,35 +70,36 @@ 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 %c in a row\n", str, str[i]);
|
ft_eprintf("bozoshell: too many %s in a row\n", str);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
i = i + y;
|
i = i + y;
|
||||||
}
|
}
|
||||||
else
|
else if (str[i] != '\0')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_empty_verif(const char *str)
|
static int ft_empty_verif(const char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] == ' ')
|
while (str[i] == ' ' || str[i] == '\t')
|
||||||
i++;
|
i++;
|
||||||
return (str[i] == '\0');
|
return (str[i] == '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_syntatic_verif(t_data *data, const char *str)
|
int ft_syntax_verif(t_data *data, const char *str)
|
||||||
{
|
{
|
||||||
|
if (ft_empty_verif(str))
|
||||||
|
return (1);
|
||||||
if (ft_quote_verif(str)
|
if (ft_quote_verif(str)
|
||||||
|| ft_empty_verif(str)
|
|
||||||
|| ft_pipe_is_alone(str)
|
|| ft_pipe_is_alone(str)
|
||||||
|| ft_special_char_dub(str))
|
|| ft_special_char_dub(str))
|
||||||
{
|
{
|
||||||
data->exit_code = 2;
|
*data->exit_code = 2;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
19
syntax/syntax.h
Normal file
19
syntax/syntax.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
|
# define SYNTAX_H
|
||||||
|
# include "../data/data.h"
|
||||||
|
|
||||||
|
int ft_syntax_verif(t_data *data, const char *str);
|
||||||
|
|
||||||
|
#endif
|
290
tags
290
tags
@ -1,290 +0,0 @@
|
|||||||
!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/
|
|
||||||
!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/
|
|
||||||
!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/
|
|
||||||
!_TAG_FIELD_DESCRIPTION input /input file/
|
|
||||||
!_TAG_FIELD_DESCRIPTION name /tag name/
|
|
||||||
!_TAG_FIELD_DESCRIPTION pattern /pattern/
|
|
||||||
!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/
|
|
||||||
!_TAG_FIELD_DESCRIPTION!C++ name /aliased names/
|
|
||||||
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
|
||||||
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C d,macro /macro definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C e,enumerator /enumerators (values inside an enumeration)/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C f,function /function definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C g,enum /enumeration names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C h,header /included header files/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C m,member /struct, and union members/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C s,struct /structure names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C t,typedef /typedefs/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C u,union /union names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C v,variable /variable definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ c,class /classes/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ d,macro /macro definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ e,enumerator /enumerators (values inside an enumeration)/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ f,function /function definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ g,enum /enumeration names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ h,header /included header files/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ m,member /class, struct, and union members/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ n,namespace /namespaces/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ s,struct /structure names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ t,typedef /typedefs/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ u,union /union names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ v,variable /variable definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown S,subsection /level 2 sections/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown T,l4subsection /level 4 sections/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown c,chapter /chapters/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown n,footnote /footnotes/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown s,section /sections/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown t,subsubsection /level 3 sections/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Markdown u,l5subsection /level 5 sections/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Sh a,alias /aliases/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Sh f,function /functions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Sh h,heredoc /label for here document/
|
|
||||||
!_TAG_KIND_DESCRIPTION!Sh s,script /script files/
|
|
||||||
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
|
|
||||||
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
|
|
||||||
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
|
|
||||||
!_TAG_OUTPUT_VERSION 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!C 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!C++ 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!Markdown 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!Sh 0.0 /current.age/
|
|
||||||
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
|
|
||||||
!_TAG_PROC_CWD /nfs/homes/cchauvet/42/minishell/ //
|
|
||||||
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
|
|
||||||
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
|
|
||||||
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
|
|
||||||
!_TAG_PROGRAM_VERSION 6.0.0 //
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!header local /local header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!header system /system header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!header local /local header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!header system /system header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!macro undef /undefined/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!Sh!heredoc endmarker /end marker/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!Sh!script loaded /loaded/
|
|
||||||
BUFFER_SIZE libftx/gnl/get_next_line.h /^# define BUFFER_SIZE /;" d
|
|
||||||
Bonus minishell_tester/README.md /^# Bonus $/;" c
|
|
||||||
DEBUG minishell.h /^# define DEBUG /;" d
|
|
||||||
EXTRA_H libftx/extra/extra.h /^# define EXTRA_H$/;" d
|
|
||||||
Extra tests minishell_tester/README.md /^# Extra tests$/;" c
|
|
||||||
FT_PRINTF_H libftx/printf/ft_printf.h /^# define FT_PRINTF_H$/;" d
|
|
||||||
GET_NEXT_LINE_H libftx/gnl/get_next_line.h /^# define GET_NEXT_LINE_H$/;" d
|
|
||||||
How to run minishell_tester/README.md /^# How to run $/;" c
|
|
||||||
Installation minishell_tester/README.md /^# Installation $/;" c
|
|
||||||
LIBFTX_H libftx/libftx.h /^# define LIBFTX_H$/;" d
|
|
||||||
LIBFT_H libftx/libft/libft.h /^# define LIBFT_H$/;" d
|
|
||||||
MINISHELL_H minishell.h /^# define MINISHELL_H$/;" d
|
|
||||||
Manual tests minishell_tester/README.md /^# Manual tests $/;" c
|
|
||||||
Separate tests minishell_tester/README.md /^# Separate tests$/;" c
|
|
||||||
UTILS_H utils/utils.h /^# define UTILS_H$/;" d
|
|
||||||
add_export builtins/export.c /^void add_export(t_list **env, char *args, int fd, int *err)$/;" f typeref:typename:void
|
|
||||||
add_sort env.c /^void add_sort(t_list **head, t_env *var)$/;" f typeref:typename:void
|
|
||||||
args minishell.h /^ char **args;$/;" m struct:s_cmd typeref:typename:char **
|
|
||||||
check_argument builtins/echo.c /^int check_argument(char *str, int *check)$/;" f typeref:typename:int
|
|
||||||
content libftx/libft/libft.h /^ void *content;$/;" m struct:s_list typeref:typename:void *
|
|
||||||
content libftx/libftx.h /^ void *content;$/;" m struct:s_list typeref:typename:void *
|
|
||||||
create_value_by_key env.c /^int create_value_by_key(char *key, char *value, t_list **head)$/;" f typeref:typename:int
|
|
||||||
create_value_by_key_dup env3.c /^int create_value_by_key_dup(char *key, char *value, t_list **env)$/;" f typeref:typename:int
|
|
||||||
delete_by_key env3.c /^int delete_by_key(char *key, t_list **head)$/;" f typeref:typename:int
|
|
||||||
echo builtins/echo.c /^int echo(int fd, char **strs)$/;" f typeref:typename:int
|
|
||||||
env minishell.h /^ t_list **env;$/;" m struct:s_data typeref:typename:t_list **
|
|
||||||
env_del env2.c /^void env_del(void *ptr)$/;" f typeref:typename:void
|
|
||||||
env_to_strs env2.c /^char **env_to_strs(t_list **head)$/;" f typeref:typename:char **
|
|
||||||
error builtins/exit.c /^static int error(int err, char *reason, char *problem, int fd)$/;" f typeref:typename:int file:
|
|
||||||
error builtins/export.c /^static int error(char *str, int fd)$/;" f typeref:typename:int file:
|
|
||||||
error builtins/unset.c /^int error(char *str, int fd)$/;" f typeref:typename:int
|
|
||||||
executable minishell.h /^ char *executable;$/;" m struct:s_cmd typeref:typename:char *
|
|
||||||
exit_code minishell.h /^ int exit_code;$/;" m struct:s_data typeref:typename:int
|
|
||||||
export builtins/export.c /^int export(t_list **env, char **args, int fd)$/;" f typeref:typename:int
|
|
||||||
fd_in minishell.h /^ int fd_in;$/;" m struct:s_cmd typeref:typename:int
|
|
||||||
fd_out minishell.h /^ int fd_out;$/;" m struct:s_cmd typeref:typename:int
|
|
||||||
ft_atoi libftx/libft/ft_atoi.c /^int ft_atoi(const char *nptr)$/;" f typeref:typename:int
|
|
||||||
ft_atoi_check utils/ft_atoi_check.c /^int ft_atoi_check(const char *nptr)$/;" f typeref:typename:int
|
|
||||||
ft_base_size libftx/extra/ft_ultoa_base.c /^static size_t ft_base_size(char *base)$/;" f typeref:typename:size_t file:
|
|
||||||
ft_base_size libftx/printf/ft_dprintul_base.c /^static size_t ft_base_size(char *base)$/;" f typeref:typename:size_t file:
|
|
||||||
ft_bzero libftx/libft/ft_bzero.c /^void ft_bzero(void *s, size_t n)$/;" f typeref:typename:void
|
|
||||||
ft_calloc libftx/libft/ft_calloc.c /^void *ft_calloc(size_t nmemb, size_t size)$/;" f typeref:typename:void *
|
|
||||||
ft_cancel libftx/libft/ft_split.c /^void *ft_cancel(void **tab, size_t len)$/;" f typeref:typename:void *
|
|
||||||
ft_change_exit_code utils/ft_change_exit_code.c /^int ft_change_exit_code(t_data *data, int new_value)$/;" f typeref:typename:int
|
|
||||||
ft_cmd_filler cmd.c /^int ft_cmd_filler(t_list *element, char **args, t_list **env)$/;" f typeref:typename:int
|
|
||||||
ft_cmddel cmd.c /^void ft_cmddel(void *ptr)$/;" f typeref:typename:void
|
|
||||||
ft_cmds_executor execution.c /^int ft_cmds_executor(t_data *data, t_list **cmds)$/;" f typeref:typename:int
|
|
||||||
ft_cmds_fill cmds.c /^static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_cmds_init cmds.c /^static int ft_cmds_init(t_list **cmds, size_t len)$/;" f typeref:typename:int file:
|
|
||||||
ft_cmds_prep cmds.c /^static int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile)$/;" f typeref:typename:int file:
|
|
||||||
ft_contain_only libftx/extra/ft_contain_only.c /^int ft_contain_only(char *str, char c)$/;" f typeref:typename:int
|
|
||||||
ft_contain_only_str libftx/extra/ft_contain_only.c /^int ft_contain_only_str(char *str, char *to_find)$/;" f typeref:typename:int
|
|
||||||
ft_ctrlc main.c /^void ft_ctrlc(int num)$/;" f typeref:typename:void
|
|
||||||
ft_dprint_upperx libftx/printf/ft_dprintX.c /^int ft_dprint_upperx(int fd, unsigned int n)$/;" f typeref:typename:int
|
|
||||||
ft_dprintarg libftx/printf/ft_dprintarg.c /^int ft_dprintarg(int fd, int arg, va_list args)$/;" f typeref:typename:int
|
|
||||||
ft_dprintf libftx/printf/ft_printf.c /^int ft_dprintf(int fd, const char *format, ...)$/;" f typeref:typename:int
|
|
||||||
ft_dprintflag libftx/printf/ft_dprintflag.c /^int ft_dprintflag(int fd, const char *flag, va_list va)$/;" f typeref:typename:int
|
|
||||||
ft_dprintl_base libftx/printf/ft_dprintl_base.c /^int ft_dprintl_base(int fd, long long int n, char *base)$/;" f typeref:typename:int
|
|
||||||
ft_dprintptr libftx/printf/ft_dprintptr.c /^int ft_dprintptr(int fd, void *ptr)$/;" f typeref:typename:int
|
|
||||||
ft_dprintseg libftx/printf/ft_vdprintf.c /^static int ft_dprintseg(int fd, const char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_dprintstrtab libftx/printf/ft_dprintstrtab.c /^int ft_dprintstrtab(int fd, char **tab)$/;" f typeref:typename:int
|
|
||||||
ft_dprintul libftx/printf/ft_dprintul.c /^int ft_dprintul(int fd, unsigned long long n)$/;" f typeref:typename:int
|
|
||||||
ft_dprintul_base libftx/printf/ft_dprintul_base.c /^int ft_dprintul_base(int fd, unsigned long long n, char *base)$/;" f typeref:typename:int
|
|
||||||
ft_dprintx libftx/printf/ft_dprintx.c /^int ft_dprintx(int fd, unsigned int n)$/;" f typeref:typename:int
|
|
||||||
ft_empty_verif syntatics.c /^int ft_empty_verif(const char *str)$/;" f typeref:typename:int
|
|
||||||
ft_env_filler env_fill.c /^char *ft_env_filler(t_list **env, const char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_eprintf libftx/printf/ft_eprintf.c /^int ft_eprintf(const char *format, ...)$/;" f typeref:typename:int
|
|
||||||
ft_executor execution.c /^static int ft_executor(t_cmd *cmd, t_list **env)$/;" f typeref:typename:int file:
|
|
||||||
ft_exit builtins/exit.c /^int ft_exit(char **args, int fd)$/;" f typeref:typename:int
|
|
||||||
ft_file_is_appendable file.c /^int ft_file_is_appendable(const char *path)$/;" f typeref:typename:int
|
|
||||||
ft_file_is_executable file.c /^int ft_file_is_executable(const char *path)$/;" f typeref:typename:int
|
|
||||||
ft_file_is_readable file.c /^int ft_file_is_readable(const char *path)$/;" f typeref:typename:int
|
|
||||||
ft_file_is_writable file.c /^int ft_file_is_writable(const char *path)$/;" f typeref:typename:int
|
|
||||||
ft_freer_tab libftx/extra/ft_freer.c /^void ft_freer_tab(char **tab)$/;" f typeref:typename:void
|
|
||||||
ft_freer_tab_ultimate libftx/extra/ft_freer.c /^void ft_freer_tab_ultimate(size_t len, ...)$/;" f typeref:typename:void
|
|
||||||
ft_freer_ultimate libftx/extra/ft_freer.c /^void ft_freer_ultimate(size_t len, ...)$/;" f typeref:typename:void
|
|
||||||
ft_gen_exit_code_var env_fill.c /^int ft_gen_exit_code_var(t_data *data)$/;" f typeref:typename:int
|
|
||||||
ft_get_executable_path execution.c /^static char *ft_get_executable_path(char *executable_name, t_list **env)$/;" f typeref:typename:char * file:
|
|
||||||
ft_get_heredoc heredoc.c /^int *ft_get_heredoc()$/;" f typeref:typename:int *
|
|
||||||
ft_get_infile infile.c /^static int ft_get_infile(const char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_get_key env_fill.c /^static char *ft_get_key(char *str)$/;" f typeref:typename:char * file:
|
|
||||||
ft_get_outfile outfile.c /^static int ft_get_outfile(const char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_get_user_input main.c /^static char *ft_get_user_input()$/;" f typeref:typename:char * file:
|
|
||||||
ft_get_value env_fill.c /^static char *ft_get_value(t_list **env, char *key)$/;" f typeref:typename:char * file:
|
|
||||||
ft_getextra libftx/gnl/get_next_line.c /^char *ft_getextra(char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_getline libftx/gnl/get_next_line.c /^char *ft_getline(int fd)$/;" f typeref:typename:char *
|
|
||||||
ft_getreturn libftx/gnl/get_next_line.c /^char *ft_getreturn(char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_getstash libftx/gnl/get_next_line.c /^char *ft_getstash(int fd)$/;" f typeref:typename:char *
|
|
||||||
ft_heredoc heredoc.c /^int ft_heredoc(char *stop)$/;" f typeref:typename:int
|
|
||||||
ft_heredoc_creator heredoc.c /^int ft_heredoc_creator(char *stop, int fd)$/;" f typeref:typename:int
|
|
||||||
ft_infile infile.c /^int ft_infile(t_data *data, char *line)$/;" f typeref:typename:int
|
|
||||||
ft_infile_is_valid infile.c /^static int ft_infile_is_valid(const char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_is_in libftx/extra/ft_is_in.c /^int ft_is_in(char *str, char c)$/;" f typeref:typename:int
|
|
||||||
ft_is_in libftx/libft/ft_strtrim.c /^static int ft_is_in(const char c, const char *charset)$/;" f typeref:typename:int file:
|
|
||||||
ft_is_in_quote utils/ft_is_in_quote.c /^int ft_is_in_quote(const char *str, size_t n)$/;" f typeref:typename:int
|
|
||||||
ft_isalnum libftx/libft/ft_isalnum.c /^int ft_isalnum(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isalpha libftx/libft/ft_isalpha.c /^int ft_isalpha(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isarg libftx/printf/ft_isarg.c /^int ft_isarg(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isascii libftx/libft/ft_isascii.c /^int ft_isascii(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isdigit libftx/libft/ft_isdigit.c /^int ft_isdigit(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isdigit libftx/printf/ft_isdigit.c /^int ft_isdigit(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isdup libftx/extra/ft_ultoa_base.c /^static int ft_isdup(char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_isdup libftx/printf/ft_dprintul_base.c /^static int ft_isdup(char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_isprint libftx/libft/ft_isprint.c /^int ft_isprint(int c)$/;" f typeref:typename:int
|
|
||||||
ft_isspace utils/ft_atoi_check.c /^static int ft_isspace(char c)$/;" f typeref:typename:int file:
|
|
||||||
ft_itoa libftx/libft/ft_itoa.c /^char *ft_itoa(int n)$/;" f typeref:typename:char *
|
|
||||||
ft_lstadd_back libftx/libft/ft_lstadd_back.c /^void ft_lstadd_back(t_list **lst, t_list *new)$/;" f typeref:typename:void
|
|
||||||
ft_lstadd_front libftx/libft/ft_lstadd_front.c /^void ft_lstadd_front(t_list **lst, t_list *new)$/;" f typeref:typename:void
|
|
||||||
ft_lstclear libftx/libft/ft_lstclear.c /^void ft_lstclear(t_list **lst, void (*del)(void *))$/;" f typeref:typename:void
|
|
||||||
ft_lstdelone libftx/libft/ft_lstdelone.c /^void ft_lstdelone(t_list *lst, void (*del)(void *))$/;" f typeref:typename:void
|
|
||||||
ft_lstiter libftx/libft/ft_lstiter.c /^void ft_lstiter(t_list *lst, void (*f)(void *))$/;" f typeref:typename:void
|
|
||||||
ft_lstlast libftx/libft/ft_lstlast.c /^t_list *ft_lstlast(t_list *lst)$/;" f typeref:typename:t_list *
|
|
||||||
ft_lstmap libftx/libft/ft_lstmap.c /^t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))$/;" f typeref:typename:t_list *
|
|
||||||
ft_lstnew libftx/libft/ft_lstnew.c /^t_list *ft_lstnew(void *content)$/;" f typeref:typename:t_list *
|
|
||||||
ft_lstsize libftx/libft/ft_lstsize.c /^int ft_lstsize(t_list *lst)$/;" f typeref:typename:int
|
|
||||||
ft_memchr libftx/libft/ft_memchr.c /^void *ft_memchr(const void *s, int c, size_t n)$/;" f typeref:typename:void *
|
|
||||||
ft_memcmp libftx/libft/ft_memcmp.c /^int ft_memcmp(const void *s1, const void *s2, size_t n)$/;" f typeref:typename:int
|
|
||||||
ft_memcpy libftx/libft/ft_memcpy.c /^void *ft_memcpy(void *dest, const void *src, size_t n)$/;" f typeref:typename:void *
|
|
||||||
ft_memmove libftx/libft/ft_memmove.c /^void *ft_memmove(void *dest, const void *src, size_t n)$/;" f typeref:typename:void *
|
|
||||||
ft_memset libftx/libft/ft_memset.c /^void *ft_memset(void *s, int c, size_t n)$/;" f typeref:typename:void *
|
|
||||||
ft_minishell main.c /^static int ft_minishell(t_data *data, char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_nb_digit libftx/libft/ft_itoa.c /^static int ft_nb_digit(int n)$/;" f typeref:typename:int file:
|
|
||||||
ft_normalizer spacer.c /^char *ft_normalizer(char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_outfile outfile.c /^int ft_outfile(t_data *data, char *line)$/;" f typeref:typename:int
|
|
||||||
ft_outfile_is_valid outfile.c /^static int ft_outfile_is_valid(const char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_own_cmd execution.c /^static int ft_own_cmd(t_data *data, t_cmd *cmd)$/;" f typeref:typename:int file:
|
|
||||||
ft_parse_cmds cmds.c /^t_list **ft_parse_cmds(t_data *data, char *line, int infile, int outfile)$/;" f typeref:typename:t_list **
|
|
||||||
ft_pipe_is_alone syntatics.c /^static int ft_pipe_is_alone(const char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_printf libftx/printf/ft_printf.c /^int ft_printf(const char *format, ...)$/;" f typeref:typename:int
|
|
||||||
ft_printn utils/ft_printn.c /^void ft_printn(const char *str, size_t n)$/;" f typeref:typename:void
|
|
||||||
ft_putchar_fd libftx/libft/ft_putchar_fd.c /^void ft_putchar_fd(char c, int fd)$/;" f typeref:typename:void
|
|
||||||
ft_putchar_fd_p libftx/printf/ft_putchar_fd.c /^int ft_putchar_fd_p(int fd, char c)$/;" f typeref:typename:int
|
|
||||||
ft_putendl_fd libftx/libft/ft_putendl_fd.c /^void ft_putendl_fd(char *s, int fd)$/;" f typeref:typename:void
|
|
||||||
ft_putnbr_fd libftx/libft/ft_putnbr_fd.c /^void ft_putnbr_fd(int n, int fd)$/;" f typeref:typename:void
|
|
||||||
ft_putstr_fd libftx/libft/ft_putstr_fd.c /^void ft_putstr_fd(char *s, int fd)$/;" f typeref:typename:void
|
|
||||||
ft_putstr_fd_p libftx/printf/ft_putstr_fd.c /^int ft_putstr_fd_p(int fd, char *str)$/;" f typeref:typename:int
|
|
||||||
ft_quit main.c /^void ft_quit(int num)$/;" f typeref:typename:void
|
|
||||||
ft_quote_remover utils/ft_quote_remover.c /^char *ft_quote_remover(char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_quote_verif syntatics.c /^static int ft_quote_verif(const char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_random_generator libftx/extra/ft_random_generator.c /^size_t ft_random_generator(size_t start, size_t stop)$/;" f typeref:typename:size_t
|
|
||||||
ft_remove_infile infile.c /^static int ft_remove_infile(char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_remove_outfile outfile.c /^static int ft_remove_outfile(char *line)$/;" f typeref:typename:int file:
|
|
||||||
ft_seglen libftx/libft/ft_split.c /^static size_t ft_seglen(const char *s, char c)$/;" f typeref:typename:size_t file:
|
|
||||||
ft_seglen_quoted utils/ft_split_quoted.c /^size_t ft_seglen_quoted(const char *str, char c)$/;" f typeref:typename:size_t
|
|
||||||
ft_segsplitter libftx/libft/ft_split.c /^static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)$/;" f typeref:typename:char ** file:
|
|
||||||
ft_segsplitter utils/ft_split_quoted.c /^static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)$/;" f typeref:typename:char ** file:
|
|
||||||
ft_skipflag libftx/printf/ft_skipflag.c /^int ft_skipflag(const char *str)$/;" f typeref:typename:int
|
|
||||||
ft_space_simplifier spacer.c /^static void ft_space_simplifier(char *str)$/;" f typeref:typename:void file:
|
|
||||||
ft_spacer_after spacer.c /^static char *ft_spacer_after(const char *str)$/;" f typeref:typename:char * file:
|
|
||||||
ft_spacer_before spacer.c /^static char *ft_spacer_before(const char *str)$/;" f typeref:typename:char * file:
|
|
||||||
ft_special_char_dub syntatics.c /^static int ft_special_char_dub(const char *str)$/;" f typeref:typename:int file:
|
|
||||||
ft_split libftx/libft/ft_split.c /^char **ft_split(const char *s, char c)$/;" f typeref:typename:char **
|
|
||||||
ft_split_quoted utils/ft_split_quoted.c /^char **ft_split_quoted(const char *s, char c)$/;" f typeref:typename:char **
|
|
||||||
ft_str_is_empty utils/ft_str_is_empty.c /^int ft_str_is_empty(const char *str)$/;" f typeref:typename:int
|
|
||||||
ft_str_size libftx/extra/ft_ultoa_base.c /^static size_t ft_str_size(unsigned long long n, size_t base_size)$/;" f typeref:typename:size_t file:
|
|
||||||
ft_str_size libftx/printf/ft_dprintul_base.c /^static size_t ft_str_size(unsigned long long n, size_t base_size)$/;" f typeref:typename:size_t file:
|
|
||||||
ft_strchr libftx/libft/ft_strchr.c /^char *ft_strchr(const char *s, int c)$/;" f typeref:typename:char *
|
|
||||||
ft_strchri libftx/extra/ft_strchri.c /^ssize_t ft_strchri(char *str, char c)$/;" f typeref:typename:ssize_t
|
|
||||||
ft_strcmp libftx/extra/ft_strcmp.c /^int ft_strcmp(char *s1, char *s2)$/;" f typeref:typename:int
|
|
||||||
ft_strdup libftx/libft/ft_strdup.c /^char *ft_strdup(const char *s)$/;" f typeref:typename:char *
|
|
||||||
ft_strfjoin libftx/extra/ft_strfjoin.c /^char *ft_strfjoin(char *s1, char *s2)$/;" f typeref:typename:char *
|
|
||||||
ft_strgen libftx/extra/ft_strgen.c /^char *ft_strgen(char c, size_t len)$/;" f typeref:typename:char *
|
|
||||||
ft_striteri libftx/libft/ft_striteri.c /^void ft_striteri(char *s, void (*f)(unsigned int, char *))$/;" f typeref:typename:void
|
|
||||||
ft_strjoin libftx/libft/ft_strjoin.c /^char *ft_strjoin(const char *s1, const char *s2)$/;" f typeref:typename:char *
|
|
||||||
ft_strlcat libftx/libft/ft_strlcat.c /^size_t ft_strlcat(char *dest, const char *src, size_t size)$/;" f typeref:typename:size_t
|
|
||||||
ft_strlcpy libftx/libft/ft_strlcpy.c /^size_t ft_strlcpy(char *dst, const char *src, size_t size)$/;" f typeref:typename:size_t
|
|
||||||
ft_strlen libftx/libft/ft_strlen.c /^size_t ft_strlen(const char *s)$/;" f typeref:typename:size_t
|
|
||||||
ft_strlen libftx/printf/ft_strlen.c /^size_t ft_strlen(const char *s)$/;" f typeref:typename:size_t
|
|
||||||
ft_strmapi libftx/libft/ft_strmapi.c /^char *ft_strmapi(char const *s, char (*f)(unsigned int, char))$/;" f typeref:typename:char *
|
|
||||||
ft_strmerger libftx/extra/ft_strmerger.c /^char *ft_strmerger(size_t arg_len, ...)$/;" f typeref:typename:char *
|
|
||||||
ft_strnchr utils/ft_strnchr.c /^ssize_t ft_strnchr(const char *str, char c)$/;" f typeref:typename:ssize_t
|
|
||||||
ft_strncmp libftx/libft/ft_strncmp.c /^int ft_strncmp(const char *s1, const char *s2, size_t n)$/;" f typeref:typename:int
|
|
||||||
ft_strncpy utils/ft_strncpy.c /^size_t ft_strncpy(char *dst, const char *src, size_t n)$/;" f typeref:typename:size_t
|
|
||||||
ft_strndup libftx/extra/ft_strndup.c /^char *ft_strndup(const char *src, size_t n)$/;" f typeref:typename:char *
|
|
||||||
ft_strnstr libftx/libft/ft_strnstr.c /^char *ft_strnstr(const char *big, const char *little, size_t len)$/;" f typeref:typename:char *
|
|
||||||
ft_strrchr libftx/libft/ft_strrchr.c /^char *ft_strrchr(const char *s, int c)$/;" f typeref:typename:char *
|
|
||||||
ft_strreplace utils/ft_strreplace.c /^char *ft_strreplace(const char *str, const char *fill,$/;" f typeref:typename:char *
|
|
||||||
ft_strshift utils/ft_strshift.c /^void ft_strshift(char *str, int shift)$/;" f typeref:typename:void
|
|
||||||
ft_strtrim libftx/libft/ft_strtrim.c /^char *ft_strtrim(const char *s1, const char *set)$/;" f typeref:typename:char *
|
|
||||||
ft_substr libftx/libft/ft_substr.c /^char *ft_substr(char const *s, unsigned int start, size_t len)$/;" f typeref:typename:char *
|
|
||||||
ft_swap libftx/extra/ft_swap.c /^void ft_swap(void *a, void *b)$/;" f typeref:typename:void
|
|
||||||
ft_swap_char libftx/extra/ft_swap.c /^void ft_swap_char(char *a, char *b)$/;" f typeref:typename:void
|
|
||||||
ft_swap_int libftx/extra/ft_swap.c /^void ft_swap_int(int *a, int *b)$/;" f typeref:typename:void
|
|
||||||
ft_syntatic_verif syntatics.c /^int ft_syntatic_verif(t_data *data, const char *str)$/;" f typeref:typename:int
|
|
||||||
ft_tabrealloc libftx/extra/ft_tabrealloc.c /^char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size)$/;" f typeref:typename:char **
|
|
||||||
ft_tolower libftx/libft/ft_tolower.c /^int ft_tolower(int c)$/;" f typeref:typename:int
|
|
||||||
ft_toupper libftx/libft/ft_toupper.c /^int ft_toupper(int c)$/;" f typeref:typename:int
|
|
||||||
ft_ultoa_base libftx/extra/ft_ultoa_base.c /^char *ft_ultoa_base(unsigned long long n, char *base)$/;" f typeref:typename:char *
|
|
||||||
ft_vdprintf libftx/printf/ft_vdprintf.c /^int ft_vdprintf(int fd, const char *format, va_list va)$/;" f typeref:typename:int
|
|
||||||
get_index env2.c /^int get_index(char *s, char c)$/;" f typeref:typename:int
|
|
||||||
get_key env3.c /^char *get_key(char *str)$/;" f typeref:typename:char *
|
|
||||||
get_next_line libftx/gnl/get_next_line.c /^char *get_next_line(int fd)$/;" f typeref:typename:char *
|
|
||||||
get_pwd builtins/pwd.c /^char *get_pwd(int fd)$/;" f typeref:typename:char *
|
|
||||||
get_value env3.c /^char *get_value(char *str)$/;" f typeref:typename:char *
|
|
||||||
get_value_by_key env.c /^char *get_value_by_key(char *key, t_list **head)$/;" f typeref:typename:char *
|
|
||||||
init_env env.c /^t_list **init_env(char **env)$/;" f typeref:typename:t_list **
|
|
||||||
is_space builtins/echo.c /^int is_space(char c)$/;" f typeref:typename:int
|
|
||||||
key minishell.h /^ char *key;$/;" m struct:s_env typeref:typename:char *
|
|
||||||
main main.c /^int main(int ac, char **av, char **env)$/;" f typeref:typename:int
|
|
||||||
main minishell_tester/test_files/loop.c /^int main(int argc, char const *argv[])$/;" f typeref:typename:int
|
|
||||||
move_folder builtins/cd.c /^int move_folder(char *path, int fd)$/;" f typeref:typename:int
|
|
||||||
next libftx/libft/libft.h /^ struct s_list *next;$/;" m struct:s_list typeref:struct:s_list *
|
|
||||||
next libftx/libftx.h /^ struct s_list *next;$/;" m struct:s_list typeref:struct:s_list *
|
|
||||||
possible_key env3.c /^int possible_key(char *key)$/;" f typeref:typename:int
|
|
||||||
print_env builtins/env.c /^int print_env(t_list **env, int fd)$/;" f typeref:typename:int
|
|
||||||
print_export builtins/export.c /^void print_export(t_list **env, int fd)$/;" f typeref:typename:void
|
|
||||||
pwd builtins/pwd.c /^int pwd(int fd)$/;" f typeref:typename:int
|
|
||||||
s_cmd minishell.h /^typedef struct s_cmd$/;" s
|
|
||||||
s_data minishell.h /^typedef struct s_data$/;" s
|
|
||||||
s_env minishell.h /^typedef struct s_env$/;" s
|
|
||||||
s_list libftx/libft/libft.h /^typedef struct s_list$/;" s
|
|
||||||
s_list libftx/libftx.h /^typedef struct s_list$/;" s
|
|
||||||
set_value_by_key env.c /^int set_value_by_key(char *key, char *value, t_list **head)$/;" f typeref:typename:int
|
|
||||||
swap_env env2.c /^void swap_env(void **a, void **b)$/;" f typeref:typename:void
|
|
||||||
swap_env_3 env2.c /^void swap_env_3(void **a, void **b, void **c)$/;" f typeref:typename:void
|
|
||||||
t_cmd minishell.h /^} t_cmd;$/;" t typeref:struct:s_cmd
|
|
||||||
t_data minishell.h /^} t_data;$/;" t typeref:struct:s_data
|
|
||||||
t_env minishell.h /^} t_env;$/;" t typeref:struct:s_env
|
|
||||||
t_list libftx/libft/libft.h /^} t_list;$/;" t typeref:struct:s_list
|
|
||||||
t_list libftx/libftx.h /^} t_list;$/;" t typeref:struct:s_list
|
|
||||||
unset builtins/unset.c /^int unset(t_list **env, char **args, int fd)$/;" f typeref:typename:int
|
|
||||||
value minishell.h /^ char *value;$/;" m struct:s_env typeref:typename:char *
|
|
40
utils/fd.c
Normal file
40
utils/fd.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:39:58 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/03/29 18:51:58 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "./utils.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void ft_closer(int fds[2])
|
||||||
|
{
|
||||||
|
if (fds[0] > 2)
|
||||||
|
{
|
||||||
|
close(fds[0]);
|
||||||
|
}
|
||||||
|
if (fds[1] > 2)
|
||||||
|
{
|
||||||
|
close(fds[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_mega_closer(int fds1[2], int fds2[2])
|
||||||
|
{
|
||||||
|
ft_closer(fds1);
|
||||||
|
ft_closer(fds2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_add_fd(int fds[2], int fd)
|
||||||
|
{
|
||||||
|
if (fds[0] == -1)
|
||||||
|
fds[0] = fd;
|
||||||
|
else
|
||||||
|
fds[1] = fd;
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/28 13:52:13 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/04 13:40:43 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ static int ft_isspace(char c)
|
|||||||
|
|
||||||
int ft_atoi_check(const char *nptr)
|
int ft_atoi_check(const char *nptr)
|
||||||
{
|
{
|
||||||
long result;
|
int64_t result;
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
while (ft_isspace(*nptr))
|
while (ft_isspace(*nptr))
|
||||||
@ -37,9 +37,9 @@ int ft_atoi_check(const char *nptr)
|
|||||||
result = 0;
|
result = 0;
|
||||||
while (*nptr >= '0' && *nptr <= '9')
|
while (*nptr >= '0' && *nptr <= '9')
|
||||||
{
|
{
|
||||||
result = result * 10 + *nptr++ - '0';
|
result = result * 10 + (*nptr++ - '0') * sign;
|
||||||
if ((result > 2147483647 && sign == 1)
|
if ((result < 0 && sign == 1)
|
||||||
|| (result > 2147483647 && sign == 1))
|
|| (result > 0 && sign == -1))
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
if (*nptr--)
|
if (*nptr--)
|
||||||
|
@ -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);
|
||||||
|
115
utils/ft_get_executable.c
Normal file
115
utils/ft_get_executable.c
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_get_executable.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/04/05 15:09:29 by alouis-j ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "./utils.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
char *ft_get_executable_with_path(t_data *data, const char *name)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (access(name, F_OK) != 0)
|
||||||
|
{
|
||||||
|
*data->exit_code = 127;
|
||||||
|
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("bozoshell: %s: permission denied\n", name);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
path = ft_strdup(name);
|
||||||
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char **ft_get_paths(t_data *data, const char *name)
|
||||||
|
{
|
||||||
|
char *paths;
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
paths = get_value_by_key("PATH", data->env);
|
||||||
|
if (paths == NULL)
|
||||||
|
{
|
||||||
|
*data->exit_code = 127;
|
||||||
|
ft_eprintf("bozoshell: %s: command not found\n", name);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
tab = ft_split(paths, ':');
|
||||||
|
if (tab == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *ft_file_is_executable(const char *path, const char *name)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
out = ft_strmerger(3, path, "/", name);
|
||||||
|
if (out == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
free(out);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (access(out, X_OK) == 0)
|
||||||
|
return (out);
|
||||||
|
free(out);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *ft_get_executable_without_path(t_data *data, const char *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_file_is_executable(paths[i], name);
|
||||||
|
if (path != NULL)
|
||||||
|
break ;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ft_freer_tab_ultimate(1, paths);
|
||||||
|
if (path == NULL)
|
||||||
|
{
|
||||||
|
*data->exit_code = 127;
|
||||||
|
ft_eprintf("bozoshell: %s: command not found\n", name);
|
||||||
|
}
|
||||||
|
return (path);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_get_executable(t_data *data, const char *name)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (name[0] == '.' || name[0] == '/')
|
||||||
|
path = ft_get_executable_with_path(data, name);
|
||||||
|
else
|
||||||
|
path = ft_get_executable_without_path(data, name);
|
||||||
|
return (path);
|
||||||
|
}
|
Binary file not shown.
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_is_in_quote.c :+: :+: :+: */
|
/* ft_is_in_quote.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
|
/* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/21 23:08:10 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/30 15:52:10 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,26 +14,27 @@
|
|||||||
|
|
||||||
int ft_is_in_quote(const char *str, size_t n)
|
int ft_is_in_quote(const char *str, size_t n)
|
||||||
{
|
{
|
||||||
size_t double_quoted;
|
|
||||||
size_t simple_quoted;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
ssize_t start;
|
||||||
|
|
||||||
double_quoted = 0;
|
start = -1;
|
||||||
simple_quoted = 0;
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] != '\0' && i < n)
|
while (str[i] != '\0')
|
||||||
{
|
{
|
||||||
if (str[i] == '"')
|
if (i == n)
|
||||||
|
break ;
|
||||||
|
if (str[i] == '\"' || str[i] == '\'')
|
||||||
{
|
{
|
||||||
if (simple_quoted == 0)
|
if (start == -1)
|
||||||
double_quoted = !double_quoted;
|
start = i;
|
||||||
}
|
else if (str[i] == str[start])
|
||||||
else if (str[i] == '\'')
|
start = -1;
|
||||||
{
|
|
||||||
if (double_quoted == 0)
|
|
||||||
simple_quoted = !simple_quoted;
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (simple_quoted + double_quoted * 2);
|
if (start == -1)
|
||||||
|
return (0);
|
||||||
|
if (str[start] == '\'')
|
||||||
|
return (1);
|
||||||
|
return (2);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -6,12 +6,20 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
static void ft_remove_quote_and_reset(char *str, ssize_t *start, ssize_t *stop)
|
||||||
|
{
|
||||||
|
ft_strshift(str + *start, -1);
|
||||||
|
ft_strshift(str + *stop - 1, -1);
|
||||||
|
*start = -1;
|
||||||
|
*stop = -1;
|
||||||
|
}
|
||||||
|
|
||||||
char *ft_quote_remover(char *str)
|
char *ft_quote_remover(char *str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -32,11 +40,8 @@ char *ft_quote_remover(char *str)
|
|||||||
}
|
}
|
||||||
if (stop != -1)
|
if (stop != -1)
|
||||||
{
|
{
|
||||||
ft_strshift(str + start, -1);
|
ft_remove_quote_and_reset(str, &start, &stop);
|
||||||
ft_strshift(str + stop - 1, -1);
|
i = i - 1;
|
||||||
start = -1;
|
|
||||||
stop = -1;
|
|
||||||
i = i - 2;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i++;
|
i++;
|
||||||
|
90
utils/ft_split_charset_quoted.c
Normal file
90
utils/ft_split_charset_quoted.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split_charset_quoted.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
int new_strs(char ***strs, const char *to_split, int *i, int *j)
|
||||||
|
{
|
||||||
|
if (ft_strlen((*strs)[(*i)]) <= 0)
|
||||||
|
return (0);
|
||||||
|
(*i)++;
|
||||||
|
(*j) = 0;
|
||||||
|
(*strs)[(*i)] = ft_calloc(sizeof(char),
|
||||||
|
(ft_strlen(to_split) + 1));
|
||||||
|
if (!(*strs)[(*i)])
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
check = 0;
|
||||||
|
if (new_strs(strs, to_split, i, &j))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
strs = ft_calloc(sizeof(char *), (ft_strlen(to_split) + 1));
|
||||||
|
if (!strs)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
strs[0] = ft_calloc(sizeof(char), (ft_strlen(to_split) + 1));
|
||||||
|
if (!strs[0])
|
||||||
|
{
|
||||||
|
free(strs);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (get_strs(to_split, charset, &strs, &i))
|
||||||
|
{
|
||||||
|
i = -1;
|
||||||
|
while (strs[++i])
|
||||||
|
free(strs[i]);
|
||||||
|
free(strs);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
free_set_null(&strs, i);
|
||||||
|
return (strs);
|
||||||
|
}
|
@ -1,75 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split_quoted.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/15 14:25:56 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
size_t ft_seglen_quoted(const char *str, char c)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
i = 0;
|
|
||||||
while (str[i] != 0)
|
|
||||||
{
|
|
||||||
while ((str[i] == c || ft_is_in_quote(str, i)) && str[i] != 0)
|
|
||||||
i++;
|
|
||||||
if (str[i] != 0)
|
|
||||||
len++;
|
|
||||||
while ((str[i] != c || ft_is_in_quote(str, i)) && str[i] != 0)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
|
|
||||||
{
|
|
||||||
size_t tab_index;
|
|
||||||
size_t let_i;
|
|
||||||
size_t start;
|
|
||||||
|
|
||||||
tab_index = 0;
|
|
||||||
let_i = 0;
|
|
||||||
start = 0;
|
|
||||||
if (tab == NULL || s == NULL)
|
|
||||||
return (NULL);
|
|
||||||
while (tab_index < len)
|
|
||||||
{
|
|
||||||
while ((s[let_i] == c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
|
|
||||||
let_i++;
|
|
||||||
start = let_i;
|
|
||||||
while ((s[let_i] != c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
|
|
||||||
let_i++;
|
|
||||||
tab[tab_index] = ft_substr(s, start, let_i - start);
|
|
||||||
if (tab[tab_index] == NULL)
|
|
||||||
return (ft_cancel((void *)tab, tab_index));
|
|
||||||
tab_index++;
|
|
||||||
}
|
|
||||||
return (tab);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split_quoted(const char *s, char c)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
if (s == NULL)
|
|
||||||
return (NULL);
|
|
||||||
len = ft_seglen_quoted(s, c);
|
|
||||||
tab = malloc((len + 1) * sizeof(char *));
|
|
||||||
if (tab == NULL)
|
|
||||||
return (NULL);
|
|
||||||
tab[len] = NULL;
|
|
||||||
if (ft_segsplitter(tab, len, s, c) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return (tab);
|
|
||||||
}
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/16 16:13:47 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/11 16:55:16 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,8 @@
|
|||||||
# define UTILS_H
|
# define UTILS_H
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
|
# include "../data/data.h"
|
||||||
|
# include "../env/env.h"
|
||||||
|
|
||||||
size_t ft_strncpy(char *dst, const char *src, size_t n);
|
size_t ft_strncpy(char *dst, const char *src, size_t n);
|
||||||
int ft_is_in_quote(const char *str, size_t n);
|
int ft_is_in_quote(const char *str, size_t n);
|
||||||
@ -22,9 +24,13 @@ char *ft_strreplace(const char *str, const char *fill,
|
|||||||
ssize_t ft_strnchr(const char *str, char c);
|
ssize_t ft_strnchr(const char *str, char c);
|
||||||
char *ft_getstr(const char *str, size_t n);
|
char *ft_getstr(const char *str, size_t n);
|
||||||
int ft_str_is_empty(const char *str);
|
int ft_str_is_empty(const char *str);
|
||||||
char **ft_split_quoted(const char *s, char c);
|
char **ft_split_charset_quoted(const char *s, const char *charset);
|
||||||
void ft_strshift(char *str, int shift);
|
void ft_strshift(char *str, int shift);
|
||||||
char *ft_quote_remover(char *str);
|
char *ft_quote_remover(char *str);
|
||||||
int ft_atoi_check(const char *nptr);
|
int ft_atoi_check(const char *nptr);
|
||||||
|
char *ft_get_executable(t_data *data, const char *name);
|
||||||
|
void ft_closer(int fds[2]);
|
||||||
|
void ft_mega_closer(int fds1[2], int fds2[2]);
|
||||||
|
void ft_add_fd(int fds[2], int fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user