[waffle] [PATCH 14/17] core: Add func wcore_attrib_list_pop()
Chad Versace
chad.versace at intel.com
Sun Jan 4 14:03:07 PST 2015
This is useful for removing attributes as they are parsed.
Signed-off-by: Chad Versace <chad.versace at intel.com>
---
src/waffle/core/wcore_attrib_list.c | 40 +++++++++++++++++++++++++++++++++++++
src/waffle/core/wcore_attrib_list.h | 6 ++++++
2 files changed, 46 insertions(+)
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,
--
2.2.0
More information about the waffle
mailing list