2017-04-03 13:07:53 +02:00
|
|
|
/* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/** printing utilities to replace the large printf from the standard library (API)
|
2017-12-14 10:23:31 +01:00
|
|
|
* @note use % as format specifier prefix, followed by + to enforce sign or 0x prefix, 0 followed by n for padding or forcing integer part of floating point number, . followed by n for number for fractional precision of floating point numbers, and format specifier
|
2017-12-13 14:01:05 +01:00
|
|
|
* format specifier supported are:
|
|
|
|
* - c for character
|
|
|
|
* - s for string
|
2017-12-13 14:11:34 +01:00
|
|
|
* - u for up to uint32_t unsigned integer
|
|
|
|
* - U for uint64_t unsigned integer
|
|
|
|
* - d for up to int32_t signed integer
|
|
|
|
* - D for int64_t signed integer
|
2017-12-14 10:23:31 +01:00
|
|
|
* - f for float and double floating point numbers
|
2017-12-13 14:11:34 +01:00
|
|
|
* - x for up to uint32_t lower case hexadecimal
|
|
|
|
* - X for uint64_t lower case hexadecimal
|
|
|
|
* - h for up to uint32_t upper case hexadecimal
|
|
|
|
* - H for uint64_t upper case hexadecimal
|
2017-12-13 14:16:28 +01:00
|
|
|
* - b for up to uint32_t bits
|
|
|
|
* - B for uint64_t bits
|
2017-04-03 13:07:53 +02:00
|
|
|
* @file print.h
|
|
|
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
|
|
|
* @date 2017
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-13 13:48:29 +01:00
|
|
|
extern uint8_t print_error; /**< flags to indicate which error(s) occurred within printf or snprintf */
|
|
|
|
|
|
|
|
#define PRINT_ERROR_NONE 0 /**< no error occurred */
|
|
|
|
#define PRINT_ERROR_MALFORMED 0x1 /**< input format string is malformed */
|
|
|
|
#define PRINT_ERROR_UNSUPPORTED 0x2 /**< input format string is not supported */
|
|
|
|
#define PRINT_ERROR_MAX 0x04 /**< maximum returned printed length reached but more has been printed */
|
|
|
|
#define PRINT_ERROR_TRUNCATED 0x08 /**< output string size is not large enough to include complete printed string */
|
|
|
|
|
2017-04-03 13:07:53 +02:00
|
|
|
/** 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 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, ...);
|