diff --git a/libftasm/src/get_next_line/get_next_line.c b/libftasm/src/get_next_line/get_next_line.c index 93f145ad..3263c520 100644 --- a/libftasm/src/get_next_line/get_next_line.c +++ b/libftasm/src/get_next_line/get_next_line.c @@ -1,8 +1,21 @@ -#include "getnextline.h" +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 12:45:02 by jhalford #+# #+# */ +/* Updated: 2016/11/04 13:43:29 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ -static char *ft_realloc(char *line, int size) +#include "libft.h" +#define BUFF_SIZE 32 + +static char *ft_realloc(char *line, int size) { - char *str; + char *str; str = (char *)malloc(sizeof(char) * (ft_strlen(line) + size + 1)); if (str == NULL) @@ -12,27 +25,18 @@ static char *ft_realloc(char *line, int size) 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]; - int ret; + char buf[BUFF_SIZE + 1]; 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) { buf[ret] = '\0'; if ((pos = ft_strchr(buf, '\n'))) { - ft_strcpy(save, pos + 1); + ft_strcpy(*save, pos + 1); *pos = '\0'; ft_strcat(*line, buf); return (1); @@ -43,3 +47,19 @@ int get_next_line(int const fd, char **line) } 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)); +} diff --git a/libftasm/src/lst/ft_lst_removeif.c b/libftasm/src/lst/ft_lst_removeif.c index 39303b32..85874721 100644 --- a/libftasm/src/lst/ft_lst_removeif.c +++ b/libftasm/src/lst/ft_lst_removeif.c @@ -6,7 +6,7 @@ /* 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; indirect = alst; - while (current) + while (*indirect) { if ((*cmp)((*indirect)->content, data_ref) == 0) { diff --git a/libftasm/src/lst/ft_lsteadd.c b/libftasm/src/lst/ft_lsteadd.c index a6e89757..bcc3be54 100644 --- a/libftasm/src/lst/ft_lsteadd.c +++ b/libftasm/src/lst/ft_lsteadd.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lstmap.c b/libftasm/src/lst/ft_lstmap.c index 55f28530..edf178d2 100644 --- a/libftasm/src/lst/ft_lstmap.c +++ b/libftasm/src/lst/ft_lstmap.c @@ -6,28 +6,12 @@ /* 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" -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 *out; diff --git a/libftasm/src/math/ft_itoa.c b/libftasm/src/math/ft_itoa.c index 94a83c8f..c67a6f39 100644 --- a/libftasm/src/math/ft_itoa.c +++ b/libftasm/src/math/ft_itoa.c @@ -6,32 +6,12 @@ /* 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" -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) { size_t i; diff --git a/libftasm/src/printing/ft_putchar.c b/libftasm/src/printing/ft_putchar.c index bd6d350a..afd2d6bb 100644 --- a/libftasm/src/printing/ft_putchar.c +++ b/libftasm/src/printing/ft_putchar.c @@ -6,13 +6,14 @@ /* 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" -void ft_putchar(char c) +int ft_putchar(int c) { write(1, &c, 1); + return (0); } diff --git a/libftasm/src/str/ft_strtrim.c b/libftasm/src/str/ft_strtrim.c index 0ea9dd0b..844ac335 100644 --- a/libftasm/src/str/ft_strtrim.c +++ b/libftasm/src/str/ft_strtrim.c @@ -6,7 +6,7 @@ /* 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; out = ft_strdup(s); - while (*out && FT_SEP(*out)) + while (*out && FT_WS(*out)) out++; size = ft_strlen(out); - while (size - 1 && FT_SEP(out[size - 1])) + while (size - 1 && FT_WS(out[size - 1])) { size--; out[size] = '\0';