-
Notifications
You must be signed in to change notification settings - Fork 0
/
libft.h
286 lines (233 loc) · 10.6 KB
/
libft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgalaup <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 16:16:00 by fgalaup #+# #+# */
/* Updated: 2021/05/11 14:57:47 by fgalaup ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stdlib.h>
# include <unistd.h>
# include "ft_type.h"
# include "ft_define.h"
# include "ft_format.h"
# include "ft_format_type.h"
# ifdef DEBUG
# include "Memory/Manager/Debug/ft_managed_debug.h"
# include "Memory/Manager/Debug/ft_managed_debug.c"
# endif
/*
** =============================================================================
** NORME
** =============================================================================
*/
void *ftn(void **dest, void *src);
int fti(int *dest, int src);
void *ft_tern_pt(t_bool condition, void *value1, void *value2);
int ft_tern_nu(t_bool condition, int value1, int value2);
/*
** =============================================================================
** MEMORY
** =============================================================================
*/
void *ft_calloc(size_t count, size_t size);
void *ft_memdup(void *bytes_array, size_t array_size);
void *ft_memset(void *b, int c, size_t len);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n);
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
void *ft_memmove(void *dst, const void *src, size_t len);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void ft_nothing(void *address);
void ft_2d_free(void **address);
size_t ft_2d_count(void **array);
/*
** -----------------------------------------------------------------------------
** Managed Alloc
** -----------------------------------------------------------------------------
*/
# ifndef DEBUG
t_list **ft_managed_get_malloc_list(void);
void *ft_managed_malloc(size_t size);
void ft_managed_free(void *ptr);
void ft_managed_free_all(void);
# endif
t_term ft_managed_termination_function(t_ftermination f);
void *ft_managed_termination_params(void *params);
/*
** =============================================================================
** TYPE
** =============================================================================
*/
int ft_is_in_charset(const int c, char const *charset);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isprint(int c);
int ft_isascii(int c);
/*
** -----------------------------------------------------------------------------
** Overflow
** -----------------------------------------------------------------------------
*/
int64_t ft_overflow_get_min(int type);
int64_t ft_overflow_get_max(int type);
t_bool ft_badflow_addition(long long a, long long b, int type);
t_bool ft_overflow_addition(long long a, long long b, int type);
t_bool ft_underflow_addition(long long a, long long b, int type);
t_bool ft_badflow_subtraction(long long a, long long b, int type);
t_bool ft_overflow_subtraction(long long a, long long b, int type);
t_bool ft_underflow_subtraction(long long a, long long b, int type);
t_bool ft_badflow_multiplication(long long a, long long b, int type);
t_bool ft_overflow_multiplication(long long a, long long b, int type);
t_bool ft_underflow_multiplication(long long a, long long b, int type);
/*
** -----------------------------------------------------------------------------
** Convertion
** -----------------------------------------------------------------------------
*/
int ft_atoi(const char *str);
size_t ft_strtoll(const char *str, long long *number);
char *ft_itoa(int n);
char *ft_lltostr(long long number);
char *ft_ulltostr(unsigned long long number);
char *ft_base_ulltostr(unsigned long long number, char *base);
size_t ft_count_digits_base(int base_size, unsigned long long number);
char ft_is_in_base(char c, char *base);
int ft_check_base(char *base);
char *ft_is_negative(char *str, char *is_negative);
int ft_toupper(int c);
int ft_tolower(int c);
/*
** =============================================================================
** STRING
** =============================================================================
*/
size_t ft_strlen(const char *s);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
char *ft_strnstr(const char *str, const char *find, size_t len);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_stricmp(const char *s1, const char *s2);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strdup(const char *s1);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_strsplit_last(const char *string, int separator);
t_bool ft_strtest(const char *string, int (*f)(int));
char *ft_striter(char *string, int (*f)(int));
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
int ft_strformat(char **result, const char *format, ...);
char *ft_2d_merge(char **array);
/*
** =============================================================================
** FILE
** =============================================================================
*/
void ft_putchar_fd(int fd, char c);
void ft_putstr_fd(int fd, char *s);
void ft_putendl_fd(int fd, char *s);
void ft_putnbr_fd(int fd, long long n);
int ft_printf(const char *format, ...);
int ft_printf_fd(int fd, const char *format, ...);
char *ft_file_get_extention(char *file_name);
int get_next_line(int fd, char **line);
int get_next_line_core(t_open_fd *context, char **line);
int ft_reads_line(t_open_fd *context, char *buff, t_list **lst);
int ft_add_line_segment(t_list **list, char *str, int str_size);
/*
** =============================================================================
** MATH
** =============================================================================
*/
size_t ft_count_digits(long long number);
size_t ft_count_udigits(unsigned long long number);
size_t ft_absolute_ll(long number);
double ft_absolute_f(double number);
size_t ft_abs(long long number);
double ft_absf(double number);
/*
** -----------------------------------------------------------------------------
** Trigonometry
** -----------------------------------------------------------------------------
*/
double ft_degree_to_radian(double angle);
double ft_radian_to_degree(double angle);
t_xy ft_get_vector(double angle, double magnitude);
double ft_get_x_vector(double angle, double magnitude);
double ft_get_y_vector(double angle, double magnitude);
/*
** =============================================================================
** LIST
** =============================================================================
*/
t_list *ft_lstnew(void *content);
t_list *ft_lstnew_back(t_list **list, void *content, void (*del)(void *));
t_list *ft_lstnew_front(t_list **list, void *content, void (*del)(void *));
void ft_lstadd_front(t_list **alst, t_list *new);
void ft_lstadd_back(t_list **alst, t_list *new);
void ft_lstdel_link(t_list *lst, void (*del)(void*));
void ft_lstremove_link(t_list **list, t_list *link_del, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void*));
t_list *ft_lstlast(t_list *lst);
int ft_lstsize(t_list *lst);
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
char *ft_lstmerge_str_segments(t_list *segments);
void **ft_lstmerge_2d(t_list *list);
t_list *ft_lst_sort(t_list *list, t_boolean (*is_sort)(void *, void *));
/*
** -----------------------------------------------------------------------------
** Associative
** -----------------------------------------------------------------------------
*/
t_list *ft_lst_associative_set(t_list **list, char *key, void *value);
t_list *ft_lst_get_associative_link(const t_list *list, const char *key);
t_asso *ft_lst_get_associative(const t_list *list, const char *key);
void *ft_lst_associative_get(const t_list *list, const char *key);
t_bool ft_lst_associative_remove(t_list **lst, char *key, void (*del)(void *));
void ft_lst_associative_del(t_associative *to_del, void (*del)(void *));
void ft_lst_associative_del_free(void *to_del);
/*
** -----------------------------------------------------------------------------
** Binary Tree
** -----------------------------------------------------------------------------
*/
t_bnode *ft_binarytree_node_create(void *value);
/*
** -----------------------------------------------------------------------------
** bidirectional
** -----------------------------------------------------------------------------
*/
t_blst ft_blst_first(t_bidirectional_list *list);
t_blst ft_blst_last(t_bidirectional_list *list);
t_blst ft_blst_add_front(t_bidirectional_list **list, t_blst link);
t_blst ft_blst_add_back(t_bidirectional_list **list, t_blst link);
t_blst ft_blst_insert_link_before(t_bidirectional_list **list, t_blst link);
t_blst ft_blst_insert_link_after(t_bidirectional_list **list, t_blst link);
t_blst ft_blst_new(void *content);
t_blst ft_blst_new_back(t_blst *list, void *content, void (*del)(void *));
t_blst ft_blst_new_front(t_blst *list, void *content, void (*del)(void *));
void ft_blst_swap(t_bidirectional_list *lnk_a, t_bidirectional_list *lnk_b);
void ft_blst_move_before(t_blst *link, t_blst *dest_list);
void ft_blst_delete_link(t_bidirectional_list *link, void (*del)(void*));
void ft_blst_remove_link(t_blst *list, t_blst link, void (*del)(void*));
void ft_blst_clear(t_bidirectional_list **list, void (*del)(void*));
/*
** -----------------------------------------------------------------------------
** Segment
** -----------------------------------------------------------------------------
*/
t_list *ft_lstadd_array_segment(t_list **segments, int size, char *array);
int ft_lstmerge_segment(t_list *segment_list, char **str);
void ft_lstdel_array_segment(void *to_del);
#endif