From 0f8f21510a282db03f53b40078335fd2d8bc2424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 22:48:23 +0100 Subject: [PATCH] particle/empty: expose info through the new struct particle_info struct --- config-verify.c | 29 ++++++++++++++++++++++++----- config.c | 11 ++--------- particles/empty.c | 22 +++++++++++++++++++--- particles/empty.h | 3 +-- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/config-verify.c b/config-verify.c index 6597b39..69735b5 100644 --- a/config-verify.c +++ b/config-verify.c @@ -9,6 +9,8 @@ #include "plugin.h" #include "tllist.h" +#include "particles/empty.h" + const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) { @@ -315,10 +317,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) {"right-margin", false, &conf_verify_int}, \ {"on-click", false, &conf_verify_string}, - static const struct attr_info empty[] = { - COMMON_ATTRS - }; - static const struct attr_info list[] = { {"items", true, &verify_list_items}, {"spacing", false, &conf_verify_int}, @@ -363,12 +361,18 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) #undef COMMON_ATTRS + static const struct { + const char *name; + const struct particle_info *info; + } particles_v2[] = { + {"empty", &particle_empty}, + }; + static const struct { const char *name; const struct attr_info *attrs; size_t count; } particles[] = { - {"empty", empty, sizeof(empty) / sizeof(empty[0])}, {"list", list, sizeof(list) / sizeof(list[0])}, {"map", map, sizeof(map) / sizeof(map[0])}, {"progress-bar", progress_bar, sizeof(progress_bar) / sizeof(progress_bar[0])}, @@ -376,6 +380,21 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) {"string", string, sizeof(string) / sizeof(string[0])}, }; + for (size_t i = 0; i < sizeof(particles_v2) / sizeof(particles_v2[0]); i++) { + if (strcmp(particles_v2[i].name, particle_name) != 0) + continue; + + if (!conf_verify_dict(chain_push(chain, particle_name), values, + particles_v2[i].info->attrs, + particles_v2[i].info->attr_count)) + { + return false; + } + + chain_pop(chain); + return true; + } + for (size_t i = 0; i < sizeof(particles) / sizeof(particles[0]); i++) { if (strcmp(particles[i].name, particle_name) != 0) continue; diff --git a/config.c b/config.c index e18660c..74f970a 100644 --- a/config.c +++ b/config.c @@ -137,14 +137,6 @@ deco_from_config(const struct yml_node *node) return NULL; } -static struct particle * -particle_empty_from_config(const struct yml_node *node, - const struct font *parent_font, - int left_margin, int right_margin, - const char *on_click_template) -{ - return particle_empty_new(left_margin, right_margin, on_click_template); -} static struct particle * particle_string_from_config(const struct yml_node *node, @@ -323,8 +315,9 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font) struct particle *ret = NULL; if (strcmp(type, "empty") == 0) - ret = particle_empty_from_config( + ret = particle_empty.from_conf( pair.value, parent_font, left, right, on_click_template); + else if (strcmp(type, "string") == 0) ret = particle_string_from_config( pair.value, parent_font, left, right, on_click_template); diff --git a/particles/empty.c b/particles/empty.c index ead1dfc..0ab63a2 100644 --- a/particles/empty.c +++ b/particles/empty.c @@ -2,6 +2,8 @@ #include +#include "../config.h" + static int begin_expose(struct exposable *exposable) { @@ -29,9 +31,8 @@ instantiate(const struct particle *particle, const struct tag_set *tags) return exposable; } -struct particle * -particle_empty_new(int left_margin, int right_margin, - const char *on_click_template) +static struct particle * +empty_new(int left_margin, int right_margin, const char *on_click_template) { struct particle *particle = particle_common_new( left_margin, right_margin, on_click_template); @@ -39,3 +40,18 @@ particle_empty_new(int left_margin, int right_margin, particle->instantiate = &instantiate; return particle; } + +static struct particle * +from_conf(const struct yml_node *node, const struct font *parent_font, + int left_margin, int right_margin, const char *on_click_template) +{ + return empty_new(left_margin, right_margin, on_click_template); +} + +const struct particle_info particle_empty = { + .from_conf = &from_conf, + .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 0, + .attrs = { + PARTICLE_COMMON_ATTRS, + }, +}; diff --git a/particles/empty.h b/particles/empty.h index b353f3e..5e2f567 100644 --- a/particles/empty.h +++ b/particles/empty.h @@ -1,5 +1,4 @@ #pragma once #include "../particle.h" -struct particle *particle_empty_new( - int left_margin, int right_margin, const char *on_click_template); +extern const struct particle_info particle_empty;