format with clang-format

This commit is contained in:
CK Tan 2021-12-25 23:42:50 -08:00
parent 64e280e20b
commit 32c38751b9
6 changed files with 2401 additions and 2360 deletions

View file

@ -6,8 +6,8 @@ insert_final_newline = false
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.{c,h}] [*.{c,h}]
indent_style = tab indent_style = space
indent_size = 4 indent_size = 2
[Makefile] [Makefile]
indent_style = tab indent_style = tab

1303
toml.c

File diff suppressed because it is too large Load diff

104
toml.h
View file

@ -25,10 +25,8 @@
#ifndef TOML_H #ifndef TOML_H
#define TOML_H #define TOML_H
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
#define TOML_EXTERN extern "C" #define TOML_EXTERN extern "C"
@ -44,24 +42,20 @@ 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.
*/ */
TOML_EXTERN toml_table_t* toml_parse_file(FILE* fp, TOML_EXTERN toml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz);
char* errbuf,
int errbufsz);
/* Parse a string containing the full config. /* Parse a string containing the full config.
* Return a table on success, or 0 otherwise. * 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.
*/ */
TOML_EXTERN toml_table_t* toml_parse(char* conf, /* NUL terminated, please. */ TOML_EXTERN toml_table_t *toml_parse(char *conf, /* NUL terminated, please. */
char* errbuf, char *errbuf, int errbufsz);
int errbufsz);
/* Free the table returned by toml_parse() or toml_parse_file(). Once /* Free the table returned by toml_parse() or toml_parse_file(). Once
* this function is called, any handles accessed through this tab * this function is called, any handles accessed through this tab
* directly or indirectly are no longer valid. * directly or indirectly are no longer valid.
*/ */
TOML_EXTERN void toml_free(toml_table_t* tab); TOML_EXTERN void toml_free(toml_table_t *tab);
/* Timestamp types. The year, month, day, hour, minute, second, z /* Timestamp types. The year, month, day, hour, minute, second, z
* fields may be NULL if they are not relevant. e.g. In a DATE * fields may be NULL if they are not relevant. e.g. In a DATE
@ -75,18 +69,17 @@ struct toml_timestamp_t {
} __buffer; } __buffer;
int *year, *month, *day; int *year, *month, *day;
int *hour, *minute, *second, *millisec; int *hour, *minute, *second, *millisec;
char* z; char *z;
}; };
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* Enhanced access methods * Enhanced access methods
*/ */
struct toml_datum_t { struct toml_datum_t {
int ok; int ok;
union { union {
toml_timestamp_t* ts; /* ts must be freed after use */ toml_timestamp_t *ts; /* ts must be freed after use */
char* s; /* string value. s must be freed after use */ char *s; /* string value. s must be freed after use */
int b; /* bool value */ int b; /* bool value */
int64_t i; /* int value */ int64_t i; /* int value */
double d; /* double value */ double d; /* double value */
@ -95,83 +88,84 @@ struct toml_datum_t {
/* on arrays: */ /* on arrays: */
/* ... 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_datum_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_datum_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_datum_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_datum_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_datum_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);
/* on tables: */ /* on tables: */
/* ... 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);
/* ... returns 1 if key exists in tab, 0 otherwise */ /* ... returns 1 if key exists in tab, 0 otherwise */
TOML_EXTERN int toml_key_exists(const toml_table_t* tab, const char* key); TOML_EXTERN int toml_key_exists(const toml_table_t *tab, const char *key);
/* ... retrieve values using key. */ /* ... retrieve values using key. */
TOML_EXTERN toml_datum_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,
TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key); const char *key);
TOML_EXTERN toml_datum_t toml_int_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_datum_t toml_double_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_datum_t toml_timestamp_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_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);
TOML_EXTERN toml_table_t* toml_table_in(const toml_table_t* tab, TOML_EXTERN toml_table_t *toml_table_in(const toml_table_t *tab,
const char* key); const char *key);
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* lesser used * lesser used
*/ */
/* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */ /* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */
TOML_EXTERN char toml_array_kind(const toml_array_t* arr); TOML_EXTERN char toml_array_kind(const toml_array_t *arr);
/* For array kind 'v'alue, return the type of values /* For array kind 'v'alue, return the type of values
i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed
0 if unknown 0 if unknown
*/ */
TOML_EXTERN char toml_array_type(const toml_array_t* arr); TOML_EXTERN char toml_array_type(const toml_array_t *arr);
/* Return the key of an array */ /* Return the key of an array */
TOML_EXTERN const char* toml_array_key(const toml_array_t* arr); TOML_EXTERN const char *toml_array_key(const toml_array_t *arr);
/* Return the number of key-values in a table */ /* Return the number of key-values in a table */
TOML_EXTERN int toml_table_nkval(const toml_table_t* tab); TOML_EXTERN int toml_table_nkval(const toml_table_t *tab);
/* Return the number of arrays in a table */ /* Return the number of arrays in a table */
TOML_EXTERN int toml_table_narr(const toml_table_t* tab); TOML_EXTERN int toml_table_narr(const toml_table_t *tab);
/* Return the number of sub-tables in a table */ /* Return the number of sub-tables in a table */
TOML_EXTERN int toml_table_ntab(const toml_table_t* tab); TOML_EXTERN int toml_table_ntab(const toml_table_t *tab);
/* Return the key of a table*/ /* Return the key of a table*/
TOML_EXTERN const char* toml_table_key(const toml_table_t* tab); TOML_EXTERN const char *toml_table_key(const toml_table_t *tab);
/*-------------------------------------------------------------- /*--------------------------------------------------------------
* misc * misc
*/ */
TOML_EXTERN int toml_utf8_to_ucs(const char* orig, int len, int64_t* ret); TOML_EXTERN int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret);
TOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]); TOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]);
TOML_EXTERN void toml_set_memutil(void* (*xxmalloc)(size_t), TOML_EXTERN void toml_set_memutil(void *(*xxmalloc)(size_t),
void (*xxfree)(void*)); void (*xxfree)(void *));
/*-------------------------------------------------------------- /*--------------------------------------------------------------
* deprecated * deprecated
*/ */
/* A raw value, must be processed by toml_rto* before using. */ /* A raw value, must be processed by toml_rto* before using. */
typedef const char* toml_raw_t; typedef const char *toml_raw_t;
TOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t* tab, const char* key); TOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key);
TOML_EXTERN toml_raw_t toml_raw_at(const toml_array_t* arr, int idx); TOML_EXTERN toml_raw_t toml_raw_at(const toml_array_t *arr, int idx);
TOML_EXTERN int toml_rtos(toml_raw_t s, char** ret); TOML_EXTERN int toml_rtos(toml_raw_t s, char **ret);
TOML_EXTERN int toml_rtob(toml_raw_t s, int* ret); TOML_EXTERN int toml_rtob(toml_raw_t s, int *ret);
TOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t* ret); TOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t *ret);
TOML_EXTERN int toml_rtod(toml_raw_t s, double* ret); TOML_EXTERN int toml_rtod(toml_raw_t s, double *ret);
TOML_EXTERN int toml_rtod_ex(toml_raw_t s, double* ret, char* buf, int buflen); TOML_EXTERN int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen);
TOML_EXTERN int toml_rtots(toml_raw_t s, toml_timestamp_t* ret); TOML_EXTERN int toml_rtots(toml_raw_t s, toml_timestamp_t *ret);
#endif /* TOML_H */ #endif /* TOML_H */

View file

@ -27,36 +27,34 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include <assert.h>
#include <inttypes.h>
#include <ctype.h>
#include "toml.h" #include "toml.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node_t node_t; typedef struct node_t node_t;
struct node_t { struct node_t {
const char* key; const char *key;
toml_table_t* tab; toml_table_t *tab;
}; };
node_t stack[20]; node_t stack[20];
int stacktop = 0; int stacktop = 0;
int indent = 0; int indent = 0;
static void prindent() static void prindent() {
{ for (int i = 0; i < indent; i++)
for (int i = 0; i < indent; i++) printf(" "); printf(" ");
} }
static void print_string(const char *s) {
static void print_string(const char* s)
{
int ok = 1; int ok = 1;
for (const char* p = s; *p && ok; p++) { for (const char *p = s; *p && ok; p++) {
int ch = *p; int ch = *p;
ok = isprint(ch) && ch != '"' && ch != '\\'; ok = isprint(ch) && ch != '"' && ch != '\\';
} }
@ -69,7 +67,7 @@ static void print_string(const char* s)
int len = strlen(s); int len = strlen(s);
printf("\""); printf("\"");
for ( ; len; len--, s++) { for (; len; len--, s++) {
int ch = *s; int ch = *s;
if (isprint(ch) && ch != '"' && ch != '\\') { if (isprint(ch) && ch != '"' && ch != '\\') {
putchar(ch); putchar(ch);
@ -77,24 +75,38 @@ static void print_string(const char* s)
} }
switch (ch) { switch (ch) {
case 0x8: printf("\\b"); continue; case 0x8:
case 0x9: printf("\\t"); continue; printf("\\b");
case 0xa: printf("\\n"); continue; continue;
case 0xc: printf("\\f"); continue; case 0x9:
case 0xd: printf("\\r"); continue; printf("\\t");
case '"': printf("\\\""); continue; continue;
case '\\': printf("\\\\"); continue; case 0xa:
default: printf("\\0x%02x", ch & 0xff); continue; printf("\\n");
continue;
case 0xc:
printf("\\f");
continue;
case 0xd:
printf("\\r");
continue;
case '"':
printf("\\\"");
continue;
case '\\':
printf("\\\\");
continue;
default:
printf("\\0x%02x", ch & 0xff);
continue;
} }
} }
printf("\""); printf("\"");
} }
static void print_array(toml_array_t *arr);
static void print_array(toml_array_t* arr); static void print_timestamp(toml_datum_t d) {
static void print_timestamp(toml_datum_t d)
{
if (d.u.ts->year) { if (d.u.ts->year) {
printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day, printf("%04d-%02d-%02d%s", *d.u.ts->year, *d.u.ts->month, *d.u.ts->day,
d.u.ts->hour ? "T" : ""); d.u.ts->hour ? "T" : "");
@ -110,15 +122,12 @@ static void print_timestamp(toml_datum_t d)
} }
} }
static void print_table(toml_table_t *curtab) {
static void print_table(toml_table_t* curtab)
{
toml_datum_t d; toml_datum_t d;
int i; int i;
const char* key; const char *key;
toml_array_t* arr; toml_array_t *arr;
toml_table_t* tab; toml_table_t *tab;
for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) { for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) {
@ -195,12 +204,10 @@ static void print_table(toml_table_t* curtab)
} }
} }
static void print_array(toml_array_t *curarr) {
static void print_array(toml_array_t* curarr)
{
toml_datum_t d; toml_datum_t d;
toml_array_t* arr; toml_array_t *arr;
toml_table_t* tab; toml_table_t *tab;
const int n = toml_array_nelem(curarr); const int n = toml_array_nelem(curarr);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
@ -272,14 +279,10 @@ static void print_array(toml_array_t* curarr)
} }
} }
static void cat(FILE *fp) {
static void cat(FILE* fp)
{
char errbuf[200]; char errbuf[200];
toml_table_t* tab = toml_parse_file(fp, errbuf, sizeof(errbuf)); toml_table_t *tab = toml_parse_file(fp, errbuf, sizeof(errbuf));
if (!tab) { if (!tab) {
fprintf(stderr, "ERROR: %s\n", errbuf); fprintf(stderr, "ERROR: %s\n", errbuf);
return; return;
@ -298,19 +301,17 @@ static void cat(FILE* fp)
toml_free(tab); toml_free(tab);
} }
int main(int argc, const char *argv[]) {
int main(int argc, const char* argv[])
{
int i; int i;
if (argc == 1) { if (argc == 1) {
cat(stdin); cat(stdin);
} else { } else {
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
FILE* fp = fopen(argv[i], "r"); FILE *fp = fopen(argv[i], "r");
if (!fp) { if (!fp) {
fprintf(stderr, "ERROR: cannot open %s: %s\n", fprintf(stderr, "ERROR: cannot open %s: %s\n", argv[i],
argv[i], strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
cat(fp); cat(fp);

View file

@ -26,34 +26,47 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <inttypes.h>
#include "toml.h" #include "toml.h"
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
static void print_escape_string(const char *s) {
static void print_escape_string(const char* s) for (; *s; s++) {
{
for ( ; *s; s++) {
int ch = *s; int ch = *s;
switch (ch) { switch (ch) {
case '\b': printf("\\b"); break; case '\b':
case '\t': printf("\\t"); break; printf("\\b");
case '\n': printf("\\n"); break; break;
case '\f': printf("\\f"); break; case '\t':
case '\r': printf("\\r"); break; printf("\\t");
case '"': printf("\\\""); break; break;
case '\\': printf("\\\\"); break; case '\n':
default: printf("%c", ch); break; printf("\\n");
break;
case '\f':
printf("\\f");
break;
case '\r':
printf("\\r");
break;
case '"':
printf("\\\"");
break;
case '\\':
printf("\\\\");
break;
default:
printf("%c", ch);
break;
} }
} }
} }
static void print_raw(const char* s) static void print_raw(const char *s) {
{ char *sval;
char* sval;
int64_t ival; int64_t ival;
int bval; int bval;
double dval; double dval;
@ -78,16 +91,16 @@ static void print_raw(const char* s)
else else
millisec[0] = 0; millisec[0] = 0;
if (ts.year && ts.hour) { if (ts.year && ts.hour) {
printf("{\"type\":\"datetime\",\"value\":\"%04d-%02d-%02dT%02d:%02d:%02d%s%s\"}", printf("{\"type\":\"datetime\",\"value\":\"%04d-%02d-%02dT%02d:%02d:%02d%"
"s%s\"}",
*ts.year, *ts.month, *ts.day, *ts.hour, *ts.minute, *ts.second, *ts.year, *ts.month, *ts.day, *ts.hour, *ts.minute, *ts.second,
millisec, millisec, (ts.z ? ts.z : ""));
(ts.z ? ts.z : ""));
} else if (ts.year) { } else if (ts.year) {
printf("{\"type\":\"date\",\"value\":\"%04d-%02d-%02d\"}", printf("{\"type\":\"date\",\"value\":\"%04d-%02d-%02d\"}", *ts.year,
*ts.year, *ts.month, *ts.day); *ts.month, *ts.day);
} else if (ts.hour) { } else if (ts.hour) {
printf("{\"type\":\"time\",\"value\":\"%02d:%02d:%02d%s\"}", printf("{\"type\":\"time\",\"value\":\"%02d:%02d:%02d%s\"}", *ts.hour,
*ts.hour, *ts.minute, *ts.second, millisec); *ts.minute, *ts.second, millisec);
} }
} else { } else {
fprintf(stderr, "unknown type\n"); fprintf(stderr, "unknown type\n");
@ -95,16 +108,13 @@ static void print_raw(const char* s)
} }
} }
static void print_array(toml_array_t *arr);
static void print_array(toml_array_t* arr); static void print_table(toml_table_t *curtab) {
static void print_table(toml_table_t* curtab)
{
int i; int i;
const char* key; const char *key;
const char* raw; const char *raw;
toml_array_t* arr; toml_array_t *arr;
toml_table_t* tab; toml_table_t *tab;
printf("{"); printf("{");
for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) { for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) {
@ -126,10 +136,9 @@ static void print_table(toml_table_t* curtab)
printf("}"); printf("}");
} }
static void print_table_array(toml_array_t* curarr) static void print_table_array(toml_array_t *curarr) {
{
int i; int i;
toml_table_t* tab; toml_table_t *tab;
printf("["); printf("[");
for (i = 0; 0 != (tab = toml_table_at(curarr, i)); i++) { for (i = 0; 0 != (tab = toml_table_at(curarr, i)); i++) {
@ -139,10 +148,9 @@ static void print_table_array(toml_array_t* curarr)
printf("]"); printf("]");
} }
static void print_array(toml_array_t* curarr) static void print_array(toml_array_t *curarr) {
{ toml_array_t *arr;
toml_array_t* arr; const char *raw;
const char* raw;
int i; int i;
if (toml_array_kind(curarr) == 't') { if (toml_array_kind(curarr) == 't') {
@ -173,13 +181,10 @@ static void print_array(toml_array_t* curarr)
printf("]}"); printf("]}");
} }
static void cat(FILE *fp) {
static void cat(FILE* fp)
{
char errbuf[200]; char errbuf[200];
toml_table_t* tab = toml_parse_file(fp, errbuf, sizeof(errbuf)); toml_table_t *tab = toml_parse_file(fp, errbuf, sizeof(errbuf));
if (!tab) { if (!tab) {
fprintf(stderr, "ERROR: %s\n", errbuf); fprintf(stderr, "ERROR: %s\n", errbuf);
exit(1); exit(1);
@ -191,19 +196,17 @@ static void cat(FILE* fp)
toml_free(tab); toml_free(tab);
} }
int main(int argc, const char *argv[]) {
int main(int argc, const char* argv[])
{
int i; int i;
if (argc == 1) { if (argc == 1) {
cat(stdin); cat(stdin);
} else { } else {
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
FILE* fp = fopen(argv[i], "r"); FILE *fp = fopen(argv[i], "r");
if (!fp) { if (!fp) {
fprintf(stderr, "ERROR: cannot open %s: %s\n", fprintf(stderr, "ERROR: cannot open %s: %s\n", argv[i],
argv[i], strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
cat(fp); cat(fp);

View file

@ -1,19 +1,16 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include "toml.h" #include "toml.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void fatal(const char* msg, const char* msg1) static void fatal(const char *msg, const char *msg1) {
{ fprintf(stderr, "ERROR: %s%s\n", msg, msg1 ? msg1 : "");
fprintf(stderr, "ERROR: %s%s\n", msg, msg1?msg1:"");
exit(1); exit(1);
} }
int main() {
int main() FILE *fp;
{
FILE* fp;
char errbuf[200]; char errbuf[200];
// 1. Read and parse toml file // 1. Read and parse toml file
@ -22,7 +19,7 @@ int main()
fatal("cannot open sample.toml - ", strerror(errno)); fatal("cannot open sample.toml - ", strerror(errno));
} }
toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf)); toml_table_t *conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
fclose(fp); fclose(fp);
if (!conf) { if (!conf) {
@ -30,7 +27,7 @@ int main()
} }
// 2. Traverse to a table. // 2. Traverse to a table.
toml_table_t* server = toml_table_in(conf, "server"); toml_table_t *server = toml_table_in(conf, "server");
if (!server) { if (!server) {
fatal("missing [server]", ""); fatal("missing [server]", "");
} }
@ -41,16 +38,17 @@ int main()
fatal("cannot read server.host", ""); fatal("cannot read server.host", "");
} }
toml_array_t* portarray = toml_array_in(server, "port"); toml_array_t *portarray = toml_array_in(server, "port");
if (!portarray) { if (!portarray) {
fatal("cannot read server.port", ""); fatal("cannot read server.port", "");
} }
printf("host: %s\n", host.u.s); printf("host: %s\n", host.u.s);
printf("port: "); printf("port: ");
for (int i = 0; ; i++) { for (int i = 0;; i++) {
toml_datum_t port = toml_int_at(portarray, i); toml_datum_t port = toml_int_at(portarray, i);
if (!port.ok) break; if (!port.ok)
break;
printf("%d ", (int)port.u.i); printf("%d ", (int)port.u.i);
} }
printf("\n"); printf("\n");