aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/main.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-04-19 22:44:11 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-04-20 09:14:41 -0600
commit9099adbbe6fffcd7510b31efc8e547da7fa24f65 (patch)
tree96535c4292d14ca1e5315d387f0282f78cd7167a /swaynag/main.c
parentipc: fix criteria for emitting bar_state_update (diff)
downloadsway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.tar.gz
sway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.tar.zst
sway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.zip
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.c19
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) {
63 } 63 }
64 64
65 if (argc > 1) { 65 if (argc > 1) {
66 struct swaynag_type *type_args; 66 struct swaynag_type *type_args = swaynag_type_new("<args>");
67 type_args = calloc(1, sizeof(struct swaynag_type));
68 type_args->name = strdup("<args>");
69 list_add(types, type_args); 67 list_add(types, type_args);
70 68
71 int result = swaynag_parse_options(argc, argv, &swaynag, types, 69 int result = swaynag_parse_options(argc, argv, &swaynag, types,
@@ -86,15 +84,14 @@ int main(int argc, char **argv) {
86 swaynag.type = swaynag_type_get(types, "error"); 84 swaynag.type = swaynag_type_get(types, "error");
87 } 85 }
88 86
89 // Construct a new type using the config defaults as base, then merging 87 // Construct a new type with the defaults as the base, the general config
90 // config type defaults on top, then merging arguments on top of that, and 88 // on top of that, followed by the type config, and finally any command
91 // finally merging defaults on top. 89 // line arguments
92 struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type)); 90 struct swaynag_type *type = swaynag_type_new(swaynag.type->name);
93 type->name = strdup(swaynag.type->name);
94 swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
95 swaynag_type_merge(type, swaynag.type);
96 swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
97 swaynag_type_merge(type, swaynag_type_get(types, "<defaults>")); 91 swaynag_type_merge(type, swaynag_type_get(types, "<defaults>"));
92 swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
93 swaynag_type_merge(type, swaynag.type);
94 swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
98 swaynag.type = type; 95 swaynag.type = type;
99 96
100 swaynag_types_free(types); 97 swaynag_types_free(types);