|
TA-REF
|
#include <stdbool.h>#include <stdint.h>#include <stdarg.h>#include <stddef.h>
Include dependency graph for vsnprintf.c:Classes | |
| struct | out_fct_wrap_type |
Macros | |
| #define | PRINTF_NTOA_BUFFER_SIZE 32U |
| #define | PRINTF_FTOA_BUFFER_SIZE 32U |
| #define | PRINTF_SUPPORT_FLOAT |
| #define | PRINTF_SUPPORT_LONG_LONG |
| #define | PRINTF_SUPPORT_PTRDIFF_T |
| #define | FLAGS_ZEROPAD (1U << 0U) |
| #define | FLAGS_LEFT (1U << 1U) |
| #define | FLAGS_PLUS (1U << 2U) |
| #define | FLAGS_SPACE (1U << 3U) |
| #define | FLAGS_HASH (1U << 4U) |
| #define | FLAGS_UPPERCASE (1U << 5U) |
| #define | FLAGS_CHAR (1U << 6U) |
| #define | FLAGS_SHORT (1U << 7U) |
| #define | FLAGS_LONG (1U << 8U) |
| #define | FLAGS_LONG_LONG (1U << 9U) |
| #define | FLAGS_PRECISION (1U << 10U) |
| #define | _putchar putchar |
Typedefs | |
| typedef void(* | out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen) |
Functions | |
| int | putchar (char ch) |
| static void | _out_buffer (char character, void *buffer, size_t idx, size_t maxlen) |
| static void | _out_null (char character, void *buffer, size_t idx, size_t maxlen) |
| static void | _out_char (char character, void *buffer, size_t idx, size_t maxlen) |
| static void | _out_fct (char character, void *buffer, size_t idx, size_t maxlen) |
| static unsigned int | _strlen (const char *str) |
| static bool | _is_digit (char ch) |
| static unsigned int | _atoi (const char **str) |
| static size_t | _ntoa_format (out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) |
| static size_t | _ntoa_long (out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) |
| static size_t | _ntoa_long_long (out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) |
| static size_t | _ftoa (out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) |
| static int | _vsnprintf (out_fct_type out, char *buffer, const size_t maxlen, const char *format, va_list va) |
| int | sprintf (char *buffer, const char *format,...) |
| int | snprintf (char *buffer, size_t count, const char *format,...) |
| int | vsnprintf (char *buffer, size_t count, const char *format, va_list va) |
| int | fctprintf (void(*out)(char character, void *arg), void *arg, const char *format,...) |
| #define _putchar putchar |
| #define FLAGS_CHAR (1U << 6U) |
| #define FLAGS_HASH (1U << 4U) |
| #define FLAGS_LEFT (1U << 1U) |
| #define FLAGS_LONG (1U << 8U) |
| #define FLAGS_LONG_LONG (1U << 9U) |
| #define FLAGS_PLUS (1U << 2U) |
| #define FLAGS_PRECISION (1U << 10U) |
| #define FLAGS_SHORT (1U << 7U) |
| #define FLAGS_SPACE (1U << 3U) |
| #define FLAGS_UPPERCASE (1U << 5U) |
| #define FLAGS_ZEROPAD (1U << 0U) |
| #define PRINTF_FTOA_BUFFER_SIZE 32U |
| #define PRINTF_NTOA_BUFFER_SIZE 32U |
| #define PRINTF_SUPPORT_FLOAT |
| #define PRINTF_SUPPORT_LONG_LONG |
| #define PRINTF_SUPPORT_PTRDIFF_T |
| typedef void(* out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen) |
|
static |
_atoi() - Converts the internal ASCII string into an unsigned integer.
This function is to convert the internal ASCII string into unsigned integer.
| str | string representation of an integral number. |
|
static |
_ftoa() - Converts a given floating-point number or a double to a string with the use of standard library functions.
This function checks whether the value is negative or not, then it checks with if condtion default precision to 6, if it not set it will set explicitly. Using the while loop it limits the precision to 9,because it causes a overflow error when precision crosses above 10. Using the if condition rollover or round If the precsion value is greater than 0.5 up the precision value.it round up to
| out | type of out_fct_type |
| buffer | Pointer to a character string to write the result. |
| idx | idx bytes of size_t |
| maxlen | Maximum number of characters to write. |
| negative | boolean type |
| base | an unsigned long data type |
| prec | an unsigned integral data type |
| width | an unsigned integral data type |
| flags | an unsigned integral data type |
|
inlinestatic |
_is_digit() - Is for the internal test if char is a digit from 0 to 9
| ch | This is the character to be checked. |
|
static |
_ntoa_format() - Converts the string into the defined format structure.
This function uses the while condition for padding the leading zeroes and also applies the if conditions to handle the hash. Using the if condtion pad spaces up to given width what specifies in that. It reverse the string and again append pad spaces up to given width.
| out | type of out_fct_type |
| buffer | Pointer to a character string to write the result. |
| idx | idx bytes of size_t |
| maxlen | Maximum number of characters to write. |
| negative | boolean type |
| base | an unsigned long data type |
| prec | an unsigned integer data type |
| width | an unsigned integer data type |
| flags | an unsigned integer data type |
|
static |
_ntoa_long() - Converts string into long value.
This function begins with an if condition value then it assigns ~FLAGS_HASH into flags & value. Later it uses the if condition and do while write if precision not equal to zero and value is not equals to zero.
| out | type of out_fct_type |
| buffer | Pointer to a character string to write the result. |
| id | idx bytes of size_t |
| maxlen | Maximum number of characters to write. |
| negative | boolean type |
| base | an unsigned long data type |
| prec | an unsigned integral data type |
| width | an unsigned integral data type |
| flags | an unsigned integral data type |
|
static |
_ntoa_long_long() - Function to convert string to long value.
This function begins with an if condition then it assigns ~FLAGS_HASH into flags & value. Later it uses the if condition and do while write if precision not equal to zero and value is not equals to zero.
| out | type of out_fct_type |
| buffer | Pointer to a character string to write the result. |
| idx | idx bytes of size_t |
| maxlen | Maximum number of characters to write. |
| negative | boolean type |
| base | an unsigned long data type |
| prec | an unsigned integral data type |
| width | an unsigned integral data type |
| flag | an unsigned integral data type |
|
inlinestatic |
_out_buffer() - Internal buffer output
This function compares the idx and maxlen, If "idx" is less than "maxlen" then it will assign "character" value into the typecasting char "buffer[idx]"
| character | character type string |
| buffer | Pointer to a character string to write the result. |
| idx | bytes of size_t |
| maxlen | Maximum number of characters to write. |
|
inlinestatic |
_out_char() - Internal putchar wrapper
The typecasting of arguments with void is to avoid unused variable warnings in some compilers. Checks the character value once the if condtion is success then putchar() writes a character into stdout.
| character | character type string |
| buffer | Pointer to a character string to write the result. |
| idx | bytes of size_t |
| maxlen | Maximum number of characters to write. |
|
inlinestatic |
_out_fct() - Internal output function wrapper
This function typecasting idx and maxlen arguments is to avoid compiler error. And then output function wrapper and the buffer is the output fct pointer.
| character | character type string |
| buffer | Pointer to a character string to write the result. |
| idx | bytes of size_t |
| maxlen | Maximum number of characters to write. |
|
inlinestatic |
_out_null() - Internal null output.
The typecasting of arguments with void is applied to avoid unused variable warnings in some compilers.
| character | character type string |
| buffer | Pointer to a character string to write the result. |
| idx | bytes of size_t |
| maxlen | Maximum number of characters to write. |
|
inlinestatic |
_strlen() - calculates the length of the string.
| str | str is an argument of type pointer. |
|
static |
_vsnprintf() - Function writes formatted output to a character array, up to a maximum number of characters.
The _vsnprintf fucntion firstly initializes the varibles of format specifers like flags, width, precsion in this they evaluate all the specifiers invidually.First it checks the buffer equal to zero or not for null output function. After that flags evaluation will start using the switch case, then width field evalucation take process using if condition.
| out | type of out_fct_type. |
| buffer | pointer to the buffer where you want to function to store the formatted string. |
| maxlen | maximum number of characters to store in the buffer. |
| format | string that specifies the format of the output. |
| va | variable-argument list of the additional argument. |
| int fctprintf | ( | void(*)(char character, void *arg) | out, |
| void * | arg, | ||
| const char * | format, | ||
| ... | |||
| ) |
fctprintf() - Function is using the libary macros of variable aruguments like vastart and vaend.
This function initializes the va_list variable and invokes the va_start(). Invokes _vsnprintf function and stores the value into ret. It applies the functions va_start and va_end on va and returns ret.
| out | An output function which takes one character and an argument pointer. |
| arg | An argument pointer for user data passed to output function. |
| format | A string that specifies the format of the output. |
| int putchar | ( | char | ch | ) |
| int snprintf | ( | char * | buffer, |
| size_t | count, | ||
| const char * | format, | ||
| ... | |||
| ) |
snprintf() - Places the generated output into the character array pointed to by buf, instead of writing it to a file
This function initializes the va_list variable and invokes the va_start(). Invokes _vsnprintf function and stores the value into ret. It applies the functions va_start and va_end on va and returns ret.
| buffer | pointer to buffer where you want to function to store the formatted string. |
| count | maximum number of characters to store in the buffer. |
| format | string that specifies the format of the output. |
| int sprintf | ( | char * | buffer, |
| const char * | format, | ||
| ... | |||
| ) |
sprintf() - Sends formatted output to a string pointed to by the argument buffer.
This function initialize the va_list variable and invokes the va_start(). Invokes _vsnprintf function and store the value into ret. It applies the functions va_start and va_end on va and returns ret.
| buffer | pointer to an array of char elements resulting string will store. |
| format | string that contains the text to be written to buffer. |
| int vsnprintf | ( | char * | buffer, |
| size_t | count, | ||
| const char * | format, | ||
| va_list | va | ||
| ) |
vsnprintf() - Invokes another function called _vsnprintf(). with some arguments.
| buffer | Pointer to the buffer where you want to function to store the formatted string. |
| count | maximum number of characters to store in the buffer. |
| format | string that specifies the format of the output. |