moved functions code to separate files

This commit is contained in:
2025-11-26 16:26:01 +05:00
parent 52870920c1
commit 048542d079
28 changed files with 1594 additions and 1511 deletions

View File

@@ -9,30 +9,28 @@ extern "C" {
#endif
#include <time.h>
#include "tlibc/std.h"
#include "tlibc/tlibc.h"
#include "tlibc/time.h"
#include "tlibc/errors.h"
#include "tlibc/string/str.h"
#include "tlibc/collections/HashMap.h"
typedef struct tm TomlDateTime;
typedef DateTime TomlDateTime;
typedef HashMap(TomlValue) TomlTable;
typedef enum {
TOML_OK,
TOML_ERR,
TOML_ERR_OS,
TOML_ERR_NOMEM,
TOML_ERR_SYNTAX,
TOML_ERR_UNICODE
} TomlErrCode;
typedef struct {
TomlErrCode code;
NULLABLE(char*) message;
} TomlErr;
typedef enum TlibtomlError {
TLIBTOML_OK,
TLIBTOML_ERR,
TLIBTOML_ERR_OS,
TLIBTOML_ERR_NOMEM,
TLIBTOML_ERR_SYNTAX,
TLIBTOML_ERR_UNICODE
} TlibtomlError;
ErrorCodePage_declare(TLIBTOML);
typedef struct TomlValue TomlValue;
typedef struct {
typedef struct TomlArray {
TomlValue* elements;
u64 len;
u64 _capacity;
@@ -40,70 +38,94 @@ typedef struct {
typedef enum {
TOML_INVALID_TYPE,
TOML_TABLE,
TOML_ARRAY,
TOML_STRING,
TOML_INTEGER,
TOML_FLOAT,
TOML_DATETIME,
TOML_BOOLEAN,
TLIBTOML_INVALID_TYPE,
TLIBTOML_TABLE,
TLIBTOML_ARRAY,
TLIBTOML_STRING,
TLIBTOML_INTEGER,
TLIBTOML_FLOAT,
TLIBTOML_DATETIME,
TLIBTOML_BOOLEAN,
} TomlType;
struct TomlValue {
TomlType type;
union {
TomlTable* table;
TomlArray* array;
str s;
i64 i;
f64 f;
TomlDateTime* dt;
bool b;
str* s;
TomlArray* array;
TomlTable* table;
TomlDateTime* dt;
} value;
};
const TomlErr* toml_err(void);
void toml_err_clear(void);
//////////////////////////////////////////////////////////////////////////////
// //
// toml.c //
// //
//////////////////////////////////////////////////////////////////////////////
TomlTable* toml_table_new(void);
void toml_table_free(TomlTable* self);
void toml_table_set(TomlTable* self, str key, TomlValue value);
TomlValue* toml_table_get(const TomlTable* self, str key);
TomlTable* toml_table_get_table(const TomlTable* self, str key);
TomlArray* toml_table_get_array(const TomlTable* self, str key);
str toml_table_get_str(const TomlTable* self, str key);
i64 toml_table_get_integer(const TomlTable* self, str key);
f64 toml_table_get_float(const TomlTable* self, str key);
TomlDateTime* toml_table_get_datetime(const TomlTable* self, str key);
bool toml_table_get_bool(const TomlTable* self, str key);
TomlArray* toml_array_new(void);
void toml_array_free(TomlArray* self);
void toml_array_append(TomlArray* self, TomlValue value);
TomlValue TomlValue_new(TomlType type);
TomlValue TomlValue_new_string(TomlType type);
TomlValue TomlValue_new_table(void);
TomlValue TomlValue_new_array(void);
TomlValue TomlValue_new_integer(i64 integer);
TomlValue TomlValue_new_float(f64 flt);
TomlValue TomlValue_new_datetime(void);
TomlValue TomlValue_new_bool(bool b);
TomlValue TomlValue_from_str(str s);
void TomlValue_destroy(TomlValue* self);
TomlTable* toml_load_str(str s);
TomlTable* toml_load_file(FILE* file);
TomlTable* toml_load_filename(cstr filename);
Result(TomlTable*) toml_load_str(str s);
Result(TomlTable*) toml_load_file(FILE* file);
Result(TomlTable*) toml_load_filename(cstr filename);
/* TODO: implement dump functions
str toml_dump_str(const TomlTable* self, TomlErr *err);
void toml_dump_file(const TomlTable* self, FILE* file, TomlErr *err);
*/
//////////////////////////////////////////////////////////////////////////////
// //
// TomlTable.c //
// //
//////////////////////////////////////////////////////////////////////////////
TomlTable* TomlTable_new(void);
void TomlTable_free(TomlTable* self);
void TomlTable_set(TomlTable* self, str key, TomlValue value);
NULLABLE(TomlValue*) TomlTable_get(const TomlTable* self, str key);
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key);
Result(TomlArray*) TomlTable_get_array(const TomlTable* self, str key);
Result(str*) TomlTable_get_str(const TomlTable* self, str key);
Result(i64) TomlTable_get_integer(const TomlTable* self, str key);
Result(f64) TomlTable_get_float(const TomlTable* self, str key);
Result(bool) TomlTable_get_bool(const TomlTable* self, str key);
Result(TomlDateTime*) TomlTable_get_datetime(const TomlTable* self, str key);
//////////////////////////////////////////////////////////////////////////////
// //
// TomlArray.c //
// //
//////////////////////////////////////////////////////////////////////////////
TomlArray* TomlArray_new(void);
void TomlArray_free(TomlArray* self);
void TomlArray_append(TomlArray* self, TomlValue value);
//////////////////////////////////////////////////////////////////////////////
// //
// TomlValue.c //
// //
//////////////////////////////////////////////////////////////////////////////
TomlValue TomlValue_new(TomlType type);
TomlValue TomlValue_new_table(void);
TomlValue TomlValue_new_array(void);
TomlValue TomlValue_new_integer(i64 integer);
TomlValue TomlValue_new_float(f64 flt);
TomlValue TomlValue_new_datetime(void);
TomlValue TomlValue_new_bool(bool b);
/// copies the string
TomlValue TomlValue_new_string(str s);
void TomlValue_destroy(TomlValue* self);
#ifdef __cplusplus
}
#endif