Prusa MINI Firmware overview
ini.h
Go to the documentation of this file.
1 /* inih -- simple .INI file parser
2 
3 SPDX-License-Identifier: BSD-3-Clause
4 
5 Copyright (C) 2009-2019, 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 /* Typedef for prototype of handler function. */
30 #if INI_HANDLER_LINENO
31 typedef int (*ini_handler)(void* user, const char* section,
32  const char* name, const char* value,
33  int lineno);
34 #else
35 typedef int (*ini_handler)(void* user, const char* section,
36  const char* name, const char* value);
37 #endif
38 
39 /* Typedef for prototype of fgets-style reader function. */
40 typedef char* (*ini_reader)(char* str, int num, void* stream);
41 
42 /* Parse given INI-style file. May have [section]s, name=value pairs
43  (whitespace stripped), and comments starting with ';' (semicolon). Section
44  is "" if name=value pair parsed before any section heading. name:value
45  pairs are also supported as a concession to Python's configparser.
46 
47  For each name=value pair parsed, call handler function with given user
48  pointer as well as section, name, and value (data only valid for duration
49  of handler call). Handler should return nonzero on success, zero on error.
50 
51  Returns 0 on success, line number of first error on parse error (doesn't
52  stop on first error), -1 on file open error, or -2 on memory allocation
53  error (only when INI_USE_STACK is zero).
54 */
55 int ini_parse(const char* filename, ini_handler handler, void* user);
56 
57 /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
58  close the file when it's finished -- the caller must do that. */
59 int ini_parse_file(FILE* file, ini_handler handler, void* user);
60 
61 /* Same as ini_parse(), but takes an ini_reader function pointer instead of
62  filename. Used for implementing custom or string-based I/O (see also
63  ini_parse_string). */
64 int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
65  void* user);
66 
67 /* Same as ini_parse(), but takes a zero-terminated string with the INI data
68 instead of a file. Useful for parsing INI data from a network socket or
69 already in memory. */
70 int ini_parse_string(const char* string, ini_handler handler, void* user);
71 
72 /* Nonzero to allow multi-line value parsing, in the style of Python's
73  configparser. If allowed, ini_parse() will call the handler with the same
74  name for each subsequent line parsed. */
75 #ifndef INI_ALLOW_MULTILINE
76 #define INI_ALLOW_MULTILINE 1
77 #endif
78 
79 /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
80  the file. See https://github.com/benhoyt/inih/issues/21 */
81 #ifndef INI_ALLOW_BOM
82 #define INI_ALLOW_BOM 1
83 #endif
84 
85 /* Chars that begin a start-of-line comment. Per Python configparser, allow
86  both ; and # comments at the start of a line by default. */
87 #ifndef INI_START_COMMENT_PREFIXES
88 #define INI_START_COMMENT_PREFIXES ";#"
89 #endif
90 
91 /* Nonzero to allow inline comments (with valid inline comment characters
92  specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
93  Python 3.2+ configparser behaviour. */
94 #ifndef INI_ALLOW_INLINE_COMMENTS
95 #define INI_ALLOW_INLINE_COMMENTS 1
96 #endif
97 #ifndef INI_INLINE_COMMENT_PREFIXES
98 #define INI_INLINE_COMMENT_PREFIXES ";"
99 #endif
100 
101 /* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
102 #ifndef INI_USE_STACK
103 #define INI_USE_STACK 1
104 #endif
105 
106 /* Maximum line length for any line in INI file (stack or heap). Note that
107  this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
108 #ifndef INI_MAX_LINE
109 #define INI_MAX_LINE 200
110 #endif
111 
112 /* Nonzero to allow heap line buffer to grow via realloc(), zero for a
113  fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
114  zero. */
115 #ifndef INI_ALLOW_REALLOC
116 #define INI_ALLOW_REALLOC 0
117 #endif
118 
119 /* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
120  is zero. */
121 #ifndef INI_INITIAL_ALLOC
122 #define INI_INITIAL_ALLOC 200
123 #endif
124 
125 /* Stop parsing on first error (default is to keep parsing). */
126 #ifndef INI_STOP_ON_FIRST_ERROR
127 #define INI_STOP_ON_FIRST_ERROR 0
128 #endif
129 
130 /* Nonzero to call the handler at the start of each new section (with
131  name and value NULL). Default is to only call the handler on
132  each name=value pair. */
133 #ifndef INI_CALL_HANDLER_ON_NEW_SECTION
134 #define INI_CALL_HANDLER_ON_NEW_SECTION 0
135 #endif
136 
137 /* Nonzero to allow a name without a value (no '=' or ':' on the line) and
138  call the handler with value NULL in this case. Default is to treat
139  no-value lines as an error. */
140 #ifndef INI_ALLOW_NO_VALUE
141 #define INI_ALLOW_NO_VALUE 0
142 #endif
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* __INI_H__ */
HANDLER
#define HANDLER(u, s, n, v)
ini_reader
char *(* ini_reader)(char *str, int num, void *stream)
Definition: ini.h:40
INI_INITIAL_ALLOC
#define INI_INITIAL_ALLOC
Definition: ini.h:122
auto_build.error
bool error
Definition: auto_build.py:637
ini_parse_string
int ini_parse_string(const char *string, ini_handler handler, void *user)
Definition: ini.c:277
ini_parse_string_ctx::num_left
size_t num_left
Definition: ini.c:34
g29_auto.start
start
Definition: g29_auto.py:150
ini_parse
int ini_parse(const char *filename, ini_handler handler, void *user)
Definition: ini.c:236
INI_MAX_LINE
#define INI_MAX_LINE
Definition: ini.h:109
lskip
static char * lskip(const char *s)
Definition: ini.c:47
NULL
#define NULL
Definition: usbd_def.h:53
ini_parse_string
int ini_parse_string(const char *string, ini_handler handler, void *user)
Definition: ini.c:277
ini_parse
int ini_parse(const char *filename, ini_handler handler, void *user)
Definition: ini.c:236
createSpeedLookupTable.end
end
Definition: createSpeedLookupTable.py:33
ini_parse_string_ctx
Definition: ini.c:32
ini.h
ini_parse_stream
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user)
Definition: ini.c:83
ini_parse_file
int ini_parse_file(FILE *file, ini_handler handler, void *user)
Definition: ini.c:230
find_chars_or_comment
static char * find_chars_or_comment(const char *s, const char *chars)
Definition: ini.c:57
INI_START_COMMENT_PREFIXES
#define INI_START_COMMENT_PREFIXES
Definition: ini.h:88
ini_reader_string
static char * ini_reader_string(char *str, int num, void *stream)
Definition: ini.c:251
INI_INLINE_COMMENT_PREFIXES
#define INI_INLINE_COMMENT_PREFIXES
Definition: ini.h:98
ini_parse_stream
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user)
Definition: ini.c:83
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
ini_parse_string_ctx::ptr
const char * ptr
Definition: ini.c:33
strncpy0
static char * strncpy0(char *dest, const char *src, size_t size)
Definition: ini.c:75
rstrip
static char * rstrip(char *s)
Definition: ini.c:38
MAX_NAME
#define MAX_NAME
Definition: ini.c:29
ini_handler
int(* ini_handler)(void *user, const char *section, const char *name, const char *value)
Definition: ini.h:35
MAX_SECTION
#define MAX_SECTION
Definition: ini.c:28
ini_parse_file
int ini_parse_file(FILE *file, ini_handler handler, void *user)
Definition: ini.c:230
size
static png_bytep size_t size
Definition: pngwrite.c:2170