-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcanfigger.h
113 lines (98 loc) · 3.67 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @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).
*
**/
/* This file is part of canfigger<https://github.com/andy5995/canfigger>
MIT License
Copyright (c) 2024 Andy Alt([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* \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);
/**
* @brief Frees the remainder of list allocated by canfigger_parse_file().
*
* @param list Double pointer to the current node in the linked list.
*/
void canfigger_free_list(struct Canfigger **node);
#ifdef __cplusplus
}
#endif