rename toml_access_t -> toml_datum_t

This commit is contained in:
CK Tan 2020-11-02 10:07:33 -08:00
parent 26fdad9205
commit 3fdd187b2a
3 changed files with 34 additions and 34 deletions

40
toml.c
View file

@ -2149,9 +2149,9 @@ int toml_rtos(toml_raw_t src, char** ret)
} }
toml_access_t toml_string_at(const toml_array_t* arr, int idx) toml_datum_t toml_string_at(const toml_array_t* arr, int idx)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_at(arr, idx); toml_raw_t raw = toml_raw_at(arr, idx);
if (raw) { if (raw) {
@ -2160,9 +2160,9 @@ toml_access_t toml_string_at(const toml_array_t* arr, int idx)
return ret; return ret;
} }
toml_access_t toml_bool_at(const toml_array_t* arr, int idx) toml_datum_t toml_bool_at(const toml_array_t* arr, int idx)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_at(arr, idx); toml_raw_t raw = toml_raw_at(arr, idx);
if (raw) { if (raw) {
@ -2171,9 +2171,9 @@ toml_access_t toml_bool_at(const toml_array_t* arr, int idx)
return ret; return ret;
} }
toml_access_t toml_int_at(const toml_array_t* arr, int idx) toml_datum_t toml_int_at(const toml_array_t* arr, int idx)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_at(arr, idx); toml_raw_t raw = toml_raw_at(arr, idx);
if (raw) { if (raw) {
@ -2182,9 +2182,9 @@ toml_access_t toml_int_at(const toml_array_t* arr, int idx)
return ret; return ret;
} }
toml_access_t toml_double_at(const toml_array_t* arr, int idx) toml_datum_t toml_double_at(const toml_array_t* arr, int idx)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_at(arr, idx); toml_raw_t raw = toml_raw_at(arr, idx);
if (raw) { if (raw) {
@ -2193,9 +2193,9 @@ toml_access_t toml_double_at(const toml_array_t* arr, int idx)
return ret; return ret;
} }
toml_access_t toml_timestamp_at(const toml_array_t* arr, int idx) toml_datum_t toml_timestamp_at(const toml_array_t* arr, int idx)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_at(arr, idx); toml_raw_t raw = toml_raw_at(arr, idx);
if (raw) { if (raw) {
@ -2204,9 +2204,9 @@ toml_access_t toml_timestamp_at(const toml_array_t* arr, int idx)
return ret; return ret;
} }
toml_access_t toml_string_in(const toml_table_t* arr, const char* key) toml_datum_t toml_string_in(const toml_table_t* arr, const char* key)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_in(arr, key); toml_raw_t raw = toml_raw_in(arr, key);
if (raw) { if (raw) {
@ -2215,9 +2215,9 @@ toml_access_t toml_string_in(const toml_table_t* arr, const char* key)
return ret; return ret;
} }
toml_access_t toml_bool_in(const toml_table_t* arr, const char* key) toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_in(arr, key); toml_raw_t raw = toml_raw_in(arr, key);
if (raw) { if (raw) {
@ -2226,9 +2226,9 @@ toml_access_t toml_bool_in(const toml_table_t* arr, const char* key)
return ret; return ret;
} }
toml_access_t toml_int_in(const toml_table_t* arr, const char* key) toml_datum_t toml_int_in(const toml_table_t* arr, const char* key)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_in(arr, key); toml_raw_t raw = toml_raw_in(arr, key);
if (raw) { if (raw) {
@ -2237,9 +2237,9 @@ toml_access_t toml_int_in(const toml_table_t* arr, const char* key)
return ret; return ret;
} }
toml_access_t toml_double_in(const toml_table_t* arr, const char* key) toml_datum_t toml_double_in(const toml_table_t* arr, const char* key)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_in(arr, key); toml_raw_t raw = toml_raw_in(arr, key);
if (raw) { if (raw) {
@ -2248,9 +2248,9 @@ toml_access_t toml_double_in(const toml_table_t* arr, const char* key)
return ret; return ret;
} }
toml_access_t toml_timestamp_in(const toml_table_t* arr, const char* key) toml_datum_t toml_timestamp_in(const toml_table_t* arr, const char* key)
{ {
toml_access_t ret; toml_datum_t ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
toml_raw_t raw = toml_raw_in(arr, key); toml_raw_t raw = toml_raw_in(arr, key);
if (raw) { if (raw) {

24
toml.h
View file

@ -39,7 +39,7 @@
typedef struct toml_timestamp_t toml_timestamp_t; typedef struct toml_timestamp_t toml_timestamp_t;
typedef struct toml_table_t toml_table_t; typedef struct toml_table_t toml_table_t;
typedef struct toml_array_t toml_array_t; typedef struct toml_array_t toml_array_t;
typedef struct toml_access_t toml_access_t; typedef struct toml_datum_t toml_datum_t;
/* Parse a file. Return a table on success, or 0 otherwise. /* Parse a file. Return a table on success, or 0 otherwise.
* Caller must toml_free(the-return-value) after use. * Caller must toml_free(the-return-value) after use.
@ -82,7 +82,7 @@ struct toml_timestamp_t {
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* Enhanced access methods * Enhanced access methods
*/ */
struct toml_access_t { struct toml_datum_t {
int ok; int ok;
union { union {
char* s; /* string value. s must be freed after use */ char* s; /* string value. s must be freed after use */
@ -97,11 +97,11 @@ struct toml_access_t {
/* ... retrieve size of array. */ /* ... retrieve size of array. */
TOML_EXTERN int toml_array_nelem(const toml_array_t* arr); TOML_EXTERN int toml_array_nelem(const toml_array_t* arr);
/* ... retrieve values using index. */ /* ... retrieve values using index. */
TOML_EXTERN toml_access_t toml_string_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_datum_t toml_string_at(const toml_array_t* arr, int idx);
TOML_EXTERN toml_access_t toml_bool_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_datum_t toml_bool_at(const toml_array_t* arr, int idx);
TOML_EXTERN toml_access_t toml_int_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_datum_t toml_int_at(const toml_array_t* arr, int idx);
TOML_EXTERN toml_access_t toml_double_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_datum_t toml_double_at(const toml_array_t* arr, int idx);
TOML_EXTERN toml_access_t toml_timestamp_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_datum_t toml_timestamp_at(const toml_array_t* arr, int idx);
/* ... retrieve array or table using index. */ /* ... retrieve array or table using index. */
TOML_EXTERN toml_array_t* toml_array_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_array_t* toml_array_at(const toml_array_t* arr, int idx);
TOML_EXTERN toml_table_t* toml_table_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_table_t* toml_table_at(const toml_array_t* arr, int idx);
@ -110,11 +110,11 @@ TOML_EXTERN toml_table_t* toml_table_at(const toml_array_t* arr, int idx);
/* ... retrieve the key in table at keyidx. Return 0 if out of range. */ /* ... retrieve the key in table at keyidx. Return 0 if out of range. */
TOML_EXTERN const char* toml_key_in(const toml_table_t* tab, int keyidx); TOML_EXTERN const char* toml_key_in(const toml_table_t* tab, int keyidx);
/* ... retrieve values using key. */ /* ... retrieve values using key. */
TOML_EXTERN toml_access_t toml_string_in(const toml_table_t* arr, const char* key); TOML_EXTERN toml_datum_t toml_string_in(const toml_table_t* arr, const char* key);
TOML_EXTERN toml_access_t toml_bool_in(const toml_table_t* arr, const char* key); TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key);
TOML_EXTERN toml_access_t toml_int_in(const toml_table_t* arr, const char* key); TOML_EXTERN toml_datum_t toml_int_in(const toml_table_t* arr, const char* key);
TOML_EXTERN toml_access_t toml_double_in(const toml_table_t* arr, const char* key); TOML_EXTERN toml_datum_t toml_double_in(const toml_table_t* arr, const char* key);
TOML_EXTERN toml_access_t toml_timestamp_in(const toml_table_t* arr, const char* key); TOML_EXTERN toml_datum_t toml_timestamp_in(const toml_table_t* arr, const char* key);
/* .. retrieve array or table using key. */ /* .. retrieve array or table using key. */
TOML_EXTERN toml_array_t* toml_array_in(const toml_table_t* tab, TOML_EXTERN toml_array_t* toml_array_in(const toml_table_t* tab,
const char* key); const char* key);

View file

@ -34,13 +34,13 @@ int main()
exit(1); exit(1);
} }
toml_access_t host = toml_string_in(server, "host"); toml_datum_t host = toml_string_in(server, "host");
if (!host.ok) { if (!host.ok) {
fprintf(stderr, "ERROR: cannot read server.host.\n"); fprintf(stderr, "ERROR: cannot read server.host.\n");
exit(1); exit(1);
} }
toml_access_t port = toml_int_in(server, "port"); toml_datum_t port = toml_int_in(server, "port");
if (!port.ok) { if (!port.ok) {
fprintf(stderr, "ERROR: cannot read server.port.\n"); fprintf(stderr, "ERROR: cannot read server.port.\n");
exit(1); exit(1);