MCPcopy Create free account
hub / github.com/AHXR/ghost / ini_parse_stream

Function ini_parse_stream

_src/server/ini.cpp:79–187  ·  view source on GitHub ↗

See documentation in header file. */

Source from the content-addressed store, hash-verified

77
78/* See documentation in header file. */
79int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
80 void* user)
81{
82 /* Uses a fair bit of stack (use heap instead if you need to) */
83#if INI_USE_STACK
84 char line[INI_MAX_LINE];
85#else
86 char* line;
87#endif
88 char section[MAX_SECTION] = "";
89 char prev_name[MAX_NAME] = "";
90
91 char* start;
92 char* end;
93 char* name;
94 char* value;
95 int lineno = 0;
96 int error = 0;
97
98#if !INI_USE_STACK
99 line = (char*)malloc(INI_MAX_LINE);
100 if (!line) {
101 return -2;
102 }
103#endif
104
105#if INI_HANDLER_LINENO
106#define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
107#else
108#define HANDLER(u, s, n, v) handler(u, s, n, v)
109#endif
110
111 /* Scan through stream line by line */
112 while (reader(line, INI_MAX_LINE, stream) != NULL) {
113 lineno++;
114
115 start = line;
116#if INI_ALLOW_BOM
117 if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
118 (unsigned char)start[1] == 0xBB &&
119 (unsigned char)start[2] == 0xBF) {
120 start += 3;
121 }
122#endif
123 start = lskip(rstrip(start));
124
125 if (*start == ';' || *start == '#') {
126 /* Per Python configparser, allow both ; and # comments at the
127 start of a line */
128 }
129#if INI_ALLOW_MULTILINE
130 else if (*prev_name && *start && start > line) {
131 /* Non-blank line with leading whitespace, treat as continuation
132 of previous name's value (as per Python configparser). */
133 if (!HANDLER(user, section, prev_name, start) && !error)
134 error = lineno;
135 }
136#endif

Callers 2

ini_parse_fileFunction · 0.85
ini_parse_stringFunction · 0.85

Calls 4

lskipFunction · 0.85
rstripFunction · 0.85
find_chars_or_commentFunction · 0.85
strncpy0Function · 0.85

Tested by

no test coverage detected