diff options
author | Brian Ashworth <[email protected]> | 2019-04-19 22:44:11 -0400 |
---|---|---|
committer | Drew DeVault <[email protected]> | 2019-04-20 09:14:41 -0600 |
commit | 9099adbbe6fffcd7510b31efc8e547da7fa24f65 (patch) | |
tree | 96535c4292d14ca1e5315d387f0282f78cd7167a /swaynag/main.c | |
parent | 59d9a991b425f7cf1ea05a1def7632fa4395c5a7 (diff) |
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.
Diffstat (limited to 'swaynag/main.c')
-rw-r--r-- | swaynag/main.c | 19 |
1 files changed, 8 insertions, 11 deletions
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("<args>"); + struct swaynag_type *type_args = swaynag_type_new("<args>"); 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, "<args>")); - swaynag_type_merge(type, swaynag.type); - swaynag_type_merge(type, swaynag_type_get(types, "<config>")); + // 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, "<defaults>")); + swaynag_type_merge(type, swaynag_type_get(types, "<config>")); + swaynag_type_merge(type, swaynag.type); + swaynag_type_merge(type, swaynag_type_get(types, "<args>")); swaynag.type = type; swaynag_types_free(types); |