libexplain  1.4.D001
Data Structures | Typedefs | Functions
libexplain/parse_bits.h File Reference
#include <libexplain/ac/stddef.h>
#include <libexplain/sizeof.h>

Go to the source code of this file.

Data Structures

struct  explain_parse_bits_table_t

Typedefs

typedef struct
explain_parse_bits_table_t 
explain_parse_bits_table_t

Functions

int explain_parse_bits (const char *text, const explain_parse_bits_table_t *table, size_t table_size, int *result)
const char * explain_parse_bits_get_error (void)
int explain_parse_bits_or_die (const char *text, const explain_parse_bits_table_t *table, size_t table_size, const char *caption)
const explain_parse_bits_table_texplain_parse_bits_find_by_name (const char *name, const explain_parse_bits_table_t *table, size_t table_size)
const explain_parse_bits_table_texplain_parse_bits_find_by_name_fuzzy (const char *name, const explain_parse_bits_table_t *table, size_t table_size)
const explain_parse_bits_table_texplain_parse_bits_find_by_value (int value, const explain_parse_bits_table_t *table, size_t table_size)
void explain_parse_bits_print (struct explain_string_buffer_t *sb, int value, const explain_parse_bits_table_t *table, int table_size)
void explain_parse_bits_print_single (struct explain_string_buffer_t *sb, int value, const explain_parse_bits_table_t *table, int table_size)

Typedef Documentation

Definition at line 27 of file parse_bits.h.


Function Documentation

int explain_parse_bits ( const char *  text,
const explain_parse_bits_table_t table,
size_t  table_size,
int *  result 
)

The explain_parse_bits function may be used to parse an input string against a table of bitfields. There may be symbols (from the bits table) or numeric conatsnts (using C notation) and there may be plus (+) or bit-wise-or (|) operators.

Parameters:
textThe text to be parsed.
tableThe table of symbols for the parser.
table_sizeThe lentgh of the table of symbols.
resultWhere to put the results of parsing and evluating the expression.
Returns:
0 in success, -1 on error
Note:
this function is not thread safe
const explain_parse_bits_table_t* explain_parse_bits_find_by_name ( const char *  name,
const explain_parse_bits_table_t table,
size_t  table_size 
)

The explain_parse_bits_find_by_name function is used to search a parse-bits table for the given name.

Parameters:
nameThe name to search for in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.
Returns:
pointer to table entry on succes, or NULL on no match

Definition at line 26 of file find_by_name.c.

const explain_parse_bits_table_t * explain_parse_bits_find_by_name_fuzzy ( const char *  name,
const explain_parse_bits_table_t table,
size_t  table_size 
)

The explain_parse_bits_find_by_name_fuzzy function is used to search a parse-bits table for the given name, using fuzzy matching. This is best used after explain_parse_bits_find_by_name has already failed, for the purpose of producing a better error message.

Parameters:
nameThe name to search for in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.
Returns:
pointer to table entry on succes, or NULL on no match

The explain_parse_bits_find_by_name_fuzzy function is used to search a parse-bits table for the given name, using fuzzy matching.

Parameters:
nameThe name to search for in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.
Returns:
pointer to table entry on succes, or NULL on no match

Definition at line 25 of file find_by_name_fuzzy.c.

const explain_parse_bits_table_t* explain_parse_bits_find_by_value ( int  value,
const explain_parse_bits_table_t table,
size_t  table_size 
)

The explain_parse_bits_find_by_value function is used to search a parse-bits table for the given value.

Parameters:
valueThe value to search for in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.
Returns:
pointer to table entry on succes, or NULL on no match

Definition at line 24 of file find_by_value.c.

const char* explain_parse_bits_get_error ( void  )

The explain_parse_bits_get_error function may be used to obtain the error message emitted by the parser by the previous call to explain_parse_bits.

int explain_parse_bits_or_die ( const char *  text,
const explain_parse_bits_table_t table,
size_t  table_size,
const char *  caption 
)

The explain_parse_bits_or_die function may be used to parse an input string against a table of bitfields. There may be symbols (from the bits table) or numeric conatsnts (using C notation) and there may be plus (+) or bit-wise-or (|) operators.

Parameters:
textThe text to be parsed.
tableThe table of symbols for the parser.
table_sizeThe lentgh of the table of symbols.
captionCaption to add to start of error message, or NULL for none
Returns:
The value of the expression. Does not return on error, but prints diagnostic and exits EXIT_FAILURE.
Note:
this function is not thread safe

Definition at line 31 of file or_die.c.

void explain_parse_bits_print ( struct explain_string_buffer_t sb,
int  value,
const explain_parse_bits_table_t table,
int  table_size 
)

The explain_parse_bits_print function may be used to break a bit-set value into its component bits and print the result.

Parameters:
sbThe string buffer to print into.
valueThe value to dismantle and search for bits in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.

Definition at line 25 of file print.c.

void explain_parse_bits_print_single ( struct explain_string_buffer_t sb,
int  value,
const explain_parse_bits_table_t table,
int  table_size 
)

The explain_parse_bits_print_single function may be used to lookup a value and print the name.

Parameters:
sbThe string buffer to print into.
valueThe value to dismantle and search for in the table
tableThe table to be searched.
table_sizeThe number of members in the table to be searched.

Definition at line 25 of file print_single.c.