Back to home page

Enduro/X

 
 

    


Warning, cross-references for /include/ndrx_ini.h need to be fixed.

0001 /* inih -- simple .INI file parser
0002 
0003 inih is released under the New BSD license (see LICENSE.txt). Go to the project
0004 home page for more info:
0005 
0006 https://github.com/benhoyt/inih
0007 
0008 */
0009 
0010 #ifndef __NDRX_INI_H__
0011 #define __NDRX_INI_H__
0012 
0013 /* Make this header file easier to include in C++ code */
0014 #ifdef __cplusplus
0015 extern "C" {
0016 #endif
0017 
0018 #include <stdio.h>
0019 
0020 /* Typedef for prototype of handler function. */
0021 typedef int (*ini_handler)(void* user, void *user2, void *user3, 
0022        const char* section, const char* name, const char* value);
0023 
0024 /* Typedef for prototype of fgets-style reader function. */
0025 typedef char* (*ini_reader)(char* str, int num, void* stream);
0026 
0027 /* Parse given INI-style file. May have [section]s, name=value pairs
0028    (whitespace stripped), and comments starting with ';' (semicolon). Section
0029    is "" if name=value pair parsed before any section heading. name:value
0030    pairs are also supported as a concession to Python's configparser.
0031 
0032    For each name=value pair parsed, call handler function with given user
0033    pointer as well as section, name, and value (data only valid for duration
0034    of handler call). Handler should return nonzero on success, zero on error.
0035 
0036    Returns 0 on success, line number of first error on parse error (doesn't
0037    stop on first error), -1 on file open error, or -2 on memory allocation
0038    error (only when INI_USE_STACK is zero).
0039 */
0040 int ndrx_ini_parse(const char* filename, ini_handler handler, void* user,
0041         void *user2, void *user3);
0042 
0043 /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
0044    close the file when it's finished -- the caller must do that. */
0045 int ndrx_ini_parse_file(FILE* file, ini_handler handler, void* user,
0046         void *user2, void *user3);
0047 
0048 /* Same as ini_parse(), but takes an ini_reader function pointer instead of
0049    filename. Used for implementing custom or string-based I/O. */
0050 int ndrx_ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
0051                      void* user, void *user2, void *user3);
0052 
0053 /* Nonzero to allow multi-line value parsing, in the style of Python's
0054    configparser. If allowed, ini_parse() will call the handler with the same
0055    name for each subsequent line parsed. */
0056 #ifndef INI_ALLOW_MULTILINE
0057 #define INI_ALLOW_MULTILINE 1
0058 #endif
0059 
0060 /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
0061    the file. See http://code.google.com/p/inih/issues/detail?id=21 */
0062 #ifndef INI_ALLOW_BOM
0063 #define INI_ALLOW_BOM 1
0064 #endif
0065 
0066 #if 0
0067 - no inline comments please...
0068 /* Nonzero to allow inline comments (with valid inline comment characters
0069    specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
0070    Python 3.2+ configparser behaviour. */
0071 #ifndef INI_ALLOW_INLINE_COMMENTS
0072 #define INI_ALLOW_INLINE_COMMENTS 1
0073 #endif
0074 #ifndef INI_INLINE_COMMENT_PREFIXES
0075 #define INI_INLINE_COMMENT_PREFIXES ";"
0076 #endif
0077 #endif
0078 
0079 /* Nonzero to use stack, zero to use heap (malloc/free). */
0080 #ifndef INI_USE_STACK
0081 #define INI_USE_STACK 1
0082 #endif
0083 
0084 /* Stop parsing on first error (default is to keep parsing). */
0085 #ifndef INI_STOP_ON_FIRST_ERROR
0086 #define INI_STOP_ON_FIRST_ERROR 1
0087 #endif
0088 
0089 /* Maximum line length for any line in INI file. */
0090 #ifndef INI_MAX_LINE
0091 #define INI_MAX_LINE 10240
0092 #endif
0093 
0094 #ifdef __cplusplus
0095 }
0096 #endif
0097 
0098 #endif /* __NDRX_INI_H__ */