PatchworkOS  69292a3
A non-POSIX operating system.
Loading...
Searching...
No Matches

Internal Print Implementation. More...

Collaboration diagram for Print:

Detailed Description

Internal Print Implementation.

Provides a common implementation for printing formatted output, any function that needs to print formatted output should define the _PRINT_WRITE() and _PRINT_FILL() macros before including this file.

The _PRINT_WRITE(ctx, buffer, count) macro should evaluate to an expression that writes count bytes from the buffer to the output source and takes a pointer to the current print_ctx_t, a pointer to the buffer and the number of bytes to write as arguments.

The _PRINT_FILL(ctx, c, count) macro should evaluate to an expression that writes count bytes of character c to the output source and takes a pointer to the current print_ctx_t, the character to write and the number of times to write it as arguments.

The macros should return the number of bytes written, or EOF on error.

Todo:
Implement floating point printing.
See also
https://cplusplus.com/reference/cstdio/printf/ for details on the format specifiers.

Data Structures

struct  _print_ctx_t
 
struct  _print_format_ctx_t
 
struct  _print_integer_t
 

Macros

#define _PRINT_INTEGER_PUSH(integer, c)   (*--(integer)->dataPtr = (c))
 
#define _PRINT_INTEGER_PREFIX_PUSH(integer, c)   (*--(integer)->prefixPtr = (c))
 
#define _PRINT_INTEGER_LEN(integer)   ((int)((sizeof((integer)->data)) - ((integer)->dataPtr - (integer)->data)))
 
#define _PRINT_INTEGER_PREFIX_LEN(integer)    ((int)((sizeof((integer)->prefix)) - ((integer)->prefixPtr - (integer)->prefix)))
 

Enumerations

enum  _print_format_flags_t {
  _PRINT_LEFT_ALIGNED = 1 << 1 , _PRINT_FORCE_SIGN = 1 << 2 , _PRINT_SPACE_SIGN = 1 << 3 , _PRINT_ALTERNATE_FORM = 1 << 4 ,
  _PRINT_UPPER_CASE = 1 << 5 , _PRINT_PAD_ZERO = 1 << 6
}
 
enum  _print_format_length_t {
  _PRINT_DEFAULT = 0 , _PRINT_HH , _PRINT_H , _PRINT_L ,
  _PRINT_LL , _PRINT_J , _PRINT_Z , _PRINT_T
}
 

Functions

static int _print_padding_left (_print_ctx_t *ctx, _print_format_ctx_t *format, int len)
 
static int _print_padding_right (_print_ctx_t *ctx, _print_format_ctx_t *format, int padding)
 
static int _print_integer_print (_print_ctx_t *ctx, _print_format_ctx_t *format, _print_integer_t *integer)
 
static int _print_format_signed_integer (_print_ctx_t *ctx, _print_format_ctx_t *format)
 
static int _print_format_unsigned_integer (_print_ctx_t *ctx, _print_format_ctx_t *format, uint32_t base)
 
static int _print_format_char (_print_ctx_t *ctx, _print_format_ctx_t *format)
 
static int _print_format_string (_print_ctx_t *ctx, _print_format_ctx_t *format)
 
static int _print_format_written (_print_ctx_t *ctx)
 
static int _print_format_percent (_print_ctx_t *ctx)
 
static int _print_format (_print_ctx_t *ctx)
 
static int _print (const char *_RESTRICT format, size_t n, va_list arg, void *data)
 

Macro Definition Documentation

◆ _PRINT_INTEGER_PUSH

#define _PRINT_INTEGER_PUSH (   integer,
 
)    (*--(integer)->dataPtr = (c))

Definition at line 136 of file print.h.

◆ _PRINT_INTEGER_PREFIX_PUSH

#define _PRINT_INTEGER_PREFIX_PUSH (   integer,
 
)    (*--(integer)->prefixPtr = (c))

Definition at line 138 of file print.h.

◆ _PRINT_INTEGER_LEN

#define _PRINT_INTEGER_LEN (   integer)    ((int)((sizeof((integer)->data)) - ((integer)->dataPtr - (integer)->data)))

Definition at line 140 of file print.h.

◆ _PRINT_INTEGER_PREFIX_LEN

#define _PRINT_INTEGER_PREFIX_LEN (   integer)     ((int)((sizeof((integer)->prefix)) - ((integer)->prefixPtr - (integer)->prefix)))

Definition at line 142 of file print.h.

Enumeration Type Documentation

◆ _print_format_flags_t

Enumerator
_PRINT_LEFT_ALIGNED 
_PRINT_FORCE_SIGN 
_PRINT_SPACE_SIGN 
_PRINT_ALTERNATE_FORM 
_PRINT_UPPER_CASE 
_PRINT_PAD_ZERO 

Definition at line 56 of file print.h.

◆ _print_format_length_t

Enumerator
_PRINT_DEFAULT 
_PRINT_HH 
_PRINT_H 
_PRINT_L 
_PRINT_LL 
_PRINT_J 
_PRINT_Z 
_PRINT_T 

Definition at line 66 of file print.h.

Function Documentation

◆ _print_padding_left()

static int _print_padding_left ( _print_ctx_t ctx,
_print_format_ctx_t format,
int  len 
)
inlinestatic

Definition at line 86 of file print.h.

Here is the caller graph for this function:

◆ _print_padding_right()

static int _print_padding_right ( _print_ctx_t ctx,
_print_format_ctx_t format,
int  padding 
)
inlinestatic

Definition at line 112 of file print.h.

Here is the caller graph for this function:

◆ _print_integer_print()

static int _print_integer_print ( _print_ctx_t ctx,
_print_format_ctx_t format,
_print_integer_t integer 
)
inlinestatic

Definition at line 145 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print_format_signed_integer()

static int _print_format_signed_integer ( _print_ctx_t ctx,
_print_format_ctx_t format 
)
inlinestatic

Definition at line 234 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print_format_unsigned_integer()

static int _print_format_unsigned_integer ( _print_ctx_t ctx,
_print_format_ctx_t format,
uint32_t  base 
)
inlinestatic

Definition at line 296 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print_format_char()

static int _print_format_char ( _print_ctx_t ctx,
_print_format_ctx_t format 
)
inlinestatic

Definition at line 374 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print_format_string()

static int _print_format_string ( _print_ctx_t ctx,
_print_format_ctx_t format 
)
inlinestatic

Definition at line 393 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print_format_written()

static int _print_format_written ( _print_ctx_t ctx)
inlinestatic

Definition at line 422 of file print.h.

Here is the caller graph for this function:

◆ _print_format_percent()

static int _print_format_percent ( _print_ctx_t ctx)
inlinestatic

Definition at line 429 of file print.h.

Here is the caller graph for this function:

◆ _print_format()

static int _print_format ( _print_ctx_t ctx)
inlinestatic
Todo:
Implement floating point formatting

Definition at line 439 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _print()

static int _print ( const char *_RESTRICT  format,
size_t  n,
va_list  arg,
void *  data 
)
inlinestatic

Definition at line 617 of file print.h.

Here is the call graph for this function:
Here is the caller graph for this function: