finish the bonus just need to verify some files i guess

This commit is contained in:
Maoake Teriierooiterai
2026-01-14 10:22:15 +01:00
parent fe69eeb821
commit 68dbe33733
18 changed files with 116 additions and 60 deletions

View File

@@ -11,6 +11,7 @@
/* ************************************************************************** */
#include "get_next_line.h"
#include "parsing.h"
#include <unistd.h>
static int del_before_nl(char buf[BUFFER_SIZE])
@@ -22,7 +23,7 @@ static int del_before_nl(char buf[BUFFER_SIZE])
nl_i = index_of_nl(buf, BUFFER_SIZE);
if (nl_i >= 0)
{
temp = ft_substr(buf, nl_i + 1, BUFFER_SIZE - nl_i);
temp = ft_substr_gnl(buf, nl_i + 1, BUFFER_SIZE - nl_i);
if (!temp)
return (-1);
ft_bzero(buf, BUFFER_SIZE);
@@ -51,7 +52,7 @@ static char *ft_read_one(char buf[BUFFER_SIZE], int fd, char *str)
free(str);
return (NULL);
}
if ((!str || ft_strlen(str) == 0) && temp == 0)
if ((!str || ft_strlen_1(str) == 0) && temp == 0)
{
free(str);
return (NULL);
@@ -73,7 +74,7 @@ static char *extract_all_nl(char buf[BUFFER_SIZE], int fd, char *str, int nl_i)
if (!str)
return (NULL);
nl_i = index_of_nl(buf, BUFFER_SIZE);
if (nl_i < 0 && !ft_strlen(buf))
if (nl_i < 0 && !ft_strlen_1(buf))
return (str);
}
str = ft_strjoin_new(str, buf, nl_i);
@@ -100,12 +101,12 @@ char *get_next_line(int fd)
nl_i = index_of_nl(buf, BUFFER_SIZE);
if (nl_i >= 0)
{
str = ft_substr(buf, 0, nl_i + 1);
str = ft_substr_gnl(buf, 0, nl_i + 1);
temp = del_before_nl(buf);
if (temp < 0)
return (free(str), NULL);
}
else
str = extract_all_nl(buf, fd, ft_substr("", 0, 1), nl_i);
str = extract_all_nl(buf, fd, ft_substr_gnl("", 0, 1), nl_i);
return (str);
}

View File

@@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/21 17:22:03 by dgaillet #+# #+# */
/* Updated: 2025/11/27 18:05:13 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_H
# define GET_NEXT_LINE_H
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 42
# endif
# include <stdlib.h>
char *get_next_line(int fd);
size_t ft_strlen(const char *s);
char *ft_strjoin_new(char const *s1, char const *s2, size_t limit);
void ft_bzero(void *s, size_t n);
int index_of_nl(char *str, int limit);
char *ft_substr(char const *s, unsigned int start, size_t len);
#endif

View File

@@ -29,7 +29,7 @@ int index_of_nl(char *str, int limit)
return (-1);
}
size_t ft_strlen(const char *s)
size_t ft_strlen_1(const char *s)
{
size_t i;
@@ -45,7 +45,7 @@ char *ft_strjoin_new(char const *s1, char const *s2, size_t limit)
size_t i;
size_t j;
str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
str = malloc(sizeof(char) * (ft_strlen_1(s1) + ft_strlen_1(s2) + 1));
if (!str)
return (NULL);
i = 0;
@@ -65,7 +65,7 @@ char *ft_strjoin_new(char const *s1, char const *s2, size_t limit)
return (str);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
char *ft_substr_gnl(char const *s, unsigned int start, size_t len)
{
size_t i;
char *sub_str;
@@ -73,7 +73,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
if (!s)
return (NULL);
s_len = ft_strlen(s);
s_len = ft_strlen_1(s);
if (start > s_len)
len = 0;
else if (s_len < (start + len))

View File

@@ -13,8 +13,8 @@
#include "push_swap.h"
#include "parsing.h"
#include "get_next_line.h"
#include "check_error.h"
#include <unistd.h>
#include <stdlib.h>
static int apply_operation(t_stacks *stacks, char buf[1024])
{
@@ -43,7 +43,14 @@ static int apply_operation(t_stacks *stacks, char buf[1024])
return (0);
}
static void tester(t_stacks *stacks)
static int is_stacks_b_empty(t_stacks *stacks)
{
if (stacks->b != NULL)
return (0);
return (1);
}
static int tester(t_stacks *stacks)
{
char *buf;
@@ -55,12 +62,43 @@ static void tester(t_stacks *stacks)
free(buf);
buf = get_next_line(0);
}
if ()
if (!is_stacks_b_empty(stacks))
return (write(1, "KO\n", 3));
if (!check_order(stacks->a))
return (write(1, "KO\n", 3));
write(1, "OK\n", 3);
return (0);
}
static int bonus(char **tab)
{
t_stacks *stacks;
int len;
stacks = NULL;
len = len_split(tab);
stacks = init_stacks(len, tab, 0);
stacks->print = 0;
if (!stacks)
return (0);
tester(stacks);
free_all(stacks);
return (1);
}
int main(int argc, char **argv)
{
t_stacks *stacks;
char **tab;
if (argc < 2)
return (write(2, "Error\n", 7));
tab = split_all(join_all(argc, argv));
if (!tab)
return (0);
if (!check_error_bonus(tab))
write(2, "Error\n", 7);
else
bonus(tab);
free_tab(tab);
return (0);
}

View File

@@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/09 11:59:20 by dgaillet #+# #+# */
/* Updated: 2026/01/09 11:59:46 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
void ft_bzero(void *s, unsigned int n)
{
while (n > 0)
{
*((unsigned char *) s) = '\0';
s++;
n--;
}
}