replaced numeric types to those from tlibc
This commit is contained in:
@@ -11,18 +11,8 @@ extern "C" {
|
||||
#include "tlibc/std.h"
|
||||
#include <time.h>
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#define ATTRIBUTE_THREAD_LOCAL thread_local
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
#define ATTRIBUTE_THREAD_LOCAL _Thread_local
|
||||
#elif defined(_MSC_VER)
|
||||
#define ATTRIBUTE_THREAD_LOCAL __declspec(thread)
|
||||
#else
|
||||
#define ATTRIBUTE_THREAD_LOCAL __thread
|
||||
#endif
|
||||
|
||||
#define TOML_FALSE 0
|
||||
#define TOML_TRUE 1
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
typedef enum {
|
||||
TOML_OK,
|
||||
@@ -36,28 +26,28 @@ typedef enum {
|
||||
typedef struct {
|
||||
TomlErrCode code;
|
||||
char* message;
|
||||
int _is_literal;
|
||||
i32 _is_literal;
|
||||
} TomlErr;
|
||||
|
||||
typedef struct {
|
||||
char* str;
|
||||
size_t len;
|
||||
size_t _capacity;
|
||||
u64 len;
|
||||
u64 _capacity;
|
||||
} TomlString;
|
||||
|
||||
typedef struct _TomlValue TomlValue;
|
||||
|
||||
typedef struct {
|
||||
TomlValue** elements;
|
||||
size_t len;
|
||||
size_t _capacity;
|
||||
u64 len;
|
||||
u64 _capacity;
|
||||
} TomlArray;
|
||||
|
||||
typedef struct _TomlKeyValue TomlKeyValue;
|
||||
|
||||
typedef struct {
|
||||
size_t _capacity;
|
||||
size_t len;
|
||||
u64 _capacity;
|
||||
u64 len;
|
||||
TomlKeyValue* _keyvals;
|
||||
} TomlTable;
|
||||
|
||||
@@ -82,14 +72,10 @@ struct _TomlValue {
|
||||
TomlTable* table;
|
||||
TomlArray* array;
|
||||
TomlString* string;
|
||||
#if defined(_MSC_VER) || defined(__APPLE__)
|
||||
long long integer;
|
||||
#else
|
||||
long integer;
|
||||
#endif
|
||||
double float_;
|
||||
i64 integer;
|
||||
f64 float_;
|
||||
struct tm datetime;
|
||||
int boolean;
|
||||
bool boolean;
|
||||
} value;
|
||||
};
|
||||
|
||||
@@ -99,90 +85,82 @@ struct _TomlKeyValue {
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
void* (*malloc)(void *context, size_t size);
|
||||
void* (*realloc)(void *context, void *p, size_t size);
|
||||
void (*free)(void *context, void *p);
|
||||
void* (*malloc)(void* context, u64 size);
|
||||
void* (*realloc)(void* context, void* p, u64 size);
|
||||
void (*free)(void* context, void* p);
|
||||
} TomlAllocFuncs;
|
||||
|
||||
void toml_set_allocator(void *context, const TomlAllocFuncs *funcs);
|
||||
void toml_set_allocator(void* context, const TomlAllocFuncs *funcs);
|
||||
|
||||
void* toml_malloc(size_t size);
|
||||
void* toml_realloc(void *p, size_t size);
|
||||
void toml_free(void *p);
|
||||
void* toml_malloc(u64 size);
|
||||
void* toml_realloc(void* p, u64 size);
|
||||
void toml_free(void* p);
|
||||
|
||||
char* toml_strdup(const char *str);
|
||||
char* toml_strndup(const char *str, size_t n);
|
||||
int toml_vasprintf(char **str, const char *format, va_list args);
|
||||
int toml_asprintf(char **str, const char *format, ...);
|
||||
char* toml_strdup(cstr str);
|
||||
char* toml_strndup(cstr str, u64 n);
|
||||
i32 toml_vasprintf(char** str, cstr format, va_list args);
|
||||
i32 toml_asprintf(char** str, cstr format, ...);
|
||||
|
||||
const TomlErr* toml_err(void);
|
||||
void toml_err_clear(void);
|
||||
|
||||
TomlString* toml_string_new(void);
|
||||
TomlString* toml_string_from_str(const char *str);
|
||||
TomlString* toml_string_from_nstr(const char *str, size_t len);
|
||||
void toml_string_append_char(TomlString *self, char ch);
|
||||
void toml_string_append_str(TomlString *self, const char *str);
|
||||
void toml_string_append_nstr(TomlString *self, const char *str, size_t len);
|
||||
TomlString* toml_string_clone(const TomlString *self);
|
||||
void toml_string_free(TomlString *self);
|
||||
int toml_string_equals(const TomlString *self, const TomlString *other);
|
||||
TomlString* toml_string_from_str(cstr str);
|
||||
TomlString* toml_string_from_nstr(cstr str, u64 len);
|
||||
void toml_string_append_char(TomlString* self, char ch);
|
||||
void toml_string_append_str(TomlString* self, cstr str);
|
||||
void toml_string_append_nstr(TomlString* self, cstr str, u64 len);
|
||||
TomlString* toml_string_clone(const TomlString* self);
|
||||
void toml_string_free(TomlString* self);
|
||||
i32 toml_string_equals(const TomlString* self, const TomlString* other);
|
||||
|
||||
TomlTable* toml_table_new(void);
|
||||
void toml_table_free(TomlTable *self);
|
||||
void toml_table_free(TomlTable* self);
|
||||
|
||||
void toml_table_set_by_string(TomlTable *self, TomlString *key, TomlValue *value);
|
||||
TomlValue *toml_table_get_by_string(const TomlTable *self, const TomlString *key);
|
||||
void toml_table_set(TomlTable *self, const char *key, TomlValue *value);
|
||||
void toml_table_setn(TomlTable *self, const char *key, size_t key_len, TomlValue *value);
|
||||
TomlValue* toml_table_get(const TomlTable *self, const char *key);
|
||||
TomlTable* toml_table_get_as_table(const TomlTable *self, const char *key);
|
||||
TomlArray* toml_table_get_as_array(const TomlTable *self, const char *key);
|
||||
TomlString* toml_table_get_as_string(const TomlTable *self, const char *key);
|
||||
#if defined(_MSC_VER) || defined(__APPLE__)
|
||||
long long toml_table_get_as_integer(const TomlTable *self, const char *key);
|
||||
#else
|
||||
long toml_table_get_as_integer(const TomlTable *self, const char *key);
|
||||
#endif
|
||||
double toml_table_get_as_float(const TomlTable *self, const char *key);
|
||||
const struct tm* toml_table_get_as_datetime(const TomlTable *self, const char *key);
|
||||
int toml_table_get_as_boolean(const TomlTable *self, const char *key);
|
||||
TomlValue* toml_table_getn(const TomlTable *self, const char *key, size_t key_len);
|
||||
void toml_table_set_by_string(TomlTable* self, TomlString* key, TomlValue* value);
|
||||
TomlValue* toml_table_get_by_string(const TomlTable* self, const TomlString* key);
|
||||
void toml_table_set(TomlTable* self, cstr key, TomlValue* value);
|
||||
void toml_table_setn(TomlTable* self, cstr key, u64 key_len, TomlValue* value);
|
||||
TomlValue* toml_table_get(const TomlTable* self, cstr key);
|
||||
TomlTable* toml_table_get_as_table(const TomlTable* self, cstr key);
|
||||
TomlArray* toml_table_get_as_array(const TomlTable* self, cstr key);
|
||||
TomlString* toml_table_get_as_string(const TomlTable* self, cstr key);
|
||||
i64 toml_table_get_as_integer(const TomlTable* self, cstr key);
|
||||
f64 toml_table_get_as_float(const TomlTable* self, cstr key);
|
||||
const struct tm* toml_table_get_as_datetime(const TomlTable* self, cstr key);
|
||||
i32 toml_table_get_as_boolean(const TomlTable* self, cstr key);
|
||||
TomlValue* toml_table_getn(const TomlTable* self, cstr key, u64 key_len);
|
||||
|
||||
TomlTableIter toml_table_iter_new(TomlTable *table);
|
||||
TomlKeyValue* toml_table_iter_get(TomlTableIter *self);
|
||||
int toml_table_iter_has_next(TomlTableIter *self);
|
||||
void toml_table_iter_next(TomlTableIter *self);
|
||||
TomlTableIter toml_table_iter_new(TomlTable* table);
|
||||
TomlKeyValue* toml_table_iter_get(TomlTableIter* self);
|
||||
i32 toml_table_iter_has_next(TomlTableIter* self);
|
||||
void toml_table_iter_next(TomlTableIter* self);
|
||||
|
||||
TomlArray* toml_array_new(void);
|
||||
void toml_array_free(TomlArray *self);
|
||||
void toml_array_append(TomlArray *self, TomlValue *value);
|
||||
void toml_array_free(TomlArray* self);
|
||||
void toml_array_append(TomlArray* self, TomlValue* value);
|
||||
|
||||
TomlValue* toml_value_new(TomlType type);
|
||||
TomlValue* toml_value_new_string(TomlType type);
|
||||
TomlValue* toml_value_new_table(void);
|
||||
TomlValue* toml_value_new_array(void);
|
||||
#if defined(_MSC_VER) || defined(__APPLE__)
|
||||
TomlValue *toml_value_new_integer(long long integer);
|
||||
#else
|
||||
TomlValue *toml_value_new_integer(long integer);
|
||||
#endif
|
||||
TomlValue* toml_value_new_float(double flt);
|
||||
TomlValue* toml_value_new_integer(i64 integer);
|
||||
TomlValue* toml_value_new_float(f64 flt);
|
||||
TomlValue* toml_value_new_datetime(void);
|
||||
TomlValue* toml_value_new_boolean(int boolean);
|
||||
TomlValue* toml_value_from_str(const char *str);
|
||||
TomlValue* toml_value_from_nstr(const char *str, size_t len);
|
||||
void toml_value_free(TomlValue *self);
|
||||
TomlValue* toml_value_new_boolean(i32 boolean);
|
||||
TomlValue* toml_value_from_str(cstr str);
|
||||
TomlValue* toml_value_from_nstr(cstr str, u64 len);
|
||||
void toml_value_free(TomlValue* self);
|
||||
|
||||
TomlTable* toml_load_str(const char *str);
|
||||
TomlTable* toml_load_nstr(const char *str, size_t len);
|
||||
TomlTable* toml_load_file(FILE *file);
|
||||
TomlTable* toml_load_filename(const char *filename);
|
||||
TomlTable* toml_load_str(cstr str);
|
||||
TomlTable* toml_load_nstr(cstr str, u64 len);
|
||||
TomlTable* toml_load_file(FILE* file);
|
||||
TomlTable* toml_load_filename(cstr filename);
|
||||
|
||||
/* TODO: implement dump functions
|
||||
char *toml_dump_str(const TomlTable *self, TomlErr *err);
|
||||
TomlString *toml_dump_nstr(const TomlTable *self, TomlErr *err);
|
||||
void toml_dump_file(const TomlTable *self, FILE *file, TomlErr *err);
|
||||
char* toml_dump_str(const TomlTable* self, TomlErr *err);
|
||||
TomlString* toml_dump_nstr(const TomlTable* self, TomlErr *err);
|
||||
void toml_dump_file(const TomlTable* self, FILE* file, TomlErr *err);
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user