From c021082abcc9d94c2e94679f6729265fe65529a3 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Sun, 4 Jun 2023 09:51:15 +0200 Subject: cooker: Generic attributes and ATTR_SIZE Signed-off-by: Stefano Brivio --- cooker/gluten.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'cooker/gluten.c') diff --git a/cooker/gluten.c b/cooker/gluten.c index a488dfd..01c2369 100644 --- a/cooker/gluten.c +++ b/cooker/gluten.c @@ -123,6 +123,36 @@ struct gluten_offset gluten_get_tag(struct gluten_ctx *g, const char *name) return g->tags[0].offset; /* Pro forma, not actually happening */ } +void gluten_add_attr(struct gluten_ctx *g, enum attr_type type, intptr_t id, + union value v) +{ + int i; + + for (i = 0; i < ATTRS_MAX && g->attrs[i].id; i++); + if (i == ATTRS_MAX) + die("Too many attributes"); + + g->attrs[i].type = type; + g->attrs[i].id = id; + g->attrs[i].v = v; + + debug(" attribute '%p' set", id); +} + +union value gluten_get_attr(struct gluten_ctx *g, enum attr_type type, + intptr_t id) +{ + int i; + + for (i = 0; i < ATTRS_MAX && g->attrs[i].type; i++) { + if (g->attrs[i].type == type && g->attrs[i].id == id) + return g->attrs[i].v; + } + + die(" attribute '%p' not found", id); + return g->attrs[0].v; /* Pro forma, not actually happening */ +} + /** * gluten_init() - Initialise gluten structures and layout * @g: gluten context -- cgit v1.2.3