58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
/** @file format.h
|
|
* Module handling various formating functions
|
|
*
|
|
* The module provides a lightweight printf function and the attached tools
|
|
*/
|
|
|
|
#ifndef _FORMAT_H_
|
|
#define _FORMAT_H_
|
|
|
|
//--includes--------------------------------------------------------------------
|
|
|
|
#include <stdint.h>
|
|
#include <stdarg.h>
|
|
|
|
|
|
//--type definitions------------------------------------------------------------
|
|
|
|
typedef uint32_t (*FormatCallback)(uint8_t byte, void* arg);
|
|
|
|
|
|
//--functions-------------------------------------------------------------------
|
|
|
|
/**
|
|
* Custom implementation of snprintf. Print the given format into the given
|
|
* buffer with the attached arguments properly formated.
|
|
*
|
|
* This function only provided a minimal subset of the standard library's
|
|
* snprintf : %c, %s, %i, %d, %x as well as right-justified padding for %d and
|
|
* %x
|
|
*
|
|
* Returns 0 if everything went as expected, 1 otherwise
|
|
*/
|
|
uint32_t format_snprintf(char* restrict buffer, uint32_t buffer_size,
|
|
const char* restrict format, ...);
|
|
|
|
/**
|
|
* Custom implementation of fprintf using a callback instead of a file pointer.
|
|
* Print the given format using the given callback with the attached arguments
|
|
* properly formated.
|
|
*
|
|
* This function only provided a minimal subset of the standard library's
|
|
* snprintf : %c, %s, %i, %d, %x as well as right-justified padding for %d and
|
|
* %x
|
|
*
|
|
* Returns 0 if everything went as expected, 1 otherwise
|
|
*/
|
|
uint32_t format_fctprintf(FormatCallback callback, void* arg,
|
|
const char* restrict format, ...);
|
|
|
|
/**
|
|
* Variadic variation of format_fctprintf(), see the later for more information
|
|
*/
|
|
uint32_t format_vfctprintf(FormatCallback callback, void* arg,
|
|
const char* restrict format, va_list va);
|
|
|
|
#endif //_FORMAT_H_
|
|
|