add documentation for new/remodeled functions
This commit is contained in:
parent
25e3d126c4
commit
8252ada4bb
36
lib/print.c
36
lib/print.c
|
@ -32,6 +32,12 @@
|
|||
#define CRLF true /**< if CR+LN new line should be enforced */
|
||||
/** @} */
|
||||
|
||||
/** print character
|
||||
* @param[out] str string to print character on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] c character to be printed
|
||||
* @return number of characters printed
|
||||
**/
|
||||
static size_t print_char(char** str, size_t* size, char c)
|
||||
{
|
||||
size_t length = 1; // remember how many characters have been printed or should have been added on string (normally just one)
|
||||
|
@ -50,6 +56,12 @@ static size_t print_char(char** str, size_t* size, char c)
|
|||
return length;
|
||||
}
|
||||
|
||||
/** print string
|
||||
* @param[out] str string to print string on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] s string to be printed
|
||||
* @return number of characters printed
|
||||
**/
|
||||
static size_t print_string(char** str, size_t* size, const char* s)
|
||||
{
|
||||
size_t length = 0; // number of characters printed
|
||||
|
@ -60,6 +72,8 @@ static size_t print_string(char** str, size_t* size, const char* s)
|
|||
}
|
||||
|
||||
/** print unsigned number
|
||||
* @param[out] str string to print unsigned number on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] u unsigned number to be printed
|
||||
* @param[in] padding number of 0's to pad
|
||||
* @param[in] sign if sign should be printed
|
||||
|
@ -89,7 +103,9 @@ static size_t print_unsigned(char** str, size_t* size, uint64_t u, uint8_t paddi
|
|||
}
|
||||
|
||||
/** print signed number
|
||||
* @param[in] d unsigned number to be printed
|
||||
* @param[out] str string to print signed number on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] d signed number to be printed
|
||||
* @param[in] padding number of 0's to pad
|
||||
* @param[in] sign if sign should be printed
|
||||
* @return number of characters printed
|
||||
|
@ -106,6 +122,8 @@ static size_t print_signed(char** str, size_t* size, int64_t d, uint8_t padding,
|
|||
}
|
||||
|
||||
/** print nibble (half-byte)
|
||||
* @param[out] str string to print nibble on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] nibble nibble to be printed
|
||||
* @param[in] upcase use upcase digits (A-F)
|
||||
* @return number of characters printed
|
||||
|
@ -124,6 +142,8 @@ static size_t print_nibble(char** str, size_t* size, uint8_t nibble, bool upcase
|
|||
}
|
||||
|
||||
/** print hex value
|
||||
* @param[out] str string to print hex on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] hex hex value to be printed
|
||||
* @param[in] padding number of 0's to pad
|
||||
* @param[in] prefix if 0x prefix should be printed
|
||||
|
@ -157,6 +177,8 @@ static size_t print_hex(char** str, size_t* size, uint32_t hex, uint8_t padding,
|
|||
}
|
||||
|
||||
/** print bits
|
||||
* @param[out] str string to print bits on (use NULL to print on user output)
|
||||
* @param[in,out] size size of string
|
||||
* @param[in] u bits to be printed
|
||||
* @param[in] padding number of 0's to pad
|
||||
* @param[in] prefix if 0b prefix should be printed
|
||||
|
@ -186,6 +208,13 @@ static size_t print_bits(char** str, size_t* size, uint32_t u, uint8_t padding,
|
|||
return length; // return number of characters printed
|
||||
}
|
||||
|
||||
/** print format string on string or user output
|
||||
* @param[out] str string to print format string on, or user output if str is set to NULL (str will always be terminated with a null character '\0')
|
||||
* @param[in,out] size size of string (writes at most size characters on str, including the termination null character '\0')
|
||||
* @param[in] format format string to be printed
|
||||
* @param[in] va arguments referenced by format string to be printed
|
||||
* @return number of characters printed (a return value of size or more means that the output was truncated)
|
||||
**/
|
||||
static size_t vsnprintf(char** str, size_t* size, const char *format, va_list va)
|
||||
{
|
||||
size_t length = 0; // number of characters printed
|
||||
|
@ -259,7 +288,10 @@ static size_t vsnprintf(char** str, size_t* size, const char *format, va_list va
|
|||
}
|
||||
}
|
||||
end:
|
||||
return length;
|
||||
if (NULL!=str && NULL!=*str && NULL!=size) { // when working on a string
|
||||
*str='\0'; // enforce null termination
|
||||
}
|
||||
return length; // return number of characters it should have written
|
||||
}
|
||||
|
||||
size_t printf(const char *format, ...)
|
||||
|
|
25
lib/print.h
25
lib/print.h
|
@ -13,24 +13,31 @@
|
|||
*
|
||||
*/
|
||||
/** printing utilities to replace the large printf from the standard library (API)
|
||||
* use % as format specifier prefix, followed by + to enforce sign of prefix, 0 and 0-9 for padding, and format specifier
|
||||
* format specifier supported are: c for far, s for string, u for uint32_t, d for int32_t, U for uint64_t, D for int64_t, x for lower case hex up to uint32_t, X for upper case hex up to uint32_t, b for bits up to uint32_t
|
||||
* @file print.h
|
||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @date 2017
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/** print a single character
|
||||
/** print a single character on user output
|
||||
* @warning this must be implemented by the user (using the desired output interface)
|
||||
* @param[in] c character to be printed
|
||||
* @return number of characters printed
|
||||
**/
|
||||
size_t putc(char c);
|
||||
/** print format string
|
||||
* use % as format specifier prefix, followed by + to enforce sign of prefix, 0 and 0-9 for padding, and format specifier
|
||||
* format specifier supported are: c for far, s for string, u for uint32_t, d for int32_t, U for uint64_t, D for int64_t, x for lower case hex up to uint32_t, X for upper case hex up to uint32_t, b for bits up to uint32_t
|
||||
* @param[in] fmt format string to be printed
|
||||
* @param[in] ... arguments to to be formated
|
||||
* @return number of characters printed (excluding null termination)
|
||||
*/
|
||||
/** print format string on user output
|
||||
* @param[in] format format string to be printed
|
||||
* @param[in] ... arguments referenced by format string to be printed
|
||||
* @return number of characters printed
|
||||
**/
|
||||
size_t printf(const char* format, ...);
|
||||
/** print format string on string or user output
|
||||
* @param[out] str string to print format string on, or user output if str is set to NULL (str will always be terminated with a null character '\0')
|
||||
* @param[in,out] size size of string (writes at most size characters on str, including the termination null character '\0')
|
||||
* @param[in] format format string to be printed
|
||||
* @param[in] ... arguments referenced by format string to be printed
|
||||
* @return number of characters printed (a return value of size or more means that the output was truncated)
|
||||
**/
|
||||
size_t snprintf(char* str, size_t size, const char* format, ...);
|
||||
|
||||
|
|
Loading…
Reference in New Issue