Compare commits

..

94 Commits

Author SHA1 Message Date
e7f8373b4a c la merde 2023-02-28 15:21:47 +01:00
9cbb1e139a Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:57:25 +01:00
06f6308bc4 merge 2023-02-28 14:57:16 +01:00
8ea2e6c620 SAL NEGRO 2023-02-28 14:56:28 +01:00
b2c7013cf9 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:55:18 +01:00
960daa8658 HITLER 2023-02-28 14:54:57 +01:00
7f4fd9d421 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:54:15 +01:00
da75bdbf72 SIEG HIEL 2023-02-28 14:53:56 +01:00
af7336fbf3 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:52:16 +01:00
00dc583ff8 卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍 2023-02-28 14:51:39 +01:00
4342d9a015 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:41:28 +01:00
46d30864ed MON GROS SEXE DANS LE CUL D'IDEFIXXX 2023-02-28 14:40:51 +01:00
e0e329a355 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:36:36 +01:00
6e0d7288e8 ESGIbdurifjjkigjikdthijir 2023-02-28 14:36:07 +01:00
5541a1f3fe Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:29:22 +01:00
d5eb265a3f PAS PAR LES FESSESESESESESESESESE 2023-02-28 14:28:54 +01:00
b914753c47 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 14:25:41 +01:00
5948237aad OBELIX: MAIS ASTERIX ARRETE TOUT DE SUITE 2023-02-28 14:25:20 +01:00
9a5cca3e2d Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 13:20:25 +01:00
00e570d92e IDEFIX: 'OUAFA FEJISGNNOE GSEJG SE GSKNLGSNKENE PAS PAR LES FESSES' 2023-02-28 13:19:52 +01:00
77620211da Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-28 13:17:31 +01:00
07bc37cc71 fix 2023-02-28 13:17:26 +01:00
ed546f5a8d ASTERIX IL SUCE IDEFIX DANS LES CHIOTTES 2023-02-28 13:16:10 +01:00
ca18dd4205 fix: execute own builtin 2023-02-28 13:10:02 +01:00
370e5149d5 core: exit_code work ? 2023-02-24 20:30:01 +01:00
fc82eefd7b fix: issue #3 2023-02-24 15:53:46 +01:00
51f892350a fix: bug bizarre 2023-02-24 15:51:12 +01:00
0941f3a370 fix: no command but one redirection crash 2023-02-24 13:25:29 +01:00
9f0b0f5422 add: exit cmd 2023-02-24 13:13:11 +01:00
3d66fbe9a9 NIQUE TA GROSSE MÈRE LA SALOPE PUTE PUTE -Camille Chauvet 2004/2023 2023-02-24 12:46:02 +01:00
1626424ed7 fix: main.c compile with clang 2023-02-24 11:16:35 +01:00
8e22eb210a fix: now is clang 2023-02-24 11:01:57 +01:00
57be71a168 fix: infile 2023-02-23 18:05:21 +01:00
0327d0f5d7 core: heredocs is now forked to prepare signal 2023-02-23 18:03:22 +01:00
2f386686c6 SAMANTHA EST CHAUDE 2023-02-23 17:19:25 +01:00
7728ded62d fix: empty line is now not add to the history 2023-02-23 15:21:06 +01:00
405c1937cd fix 2023-02-23 15:14:08 +01:00
b98717ae1a execution fix 2023-02-23 15:12:41 +01:00
413d75b94c Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-23 13:38:03 +01:00
4f66624667 Oubli 2023-02-23 13:37:50 +01:00
f31d805d83 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-23 13:37:42 +01:00
28fedfdd75 merge 2023-02-23 13:37:26 +01:00
0661f2fbd1 Je suis tout dur façe a Samantha 2023-02-23 13:36:26 +01:00
29a4a864c3 Bozo3 avance 2023-02-22 14:00:09 +01:00
cdde24f0d0 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-22 13:24:50 +01:00
a4befa5fa6 Finito Echo 2023-02-22 13:24:35 +01:00
94f48602d1 add: add ctrl + C support, but not work in heredoc 2023-02-22 00:26:32 +01:00
2b66ce5bc3 fix: "'''" 2023-02-21 23:55:32 +01:00
f346c5c2ce merge 2023-02-21 23:31:16 +01:00
9ace235831 teesgdmbklvr 2023-02-21 23:29:56 +01:00
4e92c03637 tetgs 2023-02-21 23:28:37 +01:00
76bc8fbfd8 fix: quoted split work now 2023-02-21 23:12:16 +01:00
916f2c3c50 fix: close fd 2023-02-21 22:38:00 +01:00
89c80e9bdb .......................prout 2023-02-21 22:26:45 +01:00
eb4a8ed663 merge 2023-02-21 22:13:08 +01:00
3fb6eb65a8 add: exitcode 2023-02-21 22:12:23 +01:00
1fdc51a668 OUAF OUAF OUAF OUAF OUAF BOUGNOUL 2023-02-21 22:10:40 +01:00
03a2cc055c Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-21 16:03:18 +01:00
a136a66522 echo.c 2023-02-21 16:03:08 +01:00
0ece156b97 fix: use own echo 2023-02-21 15:46:21 +01:00
4c45a2c603 deux tours ont despawn dans les backrooms le 11 septembres 2023-02-21 15:44:43 +01:00
b40762478a ARABIE AHLAWAKBAR 2023-02-21 15:42:05 +01:00
d7032849d6 fix: minishell rework 2023-02-21 15:32:22 +01:00
a20fa2a4c6 fix: add '\n' pwd 2023-02-21 15:12:26 +01:00
255892e12e fix: use builtin 2023-02-21 15:07:14 +01:00
96de7639cd Terrifiant Camille, par contre ses grosses fessses MIAM 2023-02-21 14:52:58 +01:00
17ece4bc7b problème de 2023-02-21 14:49:42 +01:00
73899f5905 J'ai fais des trucs pas comme toi bozo 2023-02-21 14:45:43 +01:00
373629b541 clean: norme 2023-02-21 14:38:09 +01:00
5caeed312c fix: leak 2023-02-21 14:37:41 +01:00
5e0ae80404 add: builtin makefile 2023-02-21 14:37:10 +01:00
69d6ac533b fix: add prototype create_value_by_key_dup 2023-02-21 14:36:20 +01:00
73d1f11269 clean: norm 2023-02-21 14:35:08 +01:00
e8deb0be19 fix: leak '0' creation 2023-02-21 14:34:49 +01:00
ca09c8ed26 Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell 2023-02-21 13:45:06 +01:00
3682d0a348 NIQUE TA GROSSE MERE CAMILLE 2023-02-21 13:44:51 +01:00
e2a40e07fc add: ft_dprintf 2023-02-21 13:28:45 +01:00
cfd1dffbcf fix: minishell.h 2023-02-21 13:22:50 +01:00
55e378e2cb fix: minishell.h 2023-02-21 13:21:20 +01:00
fb8186ac78 OUAF OUAF OUAF CORRECTION MINISHELL.H 2023-02-21 13:15:58 +01:00
3ef58c0116 OUAF OUAF OUAF OUAF OUAF MINISHELL.H 2023-02-21 13:14:58 +01:00
cc74fda339 fix: '$' variable 2023-02-20 15:41:03 +01:00
7eedf74847 infile fix 2023-02-20 13:08:01 +01:00
c75c6838d6 clean 2023-02-17 19:05:33 +01:00
4b5a50d7fe fix: outfile is now perfectly removed 2023-02-17 18:51:27 +01:00
922db1e08f fix: quote remover 2023-02-17 18:28:06 +01:00
e709eb0dbb norm 2023-02-17 18:24:24 +01:00
3ce5b64420 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-17 18:23:26 +01:00
a183971a7a bozo 2023-02-17 18:23:17 +01:00
5175073708 SBEUB SBEUB ARABE 2023-02-17 17:46:12 +01:00
72f9dd39cf enlève le main dans pwd.c 2023-02-17 16:56:02 +01:00
8bd58675e9 Ajout Pwd et dans le .h 2023-02-17 16:54:58 +01:00
afd71e5ed8 Merge branch 'master' of git.chauvet.pro:starnakin/minishell 2023-02-17 16:44:04 +01:00
d59562899b Ajout de Echo, a voir si il y a des bugs 2023-02-17 16:03:28 +01:00
39 changed files with 1373 additions and 385 deletions

