canfigger v0.3.2 Lightweight config file parser library

Loading...
Searching...
No Matches
canfigger.h
Go to the documentation of this file.
1
35/* This file is part of canfigger<https://github.com/andy5995/canfigger>
36
37 MIT License
38
39 Copyright (c) 2024 Andy Alt(arch_stanton5995@proton.me)
40
41 Permission is hereby granted, free of charge, to any person obtaining a copy
42 of this software and associated documentation files (the "Software"), to deal
43 in the Software without restriction, including without limitation the rights
44 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45 copies of the Software, and to permit persons to whom the Software is
46 furnished to do so, subject to the following conditions:
47
48 The above copyright notice and this permission notice shall be included in all
49 copies or substantial portions of the Software.
50
51 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57 SOFTWARE.
58*/
59
60#pragma once
61
62#include "canfigger_version.h"
63
80#define CANFIGGER_CHECK_VERSION(maj, min) \
81 (CANFIGGER_VERSION_MAJOR > (maj) || \
82 (CANFIGGER_VERSION_MAJOR == (maj) && CANFIGGER_VERSION_MINOR >= (min)))
83
84#ifdef __cplusplus
85 extern "C"
86{
87#endif
88
104 struct attributes
105 {
106 char *str;
107 char *current;
108 char *iter_ptr;
109 };
110
126 struct Canfigger
127 {
128 char *key;
129 char *value;
130 struct attributes *attributes;
131 struct Canfigger *next;
132 };
133
154 struct Canfigger *canfigger_parse_file(const char *file,
155 const int delimiter);
156
172 void canfigger_free_current_key_node_advance(struct Canfigger **node);
173
197 void canfigger_free_current_attr_str_advance(struct attributes *attributes,
198 char **attr);
199
210 void canfigger_free_list(struct Canfigger **node);
211
234 char *canfigger_config_dir(const char *appname);
235
263 char *canfigger_config_file(const char *filename);
264
279 char *canfigger_data_dir(const char *appname);
280
293 char *canfigger_cache_dir(const char *appname);
294
317 char *canfigger_path_join(const char *dir, const char *file);
318
319#ifdef __cplusplus
320}
321#endif
canfigger_config_file
char * canfigger_config_file(const char *filename)
Return the path to a config file in the platform base config directory.
Definition canfigger.c:582
canfigger_parse_file
struct Canfigger * canfigger_parse_file(const char *file, const int delimiter)
Parse a configuration file into a linked list of key-value nodes.
Definition canfigger.c:356
canfigger_cache_dir
char * canfigger_cache_dir(const char *appname)
Return the platform cache directory for an application.
Definition canfigger.c:621
canfigger_data_dir
char * canfigger_data_dir(const char *appname)
Return the platform data directory for an application.
Definition canfigger.c:610
canfigger_free_list
void canfigger_free_list(struct Canfigger **node)
Free all remaining nodes in the list.
Definition canfigger.c:166
canfigger_free_current_attr_str_advance
void canfigger_free_current_attr_str_advance(struct attributes *attributes, char **attr)
Free the current attribute string and advance to the next attribute.
Definition canfigger.c:86
canfigger_config_dir
char * canfigger_config_dir(const char *appname)
Return the platform config directory for an application.
Definition canfigger.c:571
canfigger_path_join
char * canfigger_path_join(const char *dir, const char *file)
Join a directory path and a filename with the platform separator.
Definition canfigger.c:632
canfigger_free_current_key_node_advance
void canfigger_free_current_key_node_advance(struct Canfigger **node)
Free the current node and advance the list pointer to the next node.
Definition canfigger.c:125
Canfigger
A single node in the parsed configuration linked list.
Definition canfigger.h:127
attributes
Internal iteration state for a node's attribute list.
Definition canfigger.h:105