Archived
1
0

parsing started

This commit is contained in:
Adam Joly
2023-12-18 17:19:34 +01:00
parent 7790410d54
commit 11e3eef876
116 changed files with 1549 additions and 1903 deletions

Binary file not shown.

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
/* Updated: 2023/12/08 18:17:17 by adjoly ### ########.fr */
/* Updated: 2023/12/18 09:18:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include "../libft/libft.h"
char check_line(char *res, char *buf)
{
@ -37,49 +38,38 @@ char check_line(char *res, char *buf)
return (0);
}
char *ft_read_error(char **buf, char *res)
{
free(*buf);
*buf = NULL;
if (res[0] != 0)
return (res);
free(res);
return (NULL);
}
char *get_next_line(int fd)
{
static char *buf;
char *res;
ssize_t bytes_read;
res = ft_calloc(1, 1);
if (BUFFER_SIZE <= 0 || fd < 0 || fd > 1023)
return (NULL);
if (!buf)
buf = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
while (buf && res)
res = ft_calloc(1, 1);
while (buf)
{
res = ft_strjoin(res, buf);
if (!res)
return (NULL);
if (check_line(res, buf))
return (res);
bytes_read = read(fd, buf, BUFFER_SIZE);
if (bytes_read < 1)
{
free(buf);
buf = NULL;
if (res[0] != 0)
return (res);
free(res);
return (NULL);
}
return (ft_read_error(&buf, res));
buf[bytes_read] = 0;
}
return (NULL);
}
/*#include <unistd.h>
void ft_putstr(char *str){if (str == NULL){return ;}int i = 0;while(str[i]){write(1, &str[i], 1);i++;}}
#include <fcntl.h>
#include <stdio.h>
int main(void)
{
char *ln;
int fd;
fd = open("test.txt", O_RDONLY);
while (ln)
{
ln = get_next_line(fd);
ft_putstr(ln);
free(ln);
}
close(fd);
}*/

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
/* Updated: 2023/12/08 18:01:49 by adjoly ### ########.fr */
/* Updated: 2023/12/18 09:27:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,9 +21,8 @@
# endif
char *get_next_line(int fd);
char *ft_strjoin(char *s1, char *s2);
size_t ft_strlen(char *s);
void *ft_calloc(size_t nmemb, size_t size);
size_t ft_strlen_nl(char *s);
char *ft_strjoin(const char *s1, const char *s2);
// size_t ft_strlen(char *s);
// void *ft_calloc(size_t nmemb, size_t size);
#endif

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
/* Updated: 2023/12/08 18:02:13 by adjoly ### ########.fr */
/* Updated: 2023/12/15 05:51:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,49 +37,38 @@ char check_line(char *res, char *buf)
return (0);
}
char *ft_read_error(char **buf, char *res)
{
free(*buf);
*buf = NULL;
if (res[0] != 0)
return (res);
free(res);
return (NULL);
}
char *get_next_line(int fd)
{
static char *buf[1024];
char *res;
size_t bytes_read;
ssize_t bytes_read;
res = ft_calloc(1, 1);
if (BUFFER_SIZE <= 0 || fd < 0 || fd > 1023)
return (NULL);
if (!buf[fd])
buf[fd] = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
res = ft_calloc(1, 1);
while (buf[fd] && res)
{
res = ft_strjoin(res, buf);
res = ft_strjoin(res, buf[fd]);
if (!res)
return (NULL);
if (check_line(res, buf[fd]))
return (res);
bytes_read = read(fd, buf[fd], BUFFER_SIZE);
if (bytes_read < 1)
{
free(&buf[fd]);
buf[fd] = NULL;
if (res[0] != 0)
return (res);
free(res);
return (NULL);
}
return (ft_read_error(&buf[fd], res));
buf[fd][bytes_read] = 0;
}
return (NULL);
}
/*#include <unistd.h>
void ft_putstr(char *str){if (str == NULL){return ;}int i = 0;while(str[i]){write(1, &str[i], 1);i++;}}
#include <fcntl.h>
#include <stdio.h>
int main(void)
{
char *ln;
int fd;
fd = open("test.txt", O_RDONLY);
while (ln)
{
ln = get_next_line(fd);
ft_putstr(ln);
free(ln);
}
close(fd);
}*/

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
/* Updated: 2023/12/08 18:01:40 by adjoly ### ########.fr */
/* Updated: 2023/12/15 05:43:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,6 +24,5 @@ char *get_next_line(int fd);
char *ft_strjoin(char *s1, char *s2);
size_t ft_strlen(char *s);
void *ft_calloc(size_t nmemb, size_t size);
size_t ft_strlen_nl(char *s);
#endif

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
/* Updated: 2023/12/08 17:52:41 by adjoly ### ########.fr */
/* Updated: 2023/12/15 05:38:33 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,41 +51,25 @@ char *ft_strjoin(char *s1, char *s2)
return (result);
}
size_t ft_strlcpy(char *dst, char *src, size_t size)
{
size_t i;
i = 0;
if (size == 0)
return (ft_strlen(src));
while (i < size && src[i])
{
dst[i] = src[i];
i++;
}
dst[size] = '\0';
return (ft_strlen(src));
}
void *ft_calloc(size_t nmemb, size_t size)
{
char *str;
char *result;
size_t i;
i = 0;
if (nmemb == 0 || size == 0)
return (malloc(1));
if (((unsigned long long)(size * nmemb) > 4294967295))
return (NULL);
if ((int)size < 0 && (int)nmemb < 0)
return (NULL);
if ((unsigned long long)(size * nmemb) > 4294967295)
result = malloc(size * nmemb);
if (!result)
return (NULL);
str = malloc(nmemb * size);
if (!str)
return (NULL);
while (i < (nmemb * size))
while (i < (size * nmemb))
{
*(unsigned char *)(str + i) = '\0';
*(unsigned char *)(result + i) = '\0';
i++;
}
return (str);
return (result);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
/* Updated: 2023/12/08 17:54:32 by adjoly ### ########.fr */
/* Updated: 2023/12/15 05:42:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,41 +51,25 @@ char *ft_strjoin(char *s1, char *s2)
return (result);
}
size_t ft_strlcpy(char *dst, char *src, size_t size)
{
size_t i;
i = 0;
if (size == 0)
return (ft_strlen(src));
while (i < size && src[i])
{
dst[i] = src[i];
i++;
}
dst[size] = '\0';
return (ft_strlen(src));
}
void *ft_calloc(size_t nmemb, size_t size)
{
char *str;
char *result;
size_t i;
i = 0;
if (nmemb == 0 || size == 0)
return (malloc(1));
if (((unsigned long long)(size * nmemb) > 4294967295))
return (NULL);
if ((int)size < 0 && (int)nmemb < 0)
return (NULL);
if ((unsigned long long)(size * nmemb) > 4294967295)
result = malloc(size * nmemb);
if (!result)
return (NULL);
str = malloc(nmemb * size);
if (!str)
return (NULL);
while (i < (nmemb * size))
while (i < (size * nmemb))
{
*(unsigned char *)(str + i) = '\0';
*(unsigned char *)(result + i) = '\0';
i++;
}
return (str);
return (result);
}

View File

@ -1,8 +0,0 @@
Si tu lis cette ligne GGWP
asdfasdf
sad
f
sadf
asdfasdff