summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Versace <chad.versace@intel.com>2015-01-04 13:36:32 -0800
committerChad Versace <chad.versace@intel.com>2015-01-27 09:36:06 -0800
commit793dc9b7b81cd110d61af2027284ba4eb41d7f87 (patch)
tree9178cbdcb6a23e4dfbc275fae35c4629fe12fbe3
parent7a052775c53eeeab65ae004b522c71f46c1a70f5 (diff)
core: Add func wcore_attrib_list_pop()
This is useful for removing attributes as they are parsed. Signed-off-by: Chad Versace <chad.versace@intel.com> Tested-by: Emil Velikov <emil.l.velikov@gmail.com> (msvc/wgl) Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r--src/waffle/core/wcore_attrib_list.c40
-rw-r--r--src/waffle/core/wcore_attrib_list.h6
2 files changed, 46 insertions, 0 deletions
diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c
index 6446ca0..985e13a 100644
--- a/src/waffle/core/wcore_attrib_list.c
+++ b/src/waffle/core/wcore_attrib_list.c
@@ -204,3 +204,43 @@ wcore_attrib_list_copy(const intptr_t attrib_list[])
return copy;
}
+
+bool
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value)
+{
+ // Address of key in attrib_list.
+ intptr_t *key_addr = NULL;
+
+ // Address of the terminal zero in attrib_list.
+ intptr_t *end_addr = NULL;
+
+ if (attrib_list == NULL) {
+ return false;
+ }
+
+ for (intptr_t *i = attrib_list; *i != 0; i += 2) {
+ if (i[0] == key) {
+ key_addr = i;
+ *value = i[1];
+ break;
+ }
+ }
+
+ if (!key_addr) {
+ return false;
+ }
+
+ end_addr = key_addr + 2; // Step to next pair.
+ while (*end_addr != 0) {
+ end_addr += 2; // Step to next pair.
+ }
+
+ // Move all key/value pairs located at or above (key_addr + 2), and
+ // move the terminal null too.
+ memmove(key_addr, key_addr + 2,
+ sizeof(intptr_t) * (end_addr - key_addr - 1));
+ return true;
+}
diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h
index d4a771b..561fb1d 100644
--- a/src/waffle/core/wcore_attrib_list.h
+++ b/src/waffle/core/wcore_attrib_list.h
@@ -54,6 +54,12 @@ wcore_attrib_list_get_with_default(
intptr_t default_value);
bool
+wcore_attrib_list_pop(
+ intptr_t attrib_list[],
+ intptr_t key,
+ intptr_t *value);
+
+bool
wcore_attrib_list_update(
intptr_t *attrib_list,
intptr_t key,