aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/sway/commands.h6
-rw-r--r--sway/commands.c34
-rw-r--r--sway/commands/bar.c4
-rw-r--r--sway/commands/bar/colors.c2
-rw-r--r--sway/commands/input.c4
-rw-r--r--sway/commands/mode.c2
-rw-r--r--sway/commands/output.c2
-rw-r--r--sway/commands/seat.c4
8 files changed, 29 insertions, 29 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 964b3661..29a6bec3 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -46,8 +46,8 @@ enum expected_args {
46struct cmd_results *checkarg(int argc, const char *name, 46struct cmd_results *checkarg(int argc, const char *name,
47 enum expected_args type, int val); 47 enum expected_args type, int val);
48 48
49struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers, 49const struct cmd_handler *find_handler(char *line,
50 size_t handlers_size); 50 const struct cmd_handler *cmd_handlers, size_t handlers_size);
51 51
52/** 52/**
53 * Parse and executes a command. 53 * Parse and executes a command.
@@ -68,7 +68,7 @@ struct cmd_results *config_command(char *command, char **new_block);
68 * Parse and handle a sub command 68 * Parse and handle a sub command
69 */ 69 */
70struct cmd_results *config_subcommand(char **argv, int argc, 70struct cmd_results *config_subcommand(char **argv, int argc,
71 struct cmd_handler *handlers, size_t handlers_size); 71 const struct cmd_handler *handlers, size_t handlers_size);
72/* 72/*
73 * Parses a command policy rule. 73 * Parses a command policy rule.
74 */ 74 */
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);
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index d42b7fc2..a58f5438 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -8,7 +8,7 @@
8#include "log.h" 8#include "log.h"
9 9
10// Must be in alphabetical order for bsearch 10// Must be in alphabetical order for bsearch
11static struct cmd_handler bar_handlers[] = { 11static const struct cmd_handler bar_handlers[] = {
12 { "bindcode", bar_cmd_bindcode }, 12 { "bindcode", bar_cmd_bindcode },
13 { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, 13 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
14 { "bindsym", bar_cmd_bindsym }, 14 { "bindsym", bar_cmd_bindsym },
@@ -41,7 +41,7 @@ static struct cmd_handler bar_handlers[] = {
41}; 41};
42 42
43// Must be in alphabetical order for bsearch 43// Must be in alphabetical order for bsearch
44static struct cmd_handler bar_config_handlers[] = { 44static const struct cmd_handler bar_config_handlers[] = {
45 { "id", bar_cmd_id }, 45 { "id", bar_cmd_id },
46 { "swaybar_command", bar_cmd_swaybar_command }, 46 { "swaybar_command", bar_cmd_swaybar_command },
47}; 47};
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
index 2d5b22bf..275fa3c6 100644
--- a/sway/commands/bar/colors.c
+++ b/sway/commands/bar/colors.c
@@ -4,7 +4,7 @@
4#include "util.h" 4#include "util.h"
5 5
6// Must be in alphabetical order for bsearch 6// Must be in alphabetical order for bsearch
7static struct cmd_handler bar_colors_handlers[] = { 7static const struct cmd_handler bar_colors_handlers[] = {
8 { "active_workspace", bar_colors_cmd_active_workspace }, 8 { "active_workspace", bar_colors_cmd_active_workspace },
9 { "background", bar_colors_cmd_background }, 9 { "background", bar_colors_cmd_background },
10 { "binding_mode", bar_colors_cmd_binding_mode }, 10 { "binding_mode", bar_colors_cmd_binding_mode },
diff --git a/sway/commands/input.c b/sway/commands/input.c
index c9bb8e06..77acb671 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -7,7 +7,7 @@
7#include "stringop.h" 7#include "stringop.h"
8 8
9// must be in order for the bsearch 9// must be in order for the bsearch
10static struct cmd_handler input_handlers[] = { 10static const struct cmd_handler input_handlers[] = {
11 { "accel_profile", input_cmd_accel_profile }, 11 { "accel_profile", input_cmd_accel_profile },
12 { "calibration_matrix", input_cmd_calibration_matrix }, 12 { "calibration_matrix", input_cmd_calibration_matrix },
13 { "click_method", input_cmd_click_method }, 13 { "click_method", input_cmd_click_method },
@@ -40,7 +40,7 @@ static struct cmd_handler input_handlers[] = {
40}; 40};
41 41
42// must be in order for the bsearch 42// must be in order for the bsearch
43static struct cmd_handler input_config_handlers[] = { 43static const struct cmd_handler input_config_handlers[] = {
44 { "xkb_capslock", input_cmd_xkb_capslock }, 44 { "xkb_capslock", input_cmd_xkb_capslock },
45 { "xkb_numlock", input_cmd_xkb_numlock }, 45 { "xkb_numlock", input_cmd_xkb_numlock },
46}; 46};
diff --git a/sway/commands/mode.c b/sway/commands/mode.c
index a5871dab..e23e4ee4 100644
--- a/sway/commands/mode.c
+++ b/sway/commands/mode.c
@@ -9,7 +9,7 @@
9#include "stringop.h" 9#include "stringop.h"
10 10
11// Must be in order for the bsearch 11// Must be in order for the bsearch
12static struct cmd_handler mode_handlers[] = { 12static const struct cmd_handler mode_handlers[] = {
13 { "bindcode", cmd_bindcode }, 13 { "bindcode", cmd_bindcode },
14 { "bindswitch", cmd_bindswitch }, 14 { "bindswitch", cmd_bindswitch },
15 { "bindsym", cmd_bindsym }, 15 { "bindsym", cmd_bindsym },
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 5186a2ba..4418f23f 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -6,7 +6,7 @@
6#include "log.h" 6#include "log.h"
7 7
8// must be in order for the bsearch 8// must be in order for the bsearch
9static struct cmd_handler output_handlers[] = { 9static const struct cmd_handler output_handlers[] = {
10 { "adaptive_sync", output_cmd_adaptive_sync }, 10 { "adaptive_sync", output_cmd_adaptive_sync },
11 { "background", output_cmd_background }, 11 { "background", output_cmd_background },
12 { "bg", output_cmd_background }, 12 { "bg", output_cmd_background },
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 84c6ba53..2d197b69 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -8,13 +8,13 @@
8 8
9// must be in order for the bsearch 9// must be in order for the bsearch
10// these handlers perform actions on the seat 10// these handlers perform actions on the seat
11static struct cmd_handler seat_action_handlers[] = { 11static const struct cmd_handler seat_action_handlers[] = {
12 { "cursor", seat_cmd_cursor }, 12 { "cursor", seat_cmd_cursor },
13}; 13};
14 14
15// must be in order for the bsearch 15// must be in order for the bsearch
16// these handlers alter the seat config 16// these handlers alter the seat config
17static struct cmd_handler seat_handlers[] = { 17static const struct cmd_handler seat_handlers[] = {
18 { "attach", seat_cmd_attach }, 18 { "attach", seat_cmd_attach },
19 { "fallback", seat_cmd_fallback }, 19 { "fallback", seat_cmd_fallback },
20 { "hide_cursor", seat_cmd_hide_cursor }, 20 { "hide_cursor", seat_cmd_hide_cursor },