Embedded Artistry Framework
Embedded Systems C++ Framework
Classes | Macros | Typedefs | Functions
printf.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "printf.h"
#include <float.h>
Include dependency graph for printf.c:
This graph shows which files directly or indirectly include this file:

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_EXPONENTIAL
 
#define PRINTF_DEFAULT_FLOAT_PRECISION   6U
 
#define PRINTF_MAX_FLOAT   1e9
 
#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 FLAGS_ADAPT_EXP   (1U << 11U)
 
#define PRINTF_SUPPORT_FLOAT
 
#define PRINTF_SUPPORT_EXPONENTIAL
 
#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 FLAGS_ADAPT_EXP   (1U << 11U)
 

Typedefs

typedef void(* out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen)
 

Functions

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 _strnlen_s (const char *str, size_t maxsize)
 
static bool _is_digit (char ch)
 
static unsigned int _atoi (const char **str)
 
static size_t _out_rev (out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags)
 
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 _etoa (out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, 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 printf_ (const char *format,...)
 
int sprintf_ (char *buffer, const char *format,...)
 
int snprintf_ (char *buffer, size_t count, const char *format,...)
 
int vprintf_ (const char *format, va_list va)
 
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,...)
 printf with output function You may use this as dynamic alternative to printf() with its fixed _putchar() output More...
 

Macro Definition Documentation

◆ FLAGS_ADAPT_EXP [1/2]

#define FLAGS_ADAPT_EXP   (1U << 11U)

◆ FLAGS_ADAPT_EXP [2/2]

#define FLAGS_ADAPT_EXP   (1U << 11U)

◆ FLAGS_CHAR [1/2]

#define FLAGS_CHAR   (1U << 6U)

◆ FLAGS_CHAR [2/2]

#define FLAGS_CHAR   (1U << 6U)

◆ FLAGS_HASH [1/2]

#define FLAGS_HASH   (1U << 4U)

◆ FLAGS_HASH [2/2]

#define FLAGS_HASH   (1U << 4U)

◆ FLAGS_LEFT [1/2]

#define FLAGS_LEFT   (1U << 1U)

◆ FLAGS_LEFT [2/2]

#define FLAGS_LEFT   (1U << 1U)

◆ FLAGS_LONG [1/2]

#define FLAGS_LONG   (1U << 8U)

◆ FLAGS_LONG [2/2]

#define FLAGS_LONG   (1U << 8U)

◆ FLAGS_LONG_LONG [1/2]

#define FLAGS_LONG_LONG   (1U << 9U)

◆ FLAGS_LONG_LONG [2/2]

#define FLAGS_LONG_LONG   (1U << 9U)

◆ FLAGS_PLUS [1/2]

#define FLAGS_PLUS   (1U << 2U)

◆ FLAGS_PLUS [2/2]

#define FLAGS_PLUS   (1U << 2U)

◆ FLAGS_PRECISION [1/2]

#define FLAGS_PRECISION   (1U << 10U)

◆ FLAGS_PRECISION [2/2]

#define FLAGS_PRECISION   (1U << 10U)

◆ FLAGS_SHORT [1/2]

#define FLAGS_SHORT   (1U << 7U)

◆ FLAGS_SHORT [2/2]

#define FLAGS_SHORT   (1U << 7U)

◆ FLAGS_SPACE [1/2]

#define FLAGS_SPACE   (1U << 3U)

◆ FLAGS_SPACE [2/2]

#define FLAGS_SPACE   (1U << 3U)

◆ FLAGS_UPPERCASE [1/2]

#define FLAGS_UPPERCASE   (1U << 5U)

◆ FLAGS_UPPERCASE [2/2]

#define FLAGS_UPPERCASE   (1U << 5U)

◆ FLAGS_ZEROPAD [1/2]

#define FLAGS_ZEROPAD   (1U << 0U)

◆ FLAGS_ZEROPAD [2/2]

#define FLAGS_ZEROPAD   (1U << 0U)

◆ PRINTF_DEFAULT_FLOAT_PRECISION

#define PRINTF_DEFAULT_FLOAT_PRECISION   6U

◆ PRINTF_FTOA_BUFFER_SIZE

#define PRINTF_FTOA_BUFFER_SIZE   32U

