-
Notifications
You must be signed in to change notification settings - Fork 1
/
canfigger.h
89 lines (82 loc) · 2.94 KB
/
canfigger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @file canfigger.h
* @brief Header file for the Canfigger configuration parser.
*
* Canfigger is a lightweight C language library designed to parse configuration
* files. It provides functionality to read them and represent their contents as
* a linked list of key-value pairs, along with associated attributes for each
* pair.
*
* Part of canfigger (https://github.com/andy5995/canfigger).
*
* Copyright (C) 2021-2024 Andy Alt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
/**
* \example example.c
*/
/**
* @struct attributes
* @brief Structure to hold attribute details of a configuration key.
*
* @var attributes::str Original string containing all attributes.
* @var attributes::current Pointer to the current attribute being processed.
* @var attributes::iter_ptr Pointer used for iterating through attributes.
*/
struct attributes
{
char *str;
char *current;
char *iter_ptr;
};
/**
* @struct Canfigger
* @brief Structure to represent a key-value pair with attributes in the configuration.
*
* @var Canfigger::key The key in a key-value pair.
* @var Canfigger::value The value associated with the key.
* @var Canfigger::attributes pointer to an attributes struct associated with the key.
* @var Canfigger::next Pointer to the next node in the list.
*/
struct Canfigger
{
char *key;
char *value;
struct attributes *attributes;
struct Canfigger *next;
};
/**
* @brief Parses a configuration file and creates a linked list of key-value pairs.
*
* @param file Path to the configuration file to parse.
* @param delimiter The character used to delimit the attributes following 'value'.
* @return Pointer to the head of the linked list of configuration entries.
*/
struct Canfigger *canfigger_parse_file(const char *file, const int delimiter);
/**
* @brief Frees the current key node and advances to the next node in the list.
*
* @param list Double pointer to the current node in the linked list.
*/
void canfigger_free_current_key_node_advance(struct Canfigger **list);
/**
* @brief Frees the current attribute string and advances to the next attribute.
*
* @param attributes Pointer to the attributes structure of the current node.
* @param attr Current attribute that will get reassigned after the function call.
*/
void canfigger_free_current_attr_str_advance(struct attributes *attributes, char **attr);