SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions | Variables
xformat.c File Reference
#include "xformat.h"
Include dependency graph for xformat.c:

Classes

struct  param_s
 Structure with all parameter used. More...
 

Macros

#define LONG   long
 Default largest int is long.
 
#define DOUBLE   double
 Define the double type if not defined.
 
#define LONGLONG   long long
 Default long long type.
 
#define FLOAT_LONG   LONG
 Definition to convert integer part of floating point numer if supported we use the long long type.
 
#define FLOAT_VALUE   lvalue
 
#define FLOAT_TYPE   FLAG_TYPE_LONG
 
#define FLAG_TYPE_INT   0x0000 /* Argument is integer */
 
#define FLAG_TYPE_LONG   0x0001 /* Argument is long */
 
#define FLAG_TYPE_SIZEOF   0x0002 /* Argument is size_t */
 
#define FLAG_TYPE_LONGLONG   0x0003 /* Argument is long long */
 
#define FLAG_TYPE_MASK   0x0003 /* Mask for field type */
 
#define FLAG_PREC   0x0004 /* Precision set */
 
#define FLAG_LEFT   0x0008 /* Left alignment */
 
#define FLAG_BLANK   0x0010 /* Blank before positive integer number */
 
#define FLAG_PREFIX   0x0020 /* Prefix required */
 
#define FLAG_PLUS   0x0040 /* Force a + before positive number */
 
#define FLAG_UPPER   0x0080 /* Output in upper case letter */
 
#define FLAG_DECIMAL   0x0100 /* Decimal field */
 
#define FLAG_INTEGER   0x0200 /* Integer field */
 
#define FLAG_MINUS   0x0400 /* Field is negative */
 
#define FLAG_VALUE   0x0800 /* Value set */
 
#define FLAG_BUFFER   0x1000 /* Buffer set */
 
#define args   _args
 

Enumerations

enum  State {
  ST_NORMAL = 0 , ST_PERCENT = 1 , ST_FLAG = 2 , ST_WIDTH = 3 ,
  ST_DOT = 4 , ST_PRECIS = 5 , ST_SIZE = 6 , ST_TYPE = 7
}
 Enum for the internal state machine. More...
 
enum  CharClass {
  CH_OTHER = 0 , CH_PERCENT = 1 , CH_DOT = 2 , CH_STAR = 3 ,
  CH_ZERO = 4 , CH_DIGIT = 5 , CH_FLAG = 6 , CH_SIZE = 7 ,
  CH_TYPE = 8
}
 Enum for char class. More...
 

Functions

static void ulong2a (struct param_s *param)
 Convert an unsigned value in one string.
 
unsigned xformat (void(*outchar)(void *, char), void *arg, const char *fmt,...)
 Printf like using variable arguments.
 
static unsigned xstrlen (const char *s)
 We do not want use any library function.
 
static unsigned outBuffer (void(*myoutchar)(void *arg, char), void *arg, const char *buffer, int len, unsigned toupper)
 
static unsigned outChars (void(*myoutchar)(void *arg, char), void *arg, char ch, int len)
 
unsigned xvformat (void(*outchar)(void *, char), void *arg, const char *fmt, va_list _args)
 Printf like format function.
 

Variables

static const char ms_null [] = "(null)"
 String used when s is a null parameter.
 
static const char ms_true [] = "True"
 
static const char ms_false [] = "False"
 String for false value.
 
static const char ms_digits [] = "0123456789abcdef"
 
static const unsigned char formatStates []
 

Macro Definition Documentation

◆ args

#define args   _args

◆ DOUBLE

#define DOUBLE   double

Define the double type if not defined.

◆ FLAG_BLANK

#define FLAG_BLANK   0x0010 /* Blank before positive integer number */

◆ FLAG_BUFFER

#define FLAG_BUFFER   0x1000 /* Buffer set */

◆ FLAG_DECIMAL

#define FLAG_DECIMAL   0x0100 /* Decimal field */

◆ FLAG_INTEGER

#define FLAG_INTEGER   0x0200 /* Integer field */

◆ FLAG_LEFT

#define FLAG_LEFT   0x0008 /* Left alignment */

◆ FLAG_MINUS

#define FLAG_MINUS   0x0400 /* Field is negative */

◆ FLAG_PLUS

#define FLAG_PLUS   0x0040 /* Force a + before positive number */

◆ FLAG_PREC

#define FLAG_PREC   0x0004 /* Precision set */

◆ FLAG_PREFIX

#define FLAG_PREFIX   0x0020 /* Prefix required */

◆ FLAG_TYPE_INT

#define FLAG_TYPE_INT   0x0000 /* Argument is integer */

◆ FLAG_TYPE_LONG

#define FLAG_TYPE_LONG   0x0001 /* Argument is long */

◆ FLAG_TYPE_LONGLONG

#define FLAG_TYPE_LONGLONG   0x0003 /* Argument is long long */

◆ FLAG_TYPE_MASK

#define FLAG_TYPE_MASK   0x0003 /* Mask for field type */

