A-maze-D documentation 1.0.0
Loading...
Searching...
No Matches
my.h
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2023
3** Libmy
4** File description:
5** The header file of the libmy
6*/
13#include <stdlib.h>
14#include <stddef.h>
15#include <stdarg.h>
16#include <unistd.h>
17#include <stdio.h>
18#include <errno.h>
19#include <string.h>
20#include <fcntl.h>
21#include <sys/stat.h>
22#include <sys/types.h>
23#include <sys/wait.h>
24#include <time.h>
25#include <dirent.h>
26#include <signal.h>
27
28#ifndef MY_H_
29 #define MY_H_
30
31// MACROS :
32
33 // Constants :
34
35 #define MAX_INT 2147483647
36 #define MIN_INT -2147483648
37 #define MAX_LONG 9223372036854775807
38 #define MIN_LONG -9223372036854775808
39 #define MAX_SHORT 32767
40 #define MIN_SHORT -32768
41 #define MAX_SHORT_SHORT 127
42 #define MIN_SHORT_SHORT -128
43 #define MAX_SIZE_T 18446744073709551615
44
45 // Basics macros :
46
47 #define ABS(value) ((value < 0) ? - value : value)
48 #define MAX(a, b) ((a > b) ? a : b)
49 #define MIN(a, b) ((a < b) ? a : b)
50 #define STR_CONTAINS(str, find) (my_strstr(str, find) != NULL) ? 1 : 0
51 #define NB number_settings_t
52
53 // str_to_word_array macros :
54
55 #define STR2ARRAY(str) my_str_to_word_array(str)
56 #define STR2ARRAY_SEP(str, sep) my_str_to_word_array_select(str, sep)
57 #define STR2ARRAY_STR(str, sep) my_str_to_word_array_string(str, sep)
58
59 // Free macros :
60
61 #define FREE(ptr) ptr = my_free_ptr(ptr)
62 #define FREE_WORD_ARRAY(ptr) my_free_array((void **)ptr)
63
64
65
66// TYPEDEFS :
67
68/* A reproduction of the boolean */
69typedef enum my_bool {
70 FALSE = 0, //**< FALSE */
71 TRUE = 1 //**< TRUE */
72} my_bool_t;
73
74extern int my_errno; /* The error number */
75
76/* The information of the my_params_to_array */
77struct info_param {
78 int length; //**< The length of the string */
79 char *str; //**< The string */
80 char *copy; //**< The copy of the string */
81 char **word_array; //**< The array of words */
82};
83
84/* The settings of the my_super_number */
85typedef struct number_settings_s {
86 my_bool_t multiple_signe; //**< Allow multiples signes in the string */
87 my_bool_t letter_before; //**< Allow letters before the number */
88 my_bool_t letter_after; //**< Allow letters after the number */
89 my_bool_t overflow; //**< Allow overflow in the number */
91
92
93
94// FUNCTIONS PROTOTYPES :
95
96 // Write functions :
97
104void my_putchar(char c);
105
113void my_isneg(int nb);
114
121void my_putnbr(int nb);
122
130int my_putstr(char const *str);
131
139void my_showstr(char const *str);
140
148void my_showmem(char const *str, int size);
149
158void my_print_combn(int n);
159
167void my_putnbr_base(int nbr, char const *base);
168
175void my_show_word_array(char *const *tab);
176
184void my_print_params(int argc, char **argv);
185
192int my_putstr_error(char const *str);
193
202int my_putstr_sized(char const *str, int size);
203
212int my_putstr_fd(char const *str, int fd);
213
222int my_putstr_fd_free(char *str, int fd);
223
232int my_printf(char const *format, ...);
233
242int my_fprintf(int fd, char const *format, ...);
243
244
245
246 // Char functions :
247
254int my_char_is_alpha(char const c);
255
262int my_char_is_num(char const c);
263
270int my_char_is_printable(char const c);
271
279int my_char_is(char c, const char *char_list);
280
281
282
283 // String functions :
284
292int my_str_isalpha(char const *str);
293
300int my_str_isnum(char const *str);
301
308int my_str_islower(char const *str);
309
316int my_str_isupper(char const *str);
317
324int my_str_isprintable(char const *str);
325
334int my_str_is(char *str, const char *char_list);
335
345int my_str_contains(char *str, char *char_list);
346
353int my_strlen(char const *str);
354
364char *my_strcpy(char *dest, char const *src);
365
376char *my_strncpy(char *dest, char const *src, int n);
377
385char *my_revstr(char *str);
386
396char *my_strstr(char *str, char const *to_find);
397
406int my_strcmp(char const *s1, char const *s2);
407
417int my_strncmp(char const *s1, char const *s2, int n);
418
425char *my_strupcase(char *str);
426
433char *my_strlowcase(char *str);
434
442char *my_strcapitalize(char *str);
443
452char *my_strcat(char *dest, char const *src);
453
463char *my_strncat(char *dest, char const *src, int nb);
464
471char *my_strdup(const char *src);
472
481char *my_strndup(const char *src, int n);
482
489char **my_strdup_word_array(char **array);
490
497const char *my_strerror(int error);
498
506int my_count_letter(char const *str, char c);
507
508
509
510 // Int functions :
511
518int my_nbrlen(int nb);
519
527void my_swap(int *a, int *b);
528
536void my_sort_int_array(int *tab, int size);
537
547char *my_convert_base(char const *nbr,
548 char const *base_from, char const *base_to);
549
559char *my_convert_base_unsigned(char const *nbr,
560 char const *base_from, char const *base_to);
561
571char *my_convert_base_size_t(char const *nbr,
572 char const *base_from, char const *base_to);
573
582void my_round_float_str(char *float_nb, char last_char, int i, int enable);
583
584
585
586 // Array functions :
587
594int my_array_len(void **array);
595
602char **my_str_to_word_array(char const *str);
603
612char **my_str_to_word_array_select(char const *str, char const *separator);
613
622char **my_str_to_word_array_string(char const *str, char const *separator);
623
632char **my_super_array(char *str, char *sep);
633
640void my_free_array(void **array);
641
648void *my_free_ptr(void *ptr);
649
650
651
652 // Get number functions :
653
662int my_getnbr(char const *str);
663
672int my_find_nbr(char const *str);
673
683float my_getnbr_float(char const *str);
684
695int my_getnbr_base(char const *str, char const *base);
696
705int my_strict_getnbr(char const *str);
706
715float my_strict_getnbr_float(char const *str);
716
725int my_strict_find_nbr(char const *str);
726
737int my_super_number(char *number, number_settings_t settings);
738
739
740
741 // Calculs functions :
742
750int my_compute_power_rec(int nb, int power);
751
760size_t my_compute_power_rec_size_t(int nb, int p);
761
768int my_compute_square_root(int nb);
769
777int my_compute_factorial_rec(int nb);
778
785int my_is_prime(int nb);
786
794int my_find_prime_sup(int nb);
795
803int my_find_prime_inf(int nb);
804
805
806
807 // Params functions :
808
816struct info_param *my_params_to_array(int ac, char **av);
817
824void my_show_param_array(struct info_param const *par);
825
832void my_rev_params(int argc, char **argv);
833
841void my_sort_params(int argc, char **argv);
842
850char *my_concat_params(int argc, char **argv);
851
852
853
854 // Str nbr functions :
855
862char *my_str_nbr(int nb);
863
870char *my_str_nbr_short(short int nb);
871
878char *my_str_nbr_short_short(signed char nb);
879
888char *my_str_nbr_base_unsigned(unsigned int nbr, char const *base);
889
898char *my_str_nbr_base_unsigned_short(unsigned short nbr, char const *base);
899
908char *my_str_nbr_base_unsigned_short_short(unsigned char nbr,
909 char const *base);
910
919char *my_str_nbr_base_unsigned_size_t(size_t nbr, char const *base);
920
929char *my_str_nbr_base_unsigned_long(unsigned long nbr, char const *base);
930
939char *my_str_nbr_base_long_long_int(long long int nbr, char const *base);
940
947char *my_str_nbr_unsigned(unsigned int nb);
948
955char *my_str_nbr_unsigned_long(unsigned long int nb);
956
963char *my_str_nbr_long_long(long long nb);
964
971char *my_str_nbr_size_t(size_t nb);
972
973#endif /* MY_H_ */
char * my_str_nbr_base_unsigned_long(unsigned long nbr, char const *base)
Returns the string conversion of an unsigned long number (nbr) in specific base (base)
Definition my_str_nbr_base_unsigned_long.c:30
char * my_str_nbr(int nb)
Returns the string conversion of a number (nb)
Definition my_str_nbr.c:31
void my_sort_params(int argc, char **argv)
Sorts the parameters (argc and argv) in ascending order.
Definition my_sort_params.c:52
void my_show_word_array(char *const *tab)
Prints all word in an array (tab)
Definition my_show_word_array.c:15
void my_showstr(char const *str)
Prints a string (str) but replaces non-printable characters with their hexadecimal number.
Definition my_showstr.c:22
int my_putstr_fd_free(char *str, int fd)
Writes a string (str) in a file descriptor (fd), free it and returns the length of the printed string...
Definition my_putstr_fd_free.c:16
int my_str_islower(char const *str)
Checks if a string (str) is lowercase.
Definition my_str_islower.c:16
void my_show_param_array(struct info_param const *par)
Prints the information of a parameter array (par)
Definition my_show_param_array.c:16
int my_compute_power_rec(int nb, int power)
Returns the power (p) of the number (nb)
Definition my_compute_power_rec.c:15
int my_strcmp(char const *s1, char const *s2)
Compares two strings (s1) and (s2)
Definition my_strcmp.c:16
char * my_strndup(const char *src, int n)
Duplicates a string (src) with a defined size (n) and returns the new string.
Definition my_strndup.c:15
void my_putnbr_base(int nbr, char const *base)
Prints a number (nb) in the requested base (base) in stdout.
Definition my_putnbr_base.c:28
int my_find_prime_inf(int nb)
Returns the previous prime number before a number (nb)
Definition my_find_prime_inf.c:15
char * my_strcpy(char *dest, char const *src)
Copies a string (src) and paste it on another string (dest)
Definition my_strcpy.c:15
void my_putnbr(int nb)
Prints a number (nb) in stdout.
Definition my_putnbr.c:28
int my_strict_getnbr(char const *str)
Returns an int number starting from a string number (str)
Definition my_strict_getnbr.c:16
int my_compute_square_root(int nb)
Returns the square root of a number (nb)
Definition my_compute_square_root.c:15
void my_print_params(int argc, char **argv)
Prints all the parameters of the program.
Definition my_print_params.c:15
void my_sort_int_array(int *tab, int size)
Sorts an array (array) with a defined size (size) of integers in ascending order.
Definition my_sort_int_array.c:25
void my_swap(int *a, int *b)
Swaps two integers (a) and (b)
Definition my_swap.c:15
int my_putstr_fd(char const *str, int fd)
Writes a string (str) in a file descriptor (fd) and returns the length of the printed string.
Definition my_putstr_fd.c:16
int my_is_prime(int nb)
Returns 1 if the number (nb) is prime and 0 otherwise.
Definition my_is_prime.c:15
char * my_str_nbr_unsigned_long(unsigned long int nb)
Returns the string conversion of an unsigned long number (nb)
Definition my_str_nbr_unsigned_long.c:30
int my_strlen(char const *str)
Returns the length of a string (str)
Definition my_strlen.c:15
int my_char_is(char c, const char *char_list)
Checks if a char (c) is in a list of chars (char_list)
Definition my_char_is.c:16
char * my_strncpy(char *dest, char const *src, int n)
Copies a string (src) and paste it on another string (dest) with a defined size (n)
Definition my_strncpy.c:16
char * my_str_nbr_short_short(signed char nb)
Returns the string conversion of a short short number (nb)
Definition my_str_nbr_short_short.c:31
char * my_strupcase(char *str)
Replaces lowcase by upcase of a string (str)
Definition my_strupcase.c:15
int my_find_nbr(char const *str)
Find the first number (number) found in a string.
Definition my_find_nbr.c:15
int my_strncmp(char const *s1, char const *s2, int n)
Compares two strings (s1) and (s2) with a defined size (n)
Definition my_strncmp.c:16
int my_str_is(char *str, const char *char_list)
Checks if a string (str) is composed of characters in the characters list (char_list) or 0 if not.
Definition my_str_is.c:16
int my_array_len(void **array)
Returns the length of an array (array)
Definition my_array_len.c:15
int my_str_isprintable(char const *str)
Checks if a string (str) is printable.
Definition my_str_isprintable.c:15
void my_print_combn(int n)
Prints all the numbers composed by (n) different digits numbers All digits in the number are differen...
Definition my_print_combn.c:56
float my_getnbr_float(char const *str)
Returns a float number starting from a string number (str)
Definition my_getnbr_float.c:24
char ** my_str_to_word_array_select(char const *str, char const *separator)
Returns an array of words delimited by a list of separator (separator) from a string (str)
Definition my_str_to_word_array_select.c:76
char ** my_strdup_word_array(char **array)
Duplicates a word array (array) and returns the new array.
Definition my_strdup_word_array.c:15
char * my_strcapitalize(char *str)
Capitalizes the first letter of each word in a string (str) and lowercase the other letters.
Definition my_strcapitalize.c:15
int my_str_isnum(char const *str)
Checks if a string (str) is a number.
Definition my_str_isnum.c:15
void my_rev_params(int argc, char **argv)
Prints all the arguments (argc and argv) in reverse order.
Definition my_rev_params.c:15
char * my_strstr(char *str, char const *to_find)
Search a string (to_find) on another (str) and returns the address of the first occurrence.
Definition my_strstr.c:16
int my_count_letter(char const *str, char c)
Counts the number of times a letter (c) is in a string (str)
Definition my_count_letter.c:15
int my_str_contains(char *str, char *char_list)
Checks if a string (str) contains a character in a list of characters (char_list)
Definition my_str_contains.c:25
size_t my_compute_power_rec_size_t(int nb, int p)
Returns the power (p) of the number (nb)
Definition my_compute_power_rec_size_t.c:15
int my_str_isupper(char const *str)
Checks if a string (str) is uppercase.
Definition my_str_isupper.c:16
char * my_str_nbr_base_long_long_int(long long int nbr, char const *base)
Returns the string conversion of an long long number (nbr) in specific base (base)
Definition my_str_nbr_base_long_long_int.c:30
char * my_convert_base_unsigned(char const *nbr, char const *base_from, char const *base_to)
Returns the result of the conversion of a unsigned number (nbr) in a specific base (base_from) to ano...
Definition my_convert_base_unsigned.c:84
char * my_str_nbr_base_unsigned_short_short(unsigned char nbr, char const *base)
Returns the string conversion of an unsigned short short number (nbr) in specific base (base)
Definition my_str_nbr_base_unsigned_short_short.c:30
char * my_strncat(char *dest, char const *src, int nb)
Concatenates two strings (dest) and (src) with a defined size (nb)
Definition my_strncat.c:16
char * my_strlowcase(char *str)
Replaces upcase by lowcase of a string (str)
Definition my_strlowcase.c:15
char * my_str_nbr_base_unsigned(unsigned int nbr, char const *base)
Returns the string conversion of an unsigned number (nbr) in specific base (base)
Definition my_str_nbr_base_unsigned.c:30
int my_getnbr(char const *str)
Returns an int number starting from a string number (str)
Definition my_getnbr.c:24
int my_compute_factorial_rec(int nb)
Returns the factorial of a number (nb)
Definition my_compute_factorial_rec.c:15
int my_char_is_alpha(char const c)
Checks if a char (c) is a letter.
Definition my_char_is_alpha.c:15
int my_printf(char const *format,...)
Prints a string (format) with possible flags and format in stdout and returns the length the printed ...
Definition my_printf.c:87
int my_putstr_error(char const *str)
Prints a string (str) in stderr.
Definition my_putstr_error.c:15
char * my_str_nbr_size_t(size_t nb)
Returns the string conversion of an size_t number (nb)
Definition my_str_nbr_size_t.c:29
void my_isneg(int nb)
Prints 'P' if the number (n) is positive or 'N' if the number (n) is negative.
Definition my_isneg.c:16
void * my_free_ptr(void *ptr)
Frees a pointer (ptr)
Definition my_free_ptr.c:15
char * my_str_nbr_short(short int nb)
Returns the string conversion of a short number (nb)
Definition my_str_nbr_short.c:31
struct info_param * my_params_to_array(int ac, char **av)
Returns a info_params struct of the argc (ac) and the argv (av)
Definition my_params_to_array.c:15
char * my_concat_params(int argc, char **argv)
Returns a string with all the arguments (argc and argv) concatenated.
Definition my_concat_params.c:15
char * my_strcat(char *dest, char const *src)
Concatenates two strings (dest) and (src)
Definition my_strcat.c:16
char * my_convert_base(char const *nbr, char const *base_from, char const *base_to)
Returns the result of the conversion of a number (nbr) in a specific base (base_from) to another base...
Definition my_convert_base.c:52
char ** my_super_array(char *str, char *sep)
Returns an array of words delimited by a list of separator (separator) from a string (str)
Definition my_super_array.c:74
int my_putstr_sized(char const *str, int size)
Prints a string (str) in stdout with a defined size (size) and returns the length of the printed stri...
Definition my_putstr_sized.c:16
void my_showmem(char const *str, int size)
Prints a memory dump of a string (str) with a defined size.
Definition my_showmem.c:81
void my_free_array(void **array)
Frees an array (array)
Definition my_free_array.c:15
char ** my_str_to_word_array_string(char const *str, char const *separator)
Returns an array of words delimited by a separator (separator) from a string (str)
Definition my_str_to_word_array_string.c:74
char * my_strdup(const char *src)
Duplicates a string (src) and returns the new string.
Definition my_strdup.c:15
char * my_str_nbr_unsigned(unsigned int nb)
Returns the string conversion of an unsigned number (nb)
Definition my_str_nbr_unsigned.c:29
float my_strict_getnbr_float(char const *str)
Returns a float number starting from a string number (str)
Definition my_strict_getnbr_float.c:16
const char * my_strerror(int error)
Returns the error message of the error number (error)
Definition my_strerror.c:149
void my_putchar(char c)
Prints a char (c) in the stdout.
Definition my_putchar.c:15
char ** my_str_to_word_array(char const *str)
Returns an array of words from a string (str)
Definition my_str_to_word_array.c:68
int my_char_is_num(char const c)
Checks if a char (c) is a number.
Definition my_char_is_num.c:15
int my_putstr(char const *str)
Writes a string (str) in stdout and returns the length of the printed string.
Definition my_putstr.c:16
char * my_convert_base_size_t(char const *nbr, char const *base_from, char const *base_to)
Returns the result of the conversion of a size_t number (nbr) in a specific base (base_from) to anoth...
Definition my_convert_base_size_t.c:84
char * my_str_nbr_base_unsigned_short(unsigned short nbr, char const *base)
Returns the string conversion of an unsigned short number (nbr) in specific base (base)
Definition my_str_nbr_base_unsigned_short.c:30
int my_char_is_printable(char const c)
Checks if a char (c) is printable.
Definition my_char_is_printable.c:15
int my_fprintf(int fd, char const *format,...)
Writes a string (format) with possible flags and format in a file descriptor (fd) and returns the len...
Definition my_fprintf.c:87
char * my_str_nbr_base_unsigned_size_t(size_t nbr, char const *base)
Returns the string conversion of an size_t number (nbr) in specific base (base)
Definition my_str_nbr_base_unsigned_size_t.c:30
char * my_str_nbr_long_long(long long nb)
Returns the string conversion of an long long number (nb)
int my_getnbr_base(char const *str, char const *base)
Returns a number starting from a string number (str) in the requested base (base)
Definition my_getnbr_base.c:45
int my_str_isalpha(char const *str)
Checks if a string (str) is alphabetical.
Definition my_str_isalpha.c:15
int my_super_number(char *number, number_settings_t settings)
Returns an int number starting from a string number (number) and change my_errno if an error occurs d...
Definition my_super_number.c:45
char * my_revstr(char *str)
Reverses the characters in a string (str) and returns the string (str)
Definition my_revstr.c:15
void my_round_float_str(char *float_nb, char last_char, int i, int enable)
Modify a string (float) and round it.
Definition my_round_float_str.c:29
int my_strict_find_nbr(char const *str)
Find the first number (number) found in a string.
Definition my_strict_find_nbr.c:16
int my_nbrlen(int nb)
Returns the length of a number (nb)
Definition my_nbrlen.c:15
int my_find_prime_sup(int nb)
Returns the next prime number after a number (nb)
Definition my_find_prime_sup.c:15
Definition my.h:77
Definition my.h:85