summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrmr2025-10-08 19:02:15 -0400
committerwrmr2025-10-08 19:02:15 -0400
commit46a9842938333a58a051d031e724f35f5caf56de (patch)
tree1cea341b9e15875df6712950faa3628076cc9d17
parent005e37ec1015fc0dbf7ed68e78a104dc6566ff28 (diff)
compress config property handling a little
-rw-r--r--main.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/main.c b/main.c
index 16b632c..568dd78 100644
--- a/main.c
+++ b/main.c
@@ -155,6 +155,9 @@ typedef struct {
typedef struct {
struct {
+ int help;
+ } cbink;
+ struct {
int pfp, pronouns, date;
const char *datefmt;
} post;
@@ -956,22 +959,32 @@ int prop_cstr(Str name, Str key, Str value, const char **ptr, Arena *perm) {
return 1;
}
+#define PROP_BOOL(s, p) if (prop_bool(S(s), k, v, p)) return 0
+#define PROP_INT(s, p) if (prop_int(S(s), k, v, p)) return 0
+#define PROP_CSTR(s, p) if (prop_cstr(S(s), k, v, p, perm)) return 0
+
+int sect_cbink(Str k, Str v, Arena *perm) {
+ (void)perm;
+ PROP_BOOL("help", &opt.cbink.help);
+ return -1;
+}
+
int sect_margin(Str k, Str v, Arena *perm) {
(void)perm;
- if (prop_int(S("left"), k, v, &opt.margin.left)) return 0;
- if (prop_int(S("right"), k, v, &opt.margin.right)) return 0;
- if (prop_int(S("top"), k, v, &opt.margin.top)) return 0;
- if (prop_int(S("bottom"), k, v, &opt.margin.bottom)) return 0;
- if (prop_int(S("text.x"), k, v, &opt.margin.text_x)) return 0;
- if (prop_int(S("text.y"), k, v, &opt.margin.text_y)) return 0;
+ PROP_INT("left", &opt.margin.left);
+ PROP_INT("right", &opt.margin.right);
+ PROP_INT("top", &opt.margin.top);
+ PROP_INT("bottom", &opt.margin.bottom);
+ PROP_INT("text.x", &opt.margin.text_x);
+ PROP_INT("text.y", &opt.margin.text_y);
return -1;
}
int sect_post(Str k, Str v, Arena *perm) {
- if (prop_cstr(S("datefmt"), k, v, &opt.post.datefmt, perm)) return 0;
- if (prop_bool(S("pfp"), k, v, &opt.post.pfp)) return 0;
- if (prop_bool(S("pronouns"), k, v, &opt.post.pronouns)) return 0;
- if (prop_bool(S("date"), k, v, &opt.post.date)) return 0;
+ PROP_CSTR("datefmt", &opt.post.datefmt);
+ PROP_BOOL("pfp", &opt.post.pfp);
+ PROP_BOOL("pronouns", &opt.post.pronouns);
+ PROP_BOOL("date", &opt.post.date);
return -1;
}
@@ -1042,6 +1055,7 @@ int sect_color(Str k, Str v, Arena *perm) {
}
Section sections[] = {
+ { "cbink", &sect_cbink },
{ "margin", &sect_margin },
{ "post", &sect_post },
{ "color", &sect_color },
@@ -1217,6 +1231,7 @@ resize:
free(posts.data);
regfree(&re_mention);
+ arena_free(&cfg_arena);
arena_free(&post_arena);
arena_free(&gfx_arena);
arena_free(&temp_arena);