Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/inih/include/ini.h
2 views
1
/* inih -- simple .INI file parser
2
3
SPDX-License-Identifier: BSD-3-Clause
4
5
Copyright (C) 2009-2025, Ben Hoyt
6
7
inih is released under the New BSD license (see LICENSE.txt). Go to the project
8
home page for more info:
9
10
https://github.com/benhoyt/inih
11
12
*/
13
14
#ifndef INI_H
15
#define INI_H
16
17
/* Make this header file easier to include in C++ code */
18
#ifdef __cplusplus
19
extern "C" {
20
#endif
21
22
#include <stdio.h>
23
24
/* Nonzero if ini_handler callback should accept lineno parameter. */
25
#ifndef INI_HANDLER_LINENO
26
#define INI_HANDLER_LINENO 0
27
#endif
28
29
/* Visibility symbols, required for Windows DLLs */
30
#ifndef INI_API
31
#if defined _WIN32 || defined __CYGWIN__
32
# ifdef INI_SHARED_LIB
33
# ifdef INI_SHARED_LIB_BUILDING
34
# define INI_API __declspec(dllexport)
35
# else
36
# define INI_API __declspec(dllimport)
37
# endif
38
# else
39
# define INI_API
40
# endif
41
#else
42
# if defined(__GNUC__) && __GNUC__ >= 4
43
# define INI_API __attribute__ ((visibility ("default")))
44
# else
45
# define INI_API
46
# endif
47
#endif
48
#endif
49
50
/* Typedef for prototype of handler function.
51
52
Note that even though the value parameter has type "const char*", the user
53
may cast to "char*" and modify its content, as the value is not used again
54
after the call to ini_handler. This is not true of section and name --
55
those must not be modified.
56
*/
57
#if INI_HANDLER_LINENO
58
typedef int (*ini_handler)(void* user, const char* section,
59
const char* name, const char* value,
60
int lineno);
61
#else
62
typedef int (*ini_handler)(void* user, const char* section,
63
const char* name, const char* value);
64
#endif
65
66
/* Typedef for prototype of fgets-style reader function. */
67
typedef char* (*ini_reader)(char* str, int num, void* stream);
68
69
/* Parse given INI-style file. May have [section]s, name=value pairs
70
(whitespace stripped), and comments starting with ';' (semicolon). Section
71
is "" if name=value pair parsed before any section heading. name:value
72
pairs are also supported as a concession to Python's configparser.
73
74
For each name=value pair parsed, call handler function with given user
75
pointer as well as section, name, and value (data only valid for duration
76
of handler call). Handler should return nonzero on success, zero on error.
77
78
Returns 0 on success, line number of first error on parse error (doesn't
79
stop on first error), -1 on file open error, or -2 on memory allocation
80
error (only when INI_USE_STACK is zero).
81
*/
82
INI_API int ini_parse(const char* filename, ini_handler handler, void* user);
83
84
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
85
close the file when it's finished -- the caller must do that. */
86
INI_API int ini_parse_file(FILE* file, ini_handler handler, void* user);
87
88
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
89
filename. Used for implementing custom or string-based I/O (see also
90
ini_parse_string). */
91
INI_API int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
92
void* user);
93
94
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
95
instead of a file. Useful for parsing INI data from a network socket or
96
which is already in memory. */
97
INI_API int ini_parse_string(const char* string, ini_handler handler, void* user);
98
99
/* Same as ini_parse_string(), but takes a string and its length, avoiding
100
strlen(). Useful for parsing INI data from a network socket or which is
101
already in memory, or interfacing with C++ std::string_view. */
102
INI_API int ini_parse_string_length(const char* string, size_t length, ini_handler handler, void* user);
103
104
/* Nonzero to allow multi-line value parsing, in the style of Python's
105
configparser. If allowed, ini_parse() will call the handler with the same
106
name for each subsequent line parsed. */
107
#ifndef INI_ALLOW_MULTILINE
108
#define INI_ALLOW_MULTILINE 1
109
#endif
110
111
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
112
the file. See https://github.com/benhoyt/inih/issues/21 */
113
#ifndef INI_ALLOW_BOM
114
#define INI_ALLOW_BOM 1
115
#endif
116
117
/* Chars that begin a start-of-line comment. Per Python configparser, allow
118
both ; and # comments at the start of a line by default. */
119
#ifndef INI_START_COMMENT_PREFIXES
120
#define INI_START_COMMENT_PREFIXES ";#"
121
#endif
122
123
/* Nonzero to allow inline comments (with valid inline comment characters
124
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
125
Python 3.2+ configparser behaviour. */
126
#ifndef INI_ALLOW_INLINE_COMMENTS
127
#define INI_ALLOW_INLINE_COMMENTS 1
128
#endif
129
#ifndef INI_INLINE_COMMENT_PREFIXES
130
#define INI_INLINE_COMMENT_PREFIXES ";"
131
#endif
132
133
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
134
#ifndef INI_USE_STACK
135
#define INI_USE_STACK 1
136
#endif
137
138
/* Maximum line length for any line in INI file (stack or heap). Note that
139
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
140
#ifndef INI_MAX_LINE
141
#define INI_MAX_LINE 200
142
#endif
143
144
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
145
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
146
zero. */
147
#ifndef INI_ALLOW_REALLOC
148
#define INI_ALLOW_REALLOC 0
149
#endif
150
151
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
152
is zero. */
153
#ifndef INI_INITIAL_ALLOC
154
#define INI_INITIAL_ALLOC 200
155
#endif
156
157
/* Stop parsing on first error (default is to keep parsing). */
158
#ifndef INI_STOP_ON_FIRST_ERROR
159
#define INI_STOP_ON_FIRST_ERROR 0
160
#endif
161
162
/* Nonzero to call the handler at the start of each new section (with
163
name and value NULL). Default is to only call the handler on
164
each name=value pair. */
165
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
166
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
167
#endif
168
169
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
170
call the handler with value NULL in this case. Default is to treat
171
no-value lines as an error. */
172
#ifndef INI_ALLOW_NO_VALUE
173
#define INI_ALLOW_NO_VALUE 0
174
#endif
175
176
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
177
allocation functions (INI_USE_STACK must also be 0). These functions must
178
have the same signatures as malloc/free/realloc and behave in a similar
179
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
180
#ifndef INI_CUSTOM_ALLOCATOR
181
#define INI_CUSTOM_ALLOCATOR 0
182
#endif
183
184
185
#ifdef __cplusplus
186
}
187
#endif
188
189
#endif /* INI_H */
190
191