BeRTOS
Defines | Functions
formatwr.c File Reference

Basic "printf", "sprintf" and "fprintf" formatter. More...

#include "formatwr.h"
#include "cfg/cfg_formatwr.h"
#include <cfg/debug.h>
#include <cpu/pgm.h>
#include <mware/hex.h>
#include <float.h>

Go to the source code of this file.

Defines

#define CONFIG_PRINTF_N_FORMATTER   0
 Disable the arcane n formatter.
#define CONFIG_PRINTF_OCTAL_FORMATTER   0
 Disable the o formatter.

Functions

int _formatted_write (const char *PGM_ATTR format, void put_one_char(char, void *), void *secret_pointer, va_list ap)
 This routine forms the core and entry of the formatter.

Detailed Description

Basic "printf", "sprintf" and "fprintf" formatter.

This module is 100% reentrant and can be adapted to user-defined routines that needs formatters with special properties like different output channels or new format specifiers.

To reduce size in applications not using real numbers or long integers the formatter may be compiled to exclude certain parts. This is controlled by giving a -D option a compilation time:

  -D CONFIG_PRINTF=PRINTF_FULL         Full ANSI printf formatter, with some C99 extensions
  -D CONFIG_PRINTF=PRINTF_NOFLOAT      Exclude support for floats
  -D CONFIG_PRINTF=PRINTF_REDUCED      Simplified formatter (see below)
  -D CONFIG_PRINTF=PRINTF_NOMODIFIERS  Exclude "l", "z" and "h" modifiers in reduced version
  -D CONFIG_PRINTF=PRINTF_DISABLED     No formatter at all

Code size on AVR4 with GCC 3.4.1 (-O2):

Code/data size in words on DSP56K with CodeWarrior 6.0:

The reduced version of formatter is suitable when program size is critical rather than formatting power. This routine uses less than 20 bytes of stack space which makes it practical even in systems with less than 256 bytes of user RAM.

The only formatting specifiers supported by the reduced formatter are:

    %% %c %s %d %o %x %X and %hd %ho %hx %hX %ld %lo %lx %lX

It means that real variables are not supported as well as field width and precision arguments.

Definition in file formatwr.c.


Define Documentation

#define CONFIG_PRINTF_N_FORMATTER   0

Disable the arcane n formatter.

Definition at line 89 of file formatwr.c.

#define CONFIG_PRINTF_OCTAL_FORMATTER   0

Disable the o formatter.

Definition at line 94 of file formatwr.c.


Function Documentation

int _formatted_write ( const char *PGM_ATTR  format,
void   put_one_charchar, void *,
void *  secret_pointer,
va_list  ap 
)

This routine forms the core and entry of the formatter.

The conversion performed conforms to the ANSI specification for "printf".

Definition at line 333 of file formatwr.c.