◆ FLAG_TYPE_SIZEOF

#define FLAG_TYPE_SIZEOF   0x0002 /* Argument is size_t */

◆ FLAG_UPPER

#define FLAG_UPPER   0x0080 /* Output in upper case letter */

◆ FLAG_VALUE

#define FLAG_VALUE   0x0800 /* Value set */

◆ FLOAT_LONG

#define FLOAT_LONG   LONG

Definition to convert integer part of floating point numer if supported we use the long long type.

◆ FLOAT_TYPE

#define FLOAT_TYPE   FLAG_TYPE_LONG

◆ FLOAT_VALUE

#define FLOAT_VALUE   lvalue

◆ LONG

#define LONG   long

Default largest int is long.

◆ LONGLONG

#define LONGLONG   long long

Default long long type.

Enumeration Type Documentation

◆ CharClass

enum CharClass

Enum for char class.

Enumerator
CH_OTHER 
CH_PERCENT 
CH_DOT 
CH_STAR 
CH_ZERO 
CH_DIGIT 
CH_FLAG 
CH_SIZE 
CH_TYPE 

◆ State

enum State

Enum for the internal state machine.

Enumerator
ST_NORMAL 
ST_PERCENT 
ST_FLAG 
ST_WIDTH 
ST_DOT 
ST_PRECIS 
ST_SIZE 
ST_TYPE 

Function Documentation

◆ outBuffer()

static unsigned outBuffer ( void(*)(void *arg, char)  myoutchar,
void *  arg,
const char *  buffer,
int  len,
unsigned  toupper 
)
static

◆ outChars()

static unsigned outChars ( void(*)(void *arg, char)  myoutchar,
void *  arg,
char  ch,
int  len 
)
static

◆ ulong2a()

static void ulong2a ( struct param_s param)
static

Convert an unsigned value in one string.

All parameter are in the passed structure

Parameters
prec- Minimum precision
lvalue- Unsigned value
radix- Radix (Supported values 2/8/10/16)
out- Buffer with the converted value.

◆ xformat()

unsigned xformat ( void(*)(void *, char)  outchar,
void *  arg,
const char *  fmt,
  ... 
)

Printf like using variable arguments.

Parameters
outchar- Pointer to the function to output one new char.
arg- Argument for the output function.
fmt- Format options for the list of parameters.
...- Arguments
Returns
The number of char emitted.
See also
xvformat

◆ xstrlen()

static unsigned xstrlen ( const char *  s)
static

We do not want use any library function.

Parameters
s- C string
Returns
The length of the string

◆ xvformat()

unsigned xvformat ( void(*)(void *, char)  outchar,
void *  arg,
const char *  fmt,
va_list  _args 
)

Printf like format function.

General format :

%[width][.precision][flags]type

  • width Is the minimum size of the field.
  • precision Is the maximum size of the field.

Supported flags :

  • l With integer number the argument will be of type long.
  • ll With integer number the argument will be of type long long.
  • Space for positive integer a space will be added before.
  • z Compatible with C99 the argument is size_t (aka sizeof(void *))
  • + A + sign prefix positive number.
  • # A prefix will be printed (o for octal,0x for hex,0b for binary)
  • 0 Value will be padded with zero (default is spacwe)
  • - Left justify as default filed have rigth justification.

Supported type :

  • s Null terminated string of char.
  • S Null terminated string of char in upper case.
  • i Integer number.
  • d Integer number.
  • u Unsigned number.
  • x Unsigned number in hex.
  • X Unsigned number in hex upper case.
  • b Binary number
  • o Octal number
  • p Pointer will be emitted with the prefix ->
  • P Pointer in upper case letter.
  • f Floating point number.
  • B Boolean value printed as True / False.
Parameters
outchar- Pointer to the function to output one char.
arg- Argument for the output function.
fmt- Format options for the list of parameters.
args-List parameters.
Returns
The number of char emitted.

Variable Documentation

◆ formatStates

const unsigned char formatStates[]
static
Initial value:
= {0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x03, 0x06, 0x00, 0x06, 0x02, 0x10, 0x04, 0x45, 0x45,
0x45, 0x45, 0x05, 0x05, 0x05, 0x05, 0x35, 0x30, 0x00, 0x50, 0x60, 0x00, 0x00, 0x00, 0x20, 0x28, 0x38, 0x50, 0x50,
0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x50, 0x50, 0x00, 0x00, 0x08, 0x20, 0x20, 0x28, 0x20, 0x20, 0x20, 0x00, 0x08,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x70, 0x78, 0x78, 0x78, 0x70, 0x78, 0x00, 0x07, 0x08, 0x00, 0x00,
0x07, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x07}

◆ ms_digits

const char ms_digits[] = "0123456789abcdef"
static

◆ ms_false

const char ms_false[] = "False"
static

String for false value.

◆ ms_null

const char ms_null[] = "(null)"
static

String used when s is a null parameter.

◆ ms_true

const char ms_true[] = "True"
static