-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
300 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
*.out | ||
*.o | ||
project | ||
compile_flags.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** my_printf | ||
** File description: | ||
** flags | ||
*/ | ||
|
||
#ifndef FLAGS_H_ | ||
#define FLAGS_H_ | ||
|
||
/** | ||
* @brief Parsed conversion specifier. | ||
*/ | ||
typedef struct s_flags { | ||
int flags; | ||
int converter; | ||
int width; | ||
int precision; | ||
} t_flags; | ||
|
||
#define F_ALT (1 << 0) // # | ||
#define F_ZEROS (1 << 1) // 0 | ||
#define F_BlANKS (1 << 2) // - | ||
#define F_POS (1 << 3) // ' ' | ||
#define F_SIGN (1 << 4) // + | ||
|
||
#define L_CHAR (1 << 5) // hh | ||
#define L_SHORT (1 << 6) // h | ||
#define L_LONGLONG (1 << 7) // ll | ||
#define L_LONG (1 << 8) // l | ||
#define L_LONG_DOUBLE (1 << 9) // L | ||
#define L_INTMAX (1 << 10) // j | ||
#define L_SIZE (1 << 11) // z | ||
#define L_PTRDIFF (1 << 12) // t | ||
|
||
#define C_INT (1 << 0) // d | ||
#define C_INT_ALT (1 << 1) // i | ||
#define C_OCTAL (1 << 2) // o | ||
#define C_UINT (1 << 3) // u | ||
#define C_HEX (1 << 4) // x | ||
#define C_HEX_UPPER (1 << 5) // X | ||
#define C_D_EXP (1 << 6) // e | ||
#define C_D_EXP_UPPER (1 << 7) // E | ||
#define C_D_DEC (1 << 8) // f | ||
#define C_D_DEC_UPPER (1 << 9) // F | ||
#define C_D_AUTO (1 << 10) // g | ||
#define C_D_AUTO_UPPER (1 << 11) // G | ||
#define C_D_HEX (1 << 12) // a | ||
#define C_D_HEX_UPPER (1 << 13) // A | ||
#define C_BIN (1 << 14) // b | ||
#define C_CHAR (1 << 15) // c | ||
#define C_STR (1 << 16) // s | ||
#define C_STR_OCT (1 << 17) // S | ||
#define C_PTR (1 << 18) // p | ||
#define C_COUNT (1 << 19) // n | ||
#define C_PERCENT (1 << 20) // % | ||
|
||
#endif /* !FLAGS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** my_printf | ||
** File description: | ||
** int | ||
*/ | ||
|
||
#ifndef INT_H_ | ||
#define INT_H_ | ||
|
||
#include <stdint.h> | ||
#include "my_string.h" | ||
#include "internal/flags.h" | ||
|
||
typedef enum sign_kind_e { | ||
SIGN_DEFAULT, | ||
SIGN_SPACE, | ||
SIGN_ALWAYS, | ||
} sign_kind; | ||
|
||
typedef enum alt_kind_s { | ||
ALT_NONE, | ||
ALT_OCT, | ||
ALT_HEX, | ||
ALT_HEX_UPPER, | ||
ALT_BIN, | ||
} alt_kind; | ||
|
||
/** | ||
* @brief Format used to print a number. | ||
* | ||
* @param base Base to format the string in (2 <= base <= 16) | ||
* @param uppercase `1` if letters should be uppercase. | ||
* @param sign Sign display format. | ||
*/ | ||
typedef struct int_fmt_s { | ||
int base; | ||
int uppercase; | ||
sign_kind sign; | ||
alt_kind alt; | ||
} int_fmt; | ||
|
||
/** | ||
* @brief Push a number formatted with a specific base into a string. | ||
*/ | ||
void push_base( | ||
intmax_t value, int_fmt fmt, t_flags flags, l_string *string); | ||
|
||
/** | ||
* @brief Push an unsigned number formatted with a specific base into a | ||
* string. | ||
*/ | ||
void push_ubase( | ||
uintmax_t value, int_fmt fmt, t_flags flags, l_string *string); | ||
|
||
int get_base(t_flags flags); | ||
int get_uppercase(t_flags flags); | ||
sign_kind get_sign_kind(t_flags flags); | ||
alt_kind get_alt_kind(t_flags flags); | ||
int is_signed(t_flags flags); | ||
|
||
#endif /* !INT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** my_printf | ||
** File description: | ||
** Header file for private functions used for the my_printf implementation. | ||
*/ | ||
|
||
#ifndef UTIL_H_ | ||
#define UTIL_H_ | ||
|
||
#include <stdarg.h> | ||
#include <stdint.h> | ||
|
||
#include "../internal/flags.h" | ||
|
||
#define IS_NBR(c) (c >= '0' && c <= '9') ? 1 : 0 | ||
#define IS_PRINTABLE(c) (c >= 32 && c < 127) ? 1 : 0 | ||
|
||
/** | ||
* @brief Parse a single flag. | ||
* | ||
* @param str Pointer to the start of the flag (after `%`). | ||
* @return t_flags Parsed flag (or NULL if error) | ||
*/ | ||
t_flags parse_flag(char **str, va_list *list); | ||
|
||
/** | ||
* @brief This function will return the first number in a string | ||
* | ||
* @return int The parsed number returned by the function | ||
*/ | ||
int parse_numbers(char const * str); | ||
|
||
/** | ||
* @brief Checks if the `source` string starts with the given `str`. | ||
* | ||
* @param source String to search in. | ||
* @param str String to search for. | ||
* @return int boolean | ||
*/ | ||
int p_starts_with(const char *source, const char *str); | ||
|
||
/** | ||
* @brief Checks if the `source` string starts with one of the given | ||
* `elems`. | ||
* | ||
* @param source String to search in. | ||
* @param elems List of strings to search for. | ||
* @param size Size of `elems`. | ||
* @return int Index of matched element, `-1` if no match. | ||
*/ | ||
int p_contains(char *source, char **elems, int size); | ||
|
||
/** | ||
* @brief Get the length of a string. | ||
* | ||
* @param str The string. | ||
* @return int Length of the string. | ||
*/ | ||
int p_str_len(const char *str); | ||
|
||
/** @brief Parse the string as a number. | ||
* | ||
* @param str The string to parse. | ||
* @return int The parsed number (0 if invalid). | ||
*/ | ||
int p_get_nbr(char const *str); | ||
|
||
#endif /* !UTIL_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** my_printf | ||
** File description: | ||
*/ | ||
|
||
#ifndef PRINT_H_ | ||
#define PRINT_H_ | ||
|
||
#include <stdarg.h> | ||
#include <stdint.h> | ||
|
||
#include "my_string.h" | ||
#include "internal/flags.h" | ||
|
||
/** | ||
* @brief Print a flag at the end of the given string. | ||
* | ||
* @param flag Flag to print. | ||
* @param string String to push the flag to. | ||
* @param list Variadic arguments list. | ||
*/ | ||
void print_flag(t_flags flag, l_string *string, va_list *list); | ||
|
||
/* Generic print functions */ | ||
|
||
typedef struct print_s { | ||
int flag; | ||
void (*ptr_fn)(t_flags, l_string *, va_list *); | ||
} print_t; | ||
|
||
void print_int(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_double_exp(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_double_dec(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_double_auto(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_double_hex(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_char(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_str(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_str_oct(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_ptr(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_count(t_flags flag, l_string *string, va_list *list); | ||
|
||
void print_percent(t_flags flag, l_string *string, va_list *list); | ||
|
||
/** | ||
* @brief Get a signed number from vargs according to the flags. | ||
* | ||
* @param flags Flags to use. | ||
* @param list Varargs list. | ||
* @return intmax_t The number. | ||
*/ | ||
intmax_t length_mod_signed(t_flags flags, va_list *list); | ||
|
||
/** | ||
* @brief Get an unsigned number from vargs according to the flags. | ||
* | ||
* @param flags Flags to use. | ||
* @param list Varargs list. | ||
* @return uintmax_t The number. | ||
*/ | ||
uintmax_t length_mod_unsigned(t_flags flags, va_list *list); | ||
|
||
#endif /* !PRINT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** my_printf | ||
** File description: | ||
** str | ||
*/ | ||
|
||
#ifndef STR_H_ | ||
#define STR_H_ | ||
|
||
#include "my_string.h" | ||
|
||
/** | ||
* @brief Add padding to the given string if its length is less than | ||
* `size`. | ||
* | ||
* @param string String to add the padding to. | ||
* @param size Target size of the string (after padding). | ||
* @param pad_char Character to use for the padding. | ||
* @param right `1` if the string is right-padded (left by default). | ||
*/ | ||
void add_padding(l_string *string, int size, char pad_char, int right); | ||
|
||
#endif /* !STR_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
** padding | ||
*/ | ||
|
||
#include "lib/string.h" | ||
#include "my_string.h" | ||
|
||
#include "internal/str.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters