libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
conf.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license in the file COPYING
10 * or http://www.opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file COPYING.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2023 Saso Kiselkov. All rights reserved.
24 */
42#ifndef _ACFUTILS_CONF_H_
43#define _ACFUTILS_CONF_H_
44
45#include <stdio.h>
46#include <stdint.h>
47
48#if __STDC_VERSION__ >= 199901L
49#include <stdbool.h>
50#endif
51
52#include "helpers.h"
53#include "types.h"
54#include "avl.h"
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60typedef struct conf conf_t;
61
62API_EXPORT conf_t *conf_create_empty(void);
63API_EXPORT conf_t *conf_create_copy(const conf_t *conf2);
64API_EXPORT void conf_free(conf_t *conf);
65
66API_EXPORT conf_t *conf_read_file(const char *filename, int *errline);
67API_EXPORT conf_t *conf_read(FILE *fp, int *errline);
68API_EXPORT conf_t *conf_read2(void *fp, int *errline, bool_t compressed);
69API_EXPORT conf_t *conf_read_buf(const void *buf, size_t cap, int *errline);
70
71API_EXPORT bool_t conf_write_file(const conf_t *conf, const char *filename);
72API_EXPORT bool_t conf_write_file2(const conf_t *conf, const char *filename,
73 bool_t compressed);
74API_EXPORT bool_t conf_write(const conf_t *conf, FILE *fp);
75API_EXPORT size_t conf_write_buf(const conf_t *conf, void *buf, size_t cap);
76
77API_EXPORT void conf_merge(const conf_t *conf_from, conf_t *conf_to);
78
79API_EXPORT bool_t conf_get_str(const conf_t *conf, const char *key,
80 const char **value);
81API_EXPORT bool_t conf_get_i(const conf_t *conf, const char *key,
82 int *value);
83API_EXPORT bool_t conf_get_lli(const conf_t *conf, const char *key,
84 long long *value);
85API_EXPORT bool_t conf_get_f(const conf_t *conf, const char *key,
86 float *value);
87API_EXPORT bool_t conf_get_d(const conf_t *conf, const char *key,
88 double *value);
89API_EXPORT bool_t conf_get_da(const conf_t *conf, const char *key,
90 double *value);
91API_EXPORT bool_t conf_get_b(const conf_t *conf, const char *key,
92 bool_t *value);
93API_EXPORT size_t conf_get_data(const conf_t *conf, const char *key,
94 void *buf, size_t cap);
95
96API_EXPORT void conf_set_str(conf_t *conf, const char *key, const char *value);
97API_EXPORT void conf_set_i(conf_t *conf, const char *key, int value);
98API_EXPORT void conf_set_lli(conf_t *conf, const char *key, long long value);
99API_EXPORT void conf_set_f(conf_t *conf, const char *key, float value);
100API_EXPORT void conf_set_d(conf_t *conf, const char *key, double value);
101API_EXPORT void conf_set_da(conf_t *conf, const char *key, double value);
102API_EXPORT void conf_set_b(conf_t *conf, const char *key, bool_t value);
103API_EXPORT void conf_set_data(conf_t *conf, const char *key,
104 const void *buf, size_t sz);
105
106API_EXPORT bool_t conf_get_str_v(const conf_t *conf,
107 PRINTF_FORMAT(const char *fmt), const char **value, ...) PRINTF_ATTR2(2, 4);
108API_EXPORT bool_t conf_get_i_v(const conf_t *conf,
109 PRINTF_FORMAT(const char *fmt), int *value, ...) PRINTF_ATTR2(2, 4);
110API_EXPORT bool_t conf_get_lli_v(const conf_t *conf,
111 PRINTF_FORMAT(const char *fmt), long long *value, ...) PRINTF_ATTR2(2, 4);
112API_EXPORT bool_t conf_get_f_v(const conf_t *conf,
113 PRINTF_FORMAT(const char *fmt), float *value, ...) PRINTF_ATTR2(2, 4);
114API_EXPORT bool_t conf_get_d_v(const conf_t *conf,
115 PRINTF_FORMAT(const char *fmt), double *value, ...) PRINTF_ATTR2(2, 4);
116API_EXPORT bool_t conf_get_da_v(const conf_t *conf,
117 PRINTF_FORMAT(const char *fmt), double *value, ...) PRINTF_ATTR2(2, 4);
118API_EXPORT bool_t conf_get_b_v(const conf_t *conf,
119 PRINTF_FORMAT(const char *fmt), bool_t *value, ...) PRINTF_ATTR2(2, 4);
120API_EXPORT size_t conf_get_data_v(const conf_t *conf,
121 PRINTF_FORMAT(const char *fmt), void *buf, size_t cap, ...)
122 PRINTF_ATTR2(2, 5);
123
124API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_str_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
125 const char *value, ...);
126API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_i_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
127 int value, ...);
128API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_lli_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
129 long long value, ...);
130API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_f_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
131 double value, ...);
132API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_d_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
133 double value, ...);
134API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_da_v(conf_t *conf, PRINTF_FORMAT(const char *fmt),
135 double value, ...);
136API_EXPORT PRINTF_ATTR2(2, 4) void conf_set_b_v(conf_t *conf,
137 PRINTF_FORMAT(const char *fmt), bool_t value, ...);
138API_EXPORT PRINTF_ATTR2(2, 5) void conf_set_data_v(conf_t *conf,
139 PRINTF_FORMAT(const char *fmt), const void *buf, size_t sz, ...);
140
141#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
142API_EXPORT bool conf_get_b2(const conf_t *conf, const char *key,
143 bool *value);
144API_EXPORT void conf_set_b2(conf_t *conf, const char *key, bool value);
145API_EXPORT PRINTF_ATTR2(2, 4) bool conf_get_b2_v(const conf_t *conf,
146 PRINTF_FORMAT(const char *fmt), bool *value, ...);
147/*
148 * We can't declare a native bool-type conf_set_b2_v here, because bool
149 * isn't a formally declared type. This results in default argument
150 * promotion, which is undefined behavior in varargs.
151 */
152#define conf_set_b2_v conf_set_b_v
153#endif /* __STDC_VERSION__ >= 199901L || defined(__cplusplus) */
154
155API_EXPORT bool_t conf_walk(const conf_t *conf, const char **key,
156 const char **value, void **cookie);
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif /* _ACFUTILS_CONF_H_ */
bool_t conf_get_da(const conf_t *conf, const char *key, double *value)
Definition conf.c:816
void conf_set_b(conf_t *conf, const char *key, bool_t value)
Definition conf.c:1081
bool_t conf_get_lli_v(const conf_t *conf, const char *fmt, long long *value,...)
Definition conf.c:1205
bool_t conf_get_d_v(const conf_t *conf, const char *fmt, double *value,...)
Definition conf.c:1229
void conf_set_data_v(conf_t *conf, const char *fmt, const void *buf, size_t sz,...)
Definition conf.c:1372
void conf_set_f(conf_t *conf, const char *key, float value)
Definition conf.c:1039
bool_t conf_get_i_v(const conf_t *conf, const char *fmt, int *value,...)
Definition conf.c:1192
bool_t conf_get_lli(const conf_t *conf, const char *key, long long *value)
Definition conf.c:744
void conf_set_da(conf_t *conf, const char *key, double value)
Definition conf.c:1055
void conf_set_str(conf_t *conf, const char *key, const char *value)
Definition conf.c:928
void conf_set_data(conf_t *conf, const char *key, const void *buf, size_t sz)
Definition conf.c:1108
bool_t conf_get_da_v(const conf_t *conf, const char *fmt, double *value,...)
Definition conf.c:1242
bool_t conf_get_d(const conf_t *conf, const char *key, double *value)
Definition conf.c:764
bool_t conf_write(const conf_t *conf, FILE *fp)
Definition conf.c:677
void conf_set_d_v(conf_t *conf, const char *fmt, double value,...)
Definition conf.c:1338
bool_t conf_get_b(const conf_t *conf, const char *key, bool_t *value)
Definition conf.c:850
void conf_set_lli_v(conf_t *conf, const char *fmt, long long value,...)
Definition conf.c:1316
bool_t conf_walk(const conf_t *conf, const char **key, const char **value, void **cookie)
Definition conf.c:1406
void conf_set_i_v(conf_t *conf, const char *fmt, int value,...)
Definition conf.c:1304
conf_t * conf_read2(void *fp, int *errline, bool_t compressed)
Definition conf.c:335
conf_t * conf_read_buf(const void *buf, size_t cap, int *errline)
Definition conf.c:385
void conf_merge(const conf_t *conf_from, conf_t *conf_to)
Definition conf.c:119
bool_t conf_get_b_v(const conf_t *conf, const char *fmt, bool_t *value,...)
Definition conf.c:1268
void conf_set_da_v(conf_t *conf, const char *fmt, double value,...)
Definition conf.c:1350
conf_t * conf_read_file(const char *filename, int *errline)
Definition conf.c:174
void conf_set_f_v(conf_t *conf, const char *fmt, double value,...)
Definition conf.c:1327
bool_t conf_get_str_v(const conf_t *conf, const char *fmt, const char **value,...)
Definition conf.c:1180
conf_t * conf_read(FILE *fp, int *errline)
Definition conf.c:246
size_t conf_get_data_v(const conf_t *conf, const char *fmt, void *buf, size_t cap,...)
Definition conf.c:1255
bool_t conf_get_f(const conf_t *conf, const char *key, float *value)
Definition conf.c:786
void conf_free(conf_t *conf)
Definition conf.c:142
void conf_set_i(conf_t *conf, const char *key, int value)
Definition conf.c:992
bool_t conf_get_f_v(const conf_t *conf, const char *fmt, float *value,...)
Definition conf.c:1217
bool_t conf_write_file(const conf_t *conf, const char *filename)
Definition conf.c:449
void conf_set_b_v(conf_t *conf, const char *fmt, bool_t value,...)
Definition conf.c:1361
bool_t conf_write_file2(const conf_t *conf, const char *filename, bool_t compressed)
Definition conf.c:459
bool_t conf_get_str(const conf_t *conf, const char *key, const char **value)
Definition conf.c:704
conf_t * conf_create_empty(void)
Definition conf.c:87
void conf_set_d(conf_t *conf, const char *key, double value)
Definition conf.c:1024
size_t conf_get_data(const conf_t *conf, const char *key, void *buf, size_t cap)
Definition conf.c:902
size_t conf_write_buf(const conf_t *conf, void *buf, size_t cap)
Definition conf.c:543
conf_t * conf_create_copy(const conf_t *conf2)
Definition conf.c:100
void conf_set_lli(conf_t *conf, const char *key, long long value)
Definition conf.c:1004
Definition conf.c:41