Simple coroutine library / objects in plain C Snapshot
Functions
val.c File Reference
#include "val.h"
#include <ctype.h>

Go to the source code of this file.

Functions

static int parse_spec (const char **pos, VAL_TYPE *type)
int VALUES_printv (VALUES *values, const char *format, va_list ap)
 insert typed tuple of values
int VALUES_scanv (VALUES *values, const char *format, va_list ap)
 retrieve typed tuple of values; like scanf receives varying number of arguments

Function Documentation

static int parse_spec ( const char **  pos,
VAL_TYPE type 
) [static]

Definition at line 4 of file val.c.

{
  const char *cur = *pos;
  int length = 0;

  if (*cur == '\0') {
    return 1;
  }

  for( ; isspace(*cur) ; ++cur);

  if (*cur != '%') {
    return -1;
  }
  ++cur;

  if (*cur == 's') {
    *type = VAL_TYPE_STRING;
    goto ret;
  }

  if (*cur == 'p') {
    *type = VAL_TYPE_PTR;
    goto ret;
  }

  for( length = 0; *cur == 'h'; ++cur,++length );
   
  if ( *cur == 'q') { 
     ++cur;
     length = 4;
  }

  if (*cur != 'd' && *cur != 'u') {
    return -1;
  }

  switch( length ) {
      case 2:
        *type = *cur == 'd' ?  VAL_TYPE_INT8 : VAL_TYPE_UINT8;  
        goto ret;
      case 1:
        *type = *cur == 'd' ?  VAL_TYPE_INT16 : VAL_TYPE_UINT16;  
        goto ret;
      case 0:
        *type = *cur == 'd' ?  VAL_TYPE_INT32 : VAL_TYPE_UINT32;  
        goto ret;
      case 4:
        *type = *cur == 'd' ?  VAL_TYPE_INT64 : VAL_TYPE_UINT64;  
        goto ret;
  }
  return -1;

ret:
  *pos = cur + 1;
  return 0;
}