gPass

gPass Git Source Tree

Root/cli/ini.h

1/* inih -- simple .INI file parser
2
3inih is released under the New BSD license (see LICENSE.txt). Go to the project
4home page for more info:
5
6https://github.com/benhoyt/inih
7
8*/
9
10#ifndef __INI_H__
11#define __INI_H__
12
13/* Make this header file easier to include in C++ code */
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stdio.h>
19
20/* Typedef for prototype of handler function. */
21typedef int (*ini_handler)(void* user, const char* section,
22 const char* name, const char* value);
23
24/* Typedef for prototype of fgets-style reader function. */
25typedef char* (*ini_reader)(char* str, int num, void* stream);
26
27/* Parse given INI-style file. May have [section]s, name=value pairs
28 (whitespace stripped), and comments starting with ';' (semicolon). Section
29 is "" if name=value pair parsed before any section heading. name:value
30 pairs are also supported as a concession to Python's configparser.
31
32 For each name=value pair parsed, call handler function with given user
33 pointer as well as section, name, and value (data only valid for duration
34 of handler call). Handler should return nonzero on success, zero on error.
35
36 Returns 0 on success, line number of first error on parse error (doesn't
37 stop on first error), -1 on file open error, or -2 on memory allocation
38 error (only when INI_USE_STACK is zero).
39*/
40int ini_parse(const char* filename, ini_handler handler, void* user);
41
42/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
43 close the file when it's finished -- the caller must do that. */
44int ini_parse_file(FILE* file, ini_handler handler, void* user);
45
46/* Same as ini_parse(), but takes an ini_reader function pointer instead of
47 filename. Used for implementing custom or string-based I/O. */
48int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
49 void* user);
50
51/* Nonzero to allow multi-line value parsing, in the style of Python's
52 configparser. If allowed, ini_parse() will call the handler with the same
53 name for each subsequent line parsed. */
54#ifndef INI_ALLOW_MULTILINE
55#define INI_ALLOW_MULTILINE 1
56#endif
57
58/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
59 the file. See http://code.google.com/p/inih/issues/detail?id=21 */
60#ifndef INI_ALLOW_BOM
61#define INI_ALLOW_BOM 1
62#endif
63
64/* Nonzero to allow inline comments (with valid inline comment characters
65 specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
66 Python 3.2+ configparser behaviour. */
67#ifndef INI_ALLOW_INLINE_COMMENTS
68#define INI_ALLOW_INLINE_COMMENTS 1
69#endif
70#ifndef INI_INLINE_COMMENT_PREFIXES
71#define INI_INLINE_COMMENT_PREFIXES ";"
72#endif
73
74/* Nonzero to use stack, zero to use heap (malloc/free). */
75#ifndef INI_USE_STACK
76#define INI_USE_STACK 1
77#endif
78
79/* Stop parsing on first error (default is to keep parsing). */
80#ifndef INI_STOP_ON_FIRST_ERROR
81#define INI_STOP_ON_FIRST_ERROR 0
82#endif
83
84/* Maximum line length for any line in INI file. */
85#ifndef INI_MAX_LINE
86#define INI_MAX_LINE 200
87#endif
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif /* __INI_H__ */

Archive Download this file