aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Manuel Stoeckl <code@mstoeckl.com>2021-02-02 19:54:35 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2021-02-04 09:49:06 +0100
commitcb3c7276324b5b0862088df9ffe5498998edae91 (patch)
treeb4576f3715e53300794f92e4c6339df0ac1e447a /sway/commands.c
parentxdg-foreign: add v1 and v2 implementations (diff)
downloadsway-cb3c7276324b5b0862088df9ffe5498998edae91.tar.gz
sway-cb3c7276324b5b0862088df9ffe5498998edae91.tar.zst
sway-cb3c7276324b5b0862088df9ffe5498998edae91.zip
Declare all struct cmd_handler arrays const
And make the functions handling these arrays use const types.
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/sway/commands.c b/sway/commands.c
index fe1e98b5..966b1fe3 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -42,7 +42,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
42} 42}
43 43
44/* Keep alphabetized */ 44/* Keep alphabetized */
45static struct cmd_handler handlers[] = { 45static const struct cmd_handler handlers[] = {
46 { "assign", cmd_assign }, 46 { "assign", cmd_assign },
47 { "bar", cmd_bar }, 47 { "bar", cmd_bar },
48 { "bindcode", cmd_bindcode }, 48 { "bindcode", cmd_bindcode },
@@ -98,7 +98,7 @@ static struct cmd_handler handlers[] = {
98}; 98};
99 99
100/* Config-time only commands. Keep alphabetized */ 100/* Config-time only commands. Keep alphabetized */
101static struct cmd_handler config_handlers[] = { 101static const struct cmd_handler config_handlers[] = {
102 { "default_orientation", cmd_default_orientation }, 102 { "default_orientation", cmd_default_orientation },
103 { "include", cmd_include }, 103 { "include", cmd_include },
104 { "swaybg_command", cmd_swaybg_command }, 104 { "swaybg_command", cmd_swaybg_command },
@@ -108,7 +108,7 @@ static struct cmd_handler config_handlers[] = {
108}; 108};
109 109
110/* Runtime-only commands. Keep alphabetized */ 110/* Runtime-only commands. Keep alphabetized */
111static struct cmd_handler command_handlers[] = { 111static const struct cmd_handler command_handlers[] = {
112 { "border", cmd_border }, 112 { "border", cmd_border },
113 { "create_output", cmd_create_output }, 113 { "create_output", cmd_create_output },
114 { "exit", cmd_exit }, 114 { "exit", cmd_exit },
@@ -144,22 +144,22 @@ static int handler_compare(const void *_a, const void *_b) {
144 return strcasecmp(a->command, b->command); 144 return strcasecmp(a->command, b->command);
145} 145}
146 146
147struct cmd_handler *find_handler(char *line, struct cmd_handler *handlers, 147const struct cmd_handler *find_handler(char *line,
148 size_t handlers_size) { 148 const struct cmd_handler *handlers, size_t handlers_size) {
149 if (!handlers || !handlers_size) { 149 if (!handlers || !handlers_size) {
150 return NULL; 150 return NULL;
151 } 151 }
152 struct cmd_handler query = { .command = line }; 152 const struct cmd_handler query = { .command = line };
153 return bsearch(&query, handlers, 153 return bsearch(&query, handlers,
154 handlers_size / sizeof(struct cmd_handler), 154 handlers_size / sizeof(struct cmd_handler),
155 sizeof(struct cmd_handler), handler_compare); 155 sizeof(struct cmd_handler), handler_compare);
156} 156}
157 157
158static struct cmd_handler *find_handler_ex(char *line, 158static const struct cmd_handler *find_handler_ex(char *line,
159 struct cmd_handler *config_handlers, size_t config_handlers_size, 159 const struct cmd_handler *config_handlers, size_t config_handlers_size,
160 struct cmd_handler *command_handlers, size_t command_handlers_size, 160 const struct cmd_handler *command_handlers, size_t command_handlers_size,
161 struct cmd_handler *handlers, size_t handlers_size) { 161 const struct cmd_handler *handlers, size_t handlers_size) {
162 struct cmd_handler *handler = NULL; 162 const struct cmd_handler *handler = NULL;
163 if (config->reading) { 163 if (config->reading) {
164 handler = find_handler(line, config_handlers, config_handlers_size); 164 handler = find_handler(line, config_handlers, config_handlers_size);
165 } else if (config->active) { 165 } else if (config->active) {
@@ -168,7 +168,7 @@ static struct cmd_handler *find_handler_ex(char *line,
168 return handler ? handler : find_handler(line, handlers, handlers_size); 168 return handler ? handler : find_handler(line, handlers, handlers_size);
169} 169}
170 170
171static struct cmd_handler *find_core_handler(char *line) { 171static const struct cmd_handler *find_core_handler(char *line) {
172 return find_handler_ex(line, config_handlers, sizeof(config_handlers), 172 return find_handler_ex(line, config_handlers, sizeof(config_handlers),
173 command_handlers, sizeof(command_handlers), 173 command_handlers, sizeof(command_handlers),
174 handlers, sizeof(handlers)); 174 handlers, sizeof(handlers));
@@ -265,7 +265,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
265 } 265 }
266 } 266 }
267 } 267 }
268 struct cmd_handler *handler = find_core_handler(argv[0]); 268 const struct cmd_handler *handler = find_core_handler(argv[0]);
269 if (!handler) { 269 if (!handler) {
270 list_add(res_list, cmd_results_new(CMD_INVALID, 270 list_add(res_list, cmd_results_new(CMD_INVALID,
271 "Unknown/invalid command '%s'", argv[0])); 271 "Unknown/invalid command '%s'", argv[0]));
@@ -370,7 +370,7 @@ struct cmd_results *config_command(char *exec, char **new_block) {
370 370
371 // Determine the command handler 371 // Determine the command handler
372 sway_log(SWAY_INFO, "Config command: %s", exec); 372 sway_log(SWAY_INFO, "Config command: %s", exec);
373 struct cmd_handler *handler = find_core_handler(argv[0]); 373 const struct cmd_handler *handler = find_core_handler(argv[0]);
374 if (!handler || !handler->handle) { 374 if (!handler || !handler->handle) {
375 const char *error = handler 375 const char *error = handler
376 ? "Command '%s' is shimmed, but unimplemented" 376 ? "Command '%s' is shimmed, but unimplemented"
@@ -418,12 +418,12 @@ cleanup:
418} 418}
419 419
420struct cmd_results *config_subcommand(char **argv, int argc, 420struct cmd_results *config_subcommand(char **argv, int argc,
421 struct cmd_handler *handlers, size_t handlers_size) { 421 const struct cmd_handler *handlers, size_t handlers_size) {
422 char *command = join_args(argv, argc); 422 char *command = join_args(argv, argc);
423 sway_log(SWAY_DEBUG, "Subcommand: %s", command); 423 sway_log(SWAY_DEBUG, "Subcommand: %s", command);
424 free(command); 424 free(command);
425 425
426 struct cmd_handler *handler = find_handler(argv[0], handlers, 426 const struct cmd_handler *handler = find_handler(argv[0], handlers,
427 handlers_size); 427 handlers_size);
428 if (!handler) { 428 if (!handler) {
429 return cmd_results_new(CMD_INVALID, 429 return cmd_results_new(CMD_INVALID,
@@ -453,7 +453,7 @@ struct cmd_results *config_commands_command(char *exec) {
453 goto cleanup; 453 goto cleanup;
454 } 454 }
455 455
456 struct cmd_handler *handler = find_handler(cmd, NULL, 0); 456 const struct cmd_handler *handler = find_handler(cmd, NULL, 0);
457 if (!handler && strcmp(cmd, "*") != 0) { 457 if (!handler && strcmp(cmd, "*") != 0) {
458 results = cmd_results_new(CMD_INVALID, 458 results = cmd_results_new(CMD_INVALID,
459 "Unknown/invalid command '%s'", cmd); 459 "Unknown/invalid command '%s'", cmd);