This commit is contained in:
CK Tan 2019-02-16 17:37:59 -08:00
parent 3b6fe37d66
commit 43f7a52064
3 changed files with 702 additions and 699 deletions

1380
toml.c

File diff suppressed because it is too large Load Diff

19
toml.h
View File

@ -25,6 +25,11 @@ SOFTWARE.
#ifndef TOML_H #ifndef TOML_H
#define TOML_H #define TOML_H
#include <stdio.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
#define TOML_EXTERN extern "C" #define TOML_EXTERN extern "C"
#else #else
@ -38,16 +43,16 @@ typedef struct toml_array_t toml_array_t;
* 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, char* errbuf,
int errbufsz); 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(). */ /* Free the table returned by toml_parse() or toml_parse_file(). */
TOML_EXTERN void toml_free(toml_table_t* tab); TOML_EXTERN void toml_free(toml_table_t* tab);
@ -108,9 +113,9 @@ TOML_EXTERN int toml_rtod(const char* s, double* ret);
typedef struct toml_timestamp_t toml_timestamp_t; typedef struct toml_timestamp_t toml_timestamp_t;
struct toml_timestamp_t { struct toml_timestamp_t {
struct { /* internal. do not use. */ struct { /* internal. do not use. */
int year, month, day; int year, month, day;
int hour, minute, second; int hour, minute, second;
char z[10]; char z[10];
} __buffer; } __buffer;
int *year, *month, *day; int *year, *month, *day;
int *hour, *minute, *second; int *hour, *minute, *second;

View File

@ -26,11 +26,9 @@ SOFTWARE.
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <stdint.h>
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include "toml.h" #include "toml.h"