114canfigger_free_current_key_node_advance(
struct Canfigger **node)
118 if ((*node)->attributes)
120 if ((*node)->attributes->current)
122 free((*node)->attributes->current);
123 (*node)->attributes->current = NULL;
126 if ((*node)->attributes->str)
128 free((*node)->attributes->str);
129 (*node)->attributes->str = NULL;
132 free((*node)->attributes);
133 (*node)->attributes = NULL;
138 free((*node)->value);
139 (*node)->value = NULL;
145 struct Canfigger *temp_node = (*node)->next;
293 fread(buffer, 1, file_size, fp);
332 struct Canfigger *root = NULL, *cur_node = NULL;
334 char *buffer = read_entire_file(file);
338 char file_contents[strlen(buffer) + 1];
339 memcpy(file_contents, buffer,
sizeof file_contents);
343 line.start = file_contents;
344 line.end = strchr(line.start,
'\n');
350 line.len = line.end - line.start;
351 char tmp_line[line.len + 1];
352 memcpy(tmp_line, line.start, line.len);
353 tmp_line[line.len] =
'\0';
358 line.start = line.end + 1;
359 line.end = strchr(line.start,
'\n');
362 char *line_ptr = tmp_line;
363 truncate_whitespace(line_ptr);
365 while (isspace(*line_ptr))
366 line_ptr = erase_lead_char(*line_ptr, line_ptr);
368 if (*line_ptr ==
'\0' || *line_ptr ==
'#' || *line_ptr ==
'[')
371 node_complete =
false;
372 add_key_node(&root, &cur_node);
377 cur_node->key = NULL;
378 line_ptr = grab_str_segment(line_ptr, &cur_node->key,
'=');
381 free_incomplete_node(&cur_node);
386 cur_node->value = NULL;
390 line_ptr = grab_str_segment(line_ptr, &cur_node->value, delimiter);
391 if (!cur_node->value)
393 free_incomplete_node(&cur_node);
401 cur_node->attributes = malloc_wrap(
sizeof(
struct attributes));
402 if (!cur_node->attributes)
404 free_incomplete_node(&cur_node);
408 struct attributes *attr_ptr = cur_node->attributes;
409 attr_ptr->current = NULL;
411 attr_ptr->str = strdup_wrap(line_ptr);
414 free_incomplete_node(&cur_node);
418 attr_ptr->iter_ptr = attr_ptr->str;
422 char *delimiter_ptr = strchr(attr_ptr->iter_ptr, delimiter);
423 while (delimiter_ptr)
425 *delimiter_ptr =
'\n';
426 delimiter_ptr = strchr(delimiter_ptr, delimiter);
430 cur_node->attributes = NULL;
432 cur_node->next = NULL;
433 node_complete =
true;