From 9099adbbe6fffcd7510b31efc8e547da7fa24f65 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 19 Apr 2019 22:44:11 -0400 Subject: swaynag: revamp type configs This revamps the type configs for swaynag. All sizing attributes for swaynag are now `ssize_t` instead of `uint32_t` to allow for a default value of `-1`, which allows for `0` to be a valid value. Additionally, the initialization of the type configs has been changed from a simple calloc to use a new function `swaynag_type_new`. `swaynag_type_new` calloc's the memory, checks for an allocation failure, sets the name, and all sizes to -1. The layering order has also been changed to default, general config, type config, and as highest priority command line arguments. Finally, `swaynag_type_merge` has been modified to handle the layering and sizing changes. --- swaynag/main.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'swaynag/main.c') diff --git a/swaynag/main.c b/swaynag/main.c index 4a785f40..542e3472 100644 --- a/swaynag/main.c +++ b/swaynag/main.c @@ -63,9 +63,7 @@ int main(int argc, char **argv) { } if (argc > 1) { - struct swaynag_type *type_args; - type_args = calloc(1, sizeof(struct swaynag_type)); - type_args->name = strdup(""); + struct swaynag_type *type_args = swaynag_type_new(""); list_add(types, type_args); int result = swaynag_parse_options(argc, argv, &swaynag, types, @@ -86,15 +84,14 @@ int main(int argc, char **argv) { swaynag.type = swaynag_type_get(types, "error"); } - // Construct a new type using the config defaults as base, then merging - // config type defaults on top, then merging arguments on top of that, and - // finally merging defaults on top. - struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type)); - type->name = strdup(swaynag.type->name); - swaynag_type_merge(type, swaynag_type_get(types, "")); - swaynag_type_merge(type, swaynag.type); - swaynag_type_merge(type, swaynag_type_get(types, "")); + // Construct a new type with the defaults as the base, the general config + // on top of that, followed by the type config, and finally any command + // line arguments + struct swaynag_type *type = swaynag_type_new(swaynag.type->name); swaynag_type_merge(type, swaynag_type_get(types, "")); + swaynag_type_merge(type, swaynag_type_get(types, "")); + swaynag_type_merge(type, swaynag.type); + swaynag_type_merge(type, swaynag_type_get(types, "")); swaynag.type = type; swaynag_types_free(types); -- cgit v1.2.3