The following is a full featured parser for configuration files using basic format "key = value". More...
Macros | |
#define | HEX_INDICES(st) |
Enumerations | |
enum | { STATE_ERROR = 1, STATE_BEGIN, STATE_COMMENT, STATE_KEY, STATE_KEYBS, STATE_KEYBSX1, STATE_KEYBSX2, STATE_KEYSQ, STATE_KEYDQ, STATE_KEYDQBS, STATE_KEYDQBSX1, STATE_KEYDQBSX2, STATE_BEQ, STATE_AEQ, STATE_VALUE, STATE_VALBS, STATE_VALBSX1, STATE_VALBSX2, STATE_VALSQ, STATE_VALDQ, STATE_VALDQBS, STATE_VALDQBSX1, STATE_VALDQBSX2, STATE_VALEND, ACTION_KEY = 0x0100, ACTION_VALUE = 0x0200, ACTION_ERROR = 0x0400, ACTION_STORE = 0x1000, ACTION_STORE_MOD = 0x2000, ACTION_STORE_HEX1 = 0x4000, ACTION_STORE_HEX2 = 0x8000 } |
Functions | |
size_t | ckvp_parse (ckvp_t *ckvp, size_t size, const char in[]) |
ckvp_parse() takes the current state (ckvp), a buffer in[size] and returns the number of characters processed. |
The following is a full featured parser for configuration files using basic format "key = value".
Well, it's big, but it can properly manage spaces, empty lines, single and double-quoted strings, hex numbers, comments, semicolons and more. It also happens to be much more robust than the original one.
#define HEX_INDICES | ( | st | ) |
anonymous enum |
size_t ckvp_parse | ( | ckvp_t * | ckvp, |
size_t | size, | ||
const char | in[] | ||
) |
ckvp_parse() takes the current state (ckvp), a buffer in[size] and returns the number of characters processed.
Each time ckvp_parse() returns, ckvp->state must be checked. If no error occured, ckvp_parse() must be called again with the remaining characters if any, otherwise the next input buffer.
At the end of input, ckvp_parse() must be called with a zero size.
This function doesn't allocate anything.
[in,out] | ckvp | Current state. |
size | Number of characters in buffer "in". | |
in | Input buffer to parse. |
State machine definition:
st[current_state][current_character] = next state | action
Special indices for current_character are: