|
|
|
@ -14,7 +14,6 @@
|
|
|
|
|
|
|
|
|
|
namespace Exiv2 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* inih -- simple .INI file parser
|
|
|
|
|
|
|
|
|
|
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
|
|
|
@ -32,15 +31,15 @@ https://github.com/benhoyt/inih
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Typedef for prototype of handler function. */
|
|
|
|
|
//! @brief typedef for prototype of handler function.
|
|
|
|
|
typedef int (*ini_handler)(void* user, const char* section,
|
|
|
|
|
const char* name, const char* value);
|
|
|
|
|
|
|
|
|
|
/* Typedef for prototype of fgets-style reader function. */
|
|
|
|
|
//! Typedef for prototype of fgets-style reader function.
|
|
|
|
|
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
|
|
|
|
|
|
|
|
|
/* Parse given INI-style file. May have [section]s, name=value pairs
|
|
|
|
|
/*!
|
|
|
|
|
@brief Parse given INI-style file. May have [section]s, name=value pairs
|
|
|
|
|
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
|
|
|
|
is "" if name=value pair parsed before any section heading. name:value
|
|
|
|
|
pairs are also supported as a concession to Python's configparser.
|
|
|
|
@ -49,37 +48,58 @@ typedef char* (*ini_reader)(char* str, int num, void* stream);
|
|
|
|
|
pointer as well as section, name, and value (data only valid for duration
|
|
|
|
|
of handler call). Handler should return nonzero on success, zero on error.
|
|
|
|
|
|
|
|
|
|
Returns 0 on success, line number of first error on parse error (doesn't
|
|
|
|
|
@param filename path to file
|
|
|
|
|
@param handler user defined handler
|
|
|
|
|
@param user void pointer passed to user handler
|
|
|
|
|
|
|
|
|
|
@return 0 on success, line number of first error on parse error (doesn't
|
|
|
|
|
stop on first error), -1 on file open error, or -2 on memory allocation
|
|
|
|
|
error (only when INI_USE_STACK is zero).
|
|
|
|
|
|
|
|
|
|
@return 0 on success
|
|
|
|
|
*/
|
|
|
|
|
int ini_parse(const char* filename, ini_handler handler, void* user);
|
|
|
|
|
|
|
|
|
|
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
|
|
|
|
close the file when it's finished -- the caller must do that. */
|
|
|
|
|
/*! @brief Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
|
|
|
|
close the file when it's finished -- the caller must do that.
|
|
|
|
|
|
|
|
|
|
@param file open "C" file
|
|
|
|
|
@param handler user defined handler
|
|
|
|
|
@param user void pointer passed to user handler
|
|
|
|
|
*/
|
|
|
|
|
int ini_parse_file(FILE* file, ini_handler handler, void* user);
|
|
|
|
|
|
|
|
|
|
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
|
|
|
|
filename. Used for implementing custom or string-based I/O. */
|
|
|
|
|
/*! @brief Same as ini_parse(), but takes an ini_reader function pointer instead of
|
|
|
|
|
filename. Used for implementing custom or string-based I/O.
|
|
|
|
|
@param reader magic
|
|
|
|
|
@param stream more magic
|
|
|
|
|
@param handler user defined handler
|
|
|
|
|
@param user void pointer passed to user handler
|
|
|
|
|
|
|
|
|
|
@return 0 on success
|
|
|
|
|
*/
|
|
|
|
|
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
|
|
|
void* user);
|
|
|
|
|
|
|
|
|
|
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
|
|
|
|
configparser. If allowed, ini_parse() will call the handler with the same
|
|
|
|
|
name for each subsequent line parsed. */
|
|
|
|
|
/*! @brief Nonzero to allow multi-line value parsing, in the style of Python's
|
|
|
|
|
configparser. If allowed, ini_parse() will call the handler with the same
|
|
|
|
|
name for each subsequent line parsed.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef INI_ALLOW_MULTILINE
|
|
|
|
|
#define INI_ALLOW_MULTILINE 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
|
|
|
|
the file. See http://code.google.com/p/inih/issues/detail?id=21 */
|
|
|
|
|
/*! @brief Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
|
|
|
|
the file. See http://code.google.com/p/inih/issues/detail?id=21
|
|
|
|
|
*/
|
|
|
|
|
#ifndef INI_ALLOW_BOM
|
|
|
|
|
#define INI_ALLOW_BOM 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Nonzero to allow inline comments (with valid inline comment characters
|
|
|
|
|
/*! @brief Nonzero to allow inline comments (with valid inline comment characters
|
|
|
|
|
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
|
|
|
|
|
Python 3.2+ configparser behaviour. */
|
|
|
|
|
Python 3.2+ configparser behaviour.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef INI_ALLOW_INLINE_COMMENTS
|
|
|
|
|
#define INI_ALLOW_INLINE_COMMENTS 1
|
|
|
|
|
#endif
|
|
|
|
@ -87,17 +107,17 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
|
|
|
#define INI_INLINE_COMMENT_PREFIXES ";"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Nonzero to use stack, zero to use heap (malloc/free). */
|
|
|
|
|
//! @brief Nonzero to use stack, zero to use heap (malloc/free).
|
|
|
|
|
#ifndef INI_USE_STACK
|
|
|
|
|
#define INI_USE_STACK 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Stop parsing on first error (default is to keep parsing). */
|
|
|
|
|
//! @brief Stop parsing on first error (default is to keep parsing).
|
|
|
|
|
#ifndef INI_STOP_ON_FIRST_ERROR
|
|
|
|
|
#define INI_STOP_ON_FIRST_ERROR 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Maximum line length for any line in INI file. */
|
|
|
|
|
//! @brief Maximum line length for any line in INI file.
|
|
|
|
|
#ifndef INI_MAX_LINE
|
|
|
|
|
#define INI_MAX_LINE 200
|
|
|
|
|
#endif
|
|
|
|
@ -109,43 +129,74 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
|
|
|
#endif /* __INI_H__ */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
|
|
|
|
|
// for simplicity here rather than speed, but it should be pretty decent.)
|
|
|
|
|
/*! @brief Read an INI file into easy-to-access name/value pairs. (Note that I've gone
|
|
|
|
|
for simplicity here rather than speed, but it should be pretty decent.)
|
|
|
|
|
*/
|
|
|
|
|
class EXIV2API INIReader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Construct INIReader and parse given filename. See ini.h for more info
|
|
|
|
|
// about the parsing.
|
|
|
|
|
/*! @brief Construct INIReader and parse given filename. See ini.h for more info
|
|
|
|
|
about the parsing.
|
|
|
|
|
*/
|
|
|
|
|
INIReader(std::string filename);
|
|
|
|
|
|
|
|
|
|
// Return the result of ini_parse(), i.e., 0 on success, line number of
|
|
|
|
|
// first error on parse error, or -1 on file open error.
|
|
|
|
|
/*! @brief Return the result of ini_parse(), i.e., 0 on success, line number of
|
|
|
|
|
first error on parse error, or -1 on file open error.
|
|
|
|
|
*/
|
|
|
|
|
int ParseError();
|
|
|
|
|
|
|
|
|
|
// Get a string value from INI file, returning default_value if not found.
|
|
|
|
|
/*! @brief Get a string value from INI file, returning default_value if not found.
|
|
|
|
|
|
|
|
|
|
@param section name of section
|
|
|
|
|
@param name name of key
|
|
|
|
|
@param default_value default if not found
|
|
|
|
|
|
|
|
|
|
@return value
|
|
|
|
|
*/
|
|
|
|
|
std::string Get(std::string section, std::string name,
|
|
|
|
|
std::string default_value);
|
|
|
|
|
|
|
|
|
|
// Get an integer (long) value from INI file, returning default_value if
|
|
|
|
|
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
|
|
|
|
|
/*! @brief Get an integer (long) value from INI file, returning default_value if
|
|
|
|
|
not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
|
|
|
|
|
|
|
|
|
|
@param section name of section
|
|
|
|
|
@param name name of key
|
|
|
|
|
@param default_value default if not found
|
|
|
|
|
|
|
|
|
|
@return value
|
|
|
|
|
*/
|
|
|
|
|
long GetInteger(std::string section, std::string name, long default_value);
|
|
|
|
|
|
|
|
|
|
// Get a real (floating point double) value from INI file, returning
|
|
|
|
|
// default_value if not found or not a valid floating point value
|
|
|
|
|
// according to strtod().
|
|
|
|
|
/*! @brief Get a real (floating point double) value from INI file, returning
|
|
|
|
|
default_value if not found or not a valid floating point value
|
|
|
|
|
according to strtod().
|
|
|
|
|
|
|
|
|
|
@param section name of section
|
|
|
|
|
@param name name of key
|
|
|
|
|
@param default_value default if not found
|
|
|
|
|
|
|
|
|
|
@return value
|
|
|
|
|
*/
|
|
|
|
|
double GetReal(std::string section, std::string name, double default_value);
|
|
|
|
|
|
|
|
|
|
// Get a boolean value from INI file, returning default_value if not found or if
|
|
|
|
|
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
|
|
|
|
|
// and valid false values are "false", "no", "off", "0" (not case sensitive).
|
|
|
|
|
/*! @brief Get a boolean value from INI file, returning default_value if not found or if
|
|
|
|
|
not a valid true/false value. Valid true values are "true", "yes", "on", "1",
|
|
|
|
|
and valid false values are "false", "no", "off", "0" (not case sensitive).
|
|
|
|
|
|
|
|
|
|
@param section name of section
|
|
|
|
|
@param name name of key
|
|
|
|
|
@param default_value default if not found
|
|
|
|
|
|
|
|
|
|
@return value
|
|
|
|
|
*/
|
|
|
|
|
bool GetBoolean(std::string section, std::string name, bool default_value);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int _error;
|
|
|
|
|
std::map<std::string, std::string> _values;
|
|
|
|
|
static std::string MakeKey(std::string section, std::string name);
|
|
|
|
|
int _error; //!< status
|
|
|
|
|
std::map<std::string, std::string> _values; //!< values from file
|
|
|
|
|
static std::string MakeKey(std::string section, std::string name); //!< return key encoded from section/name
|
|
|
|
|
static int ValueHandler(void* user, const char* section, const char* name,
|
|
|
|
|
const char* value);
|
|
|
|
|
const char* value); //!< value handler
|
|
|
|
|
};
|
|
|
|
|
} // namespace Exiv2
|
|
|
|
|
|
|
|
|
|