MCPcopy Create free account
hub / github.com/Tencent/phxsql / ini_parse_stream

Function ini_parse_stream

phxcomm/configparser/inih-master/ini.cpp:68–164  ·  view source on GitHub ↗

See documentation in header file. */

Source from the content-addressed store, hash-verified

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

Callers 2

ini_parse_fileFunction · 0.85
mainFunction · 0.85

Calls 5

lskipFunction · 0.85
rstripFunction · 0.85
find_chars_or_commentFunction · 0.85
strncpy0Function · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected