c'est vraiment le bordel j'ai rien test mais amdoulah ca passe

This commit is contained in:
starnakin 2023-02-06 20:41:10 +01:00
parent b8017175e8
commit 4258c1da62
94 changed files with 219 additions and 29 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_getstr.c UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_getstr.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c ft_split_quoted.c
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}
NAME = minishell NAME = minishell
CC = clang CC = gcc
CFLAGS = -Wall -Werror -Wextra -g CFLAGS = -Wall -Werror -Wextra -g

1
d
View File

@ -1 +0,0 @@
test

BIN
file.o

Binary file not shown.

75
ft_split_quoted.c Normal file
View File

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
/* Updated: 2023/01/06 19:33:51 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.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_index;
size_t start;
tab_index = 0;
let_index = 0;
start = 0;
if (tab == NULL || s == NULL)
return (NULL);
while (tab_index < len)
{
while ((s[let_index] == c || ft_is_in_quote(s, let_index)) && s[let_index] != 0)
let_index++;
start = let_index;
while ((s[let_index] != c || ft_is_in_quote(s, let_index)) && s[let_index] != 0)
let_index++;
tab[tab_index] = ft_substr(s, start, let_index - 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);
}

BIN
ft_split_quoted.o Normal file

Binary file not shown.

BIN
heredoc.o

Binary file not shown.

BIN
infile.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -12,7 +12,7 @@
#include "libft.h" #include "libft.h"
void *ft_cancel(char **tab, size_t len) void *ft_cancel(void **tab, size_t len)
{ {
size_t i; size_t i;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,7 +34,7 @@ int ft_strcmp(char *s1, char *s2);
ssize_t ft_strchri(char *str, char c); ssize_t ft_strchri(char *str, char c);
char *ft_strndup(char *src, size_t n); char *ft_strndup(char *src, size_t n);
void *ft_cancel(char **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);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

90
main.c
View File

@ -1,18 +1,90 @@
#include "libftx/libftx.h"
#include "minishell.h" #include "minishell.h"
#include <stdlib.h>
void ft_lstdel(void *ptr)
{
t_list *element;
t_cmd *content;
element = (t_list *) ptr;
content = (t_cmd *) element->content;
if (content->executable != NULL)
free(content->executable);
if (content->args != NULL)
free(content->args);
free(content);
free(element);
}
int ft_cmds_init(t_list **cmds, size_t len)
{
t_cmd *content;
t_list *current;
size_t i;
current = malloc(sizeof(t_list));
if (current == NULL)
return (1);
i = 0;
while (i < len)
{
content = malloc(sizeof(t_cmd *));
if (content == NULL)
ft_lstclear(cmds, ft_lstdel);
content->args = NULL;
content->executable = NULL;
content->fd_in = -1;
content->fd_out = -1;
current->next = malloc(sizeof(t_list *));
if (current->next == NULL)
ft_lstclear(cmds, ft_lstdel);
current = current->next;
}
}
int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile)
{
size_t i;
size_t len;
t_cmd *cmd;
t_list *current;
len = ft_seglen_quoted(line, '|');
if (len == 0)
return (0);
cmds = malloc(sizeof(t_list *));
if (ft_cmds_init(cmds, ft_seglen_quoted(line, '|')))
return (1);
cmd = (t_cmd *)(*cmds)->content;
cmd->fd_in = infile;
current = *cmds;
while (current->next != NULL)
current = current->next;
cmd = (t_cmd *) current->content;
cmd->fd_out = outfile;
return (0);
}
int ft_cmds_fill(t_list **cmds, const char *line)
{
//TODO
//remplir les executables;
// les args;
}
t_list **ft_parse_cmd(char *line) t_list **ft_parse_cmd(char *line)
{ {
char infile; int infile;
char outfile; int outfile;
t_list **cmds; t_list **cmds;
size_t i;
(void) outfile; cmds = NULL;
(void) cmds; outfile = ft_outfile(line);
(void) infile; infile = ft_infile(line);
i = 0; if (ft_syntatic_verif(line) == 1)
ft_outfile(line); return (NULL);
ft_infile(line); ft_cmds_prep(cmds, line, infile, outfile);
ft_printf("%s\n", line); ft_printf("%s\n", line);
return (NULL); return (NULL);
} }

BIN
main.o

Binary file not shown.

BIN
minishell

Binary file not shown.

View File

@ -9,19 +9,22 @@
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
int ft_file_is_readable(char *path); int ft_syntatic_verif(const char *str);
int ft_file_is_writeable(char *path); int ft_file_is_readable(const char *path);
char *ft_get_file_path(char *infile); int ft_file_is_writeable(const char *path);
char *ft_get_file_path(const char *infile);
int ft_infile(char *line); int ft_infile(char *line);
int ft_outfile(char *line); int ft_outfile(char *line);
int ft_heredoc(char *stop); int ft_heredoc(char *stop);
size_t ft_seglen_quoted(const char *str, char c);
char **ft_split_quoted(const char *s, char c);
typedef struct cmd typedef struct s_cmd
{ {
int fd_in; int fd_in;
int fd_out; int fd_out;
char *cmd; char *executable;
char *args; char *args;
} cmd; } t_cmd;
#endif #endif

BIN
outfile.o

Binary file not shown.

41
syntatics.c Normal file
View File

@ -0,0 +1,41 @@
#include "libftx/libftx.h"
#include "minishell.h"
static int ft_quote_verif(char *str)
{
if (ft_is_in_quote(str, ft_strlen(str)))
{
ft_eprintf("minishell: Quote is note closed");
return (1);
}
else
return (0);
}
static int ft_multipipe(char *str)
{
size_t i;
size_t y;
i = 0;
while (str[i] != '\0')
{
y = 0;
while (str[i + y] == '|' && ft_is_in_quote(str, i))
{
y++;
if (y > 1)
{
ft_eprintf("minishell: Multiple pipes is not supported\n");
return (1);
}
}
i++;
}
return (0);
}
int ft_syntatic_verif(char *str)
{
return (ft_quote_verif(str) || ft_multipipe(str));
}

BIN
syntatics.o Normal file

Binary file not shown.

0
t Normal file
View File

Binary file not shown.

View File

@ -1,6 +1,6 @@
#include "utils.h" #include "utils.h"
int ft_is_in_quote(char *str, size_t n) int ft_is_in_quote(const char *str, size_t n)
{ {
size_t double_quoted; size_t double_quoted;
size_t simple_quoted; size_t simple_quoted;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,10 +3,10 @@
# include <stdlib.h> # include <stdlib.h>
# include "../libftx/libftx.h" # include "../libftx/libftx.h"
size_t ft_strncpy(char *dst, char *src, size_t n); size_t ft_strncpy(char *dst, const char *src, size_t n);
int ft_is_in_quote(char *str, size_t n); int ft_is_in_quote(const char *str, size_t n);
char *ft_strreplace(char *str, char *fill, size_t start, size_t stop); char *ft_strreplace(char *str, const char *fill, size_t start, size_t stop);
ssize_t ft_strnchr(char *str, char c); ssize_t ft_strnchr(const char *str, char c);
char *ft_getstr(char *str, size_t n); char *ft_getstr(const char *str, size_t n);
#endif #endif