diff --git a/libftasm/includes/ft_printf.h b/libftasm/includes/ft_printf.h index 9a439cec..0cef383e 100644 --- a/libftasm/includes/ft_printf.h +++ b/libftasm/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2016/11/16 10:53:57 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 18:20:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,7 @@ struct s_fmt }; int ft_vdprintf(int fd, const char *format, va_list ap); +int ft_fmtcalc(char **final, char **str, va_list ap); extern t_conv g_convs[]; diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 3a7b0c6f..216c1b6d 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/16 10:58:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 13:56:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -119,7 +119,7 @@ size_t ft_lllen_base(long long n, int base); int ft_addrcmp(void *a, void *b); char **ft_sstradd(char **list, char *new); -void ft_sstrsort(char **list, int size, int (*cmp)()); +void ft_sstrsort(char **list, int (*cmp)()); void ft_sstrprint(char **list, char sep); char **ft_sstrdup(char **list); void ft_sstrdel(char **sstr, int index); diff --git a/libftasm/includes/lst.h b/libftasm/includes/lst.h index 3b851fff..bff4ef8e 100644 --- a/libftasm/includes/lst.h +++ b/libftasm/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2016/11/08 11:25:38 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 14:50:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); t_list *ft_lstnew_range(int a, int b); void ft_lsteadd(t_list **alst, t_list *new); void ft_lstnadd(t_list **alst, t_list *new, int n); -void ft_lst_sort(t_list **begin_list, int (*cmp)()); +void ft_lstsort(t_list **begin_list, int (*cmp)()); void ft_lst_print(t_list *list, void (*printer)()); int ft_lstsize(t_list *lst); t_list *ft_lstlast(t_list *lst); diff --git a/libftasm/src/ft_printf/ft_printf.c b/libftasm/src/ft_printf/ft_printf.c index f3989d5e..79a78e4f 100644 --- a/libftasm/src/ft_printf/ft_printf.c +++ b/libftasm/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/21 15:15:04 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 18:22:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,32 +44,44 @@ int ft_dprintf(int fd, const char *format, ...) int ft_vdprintf(int fd, const char *format, va_list ap) { char *str; - char *transform; - char final[1000]; - t_fmt *fmt; + char *tmp; + char *final; str = (char *)format; - ft_bzero(final, 1000); + final = ft_strnew(1); while (*str) { + tmp = final; if (*str == '%') { - str++; - if (!(fmt = ft_printf_parse(&str, ap))) + if (ft_fmtcalc(&final, &str, ap)) return (1); - if (!fmt->valid) - ft_strncat(final, &fmt->conversion, 1); - else - { - transform = ft_transform(fmt, ap); - ft_strcat(final, transform); - free(transform); - } - free(fmt); } else - ft_strncat(final, str++, 1); + final = ft_strjoin(final, (char[]){*str++, 0}); + ft_strdel(&tmp); } ft_putstr_fd(final, fd); + ft_strdel(&final); + return (0); +} + +int ft_fmtcalc(char **final, char **str, va_list ap) +{ + t_fmt *fmt; + char *transform; + + *str += 1; + if (!(fmt = ft_printf_parse(str, ap))) + return (1); + if (!fmt->valid) + ft_strncat(*final, &fmt->conversion, 1); + else + { + transform = ft_transform(fmt, ap); + *final = ft_strjoin(*final, transform); + ft_strdel(&transform); + } + free(fmt); return (0); } diff --git a/libftasm/src/lst/ft_lst_sort.c b/libftasm/src/lst/ft_lst_sort.c deleted file mode 100644 index f7aedb68..00000000 --- a/libftasm/src/lst/ft_lst_sort.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lst_sort.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/04 11:09:37 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:38 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static void ft_lst_swap(t_list **current) -{ - t_list *tmp; - - tmp = (*current)->next->next; - (*current)->next->next = (*current); - (*current)->next = tmp; -} - -void ft_lst_sort(t_list **begin_list, int (*cmp)()) -{ - t_list *current; - t_list *last; - - current = *begin_list; - if (!*begin_list) - return ; - while (current->next) - { - if ((*cmp)(current->content, current->next->content) > 0) - { - if (current != *begin_list) - last->next = current->next; - else - *begin_list = current->next; - ft_lst_swap(¤t); - current = *begin_list; - } - else - { - last = current; - current = current->next ? current->next : current; - } - } -} diff --git a/libftasm/src/lst/ft_lstsort.c b/libftasm/src/lst/ft_lstsort.c index 4f0a8817..725b532f 100644 --- a/libftasm/src/lst/ft_lstsort.c +++ b/libftasm/src/lst/ft_lstsort.c @@ -6,44 +6,33 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:58 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 15:43:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static void ft_list_swap(t_list **current) +void ft_lstsort(t_list **begin_list, int (*cmp)()) { + t_list **indirect; t_list *tmp; + t_list *tmp2; - tmp = (*current)->next->next; - (*current)->next->next = (*current); - (*current)->next = tmp; -} - -void ft_list_sort(t_list **begin_list, int (*cmp)()) -{ - t_list *current; - t_list *last; - - current = *begin_list; + indirect = begin_list; if (!*begin_list) return ; - while (current->next) + while (*indirect && (*indirect)->next) { - if ((*cmp)(current->content, current->next->content) > 0) + if ((*cmp)((*indirect)->content, (*indirect)->next->content) > 0) { - if (current != *begin_list) - last->next = current->next; - else - *begin_list = current->next; - ft_list_swap(¤t); - current = *begin_list; + tmp = *indirect; + tmp2 = (*indirect)->next; + (*indirect)->next = (*indirect)->next->next; + *indirect = tmp2; + (*indirect)->next = tmp; + indirect = begin_list; } else - { - last = current; - current = current->next ? current->next : current; - } + indirect = &(*indirect)->next; } } diff --git a/libftasm/src/path/ft_path_notdir.c b/libftasm/src/path/ft_path_notdir.c index d85fe56b..b00d21fe 100644 --- a/libftasm/src/path/ft_path_notdir.c +++ b/libftasm/src/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/11/16 12:07:21 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 15:46:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ char *ft_path_notdir(char *path) char *ret; ret = path; - if ((slash = ft_strrchr(path, '/'))) + if ((slash = ft_strrchr(path, '/')) && slash != path) ret = slash + 1; return (ret); } diff --git a/libftasm/src/sstr/ft_sstrsort.c b/libftasm/src/sstr/ft_sstrsort.c index b2985c70..180d4ea0 100644 --- a/libftasm/src/sstr/ft_sstrsort.c +++ b/libftasm/src/sstr/ft_sstrsort.c @@ -6,19 +6,19 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:04:17 by jhalford ### ########.fr */ +/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_sstrsort(char **list, int size, int (*cmp)()) +void ft_sstrsort(char **list, int (*cmp)()) { int i; char *tmp; i = 0; - while (i < size - 1) + while (list[i] && list[i + 1]) { if ((*cmp)(list[i], list[i + 1]) > 0) { diff --git a/libftasm/src/str/ft_strdel.c b/libftasm/src/str/ft_strdel.c index a434df20..19df79fe 100644 --- a/libftasm/src/str/ft_strdel.c +++ b/libftasm/src/str/ft_strdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:00 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:00 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 18:03:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,9 @@ void ft_strdel(char **as) { - free(*as); - *as = NULL; + if (as) + { + free(*as); + *as = NULL; + } } diff --git a/libftasm/src/str/ft_strinsert.c b/libftasm/src/str/ft_strinsert.c index 3548469a..fcf8b1b6 100644 --- a/libftasm/src/str/ft_strinsert.c +++ b/libftasm/src/str/ft_strinsert.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strinsert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/21 18:21:57 by jhalford #+# #+# */ +/* Updated: 2016/11/21 18:21:57 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" char *ft_strinsert(char *str, char c, int n) diff --git a/libftasm/src/str/ft_strjoin.c b/libftasm/src/str/ft_strjoin.c index 943ded51..ece5a205 100644 --- a/libftasm/src/str/ft_strjoin.c +++ b/libftasm/src/str/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */ -/* Updated: 2016/11/10 10:14:09 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 18:10:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */