Skip to content

Commit

Permalink
[Update] - Update Hephaistos
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaucoul committed Jul 27, 2024
1 parent f04be13 commit 736e071
Show file tree
Hide file tree
Showing 24 changed files with 1,655 additions and 1,189 deletions.
2 changes: 1 addition & 1 deletion Hephaistos/include/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 10:08:03 by vvaucoul #+# #+# */
/* Updated: 2024/07/26 20:10:30 by vvaucoul ### ########.fr */
/* Updated: 2024/07/28 01:24:10 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion Hephaistos/include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 20:09:04 by vvaucoul #+# #+# */
/* Updated: 2024/07/27 09:49:23 by vvaucoul ### ########.fr */
/* Updated: 2024/07/28 01:44:15 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
8 changes: 4 additions & 4 deletions Hephaistos/include/stdio/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/19 23:55:51 by vvaucoul #+# #+# */
/* Updated: 2024/07/26 22:46:29 by vvaucoul ### ########.fr */
/* Updated: 2024/07/28 01:34:29 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -35,7 +35,7 @@

typedef struct s_printk {
va_list args;
char *format;
char format[1024];

int32_t space;
bool space_is_star;
Expand All @@ -54,7 +54,7 @@ extern void vsprintk(const char *str, void (*write)(const char), const char *for
extern void __kpf_manage_space_front(const int arg_len);
extern void __kpf_manage_space_back(const int arg_len);

extern size_t __kpf_manage_mod(const char *format, size_t i);
extern uint32_t __kpf_manage_mod(const char *format, uint32_t i);
extern void __kpf_manage_char();
extern void __kpf_manage_nbr();
extern void __kpf_manage_str();
Expand All @@ -63,7 +63,7 @@ extern void __kpf_manage_hexa();
extern void __kpf_manage_unsigned();
extern void __kpf_manage_float();

extern size_t __kptrlen(const void *ptr);
extern uint32_t __kptrlen(const void *ptr);
extern uint32_t __k_get_len(uint32_t arg_len);

#endif /* !PRINTK_H */
32 changes: 24 additions & 8 deletions Hephaistos/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 11:31:06 by vvaucoul #+# #+# */
/* Updated: 2024/07/26 22:12:23 by vvaucoul ### ########.fr */
/* Updated: 2024/07/27 22:14:09 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,8 @@
// ! || ASM FUNCTIONS ||
// ! ||--------------------------------------------------------------------------------||

#define USE_ASM_STRING_FUNCTIONS 1

extern uint32_t __strlen(const char *str);
extern uint32_t __nbrlen(int32_t nbr);
extern uint32_t __nbrlen_base(int32_t nbr, const uint8_t base);
Expand All @@ -29,34 +31,48 @@ extern int32_t __strncmp(const char *s1, const char *s2, uint32_t n);
// ! || C FUNCTIONS ||
// ! ||--------------------------------------------------------------------------------||

#if USE_ASM_STRING_FUNCTIONS == 1

inline uint32_t nbrlen(int32_t nbr) {
return (__nbrlen(nbr));
return (__nbrlen(nbr));
}

inline uint32_t unbrlen(uint32_t nbr) {
return (__nbrlen((uint32_t)nbr));
return (__nbrlen((uint32_t)nbr));
}

inline uint32_t strlen(const char *str) {
return (__strlen(str));
return (__strlen(str));
}

inline uint32_t nbrlen_base(const int32_t nbr, const uint8_t base) {
return (__nbrlen_base(nbr, base));
return (__nbrlen_base(nbr, base));
}

inline uint32_t unbrlen_base(const uint32_t nbr, const uint8_t base) {
return (__nbrlen_base((uint32_t)nbr, base));
return (__nbrlen_base((uint32_t)nbr, base));
}

inline int32_t strcmp(const char *s1, const char *s2) {
return (__strcmp(s1, s2));
return (__strcmp(s1, s2));
}

inline int32_t strncmp(const char *s1, const char *s2, uint32_t n) {
return (__strncmp(s1, s2, n));
return (__strncmp(s1, s2, n));
}

#else

uint32_t nbrlen(int32_t nbr);
uint32_t unbrlen(uint32_t nbr);
uint32_t strlen(const char *str);
uint32_t nbrlen_base(const int32_t nbr, const uint8_t base);
uint32_t unbrlen_base(const uint32_t nbr, const uint8_t base);
int32_t strcmp(const char *s1, const char *s2);
int32_t strncmp(const char *s1, const char *s2, uint32_t n);

#endif

char *strtrtc(const char *str, const char c);
char *strclr(char *new_str, char *str);
char *strcpy(char *dest, const char *src);
Expand Down
7 changes: 3 additions & 4 deletions Hephaistos/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/21 14:10:07 by vvaucoul #+# #+# */
/* Updated: 2024/07/26 21:59:54 by vvaucoul ### ########.fr */
/* Updated: 2024/07/27 16:12:48 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,9 +15,8 @@

#include <stdint.h>

typedef struct s_counter
{
uint32_t start;
typedef struct s_counter {
uint32_t start;
uint32_t end;
} counter_t;

Expand Down
152 changes: 149 additions & 3 deletions Hephaistos/src/algorithms/compares.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 00:08:11 by vvaucoul #+# #+# */
/* Updated: 2024/07/26 22:00:28 by vvaucoul ### ########.fr */
/* Updated: 2024/07/28 01:28:40 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,54 +17,200 @@
// ! || COMPARE FUNCTIONS ||
// ! ||--------------------------------------------------------------------------------||

/**
* @brief Compares two integers.
*
* This function is used as a comparison function for sorting algorithms.
* It compares two integers pointed to by the parameters `a` and `b`.
*
* @param a Pointer to the first integer.
* @param b Pointer to the second integer.
* @return An integer less than, equal to, or greater than zero if the first integer is considered to be respectively less than, equal to, or greater than the second integer.
*/
int cmp_int(const void *a, const void *b) {
return (*(int *)a - *(int *)b);
}

