OFP  1.0
Option and Flag Parser
ofp.h File Reference

OFP Environment. More...

#include <setjmp.h>

Go to the source code of this file.

Macros

#define OFP_ENUMTYPE
 
#define ofp_on_ferror(S)   if(setjmp((S)->ferrbuf))
 Define behaviour for handling fatal errors.
 
#define ofp_any_error(S)   ((S)->errtop > 0)
 Return a flag that indicates if there's any errors.
 
#define OFP_API   __declspec(dllexport)
 API's visibility and/or linkage.
 
#define OFP_PREFIX_DEFAULT   '/'
 Prefix used by default by the OFP state.
 

Typedefs

typedef unsigned int ofp_uint
 
typedef enum ofp_argument_type_e ofp_argument_type
 
typedef enum ofp_argument_priority_e ofp_argument_priority
 
typedef enum ofp_errorcode_e ofp_errorcode
 
typedef void(* ofp_Cfunction) (ofp_argument *arg, ofp_errorcode ec)
 Pointer to C function used for argument error handling.
 

Functions

OFP_API ofp_state * ofp_state_new (char **argv, int argc, ofp_argument_priority prty, ofp_uint maxuda)
 
OFP_API void ofp_state_free (ofp_state *S)
 
OFP_API void ofp_state_error_throw (ofp_state *S, ofp_errorcode ec)
 
OFP_API ofp_argument * ofp_argument_register (ofp_state *S, ofp_argument_type t, ofp_argument_priority prty, int r, ofp_Cfunction ef, char *id, ofp_uint len, char *desc)
 
OFP_API void ofp_argument_error_push (ofp_state *S, ofp_argument *arg, ofp_errorcode ec)
 
OFP_API int ofp_option_enumval (ofp_argument *arg, ofp_uint count,...)
 
OFP_API void ofp_parser_parse (ofp_state *S)
 
OFP_API void * ofp_memory_allocate (ofp_state *S, ofp_uint size)
 
OFP_API void ofp_memory_array_admissible (ofp_state *S, ofp_uint top, ofp_uint limit, ofp_errorcode ferr)
 

Detailed Description

OFP Environment.

Function Documentation

◆ ofp_argument_error_push()

OFP_API void ofp_argument_error_push ( ofp_state *  S,
ofp_argument *  arg,
ofp_errorcode  ec 
)

Push an error of code "ec" concerning argument "arg" onto the error stack.

Parameters
S- OFP state
arg- argument
ec- error code

◆ ofp_argument_register()

OFP_API ofp_argument* ofp_argument_register ( ofp_state *  S,
ofp_argument_type  t,
ofp_argument_priority  prty,
int  r,
ofp_Cfunction  ef,
char *  id,
ofp_uint  len,
char *  desc 
)

Register a new argument.

Parameters
S- OFP state
t- argument type
prty- parsing priority
r- required flag
ef- error function
id- identifier
len- identifier's length
desc- description

◆ ofp_memory_allocate()

OFP_API void* ofp_memory_allocate ( ofp_state *  S,
ofp_uint  size 
)

Allocates "size" bytes of uninitialized storage.
If allocation succeds, return a pointer to the beggining of allocated memory.
On failure throw an fatal "out of memory" error.

Parameters
S- OFP state
size- number of bytes to allocate

◆ ofp_memory_array_admissible()

OFP_API void ofp_memory_array_admissible ( ofp_state *  S,
ofp_uint  top,
ofp_uint  limit,
ofp_errorcode  ferr 
)

Check if an array with the given top has hit the limit.
If it has, throw an fatal error of code "ferr".

Parameters
S- OFP state
top- array's top
limit- array's limit
ferr- error code

◆ ofp_option_enumval()

OFP_API int ofp_option_enumval ( ofp_argument *  arg,
ofp_uint  count,
  ... 
)

Simulates an "enum" behaviour.
If argument's identifier matches one of the given entries, return it's corresponding value.
Otherwise, if no matching entries were found, return -1.

Entry has the following structure

#1 #2 #3
identifier identifier length value
char* ofp_uint int

Example

ofp_option_enumval(argment, 3, // 3 entries
"one", 3, 1,
"two", 3, 2,
"three", 5, 3);
OFP_API int ofp_option_enumval(ofp_argument *arg, ofp_uint count,...)
Definition: option.c:42
Parameters
arg- argument
count- entry count
...- entries

◆ ofp_parser_parse()

OFP_API void ofp_parser_parse ( ofp_state *  S)

Parse the OFP state.

Parameters
S- OFP state

◆ ofp_state_error_throw()

OFP_API void ofp_state_error_throw ( ofp_state *  S,
ofp_errorcode  ec 
)

Throw an fatal error of code "ec".

Parameters
S- OFP state
ec- error code

◆ ofp_state_free()

OFP_API void ofp_state_free ( ofp_state *  S)

Free the OFP state.

Parameters
S- OFP state

◆ ofp_state_new()

OFP_API ofp_state* ofp_state_new ( char **  argv,
int  argc,
ofp_argument_priority  prty,
ofp_uint  maxuda 
)

Allocates and initialize a new OFP state.
Returns an pointer to it.

Parameters
argv- argument vector
argc- argument count
prty- default parsing priority
maxargs- maximum argument count that the state can handle