aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-07-04 11:37:25 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-07-04 11:37:25 +0200
commite4cff606fccdb7b8ac1c9bf5204a6b52e296bfe9 (patch)
tree43843689376e2a5f09da9ecdf5182149848980d5
parent5b429ff5fdb18ff5f37443aff96393ac950afe0d (diff)
downloadOFQT-e4cff606fccdb7b8ac1c9bf5204a6b52e296bfe9.tar.gz
OFQT-e4cff606fccdb7b8ac1c9bf5204a6b52e296bfe9.zip
store conditional
we do not have an opinion on if WIN32 is PC or Windows or whatever, we give you the tools
-rw-r--r--src/vdf/tests/files/registry.vdf5
-rw-r--r--src/vdf/vdf.c39
-rw-r--r--src/vdf/vdf.h2
3 files changed, 38 insertions, 8 deletions
diff --git a/src/vdf/tests/files/registry.vdf b/src/vdf/tests/files/registry.vdf
index 60bdfaf..7c9a1a7 100644
--- a/src/vdf/tests/files/registry.vdf
+++ b/src/vdf/tests/files/registry.vdf
@@ -22,6 +22,11 @@
"new\nline" "ab\ncd"
"back\\slash" "ab\\cd"
}
+ "conditionals"
+ {
+ "win32" "value" [$WIN32]
+ "x360" "value" [$X360]
+ }
}
}
}
diff --git a/src/vdf/vdf.c b/src/vdf/vdf.c
index 5b2f274..befe177 100644
--- a/src/vdf/vdf.c
+++ b/src/vdf/vdf.c
@@ -60,7 +60,7 @@ static char* local_strndup_escape(const char* s, size_t n)
return retval;
}
-static void puts_escaped(const char* s)
+static void print_escaped(const char* s)
{
while (*s)
{
@@ -100,6 +100,7 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size)
root_object->key = NULL;
root_object->parent = NULL;
root_object->type = VDF_TYPE_NONE;
+ root_object->conditional = NULL;
struct vdf_object* o = root_object;
@@ -177,6 +178,7 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size)
o = o->data.data_array.data_value[o->data.data_array.len];
o->key = NULL;
o->type = VDF_TYPE_NONE;
+ o->conditional = NULL;
}
}
else
@@ -203,6 +205,7 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size)
o = o->data.data_array.data_value[o->data.data_array.len];
o->key = NULL;
o->type = VDF_TYPE_NONE;
+ o->conditional = NULL;
break;
case CHAR_CLOSED_CURLY_BRACKET:
@@ -222,6 +225,7 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size)
o = o->data.data_array.data_value[o->data.data_array.len];
o->key = NULL;
o->type = VDF_TYPE_NONE;
+ o->conditional = NULL;
}
break;
@@ -234,10 +238,21 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size)
break;
case CHAR_OPEN_ANGLED_BRACKET:
- printf("%i\n", buf);
if (!buf)
+ {
+ struct vdf_object* prev = o->parent->data.data_array.data_value[o->parent->data.data_array.len-1];
+ assert(!prev->conditional);
+
+ buf = tail+1;
+
while (*tail != '\0' && *tail != CHAR_CLOSED_ANGLED_BRACKET)
++tail;
+
+ prev->conditional = local_strndup_escape(buf, tail-buf);
+
+ buf = NULL;
+ }
+
break;
default:
@@ -345,22 +360,22 @@ static void vdf_print_object_indent(struct vdf_object* o, int l)
printf("%s", spacing);
printf("\"");
- puts_escaped(o->key);
+ print_escaped(o->key);
printf("\"");
switch (o->type)
{
case VDF_TYPE_ARRAY:
- puts("");
+ printf("\n");
for (int k = 0; k < l; ++k)
printf("%s", spacing);
- puts("{");
+ printf("{\n");
for (size_t i = 0; i < o->data.data_array.len; ++i)
vdf_print_object_indent(o->data.data_array.data_value[i], l+1);
for (int k = 0; k < l; ++k)
printf("%s", spacing);
- puts("}");
+ printf("}");
break;
case VDF_TYPE_INT:
@@ -369,8 +384,8 @@ static void vdf_print_object_indent(struct vdf_object* o, int l)
case VDF_TYPE_STRING:
printf("\t\t\"");
- puts_escaped(o->data.data_string.str);
- printf("\"\n");
+ print_escaped(o->data.data_string.str);
+ printf("\"");
break;
default:
@@ -378,6 +393,11 @@ static void vdf_print_object_indent(struct vdf_object* o, int l)
assert(0);
break;
}
+
+ if (o->conditional)
+ printf("\t\t[%s]", o->conditional);
+
+ printf("\n");
}
void vdf_print_object(struct vdf_object* o)
@@ -414,5 +434,8 @@ void vdf_free_object(struct vdf_object* o)
if (o->key)
free(o->key);
+
+ if (o->conditional)
+ free(o->conditional);
free(o);
}
diff --git a/src/vdf/vdf.h b/src/vdf/vdf.h
index cf44c9c..a07d286 100644
--- a/src/vdf/vdf.h
+++ b/src/vdf/vdf.h
@@ -39,6 +39,8 @@ struct vdf_object
enum vdf_data_type type;
union vdf_data data;
+
+ char* conditional;
};
struct vdf_object* vdf_parse_buffer(const char*, size_t);