michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef prefread_h__ michael@0: #define prefread_h__ michael@0: michael@0: #include "prefapi.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /** michael@0: * Callback function used to notify consumer of preference name value pairs. michael@0: * The pref name and value must be copied by the implementor of the callback michael@0: * if they are needed beyond the scope of the callback function. michael@0: * michael@0: * @param closure michael@0: * user data passed to PREF_InitParseState michael@0: * @param pref michael@0: * preference name michael@0: * @param val michael@0: * preference value michael@0: * @param type michael@0: * preference type (PREF_STRING, PREF_INT, or PREF_BOOL) michael@0: * @param defPref michael@0: * preference type (true: default, false: user preference) michael@0: */ michael@0: typedef void (*PrefReader)(void *closure, michael@0: const char *pref, michael@0: PrefValue val, michael@0: PrefType type, michael@0: bool defPref); michael@0: michael@0: /* structure fields are private */ michael@0: typedef struct PrefParseState { michael@0: PrefReader reader; michael@0: void *closure; michael@0: int state; /* PREF_PARSE_... */ michael@0: int nextstate; /* sometimes used... */ michael@0: const char *smatch; /* string to match */ michael@0: int sindex; /* next char of smatch to check */ michael@0: /* also, counter in \u parsing */ michael@0: char16_t utf16[2]; /* parsing UTF16 (\u) escape */ michael@0: int esclen; /* length in esctmp */ michael@0: char esctmp[6]; /* raw escape to put back if err */ michael@0: char quotechar; /* char delimiter for quotations */ michael@0: char *lb; /* line buffer (only allocation) */ michael@0: char *lbcur; /* line buffer cursor */ michael@0: char *lbend; /* line buffer end */ michael@0: char *vb; /* value buffer (ptr into lb) */ michael@0: PrefType vtype; /* PREF_STRING,INT,BOOL */ michael@0: bool fdefault; /* true if (default) pref */ michael@0: } PrefParseState; michael@0: michael@0: /** michael@0: * PREF_InitParseState michael@0: * michael@0: * Called to initialize a PrefParseState instance. michael@0: * michael@0: * @param ps michael@0: * PrefParseState instance. michael@0: * @param reader michael@0: * PrefReader callback function, which will be called once for each michael@0: * preference name value pair extracted. michael@0: * @param closure michael@0: * PrefReader closure. michael@0: */ michael@0: void PREF_InitParseState(PrefParseState *ps, PrefReader reader, void *closure); michael@0: michael@0: /** michael@0: * PREF_FinalizeParseState michael@0: * michael@0: * Called to release any memory in use by the PrefParseState instance. michael@0: * michael@0: * @param ps michael@0: * PrefParseState instance. michael@0: */ michael@0: void PREF_FinalizeParseState(PrefParseState *ps); michael@0: michael@0: /** michael@0: * PREF_ParseBuf michael@0: * michael@0: * Called to parse a buffer containing some portion of a preference file. This michael@0: * function may be called repeatedly as new data is made available. The michael@0: * PrefReader callback function passed PREF_InitParseState will be called as michael@0: * preference name value pairs are extracted from the data. michael@0: * michael@0: * @param ps michael@0: * PrefParseState instance. Must have been initialized. michael@0: * @param buf michael@0: * Raw buffer containing data to be parsed. michael@0: * @param bufLen michael@0: * Length of buffer. michael@0: * michael@0: * @return false if buffer contains malformed content. michael@0: */ michael@0: bool PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: #endif /* prefread_h__ */