some changes ?
This commit is contained in:
parent
9e19c2856e
commit
2f7b7a1b2b
7 changed files with 47 additions and 62 deletions
|
|
@ -1,4 +1,17 @@
|
||||||
#include "getnextline.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/04 12:45:02 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/04 13:43:29 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
#define BUFF_SIZE 32
|
||||||
|
|
||||||
static char *ft_realloc(char *line, int size)
|
static char *ft_realloc(char *line, int size)
|
||||||
{
|
{
|
||||||
|
|
@ -12,27 +25,18 @@ static char *ft_realloc(char *line, int size)
|
||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_next_line(int const fd, char **line)
|
static int ft_loop_read(int fd, char **line, char (*save)[])
|
||||||
{
|
{
|
||||||
static char save[BUFF_SIZE] = "";
|
|
||||||
char buf[BUFF_SIZE + 1];
|
char buf[BUFF_SIZE + 1];
|
||||||
int ret;
|
|
||||||
char *pos;
|
char *pos;
|
||||||
|
int ret;
|
||||||
|
|
||||||
*line = (char *)malloc(sizeof(char *) * (BUFF_SIZE + ft_strlen(save) + 1));
|
|
||||||
*line = ft_strcpy(*line, save);
|
|
||||||
if ((pos = ft_strchr(*line, '\n')))
|
|
||||||
{
|
|
||||||
ft_strcpy(save, pos + 1);
|
|
||||||
*pos = '\0';
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
||||||
{
|
{
|
||||||
buf[ret] = '\0';
|
buf[ret] = '\0';
|
||||||
if ((pos = ft_strchr(buf, '\n')))
|
if ((pos = ft_strchr(buf, '\n')))
|
||||||
{
|
{
|
||||||
ft_strcpy(save, pos + 1);
|
ft_strcpy(*save, pos + 1);
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
ft_strcat(*line, buf);
|
ft_strcat(*line, buf);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -43,3 +47,19 @@ int get_next_line(int const fd, char **line)
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_next_line(int const fd, char **line)
|
||||||
|
{
|
||||||
|
static char save[BUFF_SIZE] = "";
|
||||||
|
char *pos;
|
||||||
|
|
||||||
|
*line = (char *)malloc(sizeof(char *) * (BUFF_SIZE + ft_strlen(save) + 1));
|
||||||
|
*line = ft_strcpy(*line, save);
|
||||||
|
if ((pos = ft_strchr(*line, '\n')))
|
||||||
|
{
|
||||||
|
ft_strcpy(save, pos + 1);
|
||||||
|
*pos = '\0';
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (ft_loop_read(fd, line, &save));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
|
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/04 11:59:13 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:07:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)())
|
||||||
|
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
indirect = alst;
|
indirect = alst;
|
||||||
while (current)
|
while (*indirect)
|
||||||
{
|
{
|
||||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:17 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:57:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/03 14:57:18 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:11:05 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,28 +6,12 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/03 16:40:39 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:11:19 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static void ft_lsteadd(t_list **alst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *lst;
|
|
||||||
|
|
||||||
lst = *alst;
|
|
||||||
new->next = NULL;
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
lst->next = new;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||||
{
|
{
|
||||||
t_list *out;
|
t_list *out;
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,12 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:10 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:57:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/03 15:27:16 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:11:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static char *ft_strrev(char *str)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
char tmp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
len = 0;
|
|
||||||
while (str[len] != '\0')
|
|
||||||
len++;
|
|
||||||
while (i < len / 2)
|
|
||||||
{
|
|
||||||
tmp = str[len - (i + 1)];
|
|
||||||
str[len - (i + 1)] = str[i];
|
|
||||||
str[i] = tmp;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t ft_size(int n)
|
static size_t ft_size(int n)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:37 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:57:37 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/03 14:57:38 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:11:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_putchar(char c)
|
int ft_putchar(int c)
|
||||||
{
|
{
|
||||||
write(1, &c, 1);
|
write(1, &c, 1);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:58:45 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:58:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/03 14:58:45 by jhalford ### ########.fr */
|
/* Updated: 2016/11/04 13:11:59 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,10 +18,10 @@ char *ft_strtrim(char const *s)
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
out = ft_strdup(s);
|
out = ft_strdup(s);
|
||||||
while (*out && FT_SEP(*out))
|
while (*out && FT_WS(*out))
|
||||||
out++;
|
out++;
|
||||||
size = ft_strlen(out);
|
size = ft_strlen(out);
|
||||||
while (size - 1 && FT_SEP(out[size - 1]))
|
while (size - 1 && FT_WS(out[size - 1]))
|
||||||
{
|
{
|
||||||
size--;
|
size--;
|
||||||
out[size] = '\0';
|
out[size] = '\0';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue