Blame lib/inih/ini.h

Packit Service 991b93
/* inih -- simple .INI file parser
Packit Service 991b93
Packit Service 991b93
inih is released under the New BSD license (see LICENSE.txt). Go to the project
Packit Service 991b93
home page for more info:
Packit Service 991b93
Packit Service 991b93
https://github.com/benhoyt/inih
Packit Service 991b93
Packit Service 991b93
*/
Packit Service 991b93
Packit Service 991b93
#ifndef __INI_H__
Packit Service 991b93
#define __INI_H__
Packit Service 991b93
Packit Service 991b93
/* Make this header file easier to include in C++ code */
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
extern "C" {
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#include <stdio.h>
Packit Service 991b93
#include <config.h>
Packit Service 991b93
Packit Service 991b93
/* Nonzero if ini_handler callback should accept lineno parameter. */
Packit Service 991b93
#ifndef INI_HANDLER_LINENO
Packit Service 991b93
#define INI_HANDLER_LINENO 0
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Typedef for prototype of handler function. */
Packit Service 991b93
#if INI_HANDLER_LINENO
Packit Service 991b93
typedef int (*ini_handler)(void* user, const char* section,
Packit Service 991b93
                           const char* name, const char* value,
Packit Service 991b93
                           int lineno);
Packit Service 991b93
#else
Packit Service 991b93
typedef int (*ini_handler)(void* user, const char* section,
Packit Service 991b93
                           const char* name, const char* value);
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Typedef for prototype of fgets-style reader function. */
Packit Service 991b93
typedef char* (*ini_reader)(char* str, int num, void* stream);
Packit Service 991b93
Packit Service 991b93
/* Parse given INI-style file. May have [section]s, name=value pairs
Packit Service 991b93
   (whitespace stripped), and comments starting with ';' (semicolon). Section
Packit Service 991b93
   is "" if name=value pair parsed before any section heading. name:value
Packit Service 991b93
   pairs are also supported as a concession to Python's configparser.
Packit Service 991b93
Packit Service 991b93
   For each name=value pair parsed, call handler function with given user
Packit Service 991b93
   pointer as well as section, name, and value (data only valid for duration
Packit Service 991b93
   of handler call). Handler should return nonzero on success, zero on error.
Packit Service 991b93
Packit Service 991b93
   Returns 0 on success, line number of first error on parse error (doesn't
Packit Service 991b93
   stop on first error), -1 on file open error, or -2 on memory allocation
Packit Service 991b93
   error (only when INI_USE_STACK is zero).
Packit Service 991b93
*/
Packit Service 991b93
int ini_parse(const char* filename, ini_handler handler, void* user);
Packit Service 991b93
Packit Service 991b93
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
Packit Service 991b93
   close the file when it's finished -- the caller must do that. */
Packit Service 991b93
int ini_parse_file(FILE* file, ini_handler handler, void* user);
Packit Service 991b93
Packit Service 991b93
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
Packit Service 991b93
   filename. Used for implementing custom or string-based I/O (see also
Packit Service 991b93
   ini_parse_string). */
Packit Service 991b93
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
Packit Service 991b93
                     void* user);
Packit Service 991b93
Packit Service 991b93
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
Packit Service 991b93
instead of a file. Useful for parsing INI data from a network socket or
Packit Service 991b93
already in memory. */
Packit Service 991b93
int ini_parse_string(const char* string, ini_handler handler, void* user);
Packit Service 991b93
Packit Service 991b93
/* Nonzero to allow multi-line value parsing, in the style of Python's
Packit Service 991b93
   configparser. If allowed, ini_parse() will call the handler with the same
Packit Service 991b93
   name for each subsequent line parsed. */
Packit Service 991b93
#ifndef INI_ALLOW_MULTILINE
Packit Service 991b93
#define INI_ALLOW_MULTILINE 1
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
Packit Service 991b93
   the file. See https://github.com/benhoyt/inih/issues/21 */
Packit Service 991b93
#ifndef INI_ALLOW_BOM
Packit Service 991b93
#define INI_ALLOW_BOM 1
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Chars that begin a start-of-line comment. Per Python configparser, allow
Packit Service 991b93
   both ; and # comments at the start of a line by default. */
Packit Service 991b93
#ifndef INI_START_COMMENT_PREFIXES
Packit Service 991b93
#define INI_START_COMMENT_PREFIXES ";#"
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Nonzero to allow inline comments (with valid inline comment characters
Packit Service 991b93
   specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
Packit Service 991b93
   Python 3.2+ configparser behaviour. */
Packit Service 991b93
#ifndef INI_ALLOW_INLINE_COMMENTS
Packit Service 991b93
#define INI_ALLOW_INLINE_COMMENTS 1
Packit Service 991b93
#endif
Packit Service 991b93
#ifndef INI_INLINE_COMMENT_PREFIXES
Packit Service 991b93
#define INI_INLINE_COMMENT_PREFIXES ";"
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
Packit Service 991b93
#ifndef INI_USE_STACK
Packit Service 991b93
#define INI_USE_STACK 1
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Maximum line length for any line in INI file (stack or heap). Note that
Packit Service 991b93
   this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
Packit Service 991b93
#ifndef INI_MAX_LINE
Packit Service 991b93
#define INI_MAX_LINE 200
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
Packit Service 991b93
   fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
Packit Service 991b93
   zero. */
Packit Service 991b93
#ifndef INI_ALLOW_REALLOC
Packit Service 991b93
#define INI_ALLOW_REALLOC 0
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
Packit Service 991b93
   is zero. */
Packit Service 991b93
#ifndef INI_INITIAL_ALLOC
Packit Service 991b93
#define INI_INITIAL_ALLOC 200
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
/* Stop parsing on first error (default is to keep parsing). */
Packit Service 991b93
#ifndef INI_STOP_ON_FIRST_ERROR
Packit Service 991b93
#define INI_STOP_ON_FIRST_ERROR 0
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
}
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#endif /* __INI_H__ */