diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vdf/vdf.c | 38 | ||||
-rw-r--r-- | src/vdf/vdf.h | 35 |
2 files changed, 18 insertions, 55 deletions
diff --git a/src/vdf/vdf.c b/src/vdf/vdf.c index 2708a5d..10c3ed1 100644 --- a/src/vdf/vdf.c +++ b/src/vdf/vdf.c @@ -18,7 +18,6 @@ #define FMT_UNKNOWN_CHAR "Encountered Unknown Character %c (%li)\n" - struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size) { if (!buffer) @@ -69,12 +68,6 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size) { o->type = VDF_TYPE_INT; } - else if (len > 6 && len < 9 && (chars+digits) == len-1 && buf[0] == '#') - { - // TODO - //o->type = VDF_TYPE_COLOR; - o->type = VDF_TYPE_STRING; - } else { o->type = VDF_TYPE_STRING; @@ -230,9 +223,8 @@ struct vdf_object* vdf_object_index_array(struct vdf_object* o, size_t index) struct vdf_object* vdf_object_index_array_str(struct vdf_object* o, char* str) { - assert(o); - assert(str); - assert(o->type == VDF_TYPE_ARRAY); + if (!o || !str || o->type != VDF_TYPE_ARRAY) + return NULL; for (size_t i = 0; i < o->data.data_array.len; ++i) { @@ -283,26 +275,18 @@ static void vdf_print_object_indent(struct vdf_object* o, int l) puts("}"); break; - default: - case VDF_TYPE_NONE: - case VDF_TYPE_FLOAT: - case VDF_TYPE_PTR: // ? - case VDF_TYPE_COLOR: - assert(0); - break; - case VDF_TYPE_INT: - printf("\t\t\"%i\"\n", o->data.data_int); + printf("\t\t\"%lli\"\n", o->data.data_int); break; case VDF_TYPE_STRING: printf("\t\t\"%s\"\n", o->data.data_string.str); break; - case VDF_TYPE_WSTRING: + default: + case VDF_TYPE_NONE: assert(0); break; - } } @@ -326,22 +310,14 @@ void vdf_free_object(struct vdf_object* o) free(o->data.data_array.data_value); break; - default: - case VDF_TYPE_NONE: - case VDF_TYPE_INT: - case VDF_TYPE_FLOAT: - case VDF_TYPE_PTR: // ? - case VDF_TYPE_COLOR: - break; case VDF_TYPE_STRING: if (o->data.data_string.str) free(o->data.data_string.str); break; - case VDF_TYPE_WSTRING: - if (o->data.data_wstring.str) - free(o->data.data_wstring.str); + default: + case VDF_TYPE_NONE: break; } diff --git a/src/vdf/vdf.h b/src/vdf/vdf.h index d9755da..cf44c9c 100644 --- a/src/vdf/vdf.h +++ b/src/vdf/vdf.h @@ -13,11 +13,7 @@ enum vdf_data_type VDF_TYPE_NONE, VDF_TYPE_ARRAY, VDF_TYPE_STRING, - VDF_TYPE_INT, - VDF_TYPE_FLOAT, - VDF_TYPE_PTR, - VDF_TYPE_WSTRING, - VDF_TYPE_COLOR + VDF_TYPE_INT }; struct vdf_object; @@ -33,17 +29,7 @@ union vdf_data { size_t len; } data_string; - int data_int; - float data_float; - - void* data_ptr; // TYPE? - - struct { - wchar_t* str; - size_t len; - } data_wstring; - - uint32_t color; // RGBA + int64_t data_int; }; struct vdf_object @@ -55,18 +41,19 @@ struct vdf_object union vdf_data data; }; -struct vdf_object* vdf_parse_file(const char* path); +struct vdf_object* vdf_parse_buffer(const char*, size_t); +struct vdf_object* vdf_parse_file(const char*); -size_t vdf_object_get_array_length(struct vdf_object* o); -struct vdf_object* vdf_object_index_array(struct vdf_object* o, size_t index); -struct vdf_object* vdf_object_index_array_str(struct vdf_object* o, char* str); +size_t vdf_object_get_array_length(struct vdf_object*); +struct vdf_object* vdf_object_index_array(struct vdf_object*, size_t); +struct vdf_object* vdf_object_index_array_str(struct vdf_object*, char*); -const char* vdf_object_get_string(struct vdf_object* o); +const char* vdf_object_get_string(struct vdf_object*); -int vdf_object_get_int(struct vdf_object* o); +int vdf_object_get_int(struct vdf_object*); -void vdf_print_object(struct vdf_object* o); -void vdf_free_object(struct vdf_object* o); +void vdf_print_object(struct vdf_object*); +void vdf_free_object(struct vdf_object*); #ifdef __cplusplus } |