MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
toml.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) CK Tan
5 https://github.com/cktan/tomlc99
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24*/
25#ifndef TOML_H
26#define TOML_H
27
28#ifdef _MSC_VER
29#pragma warning(disable : 4996)
30#endif
31
32#include <stdint.h>
33#include <stdio.h>
34
35#ifdef __cplusplus
36#define TOML_EXTERN extern "C"
37#else
38#define TOML_EXTERN extern
39#endif
40
45
46/* Parse a file. Return a table on success, or 0 otherwise.
47 * Caller must toml_free(the-return-value) after use.
48 */
49TOML_EXTERN toml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz);
50
51/* Parse a string containing the full config.
52 * Return a table on success, or 0 otherwise.
53 * Caller must toml_free(the-return-value) after use.
54 */
55TOML_EXTERN toml_table_t *toml_parse(char *conf, /* NUL terminated, please. */
56 char *errbuf, int errbufsz);
57
58/* Free the table returned by toml_parse() or toml_parse_file(). Once
59 * this function is called, any handles accessed through this tab
60 * directly or indirectly are no longer valid.
61 */
63
64/* Timestamp types. The year, month, day, hour, minute, second, z
65 * fields may be NULL if they are not relevant. e.g. In a DATE
66 * type, the hour, minute, second and z fields will be NULLs.
67 */
69 struct { /* internal. do not use. */
70 int year, month, day;
72 char z[10];
74 int *year, *month, *day;
76 char *z;
77};
78
79/*-----------------------------------------------------------------
80 * Enhanced access methods
81 */
83 int ok;
84 union {
85 toml_timestamp_t *ts; /* ts must be freed after use */
86 char *s; /* string value. s must be freed after use */
87 int b; /* bool value */
88 int64_t i; /* int value */
89 double d; /* double value */
90 } u;
91};
92
93/* on arrays: */
94/* ... retrieve size of array. */
96/* ... retrieve values using index. */
102/* ... retrieve array or table using index. */
105
106/* on tables: */
107/* ... retrieve the key in table at keyidx. Return 0 if out of range. */
108TOML_EXTERN const char *toml_key_in(const toml_table_t *tab, int keyidx);
109/* ... returns 1 if key exists in tab, 0 otherwise */
110TOML_EXTERN int toml_key_exists(const toml_table_t *tab, const char *key);
111/* ... retrieve values using key. */
113 const char *key);
114TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t *arr, const char *key);
115TOML_EXTERN toml_datum_t toml_int_in(const toml_table_t *arr, const char *key);
117 const char *key);
119 const char *key);
120/* .. retrieve array or table using key. */
122 const char *key);
124 const char *key);
125
126/*-----------------------------------------------------------------
127 * lesser used
128 */
129/* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */
131
132/* For array kind 'v'alue, return the type of values
133 i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed
134 0 if unknown
135*/
137
138/* Return the key of an array */
139TOML_EXTERN const char *toml_array_key(const toml_array_t *arr);
140
141/* Return the number of key-values in a table */
143
144/* Return the number of arrays in a table */
146
147/* Return the number of sub-tables in a table */
149
150/* Return the key of a table*/
151TOML_EXTERN const char *toml_table_key(const toml_table_t *tab);
152
153/*--------------------------------------------------------------
154 * misc
155 */
156TOML_EXTERN int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret);
157TOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]);
158TOML_EXTERN void toml_set_memutil(void *(*xxmalloc)(size_t),
159 void (*xxfree)(void *));
160
161/*--------------------------------------------------------------
162 * deprecated
163 */
164/* A raw value, must be processed by toml_rto* before using. */
165typedef const char *toml_raw_t;
166TOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key);
168TOML_EXTERN int toml_rtos(toml_raw_t s, char **ret);
169TOML_EXTERN int toml_rtob(toml_raw_t s, int *ret);
170TOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t *ret);
171TOML_EXTERN int toml_rtod(toml_raw_t s, double *ret);
172TOML_EXTERN int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen);
174
175#endif /* TOML_H */
union toml_datum_t::@034014057205341050151107111126247137201246022032 u
int b
Definition toml.h:87
double d
Definition toml.h:89
char * s
Definition toml.h:86
int ok
Definition toml.h:83
int64_t i
Definition toml.h:88
toml_timestamp_t * ts
Definition toml.h:85
char z[10]
Definition toml.h:72
struct toml_timestamp_t::@140140272151246031144276257317172000233346153225 __buffer
#define TOML_EXTERN
Definition toml.h:38
toml_table_t * toml_table_at(const toml_array_t *arr, int idx)
Definition toml.c:1960
int toml_table_ntab(const toml_table_t *tab)
Definition toml.c:1950
toml_datum_t toml_bool_at(const toml_array_t *arr, int idx)
Definition toml.c:2272
int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen)
Definition toml.c:2146
const char * toml_raw_t
Definition toml.h:165
char toml_array_type(const toml_array_t *arr)
Definition toml.c:1930
void toml_set_memutil(void *(*xxmalloc)(size_t), void(*xxfree)(void *))
Definition toml.c:41
toml_datum_t toml_string_in(const toml_table_t *arr, const char *key)
Definition toml.c:2323
toml_datum_t toml_int_at(const toml_array_t *arr, int idx)
Definition toml.c:2279
int toml_rtots(toml_raw_t s, toml_timestamp_t *ret)
Definition toml.c:1966
int toml_rtos(toml_raw_t s, char **ret)
Definition toml.c:2210
toml_array_t * toml_array_in(const toml_table_t *tab, const char *key)
Definition toml.c:1906
toml_datum_t toml_double_at(const toml_array_t *arr, int idx)
Definition toml.c:2286
int toml_table_nkval(const toml_table_t *tab)
Definition toml.c:1946
char toml_array_kind(const toml_array_t *arr)
Definition toml.c:1928
const char * toml_table_key(const toml_table_t *tab)
Definition toml.c:1952
int toml_array_nelem(const toml_array_t *arr)
Definition toml.c:1940
toml_raw_t toml_raw_at(const toml_array_t *arr, int idx)
Definition toml.c:1924
const char * toml_key_in(const toml_table_t *tab, int keyidx)
Definition toml.c:1865
toml_datum_t toml_double_in(const toml_table_t *arr, const char *key)
Definition toml.c:2347
toml_datum_t toml_int_in(const toml_table_t *arr, const char *key)
Definition toml.c:2340
const char * toml_array_key(const toml_array_t *arr)
Definition toml.c:1942
int toml_key_exists(const toml_table_t *tab, const char *key)
Definition toml.c:1880
int toml_rtod(toml_raw_t s, double *ret)
Definition toml.c:2205
toml_table_t * toml_table_in(const toml_table_t *tab, const char *key)
Definition toml.c:1915
int toml_ucs_to_utf8(int64_t code, char buf[6])
Definition toml.c:198
toml_datum_t toml_bool_in(const toml_table_t *arr, const char *key)
Definition toml.c:2333
int toml_table_narr(const toml_table_t *tab)
Definition toml.c:1948
int toml_rtoi(toml_raw_t s, int64_t *ret)
Definition toml.c:2073
toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key)
Definition toml.c:1897
int toml_rtob(toml_raw_t s, int *ret)
Definition toml.c:2055
void toml_free(toml_table_t *tab)
Definition toml.c:1583
toml_table_t * toml_parse_file(FILE *fp, char *errbuf, int errbufsz)
Definition toml.c:1480
toml_table_t * toml_parse(char *conf, char *errbuf, int errbufsz)
Definition toml.c:1402
toml_datum_t toml_timestamp_in(const toml_table_t *arr, const char *key)
Definition toml.c:2354
int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret)
Definition toml.c:97
toml_array_t * toml_array_at(const toml_array_t *arr, int idx)
Definition toml.c:1956
toml_datum_t toml_string_at(const toml_array_t *arr, int idx)
Definition toml.c:2265
toml_datum_t toml_timestamp_at(const toml_array_t *arr, int idx)
Definition toml.c:2293