/**
* @brief Compares two strings.
*
* This function is used as a comparison function for sorting strings.
* It compares two strings pointed to by the arguments `a` and `b`.
*
* @param a Pointer to the first string.
* @param b Pointer to the second string.
* @return An integer less than, equal to, or greater than zero if the first string is found to be less than, equal to, or greater than the second string, respectively.
*/
int cmp_string(const void *a, const void *b) {
return (strcmp((char *)a, (char *)b));
return (strcmp((const char *)a, (const char *)b));
}

/**
* @brief Compares two characters.
*
* This function is used as a comparison function for sorting characters.
* It compares the values of the characters pointed to by the pointers `a` and `b`.
*
* @param a Pointer to the first character.
* @param b Pointer to the second character.
* @return An integer less than, equal to, or greater than zero if the first character is found to be less than, equal to, or greater than the second character, respectively.
*/
int cmp_char(const void *a, const void *b) {
return (*(char *)a - *(char *)b);
}

/**
* @brief Compares two int8_t values.
*
* This function is used as a comparison function for sorting or searching algorithms.
* It compares the values pointed to by the pointers 'a' and 'b'.
*
* @param a Pointer to the first int8_t value.
* @param b Pointer to the second int8_t value.
* @return An integer less than, equal to, or greater than zero if the first value is found to be less than, equal to, or greater than the second value, respectively.
*/
int cmp_int8_t(const void *a, const void *b) {
return (*(int8_t *)a - *(int8_t *)b);
}

/**
* @brief Compares two int16_t values.
*
* This function is used as a comparison function for sorting int16_t values.
* It compares the values pointed to by the pointers 'a' and 'b' and returns
* an integer value indicating their relative order.
*
* @param a Pointer to the first int16_t value.
* @param b Pointer to the second int16_t value.
* @return An integer value less than, equal to, or greater than zero if the
* first value is considered to be respectively less than, equal to, or
* greater than the second value.
*/
int cmp_int16_t(const void *a, const void *b) {
return (*(int16_t *)a - *(int16_t *)b);
}

/**
* @brief Compares two int32_t values.
*
* This function is used as a comparison function for sorting int32_t values.
* It compares the values pointed to by the pointers 'a' and 'b' and returns
* an integer value indicating their relative order.
*
* @param a Pointer to the first int32_t value.
* @param b Pointer to the second int32_t value.
* @return An integer value less than, equal to, or greater than zero if the
* first value is considered to be respectively less than, equal to, or
* greater than the second value.
*/
int cmp_int32_t(const void *a, const void *b) {
return (*(int32_t *)a - *(int32_t *)b);
}

