remove inputs

This commit is contained in:
2024-12-02 12:32:14 +01:00
commit 60acac0231
247 changed files with 9071 additions and 0 deletions

42
2022/2/libft/gnl/Makefile Executable file
View File

@ -0,0 +1,42 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/04 08:03:00 by tomoron #+# #+# #
# Updated: 2023/12/04 09:49:24 by tomoron ### ########.fr #
# #
# **************************************************************************** #
NAME = gnl.a
CC = gcc
SRCS = get_next_line_bonus.c\
get_next_line_utils_bonus.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wall -Wextra -Werror
$(NAME): $(OBJS)
ar rcs $(NAME) $(OBJS)
.c.o:
$(CC) $(FLAGS) -c $< -o $@
all: $(NAME)
bonus: all
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: bonus clean all re fclean

View File

@ -0,0 +1,113 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 17:03:11 by tomoron #+# #+# */
/* Updated: 2023/12/04 09:56:26 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *get_next_line(int fd)
{
static t_buffer *buffer_start;
t_buffer *buffer;
int nl_found;
int start;
t_result *result;
nl_found = 0;
result = 0;
start = 0;
buffer = create_find_buffer(&buffer_start, fd);
if (BUFFER_SIZE < 0 || !buffer)
return (0);
if (fd >= 0 && (buffer->i == 0 || buffer->i == buffer->rd_l))
buffer->rd_l = read(fd, buffer->str, BUFFER_SIZE);
else
start = buffer->i;
while (fd >= 0 && !nl_found && buffer->rd_l > 0)
{
nl_found = find_nl(buffer, &start);
if (!ft_lstadd_bak(&result, buffer->str, buffer->i, start))
return (ft_lstclr(&result, NULL, NULL));
if (!nl_found)
buffer->rd_l = read(fd, buffer->str, BUFFER_SIZE);
}
return (result_to_str(result, &buffer_start, buffer));
}
int find_nl(t_buffer *buffer, int *start)
{
int nl_found;
nl_found = 0;
if (buffer->i == BUFFER_SIZE)
*start = 0;
buffer->i = *start;
while (buffer->i < buffer->rd_l && !nl_found)
{
if (buffer->str[buffer->i] == '\n')
nl_found = 1;
(buffer->i)++;
}
return (nl_found);
}
t_buffer *create_find_buffer(t_buffer **buffer_start, int fd)
{
t_buffer *current;
t_buffer *last;
current = *buffer_start;
last = 0;
while (current)
{
if (current->fd == fd)
return (current);
last = current;
current = current->next;
}
if (last)
{
last->next = malloc(sizeof(t_buffer));
last = last->next;
}
else
{
last = malloc(sizeof(t_buffer));
*buffer_start = last;
}
if (last)
init_buffer(last, fd);
return (last);
}
void init_buffer(t_buffer *last, int fd)
{
last->fd = fd;
last->i = 0;
last->rd_l = 0;
last->next = 0;
}
void ft_lstdelon(t_buffer *node, t_buffer **start)
{
t_buffer *current;
t_buffer *next;
if (!start || !node || !*start)
return ;
current = *start;
while (current->next && current->next != node)
current = current->next;
next = node->next;
free(node);
if (node == *start)
*start = next;
else
current->next = next;
}

View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 17:24:39 by tomoron #+# #+# */
/* Updated: 2023/12/04 09:57:06 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_BONUS_H
# define GET_NEXT_LINE_BONUS_H
# include <unistd.h>
# include <stdlib.h>
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 42
# endif
typedef struct s_result
{
char part[BUFFER_SIZE + 1];
struct s_result *next;
} t_result;
typedef struct s_buffer
{
char str[BUFFER_SIZE];
int i;
int rd_l;
int fd;
struct s_buffer *next;
} t_buffer;
char *get_next_line(int fd);
char *result_to_str(t_result *lst, t_buffer **buf_st, t_buffer *buffer);
t_result *ft_lstadd_bak(t_result **lst, char *buffer, int n, int start);
char *ft_lstclr(t_result **lst, t_buffer **buf_str, t_buffer *buffer);
int find_nl(t_buffer *buffer, int *start);
t_buffer *create_find_buffer(t_buffer **buffer_start, int fd);
void init_buffer(t_buffer *last, int fd);
void ft_lstdelon(t_buffer *node, t_buffer **start);
#endif

Binary file not shown.

View File

@ -0,0 +1,119 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 17:35:15 by tomoron #+# #+# */
/* Updated: 2023/12/04 09:58:25 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
char *ft_strncpy(char *dest, char *src, size_t n)
{
size_t i;
i = 0;
while (i < (n))
{
dest[i] = src[i];
i++;
}
dest[i] = 0;
return (dest);
}
t_result *ft_lstadd_bak(t_result **lst, char *buffer, int n, int start)
{
t_result *current;
if (!lst)
return (0);
current = *lst;
while (current && current->next)
current = current->next;
if (!current)
{
*lst = malloc(sizeof(t_result));
if (!*lst)
return (0);
ft_strncpy((*lst)->part, buffer + start, n - start);
(*lst)->next = 0;
}
else
{
current->next = malloc(sizeof(t_result));
if (!current->next)
return (0);
ft_strncpy(current->next->part, buffer + start, n - start);
current->next->next = 0;
}
return (*lst);
}
char *ft_lstclr(t_result **lst, t_buffer **buf_srt, t_buffer *buffer)
{
t_result *next;
if (lst)
{
while (*lst)
{
next = (*lst)->next;
free(*lst);
*lst = next;
}
}
if (buf_srt && buffer && (buffer->rd_l == 0 || buffer->i == buffer->rd_l
|| buffer->rd_l == -1))
ft_lstdelon(buffer, buf_srt);
return (0);
}
int lst_str_len(t_result *lst)
{
int i;
int res;
res = 0;
while (lst)
{
i = 0;
while (lst->part[i])
i++;
res += i;
lst = lst->next;
}
return (res);
}
char *result_to_str(t_result *lst, t_buffer **buf_srt, t_buffer *buffer)
{
char *res;
int res_i;
int p_i;
t_result *start;
if (!lst)
return (ft_lstclr(&lst, buf_srt, buffer));
res = malloc((lst_str_len(lst) + 1) * sizeof(char));
start = lst;
res_i = 0;
while (res && lst)
{
p_i = 0;
while (lst->part[p_i])
{
res[res_i] = lst->part[p_i];
p_i++;
res_i++;
}
lst = lst->next;
}
if (res)
res[res_i] = 0;
ft_lstclr(&start, buf_srt, buffer);
return (res);
}

Binary file not shown.

BIN
2022/2/libft/gnl/gnl.a Normal file

Binary file not shown.