42sh stuff

This commit is contained in:
Jack Halford 2017-03-31 21:42:02 +02:00
parent 39b2721eb3
commit 580c3ecc47
75 changed files with 474 additions and 251 deletions

View file

@ -66,6 +66,7 @@ ft_printf/ft_printf.c\
ft_printf/ft_printf_color.c\ ft_printf/ft_printf_color.c\
ft_printf/ft_printf_parse.c\ ft_printf/ft_printf_parse.c\
ft_printf/ft_transform.c\ ft_printf/ft_transform.c\
ft_printf/ft_vprintf.c\
ft_printf/lib_fmt.c\ ft_printf/lib_fmt.c\
ft_printf/lib_fmt_error.c\ ft_printf/lib_fmt_error.c\
ft_printf/lib_pad.c\ ft_printf/lib_pad.c\
@ -78,7 +79,6 @@ lst/ft_lst_cfree.c\
lst/ft_lst_delif.c\ lst/ft_lst_delif.c\
lst/ft_lst_delsub.c\ lst/ft_lst_delsub.c\
lst/ft_lst_filter.c\ lst/ft_lst_filter.c\
lst/ft_lst_filterout.c\
lst/ft_lst_find.c\ lst/ft_lst_find.c\
lst/ft_lst_merge.c\ lst/ft_lst_merge.c\
lst/ft_lst_order_delsub.c\ lst/ft_lst_order_delsub.c\
@ -102,6 +102,7 @@ lst/ft_lstnew_range.c\
lst/ft_lstsort.c\ lst/ft_lstsort.c\
lst/pop.c\ lst/pop.c\
lst/push.c\ lst/push.c\
lst/top.c\
math/ft_addrcmp.c\ math/ft_addrcmp.c\
math/ft_ilen.c\ math/ft_ilen.c\
math/ft_ilen_base.c\ math/ft_ilen_base.c\
@ -115,6 +116,7 @@ math/ft_uitoa_base.c\
math/ft_ulltoa_base.c\ math/ft_ulltoa_base.c\
math/id.c\ math/id.c\
mem/ft_bzero.c\ mem/ft_bzero.c\
mem/ft_malloc.c\
mem/ft_memalloc.c\ mem/ft_memalloc.c\
mem/ft_memccpy.c\ mem/ft_memccpy.c\
mem/ft_memchr.c\ mem/ft_memchr.c\
@ -134,6 +136,7 @@ sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\ sstr/ft_sstrdel.c\
sstr/ft_sstrdup.c\ sstr/ft_sstrdup.c\
sstr/ft_sstrfree.c\ sstr/ft_sstrfree.c\
sstr/ft_sstrmerge.c\
sstr/ft_sstrprint.c\ sstr/ft_sstrprint.c\
sstr/ft_sstrprint_fd.c\ sstr/ft_sstrprint_fd.c\
sstr/ft_sstrsort.c\ sstr/ft_sstrsort.c\
@ -183,10 +186,14 @@ str/ft_strstr.c\
str/ft_strsub.c\ str/ft_strsub.c\
str/ft_strtok.c\ str/ft_strtok.c\
str/ft_strtrim.c\ str/ft_strtrim.c\
sys/create_directory.c\
sys/dup2_close.c\ sys/dup2_close.c\
sys/fd_replace.c\
sys/ft_getenv.c\ sys/ft_getenv.c\
sys/ft_xattr_count.c\ sys/ft_xattr_count.c\
sys/ft_xattr_print.c\ sys/ft_xattr_print.c\
sys/is_directory.c\
sys/open_access.c\
time/ft_mytime_free.c\ time/ft_mytime_free.c\
time/ft_mytime_get.c\ time/ft_mytime_get.c\
time/ft_time_isrecent.c time/ft_time_isrecent.c

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
/* Updated: 2017/03/26 15:25:54 by jhalford ### ########.fr */ /* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,5 +39,6 @@ struct s_data_template
int cliopts_get(char **av, t_cliopts opt_map[], void *data); int cliopts_get(char **av, t_cliopts opt_map[], void *data);
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg); t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg);
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg); t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg);
int cliopts_has(char **av, char c);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
/* Updated: 2017/03/26 15:35:02 by jhalford ### ########.fr */ /* Updated: 2017/03/25 01:53:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,11 +16,12 @@
# include "libft.h" # include "libft.h"
# include <stdarg.h> # include <stdarg.h>
# define DG_PROTO "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" # define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ # define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
# define DG(s, ...) ft_dprintf(STDBUG, DG_PROTO s "{eoc}\n", DG_ARGS, ##__VA_ARGS__) # define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
# define ERR_PROTO(s, ...) "{red}%s: " s "{eoc}\n", PROGNAME, ##__VA_ARGS__ # define ERR_PROTO(u, m) "{red}%s: %s{eoc}\n", u, m
# define ERR_MSG(u, m) ft_dprintf(2, ERR_PROTO(u, m))
# define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__) # define ERR_SET(n, ...) error_set(n, ##__VA_ARGS__)
# define ERRMSG_MAX_SIZE 150 # define ERRMSG_MAX_SIZE 150
@ -29,8 +30,12 @@ enum e_errors
E_NOERR, E_NOERR,
E_CO_INV, E_CO_INV,
E_CO_INVL, E_CO_INVL,
E_CO_MULT,
E_CO_MISS, E_CO_MISS,
E_CO_MISSL, E_CO_MISSL,
E_SYS_NOFILE,
E_SYS_ISDIR,
E_SYS_NOPERM,
E_MAX, E_MAX,
}; };
@ -40,6 +45,6 @@ extern int g_errnum;
extern char **g_argv; extern char **g_argv;
int error_set(int n, ...); int error_set(int n, ...);
int ft_perror(void); int ft_perror(char *utility);
#endif #endif

View file

@ -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: 2017/03/14 18:07:10 by jhalford ### ########.fr */ /* Updated: 2017/03/20 09:23:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,6 +42,7 @@ struct s_fmt
char conversion; char conversion;
int valid; int valid;
t_conv conv; t_conv conv;
}; };
int ft_vdprintf(int fd, const char *format, va_list ap); int ft_vdprintf(int fd, const char *format, va_list ap);

View file

@ -1,22 +1,22 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* types.h :+: :+: :+: */ /* ft_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/28 10:57:17 by jhalford #+# #+# */ /* Created: 2017/03/25 01:56:58 by jhalford #+# #+# */
/* Updated: 2017/03/28 10:57:34 by jhalford ### ########.fr */ /* Updated: 2017/03/25 02:02:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef TYPES_H #ifndef FT_TYPES_H
# define TYPES_H # define FT_TYPES_H
typedef struct s_stos t_stos; typedef struct s_stos t_stos;
typedef struct s_stof t_stof; typedef struct s_stof t_stof;
typedef struct s_itof t_itof; typedef struct s_itof t_itof;
typedef long long t_type; typedef long long int t_flag;
typedef long long t_flag; typedef long long int t_type;
#endif #endif

View file

@ -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: 2017/03/28 10:58:15 by jhalford ### ########.fr */ /* Updated: 2017/03/25 01:56:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,14 +14,13 @@
# define LIBFT_H # define LIBFT_H
# include <string.h> # include <string.h>
# include <errno.h>
# include <unistd.h> # include <unistd.h>
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <time.h> # include <time.h>
# include <sys/xattr.h>
# include <sys/acl.h>
# include "types.h" # include "ft_types.h"
# include "error.h" # include "error.h"
# include "color.h" # include "color.h"
# include "cliopts.h" # include "cliopts.h"
@ -61,6 +60,7 @@ int ft_vdprintf(int fd, const char *format, va_list ap);
int ft_asprintf(char **ret, const char *format, ...); int ft_asprintf(char **ret, const char *format, ...);
int ft_vasprintf(char **ret, const char *format, va_list ap); int ft_vasprintf(char **ret, const char *format, va_list ap);
void *ft_malloc(size_t size);
void *ft_memset(void *b, int c, size_t len); void *ft_memset(void *b, int c, size_t len);
void ft_bzero(void *s, size_t n); void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n); void *ft_memcpy(void *dst, const void *src, size_t n);

View file

@ -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: 2017/03/28 20:34:27 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:09:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,12 +26,13 @@ typedef struct s_list t_list;
int pop(t_list **lst); int pop(t_list **lst);
t_list *push(t_list **stack, int elem); t_list *push(t_list **stack, int elem);
int top(t_list *top);
t_list *ft_lstnew(void const *content, size_t content_size); t_list *ft_lstnew(void const *content, size_t content_size);
void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
void ft_lstadd(t_list **alst, t_list *new); void ft_lstadd(t_list **alst, t_list *new);
int ft_lstiter(t_list *lst, int (*f)(), void *data); int ft_lstiter(t_list *lst, int (*f)());
t_list *ft_lstmap(t_list *lst, void *(*f)(void *)); t_list *ft_lstmap(t_list *lst, void *(*f)(void *));
t_list *ft_lstnew_range(int a, int b); t_list *ft_lstnew_range(int a, int b);
@ -75,11 +76,6 @@ t_list *ft_lst_find(
t_list *ft_lstpop(t_list **lst); t_list *ft_lstpop(t_list **lst);
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
void ft_lst_reverse(t_list **begin_list); void ft_lst_reverse(t_list **begin_list);
void ft_lst_filterout(
t_list **alst,
void *data_ref,
int (*cmp)(),
void (*del)(void *, size_t));
int ft_diff(void *a, void *b); int ft_diff(void *a, void *b);
t_list *ft_id(t_list *a); t_list *ft_id(t_list *a);

View file

@ -1,11 +1,12 @@
/* ************************************************************************** */ /* */ /* ************************************************************************** */
/* */
/* ::: :::::::: */ /* ::: :::::::: */
/* math.h :+: :+: :+: */ /* math.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 13:19:12 by jhalford #+# #+# */ /* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
/* Updated: 2017/02/18 13:19:57 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */ /* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */
/* Updated: 2017/03/07 11:35:11 by ariard ### ########.fr */ /* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,7 @@ void ft_sstrsort(char **list, int (*cmp)());
void ft_sstrprint(char **list, char sep); void ft_sstrprint(char **list, char sep);
void ft_sstrprint_fd(int fd, char **list, char sep); void ft_sstrprint_fd(int fd, char **list, char sep);
char **ft_sstrdup(char **list); char **ft_sstrdup(char **list);
char **ft_sstrmerge(char **s1, char **s2);
void ft_sstrdel(char **sstr, int index); void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr); void ft_sstrfree(char **sstr);
char *ft_sstrcat(char **sstr, char sep); char *ft_sstrcat(char **sstr, char sep);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
/* Updated: 2017/03/14 17:24:24 by jhalford ### ########.fr */ /* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,12 +19,25 @@
# define STDERR STDERR_FILENO # define STDERR STDERR_FILENO
# define STDBUG 3 # define STDBUG 3
# define PIPE_READ 0
# define PIPE_WRITE 1
# include <sys/types.h> # include <sys/types.h>
# include <sys/xattr.h> # include <sys/xattr.h>
# include <sys/acl.h>
# include <sys/stat.h>
# include <fcntl.h>
int ft_xattr_print(char *path); int ft_xattr_print(char *path);
int ft_xattr_count(char *path); int ft_xattr_count(char *path);
char *ft_getenv(char **env, char *key); char *ft_getenv(char **env, char *key);
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm);
int is_directory(const char *path);
char *create_directory(const char *path, const char *old_pathnames);
int dup2_close(int fd1, int fd2); int dup2_close(int fd1, int fd2);
int fd_replace(int fd1, int fd2);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
/* Updated: 2017/03/08 00:35:44 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ t_btree *btree_create_node(void const *item, size_t content_size)
{ {
t_btree *new; t_btree *new;
if (!(new = (t_btree *)malloc(sizeof(t_btree)))) if (!(new = (t_btree *)ft_malloc(sizeof(t_btree))))
return (NULL); return (NULL);
new->left = 0; new->left = 0;
new->right = 0; new->right = 0;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */ /* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */
/* Updated: 2016/12/05 11:53:24 by jhalford ### ########.fr */ /* Updated: 2017/03/21 19:43:51 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* btree_map.c :+: :+: :+: */ /* btree_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ /* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */
/* Updated: 2017/03/15 18:43:15 by ariard ### ########.fr */ /* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,9 @@ t_btree *btree_map(t_btree *root, void *(*f)(void *))
if (!root) if (!root)
return (NULL); return (NULL);
new = btree_create_node((*f)(root->item), root->content_size); if (!(new = (t_btree *)ft_malloc(sizeof(*new))))
return (NULL);
new->item = (*f)(root->item);
new->left = btree_map(root->left, f); new->left = btree_map(root->left, f);
new->right = btree_map(root->right, f); new->right = btree_map(root->right, f);
return (new); return (new);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
/* Updated: 2016/12/06 20:10:51 by jhalford ### ########.fr */ /* Updated: 2017/03/20 21:06:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
/* Updated: 2017/03/26 16:37:04 by jhalford ### ########.fr */ /* Updated: 2017/03/25 15:00:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -75,7 +75,7 @@ static int cliopts_parse_long(
if (map->get) if (map->get)
{ {
if (map->arg_required && !(tmp = check_required(av, NULL))) if (map->arg_required && !(tmp = check_required(av, NULL)))
return (ERR_SET(E_CO_MISSL, arg)); return (ERR_SET(E_CO_MISS, *arg));
if ((map->get)(tmp, data)) if ((map->get)(tmp, data))
return (ERR_SET(E_CO_MISSL, arg)); return (ERR_SET(E_CO_MISSL, arg));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */ /* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */
/* Updated: 2016/12/07 17:35:12 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ t_dlist *ft_dlstnew(void const *content, size_t content_size)
if (!content) if (!content)
{ {
new = malloc(sizeof(*new)); new = ft_malloc(sizeof(*new));
if (!new) if (!new)
return (NULL); return (NULL);
new->content_size = 0; new->content_size = 0;
@ -26,7 +26,7 @@ t_dlist *ft_dlstnew(void const *content, size_t content_size)
} }
else else
{ {
new = (t_dlist *)malloc(sizeof(*new)); new = (t_dlist *)ft_malloc(sizeof(*new));
if (!new) if (!new)
return (NULL); return (NULL);
new->content_size = content_size; new->content_size = content_size;

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* error.c :+: :+: :+: */ /* error.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */ /* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
/* Updated: 2017/03/26 16:36:54 by jhalford ### ########.fr */ /* Updated: 2017/03/25 01:53:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,11 +14,15 @@
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] = char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
{ {
"no error", "unknown error 0",
"invalid option -%c", "invalid option -%c",
"invalid option --%s", "invalid option --%s",
"option '%c' awaits argument(s): please don't combine",
"option '%c': missing argument", "option '%c': missing argument",
"option '%s': missing argument", "option '%s': missing argument",
"%s: no such file or directory",
"%s: Is a directory",
"%s: Permission denied",
}; };
int g_errnum = 0; int g_errnum = 0;
@ -36,8 +40,9 @@ int error_set(int n, ...)
return (g_errnum); return (g_errnum);
} }
int ft_perror(void) int ft_perror(char *utility)
{ {
ft_dprintf(2, "{red}%s: %s{eoc}\n", g_argv[0], g_errmsg); utility = utility ? utility : g_argv[0];
ERR_MSG(utility, g_errmsg);
return (g_errnum); return (g_errnum);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
/* Updated: 2017/03/11 13:14:19 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
char *ft_signed_conversion(t_fmt *fmt, va_list ap) char *ft_signed_conversion(t_fmt *fmt, va_list ap)
{ {
char base10[] = "0123456789"; static char base10[] = "0123456789";
long long arg; long long arg;
arg = va_arg(ap, int); arg = va_arg(ap, int);
@ -48,7 +48,7 @@ char *ft_char_conversion(t_fmt *fmt, va_list ap)
char *ret; char *ret;
(void)fmt; (void)fmt;
ret = (char *)malloc(sizeof(char) + 1); ret = (char *)ft_malloc(sizeof(char) + 1);
ret[0] = (char)va_arg(ap, int); ret[0] = (char)va_arg(ap, int);
ret[1] = '\0'; ret[1] = '\0';
return (ret); return (ret);
@ -61,7 +61,7 @@ char *ft_str_conversion(t_fmt *fmt, va_list ap)
(void)fmt; (void)fmt;
ret = va_arg(ap, char *); ret = va_arg(ap, char *);
if (ret == NULL) if (ret == NULL)
return(ft_strdup("NULL")); return (ft_strdup("NULL"));
ret = ft_strdup(ret); ret = ft_strdup(ret);
if (fmt->precision && fmt->precision < (int)ft_strlen(ret)) if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
ret[fmt->precision] = '\0'; ret[fmt->precision] = '\0';

View file

@ -6,25 +6,12 @@
/* 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: 2017/03/14 20:24:44 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:28:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "ft_printf.h" #include "ft_printf.h"
t_conv g_convs[] =
{
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'s', "-", "", &ft_str_conversion, NULL},
{'c', "-", "", &ft_char_conversion, NULL},
};
int ft_printf(const char *format, ...) int ft_printf(const char *format, ...)
{ {
va_list ap; va_list ap;
@ -44,64 +31,7 @@ int ft_dprintf(int fd, const char *format, ...)
int ft_asprintf(char **ret, const char *format, ...) int ft_asprintf(char **ret, const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
return (ft_vasprintf(ret, format, ap)); return (ft_vasprintf(ret, format, ap));
} }
int ft_vdprintf(int fd, const char *format, va_list ap)
{
char *ret;
ret = NULL;
if (ft_vasprintf(&ret, format, ap))
return (1);
ft_putstr_fd(ret, fd);
ft_strdel(&ret);
return (0);
}
int ft_vasprintf(char **ret, const char *format, va_list ap)
{
char *str;
char *tmp;
char *final;
str = (char *)format;
final = ft_strnew(1);
while (*str)
{
tmp = final;
if (*str == '{')
ft_printf_color(&final, &str, ap);
else if (*str == '%')
{
if (ft_fmtcalc(&final, &str, ap))
return (1);
}
else
final = ft_strjoin(final, (char[]){*str++, 0});
ft_strdel(&tmp);
}
*ret = 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ /* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */
/* Updated: 2017/03/11 14:00:20 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:51:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,11 +40,10 @@ void ft_printf_color(char **final, char **str, va_list ap)
*str += 5; *str += 5;
return ; return ;
} }
while(g_colors[i].key) while (g_colors[i].key)
{ {
if (ft_strncmp(*str, g_colors[i].key, 5) == 0) if (ft_strncmp(*str, g_colors[i].key, 5) == 0)
{ {
/* if (isatty(fd)) */
*final = ft_strjoin(*final, g_colors[i].val); *final = ft_strjoin(*final, g_colors[i].val);
*str += 5; *str += 5;
return ; return ;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
/* Updated: 2017/02/18 13:08:53 by jhalford ### ########.fr */ /* Updated: 2017/03/20 15:55:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -121,4 +121,3 @@ t_fmt *ft_printf_parse(char **format, va_list ap)
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1; fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
return (fmt); return (fmt);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
/* Updated: 2016/12/13 11:19:29 by jhalford ### ########.fr */ /* Updated: 2017/03/20 10:26:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,85 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:22:30 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
t_conv g_convs[] =
{
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
{'s', "-", "", &ft_str_conversion, NULL},
{'c', "-", "", &ft_char_conversion, NULL},
};
int ft_vdprintf(int fd, const char *format, va_list ap)
{
char *ret;
char size;
ret = NULL;
size = ft_vasprintf(&ret, format, ap);
if (size != -1)
ft_putstr_fd(ret, fd);
ft_strdel(&ret);
return (size);
}
int ft_vasprintf(char **ret, const char *format, va_list ap)
{
char *str;
char *tmp;
char *final;
str = (char *)format;
final = ft_strnew(1);
while (*str)
{
tmp = final;
if (*str == '{')
ft_printf_color(&final, &str, ap);
else if (*str == '%')
{
if (ft_fmtcalc(&final, &str, ap))
return (-1);
}
else if (!(final = ft_strjoin(final, (char[]){*str++, 0})))
return (-1);
ft_strdel(&tmp);
}
*ret = final;
return (ft_strlen(final));
}
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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:54:40 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ t_fmt *ft_fmt_init(void)
{ {
t_fmt *fmt; t_fmt *fmt;
fmt = (t_fmt *)malloc(sizeof(t_fmt) + 1); fmt = (t_fmt *)ft_malloc(sizeof(t_fmt) + 1);
ft_bzero(fmt->flags, 6); ft_bzero(fmt->flags, 6);
ft_bzero(fmt->modifier, 3); ft_bzero(fmt->modifier, 3);
fmt->conversion = '\0'; fmt->conversion = '\0';

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */ /* Updated: 2017/03/20 15:54:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,8 +24,11 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt)
void ft_pad_sharp_xb(char *str, t_fmt *fmt) void ft_pad_sharp_xb(char *str, t_fmt *fmt)
{ {
char start[3] = {'0',fmt->conversion, 0}; char start[3];
start[0] = '0';
start[1] = fmt->conversion;
start[2] = 0;
if (str[0] == '0') if (str[0] == '0')
{ {
if (str[1] == '0') if (str[1] == '0')

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */ /* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */
/* Updated: 2017/03/14 17:47:51 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */
/* Updated: 2017/03/26 16:55:52 by jhalford ### ########.fr */ /* Updated: 2017/01/12 14:33:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
/* Updated: 2017/03/26 17:11:27 by jhalford ### ########.fr */ /* Updated: 2017/03/02 17:47:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */
/* Updated: 2017/03/26 16:55:33 by jhalford ### ########.fr */ /* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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: 2017/03/26 17:13:28 by jhalford ### ########.fr */ /* Updated: 2017/03/13 15:31:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 13:39:33 by jhalford #+# #+# */ /* Created: 2016/12/05 13:39:33 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:31:10 by jhalford ### ########.fr */ /* Updated: 2017/03/18 17:17:50 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,17 +6,19 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */ /* Updated: 2017/03/11 16:17:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_lstiter(t_list *lst, int (*f)(), void *data) int ft_lstiter(t_list *lst, int (*f)())
{ {
if (!lst) while (lst)
return (0); {
if ((*f)(lst->content, data)) if ((*f)(lst->content))
return (1); return (1);
return (ft_lstiter(lst->next, f, data)); lst = lst->next;
}
return (0);
} }

View file

@ -6,7 +6,7 @@
/* 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: 2017/03/08 12:03:14 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,9 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *))
if (!lst) if (!lst)
return (NULL); return (NULL);
elem = ft_lstnew((*f)(lst->content), lst->content_size); if (!(elem = (t_list *)ft_malloc(sizeof(*elem))))
return (NULL);
elem->content = (*f)(lst->content);
elem->next = ft_lstmap(lst->next, f); elem->next = ft_lstmap(lst->next, f);
return (elem); return (elem);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:57:38 by jhalford #+# #+# */ /* Created: 2016/11/29 15:57:38 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:41:27 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ t_list *ft_lstnew(void const *content, size_t content_size)
{ {
t_list *new; t_list *new;
if (!(new = (t_list *)malloc(sizeof(*new)))) if (!(new = (t_list *)ft_malloc(sizeof(*new))))
return (NULL); return (NULL);
new->next = NULL; new->next = NULL;
new->content_size = content_size; new->content_size = content_size;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:49:59 by jhalford ### ########.fr */ /* Updated: 2017/03/24 20:05:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

18
libftasm/srcs/lst/top.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* top.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 20:04:27 by jhalford #+# #+# */
/* Updated: 2017/03/24 20:09:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int top(t_list *top)
{
return (top ? *(int*)top->content : 0);
}

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* id.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 12:20:59 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:21:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
void *id(void *data) void *id(void *data)

View file

@ -1,36 +1,26 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_lst_filterout.c :+: :+: :+: */ /* ft_malloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 16:56:02 by jhalford #+# #+# */ /* Created: 2017/03/21 15:45:00 by jhalford #+# #+# */
/* Updated: 2017/03/26 19:10:03 by jhalford ### ########.fr */ /* Updated: 2017/03/23 18:31:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
void ft_lst_filterout( void *ft_malloc(size_t size)
t_list **alst,
void *data_ref,
int (*cmp)(),
void (*del)(void *, size_t))
{ {
t_list *tmp; void *ptr;
t_list **indirect;
indirect = alst; ptr = malloc(size);
while (*indirect) if (!ptr)
{ {
if ((*cmp)((*indirect)->content, data_ref) == 0) ft_putstr_fd(strerror(errno), 2);
{ exit(errno);
tmp = *indirect;
(*indirect) = (*indirect)->next;
ft_lstdelone(&tmp, del);
}
else
indirect = &(*indirect)->next;
} }
return (ptr);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */
/* Updated: 2017/03/06 15:41:01 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ void *ft_memalloc(size_t size)
void *addr; void *addr;
size_t i; size_t i;
addr = malloc(size); addr = ft_malloc(size);
if (addr == NULL) if (addr == NULL)
return (NULL); return (NULL);
i = -1; i = -1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */ /* Updated: 2017/03/20 16:19:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */ /* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */
/* Updated: 2016/12/09 18:31:03 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/12/07 15:22:09 by jhalford ### ########.fr */ /* Updated: 2017/03/25 15:03:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */
/* Updated: 2017/03/07 14:28:29 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:04:07 by jhalford #+# #+# */ /* Created: 2016/11/03 18:04:07 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:09:17 by jhalford ### ########.fr */ /* Updated: 2017/03/25 01:38:51 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,9 +17,10 @@ void ft_sstrdel(char **sstr, int index)
int i; int i;
i = index; i = index;
while (sstr[i]) ft_strdel(&sstr[index]);
while (i == index || sstr[i])
{ {
sstr[i] = sstr[i + 1]; sstr[i] = sstr[i + 1];
i++; ++i;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */ /* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */
/* Updated: 2017/03/07 19:58:12 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@ char **ft_sstrdup(char **list)
size = 0; size = 0;
while (list[size]) while (list[size])
size++; size++;
cpy = (char **)malloc(sizeof(char *) * (size + 1)); cpy = (char **)ft_malloc(sizeof(char *) * (size + 1));
while (*list) while (*list)
{ {
cpy[i++] = ft_strdup(*list); cpy[i++] = ft_strdup(*list);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ /* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */
/* Updated: 2017/01/11 14:42:45 by jhalford ### ########.fr */ /* Updated: 2017/03/22 23:19:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrmerge.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 17:40:50 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:05:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_sstrmerge(char **s1, char **s2)
{
char **out;
out = ft_sstrdup(s1);
if (!s2)
return (out);
while (*s2)
{
out = ft_sstradd(out, *s2);
s2++;
}
return (out);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 15:17:29 by jhalford #+# #+# */ /* Created: 2016/11/28 15:17:29 by jhalford #+# #+# */
/* Updated: 2016/11/28 15:23:52 by jhalford ### ########.fr */ /* Updated: 2017/03/18 03:37:16 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,8 @@ void ft_sstrprint_fd(int fd, char **list, char sep)
int i; int i;
i = 0; i = 0;
if (!list || !*list)
return ;
while (list[i]) while (list[i])
{ {
ft_putstr_fd(list[i++], fd); ft_putstr_fd(list[i++], fd);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_sstrsort.c :+: :+: :+: */ /* ft_sstrsort.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */
/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ /* Updated: 2017/03/23 14:40:25 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:29:54 by ariard #+# #+# */ /* Created: 2017/03/07 11:29:54 by ariard #+# #+# */
/* Updated: 2017/03/07 12:44:17 by ariard ### ########.fr */ /* Updated: 2017/03/22 21:54:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,9 +21,6 @@ char *ft_sstrstr(char **sstr, char *find)
size = ft_strlen(find); size = ft_strlen(find);
while ((*sstr)) while ((*sstr))
{ {
DG("size : %d", size);
DG("sstr : %s", *sstr);
DG("find : %s", find);
if (ft_strncmp(*sstr, find, size) == 0) if (ft_strncmp(*sstr, find, size) == 0)
return (*sstr); return (*sstr);
sstr++; sstr++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:21:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,6 +27,8 @@ int ft_atoi(const char *str)
int res; int res;
int sign; int sign;
if (!str || !*str)
return (0);
i = 0; i = 0;
res = 0; res = 0;
sign = 1; sign = 1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */ /* Created: 2017/02/03 16:07:17 by jhalford #+# #+# */
/* Updated: 2017/02/03 16:12:40 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,7 @@ char *ft_strdupi_w(char const *s)
i = 0; i = 0;
while (s[i] && s[i] != ' ' && s[i] != '\t') while (s[i] && s[i] != ' ' && s[i] != '\t')
i++; i++;
str = (char *)malloc(sizeof(char) * (i + 1)); str = (char *)ft_malloc(sizeof(char) * (i + 1));
if (str) if (str)
{ {
str[i--] = '\0'; str[i--] = '\0';
@ -59,7 +59,7 @@ char **ft_split_whitespaces(char const *s)
str = NULL; str = NULL;
if (!(s)) if (!(s))
return (str); return (str);
str = (char **)malloc(sizeof(char *) * (ft_len_words(s) + 1)); str = (char **)ft_malloc(sizeof(char *) * (ft_len_words(s) + 1));
i = 0; i = 0;
j = 0; j = 0;
if (!(str)) if (!(str))

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */ /* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */
/* Updated: 2016/12/09 19:11:20 by jhalford ### ########.fr */ /* Updated: 2017/03/21 14:21:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -14,7 +14,7 @@
char *ft_strcatf(char *s1, const char *s2) char *ft_strcatf(char *s1, const char *s2)
{ {
char buf[ft_strlen(s2)]; char buf[ft_strlen(s1) + 1];
ft_strcpy(buf, s1); ft_strcpy(buf, s1);
ft_strcpy(s1, s2); ft_strcpy(s1, s2);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcspn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:55:33 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:00:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
size_t ft_strcspn(char *s, const char *delim) size_t ft_strcspn(char *s, const char *delim)
@ -5,8 +17,8 @@ size_t ft_strcspn(char *s, const char *delim)
char *str; char *str;
str = s; str = s;
while(*str) while (*str)
if(ft_strchr(delim,*str)) if (ft_strchr(delim, *str))
return (str - s); return (str - s);
else else
str++; str++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */ /* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */
/* Updated: 2017/03/07 14:27:58 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ char *ft_strdup(const char *s1)
{ {
char *dup; char *dup;
if (!s1 || !(dup = (char*)malloc(sizeof(*dup) * (ft_strlen(s1) + 1)))) if (!s1 || !(dup = (char*)ft_malloc(sizeof(*dup) * (ft_strlen(s1) + 1))))
return (NULL); return (NULL);
ft_strcpy(dup, s1); ft_strcpy(dup, s1);
return (dup); return (dup);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:01:15 by ariard #+# #+# */ /* Created: 2017/03/07 11:01:15 by ariard #+# #+# */
/* Updated: 2017/03/07 11:24:27 by ariard ### ########.fr */ /* Updated: 2017/03/22 23:12:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */ /* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/06 13:37:12 by ariard #+# #+# */ /* Created: 2017/01/06 13:37:12 by ariard #+# #+# */
/* Updated: 2017/03/07 12:41:20 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:43:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 15:11:28 by ariard #+# #+# */ /* Created: 2017/03/02 15:11:28 by ariard #+# #+# */
/* Updated: 2017/03/07 11:44:29 by ariard ### ########.fr */ /* Updated: 2017/03/20 16:01:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */ /* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */
/* Updated: 2017/03/07 11:06:41 by ariard ### ########.fr */ /* Updated: 2017/03/18 14:25:09 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */ /* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 16:10:54 by ariard #+# #+# */ /* Created: 2016/12/01 16:10:54 by ariard #+# #+# */
/* Updated: 2017/03/07 11:30:02 by ariard ### ########.fr */ /* Updated: 2017/03/22 22:12:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:24 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:24 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:25 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ char *ft_strmap(char const *s, char (*f)(char))
char *out; char *out;
size = ft_strlen(s); size = ft_strlen(s);
out = (char *)malloc(sizeof(char) * (size + 1)); out = (char *)ft_malloc(sizeof(char) * (size + 1));
if (out == NULL) if (out == NULL)
return (NULL); return (NULL);
i = -1; i = -1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:28 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:28 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:29 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
char *out; char *out;
size = ft_strlen(s); size = ft_strlen(s);
out = (char *)malloc(sizeof(char) * (size + 1)); out = (char *)ft_malloc(sizeof(char) * (size + 1));
if (out == NULL) if (out == NULL)
return (NULL); return (NULL);
i = -1; i = -1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:34 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:34 by jhalford #+# #+# */
/* Updated: 2017/01/11 16:37:53 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ char *ft_strnew(size_t size)
char *addr; char *addr;
size_t i; size_t i;
addr = (char *)malloc(size + 1); addr = (char *)ft_malloc(size + 1);
if (addr == NULL) if (addr == NULL)
return (NULL); return (NULL);
i = -1; i = -1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,7 +49,7 @@ char **ft_strsplit(char const *s, char c)
int k; int k;
char **str2; char **str2;
if (!s || !(str2 = (char **)malloc(sizeof(*str2) * if (!s || !(str2 = (char **)ft_malloc(sizeof(*str2) *
(ft_countwords(s, c) + 1)))) (ft_countwords(s, c) + 1))))
return (NULL); return (NULL);
i = -1; i = -1;

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */ /* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */ /* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
/* Updated: 2016/11/25 11:31:36 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ char *ft_strsub(char const *s, unsigned int start, size_t len)
char *out; char *out;
size_t i; size_t i;
if (!(out = (char *)malloc(sizeof(char) * (len + 1)))) if (!(out = (char *)ft_malloc(sizeof(char) * (len + 1))))
return (NULL); return (NULL);
i = -1; i = -1;
while (++i < len) while (++i < len)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 18:08:31 by jhalford #+# #+# */ /* Created: 2017/03/07 18:08:31 by jhalford #+# #+# */
/* Updated: 2017/03/07 18:18:30 by jhalford ### ########.fr */ /* Updated: 2017/03/22 22:23:33 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,10 +19,11 @@ char *ft_strtok(char *s, const char *delim)
if (s == 0) if (s == 0)
s = lasts; s = lasts;
do {
if ((ch = *s++) == 0) if ((ch = *s++) == 0)
return (0); return (0);
} while (ft_strchr(delim, ch)); while (ft_strchr(delim, ch))
if ((ch = *s++) == 0)
return (0);
--s; --s;
lasts = s + ft_strcspn(s, delim); lasts = s + ft_strcspn(s, delim);
if (*lasts != 0) if (*lasts != 0)

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_directory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 03:18:18 by ariard #+# #+# */
/* Updated: 2017/03/25 15:12:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *create_directory(const char *path, const char *old_pathnames)
{
char *new_pathnames;
char *newdir;
char *temp;
char *semi;
new_pathnames = ft_strdup(old_pathnames);
temp = new_pathnames;
while (new_pathnames)
{
if ((semi = ft_strchr(new_pathnames, ':')))
*semi = 0;
if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path)))
ft_strdel(&newdir);
else
break ;
new_pathnames += ft_strlen(new_pathnames) + 1;
}
ft_strdel(&temp);
return (newdir);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */ /* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */
/* Updated: 2017/02/07 16:15:52 by jhalford ### ########.fr */ /* Updated: 2017/03/24 19:33:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,9 @@
int dup2_close(int fd1, int fd2) int dup2_close(int fd1, int fd2)
{ {
if (dup2(fd1, fd2)) if (dup2(fd1, fd2) < 0)
return (-1); return (-1);
if (close(fd1)) if (close(fd1) < 0)
return (-1); return (-1);
return (0); return (0);
} }

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fd_replace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
/* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int fd_replace(int fd1, int fd2)
{
if (fd1 != fd2)
return (dup2_close(fd1, fd2));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:45 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:45 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:29:25 by jhalford ### ########.fr */ /* Updated: 2017/03/18 03:09:57 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,8 @@ char *ft_getenv(char **env, char *key)
return (NULL); return (NULL);
while (*env) while (*env)
{ {
if (ft_strcmp(*env, key) == '=') if (ft_strcmp(*env, key) == '='
&& ft_strlen(key) == ft_strlenchr(*env, '='))
return (*env + ft_strlen(key) + 1); return (*env + ft_strlen(key) + 1);
env++; env++;
} }

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_directory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */
/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int is_directory(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return (S_ISDIR(path_stat.st_mode));
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* open_access.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm)
{
int fd;
if (a_flag & F_OK && access(file, F_OK) != 0)
return (-ERR_SET(E_SYS_NOFILE, file));
if (is_directory(file))
return (-ERR_SET(E_SYS_ISDIR, file));
if (access(file, F_OK) == 0 && access(file, a_flag) != 0)
return (-ERR_SET(E_SYS_NOPERM, file));
if ((fd = open(file, o_flag, o_perm)) < 0)
{
exit(1);
}
return (fd);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */ /* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */
/* Updated: 2016/12/03 11:54:16 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ t_mytime *ft_mytime_get(time_t epoch)
char *date; char *date;
t_mytime *time; t_mytime *time;
time = (t_mytime*)malloc(sizeof(*time)); time = (t_mytime*)ft_malloc(sizeof(*time));
date = ctime(&epoch); date = ctime(&epoch);
date[ft_strlen(date) - 1] = 0; date[ft_strlen(date) - 1] = 0;
time->year = ft_isdigit(date[20]) ? time->year = ft_isdigit(date[20]) ?

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */ /* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */
/* Updated: 2016/11/25 11:43:52 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:44:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */