libft updates for ft_ls
This commit is contained in:
parent
8960d54455
commit
cf8d5f81aa
11 changed files with 73 additions and 105 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:22:54 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_vdprintf(int fd, const char *format, va_list ap);
|
||||||
|
int ft_fmtcalc(char **final, char **str, va_list ap);
|
||||||
|
|
||||||
extern t_conv g_convs[];
|
extern t_conv g_convs[];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:49:04 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);
|
int ft_addrcmp(void *a, void *b);
|
||||||
|
|
||||||
char **ft_sstradd(char **list, char *new);
|
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);
|
void ft_sstrprint(char **list, char sep);
|
||||||
char **ft_sstrdup(char **list);
|
char **ft_sstrdup(char **list);
|
||||||
void ft_sstrdel(char **sstr, int index);
|
void ft_sstrdel(char **sstr, int index);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:27:46 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);
|
t_list *ft_lstnew_range(int a, int b);
|
||||||
void ft_lsteadd(t_list **alst, t_list *new);
|
void ft_lsteadd(t_list **alst, t_list *new);
|
||||||
void ft_lstnadd(t_list **alst, t_list *new, int n);
|
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)());
|
void ft_lst_print(t_list *list, void (*printer)());
|
||||||
int ft_lstsize(t_list *lst);
|
int ft_lstsize(t_list *lst);
|
||||||
t_list *ft_lstlast(t_list *lst);
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:27 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)
|
int ft_vdprintf(int fd, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
char *transform;
|
char *tmp;
|
||||||
char final[1000];
|
char *final;
|
||||||
t_fmt *fmt;
|
|
||||||
|
|
||||||
str = (char *)format;
|
str = (char *)format;
|
||||||
ft_bzero(final, 1000);
|
final = ft_strnew(1);
|
||||||
while (*str)
|
while (*str)
|
||||||
{
|
{
|
||||||
|
tmp = final;
|
||||||
if (*str == '%')
|
if (*str == '%')
|
||||||
{
|
{
|
||||||
str++;
|
if (ft_fmtcalc(&final, &str, ap))
|
||||||
if (!(fmt = ft_printf_parse(&str, ap)))
|
return (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
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);
|
return (1);
|
||||||
if (!fmt->valid)
|
if (!fmt->valid)
|
||||||
ft_strncat(final, &fmt->conversion, 1);
|
ft_strncat(*final, &fmt->conversion, 1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
transform = ft_transform(fmt, ap);
|
transform = ft_transform(fmt, ap);
|
||||||
ft_strcat(final, transform);
|
*final = ft_strjoin(*final, transform);
|
||||||
free(transform);
|
ft_strdel(&transform);
|
||||||
}
|
}
|
||||||
free(fmt);
|
free(fmt);
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_strncat(final, str++, 1);
|
|
||||||
}
|
|
||||||
ft_putstr_fd(final, fd);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_sort.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,44 +6,33 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:58 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"
|
#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 *tmp;
|
||||||
|
t_list *tmp2;
|
||||||
|
|
||||||
tmp = (*current)->next->next;
|
indirect = begin_list;
|
||||||
(*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;
|
|
||||||
if (!*begin_list)
|
if (!*begin_list)
|
||||||
return ;
|
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)
|
tmp = *indirect;
|
||||||
last->next = current->next;
|
tmp2 = (*indirect)->next;
|
||||||
else
|
(*indirect)->next = (*indirect)->next->next;
|
||||||
*begin_list = current->next;
|
*indirect = tmp2;
|
||||||
ft_list_swap(¤t);
|
(*indirect)->next = tmp;
|
||||||
current = *begin_list;
|
indirect = begin_list;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
indirect = &(*indirect)->next;
|
||||||
last = current;
|
|
||||||
current = current->next ? current->next : current;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:45:07 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;
|
char *ret;
|
||||||
|
|
||||||
ret = path;
|
ret = path;
|
||||||
if ((slash = ft_strrchr(path, '/')))
|
if ((slash = ft_strrchr(path, '/')) && slash != path)
|
||||||
ret = slash + 1;
|
ret = slash + 1;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,19 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 18:03:37 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"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_sstrsort(char **list, int size, int (*cmp)())
|
void ft_sstrsort(char **list, int (*cmp)())
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < size - 1)
|
while (list[i] && list[i + 1])
|
||||||
{
|
{
|
||||||
if ((*cmp)(list[i], list[i + 1]) > 0)
|
if ((*cmp)(list[i], list[i + 1]) > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:58:00 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)
|
void ft_strdel(char **as)
|
||||||
{
|
{
|
||||||
|
if (as)
|
||||||
|
{
|
||||||
free(*as);
|
free(*as);
|
||||||
*as = NULL;
|
*as = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strinsert.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/21 18:21:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/21 18:21:57 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
char *ft_strinsert(char *str, char c, int n)
|
char *ft_strinsert(char *str, char c, int n)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:58:18 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue