MCPcopy Create free account
hub / github.com/apache/nuttx / parse_file

Function parse_file

tools/cfgparser.c:179–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177 ****************************************************************************/
178
179void parse_file(FILE *stream, struct variable_s **list)
180{
181 struct variable_s *curr;
182 struct variable_s *prev;
183 struct variable_s *next;
184 char *varname;
185 char *varval;
186 char *ptr;
187
188 /* Loop until the entire file has been parsed. */
189
190 do
191 {
192 /* Read the next line from the file */
193
194 ptr = read_line(stream);
195 if (ptr)
196 {
197 /* Parse the line into a variable and a value field */
198
199 parse_line(ptr, &varname, &varval);
200
201 /* If the variable has no value (or the special value 'n'), then
202 * ignore it.
203 */
204
205 if (!varval || strcmp(varval, "n") == 0)
206 {
207 continue;
208 }
209
210 /* Make sure that a variable name was found. */
211
212 if (varname)
213 {
214 int varlen = strlen(varname) + 1;
215 int vallen = 0;
216
217 /* Get the size of the value, including the NUL terminating
218 * character.
219 */
220
221 if (varval)
222 {
223 vallen = strlen(varval) + 1;
224 }
225
226 /* Allocate memory to hold the struct variable_s with the
227 * variable name and the value.
228 */
229
230 curr = malloc(sizeof(struct variable_s) +
231 varlen + vallen - 1);
232 if (curr)
233 {
234 /* Add the variable to the list */
235
236 curr->var = &curr->storage[0];

Callers 3

mainFunction · 0.85
read_configfileFunction · 0.85
read_versionfileFunction · 0.85

Calls 6

read_lineFunction · 0.70
parse_lineFunction · 0.70
strcmpFunction · 0.50
strlenFunction · 0.50
mallocFunction · 0.50
strcpyFunction · 0.50

Tested by

no test coverage detected