Format code

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-07-26 00:22:28 +03:00
parent 90a6e58dca
commit ae8d2907fc
3 changed files with 950 additions and 890 deletions

26
.clang-format Normal file
View File

@@ -0,0 +1,26 @@
UseTab: ForIndentation
TabWidth: 4
IndentWidth: 4
ColumnLimit: 80
AlignEscapedNewlines: DontAlign
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
BasedOnStyle: WebKit
BraceWrapping:
AfterFunction: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakConstructorInitializers: BeforeComma
IndentPPDirectives: AfterHash
IndentRequiresClause: false
InsertNewlineAtEOF: true
LineEnding: LF
NamespaceIndentation: None
PointerAlignment: Right # east pointer
QualifierAlignment: Right # east const
RemoveSemicolon: true
RequiresClausePosition: WithFollowing
RequiresExpressionIndentation: OuterScope
SpaceAfterTemplateKeyword: false

View File

@@ -14,8 +14,8 @@ typedef struct dcfg_Instance dcfg_Instance;
// Type definitions
typedef struct dcfg_StringView {
char const *data;
size_t size;
char const *data;
size_t size;
} dcfg_StringView;
typedef void *(*dcfg_AllocFn)(size_t); // This should automatically zero memory.
@@ -26,28 +26,28 @@ typedef int (*dcfg_FseekFn)(void *, size_t, int);
typedef long (*dcfg_FtellFn)(void *);
typedef struct dcfg_InstanceCreateInfo {
// Default using libc
dcfg_AllocFn alloc;
dcfg_FreeFn free;
// Default using libc
dcfg_AllocFn alloc;
dcfg_FreeFn free;
// If POSIX support is enabled, all of those are defined if NULL.
dcfg_RealpathFn realpath;
dcfg_FopenFn fopen;
dcfg_FseekFn fseek;
dcfg_FtellFn ftell;
// If POSIX support is enabled, all of those are defined if NULL.
dcfg_RealpathFn realpath;
dcfg_FopenFn fopen;
dcfg_FseekFn fseek;
dcfg_FtellFn ftell;
} dcfg_InstanceCreateInfo;
typedef enum dcfg_ValueKind {
dcfg_ValueType_Nil,
dcfg_ValueType_Boolean,
dcfg_ValueType_Integer,
dcfg_ValueType_Real,
dcfg_ValueType_String,
dcfg_ValueType_Path,
dcfg_ValueType_Object,
dcfg_ValueType_Array,
dcfg_ValueType_Function,
dcfg_ValueType_FunctionCall,
dcfg_ValueType_Nil,
dcfg_ValueType_Boolean,
dcfg_ValueType_Integer,
dcfg_ValueType_Real,
dcfg_ValueType_String,
dcfg_ValueType_Path,
dcfg_ValueType_Object,
dcfg_ValueType_Array,
dcfg_ValueType_Function,
dcfg_ValueType_FunctionCall,
} dcfg_ValueType;
dcfg_Instance *dcfg_make_instance(dcfg_InstanceCreateInfo const *create_info);
@@ -57,25 +57,24 @@ char const *dcfg_last_error(dcfg_Instance *instance);
// File path gets copied internally to instance to a Value * -> path hashmap for
// evaluation.
dcfg_Value *dcfg_parse(dcfg_Instance *instance,
dcfg_StringView const file_path);
dcfg_Value *dcfg_parse(
dcfg_Instance *instance, dcfg_StringView const file_path);
void dcfg_destroy(dcfg_Value *value);
bool dcfg_serialize_value(dcfg_Value *value, dcfg_StringView *out_sv);
// Value type checking
dcfg_ValueType dcfg_Value_type_ex(dcfg_Value *value, bool evaluate);
static inline dcfg_ValueType dcfg_Value_type(dcfg_Value *value) {
return dcfg_Value_type_ex(value, true);
static inline dcfg_ValueType dcfg_Value_type(dcfg_Value *value)
{
return dcfg_Value_type_ex(value, true);
}
// Value getters
bool dcfg_Value_get_object_field_ex(dcfg_Value *value,
dcfg_StringView const key,
dcfg_Value **out_value,
bool const evaluate);
dcfg_StringView const key, dcfg_Value **out_value, bool const evaluate);
bool dcfg_Value_get_array_item_ex(dcfg_Value *value, size_t const index,
dcfg_Value **out_value, bool const evaluate);
dcfg_Value **out_value, bool const evaluate);
bool dcfg_Value_get_boolean(dcfg_Value *value, bool *out_value);
bool dcfg_Value_get_integer(dcfg_Value *value, int64_t *out_value);
@@ -83,22 +82,22 @@ bool dcfg_Value_get_real(dcfg_Value *value, double *out_value);
bool dcfg_Value_get_string(dcfg_Value *value, dcfg_StringView *out_sv);
bool dcfg_Value_get_path(dcfg_Value *value, dcfg_StringView *out_sv);
bool dcfg_Value_get_object_keys(dcfg_Value *value, size_t const capacity,
size_t *out_count, dcfg_StringView *out_keys);
size_t *out_count, dcfg_StringView *out_keys);
bool dcfg_Value_get_array_size(dcfg_Value *value, size_t *out_size);
static inline bool dcfg_Value_get_object_field(dcfg_Value *value,
dcfg_StringView const key,
dcfg_Value **out_value) {
return dcfg_Value_get_object_field_ex(value, key, out_value, true);
static inline bool dcfg_Value_get_object_field(
dcfg_Value *value, dcfg_StringView const key, dcfg_Value **out_value)
{
return dcfg_Value_get_object_field_ex(value, key, out_value, true);
}
static inline bool dcfg_Value_get_array_item(dcfg_Value *value,
size_t const index,
dcfg_Value **out_value) {
return dcfg_Value_get_array_item_ex(value, index, out_value, true);
static inline bool dcfg_Value_get_array_item(
dcfg_Value *value, size_t const index, dcfg_Value **out_value)
{
return dcfg_Value_get_array_item_ex(value, index, out_value, true);
}
bool dcfg_call_function(dcfg_Value *function, dcfg_Value **args,
size_t arg_count, dcfg_Value **out_value);
size_t arg_count, dcfg_Value **out_value);
bool dcfg_Value_evaluate(dcfg_Value *value, dcfg_Value **out_value);
#ifdef __cplusplus

1739
src/dcfg.c

File diff suppressed because it is too large Load Diff