View File

@ -1,11 +1,11 @@
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
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c env_fill.c
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
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
OBJS = ${SRCS:.c=.o}
NAME = minishell
CC = gcc
CC = clang
CFLAGS = -Werror -Wextra -g

64
builtins/cd.c Normal file
View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
/* Updated: 2023/02/28 13:37:18 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int move_folder(char **args, int fd)
{
char *join;
char *path;
if (args[1] != NULL)
{
write(2, "cd: too many argument", 22);
return (1);
}
path = args[0];
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
{
if (chdir(path) == 0)
return (0);
write(2, "No suck file or directory", 25);
return (1);
}
else
{
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;
}*/

61
builtins/echo.c Normal file
View File

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
/* Updated: 2023/02/22 13:23:16 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int is_space(char c)
{
return (c == ' ' || c == '\f' || c == '\v' || c == '\t'
|| c == '\r' || c == '\n');
}
int check_argument(char *str, int *check)
{
int i;
i = -1;
while (str[++i])
if (str[i] != '-' && str[i] != 'n')
return (1);
if (ft_strnstr(str, "n", ft_strlen(str)))
*check = 1;
return (0);
}
int echo(int fd, char **strs)
{
int check;
int i;
check = 0;
i = -1;
while (strs[++i])
{
while (is_space(*strs[i]))
strs[i]++;
if (check == 1 || check_argument(strs[i], &check))
{
ft_putstr_fd(strs[i], fd);
if (strs[i + 1] != NULL)
write(fd, " ", 1);
}
}
if (!check)
write(fd, "\n", 1);
return (0);
}
/*int main(int argc, char *argv[])
{
echo(1, argv + 1);
return (0);
}*/

View File

@ -6,21 +6,33 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
/* Updated: 2023/02/14 14:58:40 by cchauvet ### ########.fr */
/* Updated: 2023/02/23 16:50:01 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int main(char **env)
int print_env(t_list **env, int fd)
{
t_list **head;
t_list *current;
while (current != NULL)
current = *env;
while (current->next != NULL)
{
ft_putendl_fd(1, current->content);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\n", 1);
current = current->next;
}
return (0);
}
/*int main(int argc, char *argv[], char **env)
{
t_list **be;
be = init_env(env);
print_env(be, 1);
return (0);
}*/

47
builtins/exit.c Normal file
View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
/* Updated: 2023/02/28 14:55:39 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
static int error(int err, char *reason, char *problem)
{
ft_putstr_fd("minishell: exit ", 2);
if (problem != NULL)
{
ft_putstr_fd(problem, 2);
write(2, ": ", 3);
}
ft_putstr_fd(reason, 2);
return (err);
}
int ft_exit(char **args)
{
int err;
if (args[0] == NULL)
return (0);
err = ft_atoi_check(args[0]);
if (err == 1)
return (error(err, "numeric argument required", args[0]));
if (args[1] != NULL)
return (error(-1, "too many arguments", NULL));
if (err > 0)
return(error(err, "numeric argument required", args[0]));
return ((ft_atoi(args[0]) % 256 + 256) % 256);
}
/*int main(int argc, char *argv[])
{
(void)argc;
return(ft_exit(argv + 1, 1));
}*/

94
builtins/export.c Normal file
View File

@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/02/28 14:37:38 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
static int error(char *str, int fd)
{
write(fd, "bash: export: `", 15);
write(fd, str, ft_strlen(str));
write(fd, "': not a valid identifier\n", 26);
return (1);
}
void print_export(t_list **env, int fd)
{
t_list *current;
current = *env;
while (current->next != NULL)
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
current = current->next;
}
}
int add_export(t_list **env, char *args, int fd, int *err)
{
char *key;
char *value;
key = args;
value = "";
if (ft_strchr(args, '=') != NULL)
{
key = ft_strndup(args, ft_strnchr(args, '='));
if (key == NULL)
return (1);
if (ft_strlen(key) == 0)
{
error(args, fd);
return (1);
}
value = ft_strchr(args, '=') + 1;
}
if (!possible_key(key))
{
*err = error(key, fd);
return (1);
}
create_value_by_key_dup(key, value, env);
return (0);
}
int export(t_list **env, char **args, int fd)
{
int err;
int i;
err = 0;
if (args[0] == NULL)
print_export(env, fd);
else
{
i = -1;
while (args[++i])
if (add_export(env, args[i], fd, &err) == 1)
err = 1;
}
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);
}*/

41
builtins/pwd.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
/* Updated: 2023/02/21 15:11:38 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int pwd(int fd)
{
char path[PATH_MAX];
if (getcwd(path, sizeof(path)) != NULL)
ft_putendl_fd(path, fd);
else
{
ft_putendl_fd("Error getcwd", fd);
return (1);
}
return (0);
}
char *get_pwd(int fd)
{
char *str;
str = ft_calloc(PATH_MAX, sizeof(char *));
if (getcwd(str, PATH_MAX) != NULL)
return (str);
else
{
ft_putendl_fd("Error getcwd", fd);
return (NULL);
}
}

35
builtins/unset.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int error(char *str, int fd)
{
write(fd, "bash: unset: `", 14);
write(fd, str, ft_strlen(str));
write(fd, "': not a valid identifier", 25);
return (1);
}
int unset(t_list **env, char **args, int fd)
{
int i;
int err;
i = -1;
err = 0;
while (args[++i])
if (delete_by_key(args[i], env))
if (!possible_key(args[i]))
err = error(args[i], fd);
return (err);
}

13
cmd.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
/* Updated: 2023/02/16 18:25:14 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,10 +22,14 @@ void ft_cmddel(void *ptr)
ft_freer_tab_ultimate(1, content->args);
if (content->executable != NULL)
free(content->executable);
if (content->fd_in > 2)
close(content->fd_in);
if (content->fd_out > 2)
close(content->fd_out);
free(content);
}
int ft_cmd_filler(t_list *element, char **args, t_list **env)
int ft_cmd_filler(t_data *data, t_list *element, char **args)
{
t_cmd *content;
char *temp;
@ -37,12 +41,9 @@ int ft_cmd_filler(t_list *element, char **args, t_list **env)
i = 0;
while (args[i] != NULL)
{
temp = ft_env_filler(env, args[i]);
temp = ft_env_filler(data, args[i]);
if (temp == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (1);
}
free(args[i]);
args[i] = temp;
ft_quote_remover(temp);

24
cmds.c
View File

@ -19,7 +19,9 @@ static int ft_cmds_init(t_list **cmds, size_t len)
t_list *current;
size_t i;
*cmds = malloc(sizeof(t_list));
*cmds = NULL;
if (len > 0)
*cmds = malloc(sizeof(t_list));
current = *cmds;
i = 0;
while (i < len)
@ -51,29 +53,27 @@ static int ft_cmds_init(t_list **cmds, size_t len)
static int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile)
{
size_t len;
t_cmd *cmd;
t_list *current;
len = ft_seglen_quoted(line, '|');
if (len == 0)
return (0);
if (ft_cmds_init(cmds, ft_seglen_quoted(line, '|')))
{
free(cmds);
return (1);
}
cmd = (t_cmd *)(*cmds)->content;
cmd->fd_in = infile;
if (*cmds == NULL)
return (0);
current = *cmds;
cmd = current->content;
cmd->fd_in = infile;
while (current->next != NULL)
current = current->next;
cmd = (t_cmd *) current->content;
cmd = current->content;
cmd->fd_out = outfile;
return (0);
}
static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line)
static int ft_cmds_fill(t_data *data, t_list **cmds, const char *line)
{
char **tab;
char **args;
@ -88,7 +88,7 @@ static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line)
while (tab[i] != NULL)
{
args = ft_split_quoted(tab[i], ' ');
if (ft_cmd_filler(current, args, env) == 1)
if (ft_cmd_filler(data, current, args) == 1)
{
ft_lstclear(cmds, ft_cmddel);
ft_freer_tab_ultimate(2, args, tab);
@ -101,14 +101,14 @@ static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line)
return (0);
}
t_list **ft_parse_cmds(char *line, t_list **env, int infile, int outfile)
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(cmds, env, line) == 1)
if (ft_cmds_fill(data, cmds, line) == 1)
return (NULL);
return (cmds);
}

169
env.c
View File

@ -6,154 +6,20 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/17 13:05:29 by erey-bet ### ########.fr */
/* Updated: 2023/02/23 13:34:41 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int get_index(char *s, char c)
{
int i;
i = -1;
while (s[++i])
if (s[i] == c)
return (i);
return (-1);
}
void print_export(t_list **head, int fd)
{
t_list *current;
current = *head;
while (current->next != NULL)
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env*)(current->content))->key, fd);
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env*)(current->content))->value, fd);
write(fd, "\"\n", 2);
current = current->next;
}
}
void print_env(t_list **head, int fd)
{
t_list *current;
current = *head;
while (current->next != NULL)
{
ft_putstr_fd(((t_env*)(current->content))->key, fd);
ft_putstr_fd("=", fd);
ft_putstr_fd(((t_env*)(current->content))->value, fd);
write(fd, "\n", 1);
current = current->next;
}
}
int strcmp_alphabet(char *s1, char *s2)
{
int i;
if (!s1 || !s2)
return (-2);
i = 0;
while (s1[i] && s2[i])
{
if (s1[i] < s2[i])
return (0);
else if (s1[i] > s2[i])
return (1);
i++;
}
return (-1);
}
void ft_double_swap(void *a, void *b)
{
void *c;
c = a;
a = b;
b = c;
}
void exchange(void *a, void *b, void *c)
{
void *d;
d = a;
a = b;
b = c;
c = d;
}
char *get_value(char *str)
{
char *s;
int i;
int start;
s = ft_calloc(ft_strlen(str), sizeof(char));
start = get_index(str, '=');
i = start;
while (str[++i])
s[i - start - 1] = str[i];
return (s);
}
void env_del(void *ptr)
{
t_env *content;
content = ptr;
free(content->key);
free(content->value);
free(content);
}
char *get_key(char *str)
{
char *s;
int i;
s = ft_calloc(ft_strlen(str), sizeof(char));
i = -1;
while (str[++i] != '=')
s[i] = str[i];
return (s);
}
void swap_env_3(void **a, void **b, void **c)
{
void *d;
d = *a;
*a = *b;
*b = *c;
*c = d;
}
void swap_env(void **a, void **b)
{
void *c;
c = *a;
*a = *b;
*b = c;
}
void add_sort(t_list **head, t_env *var)
{
t_list *current;
t_env *last;
current = *head;
while (current->next != NULL && strcmp_alphabet(var->key, ((t_env*)(current->content))->key) != 0)
while (current->next != NULL
&& ft_strcmp(var->key, ((t_env *)(current->content))->key) > 0)
current = current->next;
if (current->content == NULL)
current->content = var;
@ -182,7 +48,7 @@ char *get_value_by_key(char *key, t_list **head)
return (((t_env *)current->content)->value);
current = current->next;
}
return (NULL);
return ("");
}
int set_value_by_key(char *key, char *value, t_list **head)
@ -218,25 +84,6 @@ int create_value_by_key(char *key, char *value, t_list **head)
return (0);
}
char **env_to_strs(t_list **head)
{
t_list *current;
t_env *content;
char **env;
int i;
current = *head;
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
i = 0;
while (current->content)
{
content = current->content;
env[i++] = ft_strmerger(3, content->key, "=", content->value);
current = current->next;
}
return (env);
}
t_list **init_env(char **env)
{
t_list **head;
@ -264,9 +111,11 @@ t_list **init_env(char **env)
/*int main(int argc, char *argv[], char **env)
{
t_list **new;
t_list **n_env;
n_env = init_env(env);
delete_by_key("SSH_AUTH_SOCK", n_env);
print_env(n_env, 1);
new = init_env(env);
ft_printf("%S", env_to_strs(new));
return (0);
}*/

77
env2.c Normal file
View File

@ -0,0 +1,77 @@
/* */
/* ::: :::::::: */
/* env2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 17:22:01 by erey-bet #+# #+# */
/* Updated: 2023/02/17 17:24:57 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
int get_index(char *s, char c)
{
int i;
i = -1;
while (s[++i])
if (s[i] == c)
return (i);
return (-1);
}
void swap_env_3(void **a, void **b, void **c)
{
void *d;
d = *a;
*a = *b;
*b = *c;
*c = d;
}
void swap_env(void **a, void **b)
{
void *c;
c = *a;
*a = *b;
*b = c;
}
void env_del(void *ptr)
{
t_env *content;
if (ptr == NULL)
return ;
content = ptr;
if (content->key != NULL)
free(content->key);
if (content->key != NULL)
free(content->value);
if (content != NULL)
free(content);
}
char **env_to_strs(t_list **head)
{
t_list *current;
t_env *content;
char **env;
int i;
current = *head;
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
i = 0;
while (current->content)
{
content = current->content;
env[i++] = ft_strmerger(3, content->key, "=", content->value);
current = current->next;
}
return (env);
}

98
env3.c Normal file
View File

@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
/* Updated: 2023/02/28 12:46:33 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
char *get_value(char *str)
{
char *s;
int i;
int start;
s = ft_calloc(ft_strlen(str), sizeof(char));
start = get_index(str, '=');
i = start;
while (str[++i])
s[i - start - 1] = str[i];
return (s);
}
char *get_key(char *str)
{
char *s;
int i;
s = ft_calloc(ft_strlen(str), sizeof(char));
i = -1;
while (str[++i] != '=')
s[i] = str[i];
return (s);
}
int create_value_by_key_dup(char *key, char *value, t_list **env)
{
char *key_dup;
char *value_dup;
key_dup = ft_strdup(key);
if (key_dup == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (1);
}
value_dup = ft_strdup(value);
if (value_dup == NULL)
{
free(key);
ft_eprintf("minishell: malloc failed\n");
return (1);
}
if (create_value_by_key(key_dup, value_dup, env))
return (1);
return (0);
}
int delete_by_key(char *key, t_list **head)
{
t_list *last;
t_list *current;
current = *head;
while (current->next != NULL)
{
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
{
if (last->next != NULL)
last->next = current->next;
else
*head = current->next;
return (0);
}
last = current;
current = current->next;
}
return (1);
}
int possible_key(char *key)
{
int i;
i = -1;
if (ft_isdigit(key[i + 1]))
return (0);
while (key[++i])
if (!ft_isalnum(key[i]) && key[i] != '_')
return (0);
return (1);
}

View File

@ -6,37 +6,81 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
/* Updated: 2023/02/17 13:41:51 by cchauvet ### ########.fr */
/* Updated: 2023/02/20 15:39:28 by starnakin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include "utils/utils.h"
static char *ft_get_value(t_list **env, const char *str, size_t start,
size_t stop)
int ft_gen_exit_code_var(t_data *data)
{
char *str;
str = ft_itoa(data->exit_code);
if (str == NULL)
{
ft_printf("minishell: malloc failed");
return (1);
}
data->exit_code_str = str;
return (0);
}
static char *ft_get_value(t_data *data, char *key)
{
char *key;
char *value;
key = ft_strndup(str + start, stop);
if (key == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (NULL);
}
value = get_value_by_key(key, env);
if (key[0] == '\0')
return ("$");
if (ft_strcmp("?", key) == 0)
return (data->exit_code_str);
value = get_value_by_key(key, data->env);
if (value == NULL)
value = "";
free(key);
return (value);
}
char *ft_env_filler(t_list **env, const char *str)
static char *ft_get_key(char *str)
{
char *key;
size_t i;
i = 1;
if (ft_strncmp(str, "$$", 2) == 0)
{
key = ft_strdup("$");
if (key == NULL)
ft_eprintf("minishell: malloc failed\n");
return (key);
}
if (str[i] == ' ' || str[i] == '\0')
{
key = ft_strdup("");
if (key == NULL)
ft_eprintf("minishell: malloc failed\n");
return (key);
}
if (str[i] == '?')
{
key = ft_strdup("?");
if (key == NULL)
ft_eprintf("minishell: malloc failed\n");
return (key);
}
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)
{
size_t i;
size_t y;
char *key;
char *out;
char *temp;
char *value;
@ -54,13 +98,22 @@ char *ft_env_filler(t_list **env, const char *str)
i++;
while (out[i] == '$')
{
y = i + 1;
while (out[y] != '\0' && out[y] != '$' && out[y] != ' ')
y++;
value = ft_get_value(env, out, i + 1, y - i - 1);
if (value == NULL)
key = ft_get_key(out + i);
if (key == NULL)
{
free(out);
return (NULL);
temp = ft_strreplace(out, value, i, y);
}
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)
{

View File

@ -1,15 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 "utils/utils.h"
#include <unistd.h>
static char *ft_get_executable_path(char *executable_name, t_list **env)
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] == '/')
{
@ -27,7 +40,7 @@ static char *ft_get_executable_path(char *executable_name, t_list **env)
}
else
{
tab = ft_split(get_value_by_key("PATH", env), ':');
tab = ft_split(get_value_by_key("PATH", data->env), ':');
if (tab == NULL)
return (NULL);
i = 0;
@ -51,13 +64,14 @@ static char *ft_get_executable_path(char *executable_name, t_list **env)
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_excutor(t_cmd *cmd, t_list **env)
static int ft_executor(t_data *data, t_cmd *cmd)
{
int pid;
int return_value;
@ -70,23 +84,63 @@ static int ft_excutor(t_cmd *cmd, t_list **env)
return (1);
if (pid == 0)
{
tab = env_to_strs(env);
tab = env_to_strs(data->env);
if (tab == NULL)
return (1);
tab = NULL;
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);
}
int ft_cmds_executor(t_list **cmds, t_list **env)
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;
}
else
{
data->exit_code = 1;
return_code = -3;
}
}
if (return_code >= 0)
data->exit_code = return_code;
if (return_code != -1)
cmd->executable = NULL;
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;
@ -103,12 +157,21 @@ int ft_cmds_executor(t_list **cmds, t_list **env)
content->fd_out = fds[1];
((t_cmd *) current->next->content)->fd_in = fds[0];
}
content->executable = ft_get_executable_path(content->executable, env);
if (content->executable != NULL)
ft_excutor(content, env);
if (content->fd_in != 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 != 1 && content->fd_out != 2)
if (content->fd_out > 2)
close(content->fd_out);
current = current->next;
}

View File

@ -12,25 +12,55 @@
#include "libftx/libftx.h"
#include "minishell.h"
#include <stdlib.h>
int ft_heredoc(char *stop)
int *ft_get_heredoc()
{
static int heredoc;
return (&heredoc);
}
int ft_heredoc_creator(char *stop, int fd)
{
int fds[2];
char *line;
pipe(fds);
line = readline("> ");
while (line != NULL)
{
if (ft_strcmp(line, stop) == 0)
{
free(line);
break ;
}
ft_putendl_fd(line, fds[1]);
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]);
}
close(fds[1]);
return (fds[0]);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 17:52:10 by cchauvet #+# #+# */
/* Updated: 2023/02/17 13:19:09 by cchauvet ### ########.fr */
/* Updated: 2023/02/20 13:05:43 by starnakin ### ########.fr */
/* */
/* ************************************************************************** */
@ -86,25 +86,25 @@ static int ft_remove_infile(char *line)
while (tab[i] != NULL)
{
if (tab[i][0] == '<')
{
ft_strshift(line + y, -1 * (ft_strlen(tab[i]) + 1));
i++;
ft_strshift(line + y, -1 * (ft_strlen(tab[i]) + 1));
}
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 = y + ft_strlen(tab[i]) + (y != 0);
i++;
}
ft_freer_tab_ultimate(1, tab);
return (0);
}
int ft_infile(char *line)
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);

