norminette errors
This commit is contained in:
parent
d29a2f252d
commit
3b9498e230
@ -81,6 +81,7 @@ int ft_printf(const char *format, ...);
|
|||||||
*/
|
*/
|
||||||
# define OPEN_MAX 1024
|
# define OPEN_MAX 1024
|
||||||
# define BUFFER_SIZE 256
|
# define BUFFER_SIZE 256
|
||||||
char *get_next_line(int fd);
|
|
||||||
|
char *get_next_line(int fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,124 +1,124 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: o_ :::::: ::: */
|
/* ::: o_ :::::: ::: */
|
||||||
/* get_next_line.c :+: / :+::+: :+: */
|
/* get_next_line.c :+: / :+::+: :+: */
|
||||||
/* +:+ > +:++:+ +:+ */
|
/* +:+ > +:++:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */
|
/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */
|
/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void gnl_clean(void **ptr)
|
static void gnl_clean(void **ptr)
|
||||||
{
|
{
|
||||||
if (*ptr)
|
if (*ptr)
|
||||||
{
|
{
|
||||||
free(*ptr);
|
free(*ptr);
|
||||||
*ptr = NULL;
|
*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 *temp1;
|
||||||
char *temp2;
|
char *temp2;
|
||||||
|
|
||||||
if (!stock || !*stock)
|
if (!stock || !*stock)
|
||||||
return (0);
|
return (0);
|
||||||
temp1 = *stock;
|
temp1 = *stock;
|
||||||
while (temp1 && *temp1 != '\n')
|
while (temp1 && *temp1 != '\n')
|
||||||
if (!*temp1++)
|
if (!*temp1++)
|
||||||
return (0);
|
return (0);
|
||||||
if (temp1)
|
if (temp1)
|
||||||
temp1++;
|
temp1++;
|
||||||
temp2 = ft_strdup(temp1);
|
temp2 = ft_strdup(temp1);
|
||||||
*temp1 = '\0';
|
*temp1 = '\0';
|
||||||
*line = ft_strdup(*stock);
|
*line = ft_strdup(*stock);
|
||||||
free(*stock);
|
free(*stock);
|
||||||
*stock = temp2;
|
*stock = temp2;
|
||||||
if (!*line || !*stock)
|
if (!*line || !*stock)
|
||||||
{
|
{
|
||||||
gnl_clean((void **)line);
|
gnl_clean((void **)line);
|
||||||
gnl_clean((void **)stock);
|
gnl_clean((void **)stock);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
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)
|
if (!*buffer)
|
||||||
{
|
{
|
||||||
*buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
*buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
||||||
if (!*buffer)
|
if (!*buffer)
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
bytes_read = read(fd, *buffer, size);
|
bytes_read = read(fd, *buffer, size);
|
||||||
if (bytes_read >= 0)
|
if (bytes_read >= 0)
|
||||||
(*buffer)[bytes_read] = '\0';
|
(*buffer)[bytes_read] = '\0';
|
||||||
return (bytes_read);
|
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 *buffer;
|
||||||
char *temp;
|
char *temp;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
|
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
||||||
while (bytes_read > 0)
|
while (bytes_read > 0)
|
||||||
{
|
{
|
||||||
if (!*stock)
|
if (!*stock)
|
||||||
*stock = ft_strdup(buffer);
|
*stock = ft_strdup(buffer);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp = *stock;
|
temp = *stock;
|
||||||
*stock = ft_strjoin(temp, buffer);
|
*stock = ft_strjoin(temp, buffer);
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
if (gnl_check_and_extract(line, stock))
|
if (gnl_check_and_extract(line, stock))
|
||||||
break ;
|
break ;
|
||||||
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (!*stock)
|
if (!*stock)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (bytes_read);
|
return (bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_next_line(int fd)
|
char *get_next_line(int fd)
|
||||||
{
|
{
|
||||||
static char *stock[OPEN_MAX];
|
static char *stock[OPEN_MAX];
|
||||||
char *line;
|
char *line;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0)
|
if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (stock[fd] && gnl_check_and_extract(&line, &stock[fd]))
|
if (stock[fd] && gnl_check_and_extract(&line, &stock[fd]))
|
||||||
return (line);
|
return (line);
|
||||||
status = gnl_read_file(fd, &stock[fd], &line);
|
status = gnl_read_file(fd, &stock[fd], &line);
|
||||||
if (status > 0)
|
if (status > 0)
|
||||||
return (line);
|
return (line);
|
||||||
else if (status < 0)
|
else if (status < 0)
|
||||||
{
|
{
|
||||||
gnl_clean((void **)&stock[fd]);
|
gnl_clean((void **)&stock[fd]);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (stock[fd] && *stock[fd])
|
if (stock[fd] && *stock[fd])
|
||||||
{
|
{
|
||||||
line = ft_strdup(stock[fd]);
|
line = ft_strdup(stock[fd]);
|
||||||
gnl_clean((void **)&stock[fd]);
|
gnl_clean((void **)&stock[fd]);
|
||||||
if (line)
|
if (line)
|
||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
gnl_clean((void **)&stock[fd]);
|
gnl_clean((void **)&stock[fd]);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
#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;
|
i = 0;
|
||||||
while (s1[i] && s2[i] && s1[i] == s2[i])
|
while (s1[i] && s2[i] && s1[i] == s2[i])
|
||||||
i++;
|
i++;
|
||||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
/* Created: 2024/11/06 20:07:09 by whaffman #+#+# #+#+# #+# #+# | */
|
/* 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)
|
if (!silent)
|
||||||
ft_putstr_fd("sa\n", STDOUT_FILENO);
|
ft_putstr_fd("sa\n", STDOUT_FILENO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sb(t_state *state, int silent)
|
void sb(t_state *state, int silent)
|
||||||
{
|
{
|
||||||
swap(&(state->b));
|
swap(&(state->b));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user