2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-09-16 20:19:00 +04:00
|
|
|
|
|
|
|
#ifndef prefread_h__
|
|
|
|
#define prefread_h__
|
|
|
|
|
|
|
|
#include "prefapi.h"
|
|
|
|
|
2012-10-01 06:10:22 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2003-09-16 20:19:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function used to notify consumer of preference name value pairs.
|
|
|
|
* The pref name and value must be copied by the implementor of the callback
|
|
|
|
* if they are needed beyond the scope of the callback function.
|
|
|
|
*
|
|
|
|
* @param closure
|
|
|
|
* user data passed to PREF_InitParseState
|
|
|
|
* @param pref
|
|
|
|
* preference name
|
|
|
|
* @param val
|
|
|
|
* preference value
|
|
|
|
* @param type
|
|
|
|
* preference type (PREF_STRING, PREF_INT, or PREF_BOOL)
|
2003-09-23 21:57:22 +04:00
|
|
|
* @param defPref
|
2011-10-17 18:59:28 +04:00
|
|
|
* preference type (true: default, false: user preference)
|
2015-04-30 10:13:40 +03:00
|
|
|
* @param stickyPref
|
|
|
|
* default preference marked as a "sticky" pref
|
2003-09-16 20:19:00 +04:00
|
|
|
*/
|
|
|
|
typedef void (*PrefReader)(void *closure,
|
|
|
|
const char *pref,
|
|
|
|
PrefValue val,
|
|
|
|
PrefType type,
|
2015-04-30 10:13:40 +03:00
|
|
|
bool defPref,
|
|
|
|
bool stickyPref);
|
2003-09-16 20:19:00 +04:00
|
|
|
|
2016-04-22 22:35:01 +03:00
|
|
|
/**
|
|
|
|
* Report any errors or warnings we encounter during parsing.
|
|
|
|
*/
|
|
|
|
typedef void (*PrefParseErrorReporter)(const char* message, int line, bool error);
|
|
|
|
|
2003-09-16 20:19:00 +04:00
|
|
|
/* structure fields are private */
|
|
|
|
typedef struct PrefParseState {
|
|
|
|
PrefReader reader;
|
2016-04-22 22:35:01 +03:00
|
|
|
PrefParseErrorReporter reporter;
|
2003-09-16 20:19:00 +04:00
|
|
|
void *closure;
|
|
|
|
int state; /* PREF_PARSE_... */
|
|
|
|
int nextstate; /* sometimes used... */
|
|
|
|
const char *smatch; /* string to match */
|
|
|
|
int sindex; /* next char of smatch to check */
|
2005-09-29 22:09:06 +04:00
|
|
|
/* also, counter in \u parsing */
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t utf16[2]; /* parsing UTF16 (\u) escape */
|
2005-09-29 22:09:06 +04:00
|
|
|
int esclen; /* length in esctmp */
|
|
|
|
char esctmp[6]; /* raw escape to put back if err */
|
2003-10-17 02:33:02 +04:00
|
|
|
char quotechar; /* char delimiter for quotations */
|
2003-09-16 20:19:00 +04:00
|
|
|
char *lb; /* line buffer (only allocation) */
|
|
|
|
char *lbcur; /* line buffer cursor */
|
|
|
|
char *lbend; /* line buffer end */
|
|
|
|
char *vb; /* value buffer (ptr into lb) */
|
|
|
|
PrefType vtype; /* PREF_STRING,INT,BOOL */
|
2016-02-22 11:15:00 +03:00
|
|
|
bool fdefault; /* true if (default) pref */
|
2015-04-30 10:13:40 +03:00
|
|
|
bool fstickydefault; /* true if (sticky) pref */
|
2003-09-16 20:19:00 +04:00
|
|
|
} PrefParseState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PREF_InitParseState
|
|
|
|
*
|
|
|
|
* Called to initialize a PrefParseState instance.
|
2016-04-22 22:35:01 +03:00
|
|
|
*
|
2003-09-16 20:19:00 +04:00
|
|
|
* @param ps
|
|
|
|
* PrefParseState instance.
|
|
|
|
* @param reader
|
|
|
|
* PrefReader callback function, which will be called once for each
|
|
|
|
* preference name value pair extracted.
|
2016-04-22 22:35:01 +03:00
|
|
|
* @param reporter
|
|
|
|
* PrefParseErrorReporter callback function, which will be called if we
|
|
|
|
* encounter any errors (stop) or warnings (continue) during parsing.
|
2003-09-16 20:19:00 +04:00
|
|
|
* @param closure
|
|
|
|
* PrefReader closure.
|
|
|
|
*/
|
2016-04-22 22:35:01 +03:00
|
|
|
void PREF_InitParseState(PrefParseState *ps, PrefReader reader,
|
|
|
|
PrefParseErrorReporter reporter, void *closure);
|
2003-09-16 20:19:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PREF_FinalizeParseState
|
|
|
|
*
|
|
|
|
* Called to release any memory in use by the PrefParseState instance.
|
|
|
|
*
|
|
|
|
* @param ps
|
|
|
|
* PrefParseState instance.
|
|
|
|
*/
|
|
|
|
void PREF_FinalizeParseState(PrefParseState *ps);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PREF_ParseBuf
|
|
|
|
*
|
|
|
|
* Called to parse a buffer containing some portion of a preference file. This
|
|
|
|
* function may be called repeatedly as new data is made available. The
|
|
|
|
* PrefReader callback function passed PREF_InitParseState will be called as
|
|
|
|
* preference name value pairs are extracted from the data.
|
|
|
|
*
|
|
|
|
* @param ps
|
|
|
|
* PrefParseState instance. Must have been initialized.
|
|
|
|
* @param buf
|
|
|
|
* Raw buffer containing data to be parsed.
|
|
|
|
* @param bufLen
|
|
|
|
* Length of buffer.
|
|
|
|
*
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return false if buffer contains malformed content.
|
2003-09-16 20:19:00 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen);
|
2003-09-16 20:19:00 +04:00
|
|
|
|
2012-10-01 06:10:22 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2003-09-16 20:19:00 +04:00
|
|
|
#endif /* prefread_h__ */
|