norminette errors

This commit is contained in:
Willem Haffmans 2024-11-24 20:40:12 +00:00
parent d29a2f252d
commit 3b9498e230
4 changed files with 123 additions and 109 deletions

View File

@ -81,6 +81,7 @@ int ft_printf(const char *format, ...);
*/
# define OPEN_MAX 1024
# define BUFFER_SIZE 256
char *get_next_line(int fd);
char *get_next_line(int fd);
#endif

View File

@ -1,124 +1,124 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* get_next_line.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */
/* */
/* */
/* ::: o_ :::::: ::: */
/* get_next_line.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <unistd.h>
#include <stdlib.h>
static void gnl_clean(void **ptr)
static void gnl_clean(void **ptr)
{
if (*ptr)
{
free(*ptr);
*ptr = NULL;
}
if (*ptr)
{
free(*ptr);
*ptr = NULL;
}
}
static int gnl_check_and_extract(char **line, char **stock)
static int gnl_check_and_extract(char **line, char **stock)
{
char *temp1;
char *temp2;
char *temp1;
char *temp2;
if (!stock || !*stock)
return (0);
temp1 = *stock;
while (temp1 && *temp1 != '\n')
if (!*temp1++)
return (0);
if (temp1)
temp1++;
temp2 = ft_strdup(temp1);
*temp1 = '\0';
*line = ft_strdup(*stock);
free(*stock);
*stock = temp2;
if (!*line || !*stock)
{
gnl_clean((void **)line);
gnl_clean((void **)stock);
return (-1);
}
return (1);
if (!stock || !*stock)
return (0);
temp1 = *stock;
while (temp1 && *temp1 != '\n')
if (!*temp1++)
return (0);
if (temp1)
temp1++;
temp2 = ft_strdup(temp1);
*temp1 = '\0';
*line = ft_strdup(*stock);
free(*stock);
*stock = temp2;
if (!*line || !*stock)
{
gnl_clean((void **)line);
gnl_clean((void **)stock);
return (-1);
}
return (1);
}
static int gnl_read(int fd, char **buffer, size_t size)
static int gnl_read(int fd, char **buffer, size_t size)
{
int bytes_read;
int bytes_read;
if (!*buffer)
{
*buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1));
if (!*buffer)
return (-1);
}
bytes_read = read(fd, *buffer, size);
if (bytes_read >= 0)
(*buffer)[bytes_read] = '\0';
return (bytes_read);
if (!*buffer)
{
*buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1));
if (!*buffer)
return (-1);
}
bytes_read = read(fd, *buffer, size);
if (bytes_read >= 0)
(*buffer)[bytes_read] = '\0';
return (bytes_read);
}
static int gnl_read_file(int fd, char **stock, char **line)
static int gnl_read_file(int fd, char **stock, char **line)
{
char *buffer;
char *temp;
int bytes_read;
char *buffer;
char *temp;
int bytes_read;
buffer = NULL;
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
while (bytes_read > 0)
{
if (!*stock)
*stock = ft_strdup(buffer);
else
{
temp = *stock;
*stock = ft_strjoin(temp, buffer);
free(temp);
}
if (gnl_check_and_extract(line, stock))
break ;
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
}
free(buffer);
if (!*stock)
return (-1);
return (bytes_read);
buffer = NULL;
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
while (bytes_read > 0)
{
if (!*stock)
*stock = ft_strdup(buffer);
else
{
temp = *stock;
*stock = ft_strjoin(temp, buffer);
free(temp);
}
if (gnl_check_and_extract(line, stock))
break ;
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
}
free(buffer);
if (!*stock)
return (-1);
return (bytes_read);
}
char *get_next_line(int fd)
char *get_next_line(int fd)
{
static char *stock[OPEN_MAX];
char *line;
int status;
static char *stock[OPEN_MAX];
char *line;
int status;
if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0)
return (NULL);
if (stock[fd] && gnl_check_and_extract(&line, &stock[fd]))
return (line);
status = gnl_read_file(fd, &stock[fd], &line);
if (status > 0)
return (line);
else if (status < 0)
{
gnl_clean((void **)&stock[fd]);
return (NULL);
}
if (stock[fd] && *stock[fd])
{
line = ft_strdup(stock[fd]);
gnl_clean((void **)&stock[fd]);
if (line)
return (line);
}
gnl_clean((void **)&stock[fd]);
return (NULL);
}
if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0)
return (NULL);
if (stock[fd] && gnl_check_and_extract(&line, &stock[fd]))
return (line);
status = gnl_read_file(fd, &stock[fd], &line);
if (status > 0)
return (line);
else if (status < 0)
{
gnl_clean((void **)&stock[fd]);
return (NULL);
}
if (stock[fd] && *stock[fd])
{
line = ft_strdup(stock[fd]);
gnl_clean((void **)&stock[fd]);
if (line)
return (line);
}
gnl_clean((void **)&stock[fd]);
return (NULL);
}

View File

@ -1,11 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* ft_strcmp.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/24 20:06:19 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/24 20:07:08 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include <stddef.h>
int ft_strcmp(const char *s1, const char *s2)
int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
size_t i;
i = 0;
while (s1[i] && s2[i] && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}
i = 0;
while (s1[i] && s2[i] && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/06 20:07:09 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/06 20:10:41 by whaffman ### ### ### ### / \ */
/* Updated: 2024/11/24 20:20:23 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
@ -20,6 +20,7 @@ void sa(t_state *state, int silent)
if (!silent)
ft_putstr_fd("sa\n", STDOUT_FILENO);
}
void sb(t_state *state, int silent)
{
swap(&(state->b));