aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Stoeckl <code@mstoeckl.com>2021-02-02 19:54:35 -0500
committerSimon Ser <contact@emersion.fr>2021-02-04 09:49:06 +0100
commitcb3c7276324b5b0862088df9ffe5498998edae91 (patch)
treeb4576f3715e53300794f92e4c6339df0ac1e447a
parent89b4bc4bc7e52ecdcc809b4ffe48cba93de2794e (diff)
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 {
struct cmd_results *checkarg(int argc, const char *name,
enum expected_args type, int val);
-struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
- size_t handlers_size);
+const struct cmd_handler *find_handler(char *line,
+ const struct cmd_handler *cmd_handlers, size_t handlers_size);
/**
* Parse and executes a command.
@@ -68,7 +68,7 @@ struct cmd_results *config_command(char *command, char **new_block);
* Parse and handle a sub command
*/
struct cmd_results *config_subcommand(char **argv, int argc,
- struct cmd_handler *handlers, size_t handlers_size);
+ const struct cmd_handler *handlers, size_t handlers_size);
/*
* Parses a command policy rule.
*/
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
}
/* Keep alphabetized */
-static struct cmd_handler handlers[] = {
+static const struct cmd_handler handlers[] = {
{ "assign", cmd_assign },
{ "bar", cmd_bar },
{ "bindcode", cmd_bindcode },
@@ -98,7 +98,7 @@ static struct cmd_handler handlers[] = {
};
/* Config-time only commands. Keep alphabetized */
-static struct cmd_handler config_handlers[] = {
+static const struct cmd_handler config_handlers[] = {
{ "default_orientation", cmd_default_orientation },
{ "include", cmd_include },
{ "swaybg_command", cmd_swaybg_command },
@@ -108,7 +108,7 @@ static struct cmd_handler config_handlers[] = {
};
/* Runtime-only commands. Keep alphabetized */
-static struct cmd_handler command_handlers[] = {
+static const struct cmd_handler command_handlers[] = {
{ "border", cmd_border },
{ "create_output", cmd_create_output },
{ "exit", cmd_exit },
@@ -144,22 +144,22 @@ static int handler_compare(const void *_a, const void *_b) {
return strcasecmp(a->command, b->command);
}
-struct cmd_handler *find_handler(char *line, struct cmd_handler *handlers,
- size_t handlers_size) {
+const struct cmd_handler *find_handler(char *line,
+ const struct cmd_handler *handlers, size_t handlers_size) {
if (!handlers || !handlers_size) {
return NULL;
}
- struct cmd_handler query = { .command = line };
+ const struct cmd_handler query = { .command = line };
return bsearch(&query, handlers,
handlers_size / sizeof(struct cmd_handler),
sizeof(struct cmd_handler), handler_compare);
}
-static struct cmd_handler *find_handler_ex(char *line,
- struct cmd_handler *config_handlers, size_t config_handlers_size,
- struct cmd_handler *command_handlers, size_t command_handlers_size,
- struct cmd_handler *handlers, size_t handlers_size) {
- struct cmd_handler *handler = NULL;
+static const struct cmd_handler *find_handler_ex(char *line,
+ const struct cmd_handler *config_handlers, size_t config_handlers_size,
+ const struct cmd_handler *command_handlers, size_t command_handlers_size,
+ const struct cmd_handler *handlers, size_t handlers_size) {
+ const struct cmd_handler *handler = NULL;
if (config->reading) {
handler = find_handler(line, config_handlers, config_handlers_size);
} else if (config->active) {
@@ -168,7 +168,7 @@ static struct cmd_handler *find_handler_ex(char *line,
return handler ? handler : find_handler(line, handlers, handlers_size);
}
-static struct cmd_handler *find_core_handler(char *line) {
+static const struct cmd_handler *find_core_handler(char *line) {
return find_handler_ex(line, config_handlers, sizeof(config_handlers),
command_handlers, sizeof(command_handlers),
handlers, sizeof(handlers));
@@ -265,7 +265,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
}
}
}
- struct cmd_handler *handler = find_core_handler(argv[0]);
+ const struct cmd_handler *handler = find_core_handler(argv[0]);
if (!handler) {
list_add(res_list, cmd_results_new(CMD_INVALID,
"Unknown/invalid command '%s'", argv[0]));
@@ -370,7 +370,7 @@ struct cmd_results *config_command(char *exec, char **new_block) {
// Determine the command handler
sway_log(SWAY_INFO, "Config command: %s", exec);
- struct cmd_handler *handler = find_core_handler(argv[0]);
+ const struct cmd_handler *handler = find_core_handler(argv[0]);
if (!handler || !handler->handle) {
const char *error = handler
? "Command '%s' is shimmed, but unimplemented"
@@ -418,12 +418,12 @@ cleanup:
}
struct cmd_results *config_subcommand(char **argv, int argc,
- struct cmd_handler *handlers, size_t handlers_size) {
+ const struct cmd_handler *handlers, size_t handlers_size) {
char *command = join_args(argv, argc);
sway_log(SWAY_DEBUG, "Subcommand: %s", command);
free(command);
- struct cmd_handler *handler = find_handler(argv[0], handlers,
+ const struct cmd_handler *handler = find_handler(argv[0], handlers,
handlers_size);
if (!handler) {
return cmd_results_new(CMD_INVALID,
@@ -453,7 +453,7 @@ struct cmd_results *config_commands_command(char *exec) {
goto cleanup;
}
- struct cmd_handler *handler = find_handler(cmd, NULL, 0);
+ const struct cmd_handler *handler = find_handler(cmd, NULL, 0);
if (!handler && strcmp(cmd, "*") != 0) {
results = cmd_results_new(CMD_INVALID,
"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 @@
#include "log.h"
// Must be in alphabetical order for bsearch
-static struct cmd_handler bar_handlers[] = {
+static const struct cmd_handler bar_handlers[] = {
{ "bindcode", bar_cmd_bindcode },
{ "binding_mode_indicator", bar_cmd_binding_mode_indicator },
{ "bindsym", bar_cmd_bindsym },
@@ -41,7 +41,7 @@ static struct cmd_handler bar_handlers[] = {
};
// Must be in alphabetical order for bsearch
-static struct cmd_handler bar_config_handlers[] = {
+static const struct cmd_handler bar_config_handlers[] = {
{ "id", bar_cmd_id },
{ "swaybar_command", bar_cmd_swaybar_command },
};
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 @@
#include "util.h"
// Must be in alphabetical order for bsearch
-static struct cmd_handler bar_colors_handlers[] = {
+static const struct cmd_handler bar_colors_handlers[] = {
{ "active_workspace", bar_colors_cmd_active_workspace },
{ "background", bar_colors_cmd_background },
{ "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 @@
#include "stringop.h"
// must be in order for the bsearch
-static struct cmd_handler input_handlers[] = {
+static const struct cmd_handler input_handlers[] = {
{ "accel_profile", input_cmd_accel_profile },
{ "calibration_matrix", input_cmd_calibration_matrix },
{ "click_method", input_cmd_click_method },
@@ -40,7 +40,7 @@ static struct cmd_handler input_handlers[] = {
};
// must be in order for the bsearch
-static struct cmd_handler input_config_handlers[] = {
+static const struct cmd_handler input_config_handlers[] = {
{ "xkb_capslock", input_cmd_xkb_capslock },
{ "xkb_numlock", input_cmd_xkb_numlock },
};
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 @@
#include "stringop.h"
// Must be in order for the bsearch
-static struct cmd_handler mode_handlers[] = {
+static const struct cmd_handler mode_handlers[] = {
{ "bindcode", cmd_bindcode },
{ "bindswitch", cmd_bindswitch },
{ "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 @@
#include "log.h"
// must be in order for the bsearch
-static struct cmd_handler output_handlers[] = {
+static const struct cmd_handler output_handlers[] = {
{ "adaptive_sync", output_cmd_adaptive_sync },
{ "background", output_cmd_background },
{ "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 @@
// must be in order for the bsearch
// these handlers perform actions on the seat
-static struct cmd_handler seat_action_handlers[] = {
+static const struct cmd_handler seat_action_handlers[] = {
{ "cursor", seat_cmd_cursor },
};
// must be in order for the bsearch
// these handlers alter the seat config
-static struct cmd_handler seat_handlers[] = {
+static const struct cmd_handler seat_handlers[] = {
{ "attach", seat_cmd_attach },
{ "fallback", seat_cmd_fallback },
{ "hide_cursor", seat_cmd_hide_cursor },