/**
* @brief Compares two int64_t values.
*
* This function is used as a comparison function for sorting int64_t values.
* It compares the values pointed to by the pointers 'a' and 'b' and returns
* an integer value indicating their relative order.
*
* @param a Pointer to the first int64_t value.
* @param b Pointer to the second int64_t value.
* @return An integer value less than, equal to, or greater than zero if the
* first value is considered to be respectively less than, equal to, or
* greater than the second value.
*/
int cmp_int64_t(const void *a, const void *b) {
return (*(int64_t *)a > *(int64_t *)b) - (*(int64_t *)a < *(int64_t *)b);
}

/**
* @brief Compares two uint8_t values.
*
* This function is used as a comparison function for sorting uint8_t values.
* It compares the values pointed to by the pointers 'a' and 'b'.
*
* @param a Pointer to the first uint8_t value.
* @param b Pointer to the second uint8_t value.
* @return An integer less than, equal to, or greater than zero if the first value is found to be less than, equal to, or greater than the second value, respectively.
*/
int cmp_uint8_t(const void *a, const void *b) {
return (*(uint8_t *)a - *(uint8_t *)b);
}

/**
* @brief Compares two uint16_t values.
*
* This function is used as a comparison function for sorting or searching algorithms.
* It compares the values pointed to by the pointers 'a' and 'b' and returns an integer
* indicating their relative order.
*
* @param a Pointer to the first uint16_t value.
* @param b Pointer to the second uint16_t value.
* @return An integer less than, equal to, or greater than zero if the first value is
* considered to be less than, equal to, or greater than the second value,
* respectively.
*/
int cmp_uint16_t(const void *a, const void *b) {
return (*(uint16_t *)a - *(uint16_t *)b);
}

/**
* @brief Compares two uint32_t values.
*
* This function is used as a comparison function for sorting uint32_t values.
* It compares the values pointed to by the pointers 'a' and 'b'.
*
* @param a Pointer to the first uint32_t value.
* @param b Pointer to the second uint32_t value.
* @return An integer less than, equal to, or greater than zero if the first value is found to be less than, equal to, or greater than the second value, respectively.
*/
int cmp_uint32_t(const void *a, const void *b) {
return (*(uint32_t *)a - *(uint32_t *)b);
}

/**
* @brief Compares two uint64_t values.
*
* This function is used as a comparison function for sorting uint64_t values.
* It compares the values pointed to by the pointers 'a' and 'b' and returns
* an integer value indicating their relative order.
*
* @param a Pointer to the first uint64_t value.
* @param b Pointer to the second uint64_t value.
* @return An integer value less than, equal to, or greater than zero if the
* first value is considered to be respectively less than, equal to, or
* greater than the second value.
*/
int cmp_uint64_t(const void *a, const void *b) {
return (*(uint64_t *)a > *(uint64_t *)b) - (*(uint64_t *)a < *(uint64_t *)b);
}

/**
* @brief Compares two floating-point numbers.
*
* This function is used as a comparison function for sorting floating-point numbers.
* It compares the values pointed to by the arguments 'a' and 'b'.
*
* @param a Pointer to the first floating-point number.
* @param b Pointer to the second floating-point number.
* @return An integer less than, equal to, or greater than zero if 'a' is found to be
* less than, equal to, or greater than 'b', respectively.
*/
int cmp_float(const void *a, const void *b) {
return (*(float *)a > *(float *)b) - (*(float *)a < *(float *)b);
}

/**
* @brief Compares two double values.
*
* This function is used as a comparison function for sorting double values.
* It compares the values pointed to by the pointers 'a' and 'b'.
*
* @param a Pointer to the first double value.
* @param b Pointer to the second double value.
* @return An integer value less than, equal to, or greater than zero if the first value is found to be less than, equal to, or greater than the second value, respectively.
*/
int cmp_double(const void *a, const void *b) {
return (*(double *)a > *(double *)b) - (*(double *)a < *(double *)b);
}
}
Loading

0 comments on commit 736e071

Please sign in to comment.