◆ PRINTF_MAX_FLOAT

#define PRINTF_MAX_FLOAT   1e9

◆ PRINTF_NTOA_BUFFER_SIZE

#define PRINTF_NTOA_BUFFER_SIZE   32U

◆ PRINTF_SUPPORT_EXPONENTIAL [1/2]

#define PRINTF_SUPPORT_EXPONENTIAL

◆ PRINTF_SUPPORT_EXPONENTIAL [2/2]

#define PRINTF_SUPPORT_EXPONENTIAL

◆ PRINTF_SUPPORT_FLOAT [1/2]

#define PRINTF_SUPPORT_FLOAT

◆ PRINTF_SUPPORT_FLOAT [2/2]

#define PRINTF_SUPPORT_FLOAT

◆ PRINTF_SUPPORT_LONG_LONG [1/2]

#define PRINTF_SUPPORT_LONG_LONG

◆ PRINTF_SUPPORT_LONG_LONG [2/2]

#define PRINTF_SUPPORT_LONG_LONG

◆ PRINTF_SUPPORT_PTRDIFF_T [1/2]

#define PRINTF_SUPPORT_PTRDIFF_T

◆ PRINTF_SUPPORT_PTRDIFF_T [2/2]

#define PRINTF_SUPPORT_PTRDIFF_T

Typedef Documentation

◆ out_fct_type

typedef void(* out_fct_type) (char character, void *buffer, size_t idx, size_t maxlen)

Function Documentation

◆ _atoi()

static unsigned int _atoi ( const char **  str)
static

References _is_digit().

Referenced by _vsnprintf().

◆ _etoa()

static size_t _etoa ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
double  value,
unsigned int  prec,
unsigned int  width,
unsigned int  flags 
)
static

◆ _ftoa()

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

◆ _is_digit()

static bool _is_digit ( char  ch)
inlinestatic

Referenced by _atoi(), and _vsnprintf().

◆ _ntoa_format()

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

◆ _ntoa_long()

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

◆ _ntoa_long_long()

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

◆ _out_buffer()

static void _out_buffer ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Referenced by snprintf_(), sprintf_(), and vsnprintf_().

◆ _out_char()

static void _out_char ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

References _putchar().

Referenced by printf_(), and vprintf_().

◆ _out_fct()

static void _out_fct ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Referenced by fctprintf().

◆ _out_null()

static void _out_null ( char  character,
void *  buffer,
size_t  idx,
size_t  maxlen 
)
inlinestatic

Referenced by _vsnprintf().

◆ _out_rev()

static size_t _out_rev ( out_fct_type  out,
char *  buffer,
size_t  idx,
size_t  maxlen,
const char *  buf,
size_t  len,
unsigned int  width,
unsigned int  flags 
)
static

References buf, FLAGS_LEFT, and FLAGS_ZEROPAD.

Referenced by _ftoa(), and _ntoa_format().

◆ _strnlen_s()

static unsigned int _strnlen_s ( const char *  str,
size_t  maxsize 
)
inlinestatic

References s.

Referenced by _vsnprintf().

◆ _vsnprintf()

static int _vsnprintf ( out_fct_type  out,
char *  buffer,
const size_t  maxlen,
const char *  format,
va_list  va 
)
static

◆ fctprintf()

int fctprintf ( void(*)(char character, void *arg)  out,
void *  arg,
const char *  format,
  ... 
)

printf with output function You may use this as dynamic alternative to printf() with its fixed _putchar() output

Parameters
outAn output function which takes one character and an argument pointer
argAn argument pointer for user data passed to output function
formatA string that specifies the format of the output
Returns
The number of characters that are sent to the output function, not counting the terminating null character

Referenced by embvm::LoggerBase< TLock >::log().

Here is the caller graph for this function:

◆ printf_()

int printf_ ( const char *  format,
  ... 
)

◆ snprintf_()

int snprintf_ ( char *  buffer,
size_t  count,
const char *  format,
  ... 
)

◆ sprintf_()

int sprintf_ ( char *  buffer,
const char *  format,
  ... 
)

◆ vprintf_()

int vprintf_ ( const char *  format,
va_list  va 
)

◆ vsnprintf_()

int vsnprintf_ ( char *  buffer,
size_t  count,
const char *  format,
va_list  va 
)