canfigger v0.3.3
Lightweight config file parser library
Loading...
Searching...
No Matches
canfigger.h
Go to the documentation of this file.
1
41/* This file is part of canfigger<https://github.com/andy5995/canfigger>
42
43MIT License
44
45Copyright (c) 2024 Andy Alt(arch_stanton5995@proton.me)
46
47Permission is hereby granted, free of charge, to any person obtaining a copy
48of this software and associated documentation files (the "Software"), to deal
49in the Software without restriction, including without limitation the rights
50to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51copies of the Software, and to permit persons to whom the Software is
52furnished to do so, subject to the following conditions:
53
54The above copyright notice and this permission notice shall be included in all
55copies or substantial portions of the Software.
56
57THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
63SOFTWARE.
64*/
65
66#pragma once
67
68#include "canfigger_version.h"
69
86#define CANFIGGER_CHECK_VERSION(maj, min) \
87 (CANFIGGER_VERSION_MAJOR > (maj) || \
88 (CANFIGGER_VERSION_MAJOR == (maj) && CANFIGGER_VERSION_MINOR >= (min)))
89
90#ifdef __cplusplus
91extern "C"
92{
93#endif
94
111 {
112 char *str;
113 char *current;
114 char *iter_ptr;
115 };
116
133 {
134 char *key;
135 char *value;
136 struct attributes *attributes;
137 struct Canfigger *next;
138 };
139
160 struct Canfigger *canfigger_parse_file(const char *file,
161 const int delimiter);
162
179
204 char **attr);
205
216 void canfigger_free_list(struct Canfigger **node);
217
232 char *canfigger_config_dir(const char *appname);
233
256 char *canfigger_config_file(const char *filename);
257
272 char *canfigger_data_dir(const char *appname);
273
291 char *canfigger_cache_dir(const char *appname);
292
311 char *canfigger_state_dir(const char *appname);
312
343 char *canfigger_runtime_dir(const char *appname);
344
361 char **canfigger_config_dirs(void);
362
379 char **canfigger_data_dirs(void);
380
409 char *canfigger_find_config_file(const char *appname, const char *filename);
410
423 {
424 CANFIGGER_USER_DIR_DESKTOP,
425 CANFIGGER_USER_DIR_DOWNLOAD,
426 CANFIGGER_USER_DIR_TEMPLATES,
427 CANFIGGER_USER_DIR_PUBLICSHARE,
428 CANFIGGER_USER_DIR_DOCUMENTS,
429 CANFIGGER_USER_DIR_MUSIC,
430 CANFIGGER_USER_DIR_PICTURES,
431 CANFIGGER_USER_DIR_VIDEOS
432 };
433
464 char *canfigger_user_dir(enum canfigger_user_dir which);
465
476 void canfigger_free_dirs(char **dirs);
477
493 char *canfigger_path_join(const char *dir, const char *file);
494
495#ifdef __cplusplus
496}
497#endif
void canfigger_free_dirs(char **dirs)
Free an array returned by canfigger_config_dirs() or canfigger_data_dirs().
Definition canfigger.c:821
char * canfigger_config_file(const char *filename)
Return the path to a config file in the platform base config directory.
Definition canfigger.c:619
char ** canfigger_data_dirs(void)
Return the system data search path, most important first.
Definition canfigger.c:810
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:368
char * canfigger_state_dir(const char *appname)
Return the platform state directory for an application.
Definition canfigger.c:669
char ** canfigger_config_dirs(void)
Return the system config search path, most important first.
Definition canfigger.c:799
char * canfigger_cache_dir(const char *appname)
Return the platform cache directory for an application.
Definition canfigger.c:658
char * canfigger_data_dir(const char *appname)
Return the platform data directory for an application.
Definition canfigger.c:647
canfigger_user_dir
The well-known user directories, as named by the XDG user directories specification.
Definition canfigger.h:423
char * canfigger_find_config_file(const char *appname, const char *filename)
Find an existing config file along the full config search path.
Definition canfigger.c:882
void canfigger_free_list(struct Canfigger **node)
Free all remaining nodes in the list.
Definition canfigger.c:178
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:98
char * canfigger_config_dir(const char *appname)
Return the platform config directory for an application.
Definition canfigger.c:608
char * canfigger_path_join(const char *dir, const char *file)
Join a directory path and a filename with the platform separator.
Definition canfigger.c:834
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:137
char * canfigger_runtime_dir(const char *appname)
Return the runtime directory for an application, or NULL.
Definition canfigger.c:680
A single node in the parsed configuration linked list.
Definition canfigger.h:133
Internal iteration state for a node's attribute list.
Definition canfigger.h:111