View File

@ -36,4 +36,4 @@ fclean: clean
re: fclean all
.PHONY: all bonus clean fclean re
.PHONY: all clean fclean re

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/02/17 16:24:42 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:28:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,8 @@
char *ft_ultoa_base(unsigned long long n, char *base);
int ft_printf(const char *format, ...);
int ft_eprintf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
char *get_next_line(int fd);
size_t ft_random_generator(size_t start, size_t stop);
void ft_freer_tab_ultimate(size_t len, ...);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 22:01:28 by cchauvet #+# #+# */
/* Updated: 2022/10/12 16:34:31 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:27:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,3 +22,14 @@ int ft_printf(const char *format, ...)
va_end(va);
return (i);
}
int ft_dprintf(int fd, const char *format, ...)
{
va_list va;
int i;
va_start(va, format);
i = ft_vdprintf(fd, format, va);
va_end(va);
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
/* Updated: 2023/02/17 16:29:18 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:27:51 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,6 +32,7 @@ int ft_dprintarg(int fd, int c, va_list va);
int ft_dprintstrtab(int fd, char **tab);
int ft_printf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
int ft_eprintf(const char *format, ...);
int ft_vdprintf(int fd, const char *format, va_list va);

141
main.c
View File

@ -6,145 +6,144 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/02/17 16:06:02 by cchauvet ### ########.fr */
/* Updated: 2023/02/24 11:04:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include <readline/readline.h>
static char *ft_get_user_input(t_list **env)
static char *ft_get_user_input()
{
char *line;
char *prompt;
char *pwd;
prompt = ft_strmerger(2, get_value_by_key("PWD", env), "$ ");
pwd = get_pwd(2);
if (pwd == NULL)
return (NULL);
prompt = ft_strmerger(2, pwd, "$ ");
free(pwd);
if (prompt == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (NULL);
}
line = readline(prompt);
add_history(line);
if (line != NULL && ft_strcmp(line, "") != 0)
add_history(line);
free(prompt);
return (line);
}
static int ft_minishell(t_list **env, char *line)
static int ft_minishell(t_data *data, char *line)
{
t_list **cmds;
char *line_clean;
int infile;
int outfile;
if (ft_syntatic_verif(data, line))
return (1);
line_clean = ft_normalizer(line);
if (line_clean == NULL)
return (1);
if (ft_syntatic_verif(line_clean))
{
free(line_clean);
return (1);
}
outfile = ft_outfile(line_clean);
outfile = ft_outfile(data, line_clean);
if (outfile == -2)
{
free(line_clean);
return (1);
}
infile = ft_infile(line_clean);
infile = ft_infile(data, line_clean);
if (infile == -2)
{
close(outfile);
if (outfile > 2)
close(outfile);
free(line_clean);
return (1);
}
cmds = ft_parse_cmds(line_clean, env, infile, outfile);
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)
{
close(outfile);
close(infile);
ft_lstclear(cmds, ft_cmddel);
free(cmds);
free(line_clean);
return (1);
}
if (ft_cmds_executor(cmds, env) == 1)
{
close(outfile);
close(infile);
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);
return (0);
}
#if DEBUG
int main(int ac, char **av, char **env)
void ft_ctrlc(int num)
{
t_data data;
if (ac == 1)
return (1);
data.env = init_env(env);
if (data.env == NULL)
return (1);
free(data.env);
return (1);
}
if (ft_minishell(data.env, av[1]) == 1)
(void) num;
if (*ft_get_heredoc())
{
ft_lstclear(data.env, env_del);
free(data.env);
return (1);
kill(*ft_get_heredoc(), SIGQUIT);
}
else
{
rl_replace_line("", 0);
rl_on_new_line();
ft_putchar_fd('\n', 1);
rl_redisplay();
}
ft_lstclear(data.env, env_del);
free(data.env);
free(line);
return (0);
}
#else
void ft_quit(int num)
{
(void) num;
if (*ft_get_heredoc())
{
ft_printf("pb");
}
else
ft_printf("bozoman");
}
int main(int ac, char **av, char **env)
{
t_data data;
char *line;
(void) ac;
(void) av;
signal(SIGINT, ft_ctrlc);
signal(SIGQUIT, ft_quit);
data.exit_code = 0;
data.env = init_env(env);
if (data.env == NULL)
return (1);
line = ft_get_user_input(data.env);
if (line == NULL)
{
ft_lstclear(data.env, env_del);
free(data.env);
return (1);
}
line = ft_get_user_input();
while (line != NULL)
{
if (ft_minishell(data.env, line) == 1)
{
ft_lstclear(data.env, env_del);
free(data.env);
free(line);
return (1);
}
if (ft_minishell(&data, line) == -1)
break ;
free(line);
line = ft_get_user_input(data.env);
line = ft_get_user_input();
if (line == NULL)
{
ft_lstclear(data.env, env_del);
free(data.env);
return (1);
}
break ;
}
ft_lstclear(data.env, env_del);
free(data.env);
return (data.exit_code);
}
#endif

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/02/17 14:29:56 by cchauvet ### ########.fr */
/* Updated: 2023/02/28 14:55:52 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,31 +19,74 @@
# 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
t_list **init_env(char **env);
int set_value_by_key(char *key, char *value, t_list **env);
char *get_value_by_key(char *key, t_list **head);
int ft_syntatic_verif(const char *str);
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(char *line);
int ft_outfile(char *line);
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_list **cmds, t_list **env);
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(char *line, t_list **env, int infile, int outfile);
int ft_cmd_filler(t_list *current, char **args, t_list **env);
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_list **env, const 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;
@ -52,16 +95,10 @@ typedef struct s_cmd
char **args;
} t_cmd;
typedef struct s_data
{
t_list **env;
int heredoc;
} t_data;
typedef struct s_env
{
void *key;
void *value;
char *key;
char *value;
} t_env;
#endif

1
minishell_tester Submodule

Submodule minishell_tester added at 1c6111b2fd

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 18:01:07 by cchauvet #+# #+# */
/* Updated: 2023/02/17 13:19:46 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 19:03:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -86,24 +86,26 @@ static int ft_remove_outfile(char *line)
{
if (tab[i][0] == '>')
{
ft_strshift(line + y, -1 * (ft_strlen(tab[i]) + 1));
i++;
ft_strshift(line + y, -1 * (ft_strlen(tab[i]) + 1));
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 = y + ft_strlen(tab[i]) + (y != 0);
i++;
}
ft_freer_tab_ultimate(1, tab);
return (0);
}
int ft_outfile(char *line)
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);

View File

@ -30,7 +30,7 @@ static char *ft_spacer_after(const char *str)
i++;
if (ft_is_in("><|", out[i - 1]))
{
while (str[i] == out[i - 1])
while (out[i] == out[i - 1])
i++;
temp = ft_strreplace(out, " ", i, i);
free(out);
@ -38,7 +38,8 @@ static char *ft_spacer_after(const char *str)
if (out == NULL)
return (NULL);
}
i++;
if (out[i] != '\0')
i++;
}
return (out);
}

View File

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntatics.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/02/21 23:40:20 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include "utils/utils.h"
@ -6,7 +18,7 @@ static int ft_quote_verif(const char *str)
{
if (ft_is_in_quote(str, ft_strlen(str)))
{
ft_eprintf("minishell: Quote is note closed");
ft_eprintf("minishell: Quote is not closed\n");
return (1);
}
else
@ -24,6 +36,8 @@ static int ft_pipe_is_alone(const char *str)
{
while (str[i] == ' ')
i++;
while (ft_is_in_quote(str, i))
i++;
if (str[i] == '\0')
break ;
if (str[i] != '|')
@ -66,7 +80,7 @@ static int ft_special_char_dub(const char *str)
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|| (y > 1 && str[i] == '|'))
{
ft_eprintf("minishell: to many %c in a row", str, str[i]);
ft_eprintf("minishell: too many %c in a row\n", str, str[i]);
return (1);
}
i = i + y;
@ -84,15 +98,18 @@ int ft_empty_verif(const char *str)
i = 0;
while (str[i] == ' ')
i++;
if (str[i] == '\0')
ft_eprintf("minishell: %s: command not found \n", str);
return (str[i] == '\0');
}
int ft_syntatic_verif(const char *str)
int ft_syntatic_verif(t_data *data, const char *str)
{
return (ft_quote_verif(str)
if (ft_quote_verif(str)
|| ft_empty_verif(str)
|| ft_pipe_is_alone(str)
|| ft_special_char_dub(str));
|| ft_special_char_dub(str))
{
data->exit_code = 2;
return (1);
}
return (0);
}

1
t
View File

@ -1 +0,0 @@
bozt

290
tags Normal file
View File

@ -0,0 +1,290 @@
!_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 *

50
utils/ft_atoi_check.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
/* Updated: 2023/02/28 13:52:13 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
static int ft_isspace(char c)
{
if (c == ' ' || c == '\f'
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
return (1);
return (0);
}
int ft_atoi_check(const char *nptr)
{
long result;
int sign;
while (ft_isspace(*nptr))
nptr++;
sign = 1;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
sign = -1;
nptr++;
}
result = 0;
while (*nptr >= '0' && *nptr <= '9')
{
result = result * 10 + *nptr++ - '0';
if ((result > 2147483647 && sign == 1)
|| (result > 2147483647 && sign == 1))
return (2);
}
if (*nptr--)
return (1);
if (*nptr == '-' || *nptr == '+')
return (1);
return (0);
}

View File

@ -1,40 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* ft_change_exit_code.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/02/14 14:52:50 by cchauvet ### ########.fr */
/* Created: 2023/02/24 19:04:04 by cchauvet #+# #+# */
/* Updated: 2023/02/24 19:05:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int main(char **env)
int ft_change_exit_code(t_data *data, int new_value)
{
t_list **env_lst;
t_list *current;
char *key;
char *value;
char *exit_code_str;
env_lst = init_env(env);
current = *env_lst;
while (current != NULL)
data->exit_code = new_value;
exit_code_str = ft_itoa(new_value);
if (exit_code_str == NULL)
{
value = ft_strchr(current->content, '=') + 1;
key = ft_strndup(current->content,
ft_strlen(current->content) - ft_strlen(value));
if (key == NULL)
{
ft_lstclear(env_lst, env_del);
return (1);
}
ft_printf("declare -x %s=\"%s\"\n", key, value);
free(key);
current = current->next;
ft_eprintf("minishell: malloc failed\n");
return (1);
}
ft_lstclear(env_lst, env_del);
return (0);
}

View File

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
/* Updated: 2023/02/21 23:08:10 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_is_in_quote(const char *str, size_t n)
@ -15,15 +27,13 @@ int ft_is_in_quote(const char *str, size_t n)
{
if (simple_quoted == 0)
double_quoted = !double_quoted;
}
if (str[i] == '\'')
else if (str[i] == '\'')
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}
return (simple_quoted == 1 + (double_quoted == 1) * 2);
return (simple_quoted + double_quoted * 2);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/02/16 13:20:50 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,7 @@ char *ft_quote_remover(char *str)
ssize_t stop;
start = -1;
stop = -1;
i = 0;
while (str[i] != '\0')
{
@ -27,17 +28,18 @@ char *ft_quote_remover(char *str)
if (start == -1)
start = i;
else if (str[i] == str[start])
{
stop = i;
break ;
}
}
i++;
}
if (start != -1)
{
ft_strshift(str, -1);
ft_strshift(str + stop - 1, -1);
if (stop != -1)
{
ft_strshift(str + start, -1);
ft_strshift(str + stop - 1, -1);
start = -1;
stop = -1;
i = i - 2;
}
else
i++;
}
return (str);
}

View File

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:06 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
ssize_t ft_strnchr(const char *str, char c)

View File

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:16 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
size_t ft_strncpy(char *dst, const char *src, size_t n)

View File

@ -1,11 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strreplace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:46:20 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:58:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_strreplace(const char *str, const char *fill, size_t start, size_t stop)
char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) - (stop - start) + 1 * sizeof(char)));
out = malloc((ft_strlen(str) + ft_strlen(fill) -\
(stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
ft_strncpy(out, str, start);

View File

@ -25,5 +25,6 @@ int ft_str_is_empty(const char *str);
char **ft_split_quoted(const char *s, char c);
void ft_strshift(char *str, int shift);
char *ft_quote_remover(char *str);
int ft_atoi_check(const char *nptr);
#endif

15
vsupp Normal file
View File

@ -0,0 +1,15 @@
{
readline
Memcheck:Leak
...
fun:readline
...
}
{
readline
Memcheck:Leak
...
fun:add_history
...
}