embtextf  20130407
Embedded System Text Formatting
 All Files Functions Typedefs Macros Pages
Typedefs | Functions
uprintf.h File Reference

Declarations for core functions supporting printf(3c) and related capabilities. More...

#include <stdarg.h>

Go to the source code of this file.

Typedefs

typedef int(* embtextf_putchar_fn )(int)
 

Functions

int embtextf_vuprintf (embtextf_putchar_fn write_char, const char *format, va_list args)
 
int embtextf_uprintf (embtextf_putchar_fn emit_char, const char *fmt,...)
 

Detailed Description

Declarations for core functions supporting printf(3c) and related capabilities.

This header declares configuration options and supporting material for a printf(3c) variant that emits formatted data through a per-character callback, such as putchar(3). It can be used as the basis for routines that produce formatted output on LCDs, into character buffers, or over other communications links that can provide character-oriented interface.

vuprintf formatting capabilities

The formatting capabilities of embtextf_vuprintf() are intended to be compatible with the standard C library format string interpretation, with only a few restrictions, including:

Within those limitations, all standard format flags are supported:

Flag character Conditional on Comments
# EMBTEXTF_ENABLE_VUPRINTF_ALTERNATE_FORM Emit prefix for octal and hex values
0 Zero pad output
- Left justify
(space) Leave blank before positive number
+ Always emit sign before converted value

Field width and (optionally) precision are supported for integer and string conversions:

Example Conditional on Comments
%4d width, pad output to 4 characters
%*d width, pad output to width passed as argument
%.3d EMBTEXTF_ENABLE_VUPRINTF_PRECISION precision, minimum 3 number of digits in conversion
%.*d EMBTEXTF_ENABLE_VUPRINTF_PRECISION precision, minimum number of digits in conversion passed as argument

Some length modifiers are supported for integer conversion:

Example Conditional on Comments
%d expect input type int
%ld EMBTEXTF_ENABLE_VUPRINTF_LONG expect input type long
%lld EMBTEXTF_ENABLE_VUPRINTF_LONGLONG expect input type long long

Many conversion specifiers, excluding floating point, are supported:

Example Conditional on Comments
d i Signed decimal
o EMBTEXTF_ENABLE_VUPRINTF_OCTAL Octal
u Unsigned decimal
x X Hexadecimal (lower or upper case alphabetics)
s Null-terminated text input
c Character value of int
p EMBTEXTF_ENABLE_VUPRINTF_INTPTR Pointer output

When format specifiers are not recognized by the infrastructure the unrecognized characters are emitted as output.

Homepage
http://github.com/pabigot/embtextf
Note
embtextf_vuprintf() contains material copyright 2006-2011, Chris Liechti.

Typedef Documentation

typedef int(* embtextf_putchar_fn)(int)

Type of function required by embtextf_vuprintf() for emitting characters. putchar(3) is the template.

Function Documentation

int embtextf_uprintf ( embtextf_putchar_fn  emit_char,
const char *  fmt,
  ... 
)

Variadic print-via-callback function

This uses the standard va_arg facility to extract arguments and delegate the formatting to embtextf_vuprintf().

Parameters
emit_charas with embtextf_vuprintf()
fmtas with embtextf_vuprintf()
Returns
as with embtextf_vuprintf
int embtextf_vuprintf ( embtextf_putchar_fn  write_char,
const char *  format,
va_list  args 
)

Format text collected by a variadic function.

Parameters
write_charthe function used to emit formatted characters. The interface supports using putchar for this.
formata standard C format string
argsaggregated arguments as collected using the stdarg.h macros.
Returns
the number of characters passed to the emit_char function while generating the formatted string.
See Also
vuprintf formatting capabilities