mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
Declare all struct cmd_handler arrays const
And make the functions handling these arrays use const types.
This commit is contained in:
parent
89b4bc4bc7
commit
cb3c727632
|
@ -46,8 +46,8 @@ enum expected_args {
|
||||||
struct cmd_results *checkarg(int argc, const char *name,
|
struct cmd_results *checkarg(int argc, const char *name,
|
||||||
enum expected_args type, int val);
|
enum expected_args type, int val);
|
||||||
|
|
||||||
struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
|
const struct cmd_handler *find_handler(char *line,
|
||||||
size_t handlers_size);
|
const struct cmd_handler *cmd_handlers, size_t handlers_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse and executes a command.
|
* 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
|
* Parse and handle a sub command
|
||||||
*/
|
*/
|
||||||
struct cmd_results *config_subcommand(char **argv, int argc,
|
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.
|
* Parses a command policy rule.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep alphabetized */
|
/* Keep alphabetized */
|
||||||
static struct cmd_handler handlers[] = {
|
static const struct cmd_handler handlers[] = {
|
||||||
{ "assign", cmd_assign },
|
{ "assign", cmd_assign },
|
||||||
{ "bar", cmd_bar },
|
{ "bar", cmd_bar },
|
||||||
{ "bindcode", cmd_bindcode },
|
{ "bindcode", cmd_bindcode },
|
||||||
|
@ -98,7 +98,7 @@ static struct cmd_handler handlers[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Config-time only commands. Keep alphabetized */
|
/* Config-time only commands. Keep alphabetized */
|
||||||
static struct cmd_handler config_handlers[] = {
|
static const struct cmd_handler config_handlers[] = {
|
||||||
{ "default_orientation", cmd_default_orientation },
|
{ "default_orientation", cmd_default_orientation },
|
||||||
{ "include", cmd_include },
|
{ "include", cmd_include },
|
||||||
{ "swaybg_command", cmd_swaybg_command },
|
{ "swaybg_command", cmd_swaybg_command },
|
||||||
|
@ -108,7 +108,7 @@ static struct cmd_handler config_handlers[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Runtime-only commands. Keep alphabetized */
|
/* Runtime-only commands. Keep alphabetized */
|
||||||
static struct cmd_handler command_handlers[] = {
|
static const struct cmd_handler command_handlers[] = {
|
||||||
{ "border", cmd_border },
|
{ "border", cmd_border },
|
||||||
{ "create_output", cmd_create_output },
|
{ "create_output", cmd_create_output },
|
||||||
{ "exit", cmd_exit },
|
{ "exit", cmd_exit },
|
||||||
|
@ -144,22 +144,22 @@ static int handler_compare(const void *_a, const void *_b) {
|
||||||
return strcasecmp(a->command, b->command);
|
return strcasecmp(a->command, b->command);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_handler *find_handler(char *line, struct cmd_handler *handlers,
|
const struct cmd_handler *find_handler(char *line,
|
||||||
size_t handlers_size) {
|
const struct cmd_handler *handlers, size_t handlers_size) {
|
||||||
if (!handlers || !handlers_size) {
|
if (!handlers || !handlers_size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct cmd_handler query = { .command = line };
|
const struct cmd_handler query = { .command = line };
|
||||||
return bsearch(&query, handlers,
|
return bsearch(&query, handlers,
|
||||||
handlers_size / sizeof(struct cmd_handler),
|
handlers_size / sizeof(struct cmd_handler),
|
||||||
sizeof(struct cmd_handler), handler_compare);
|
sizeof(struct cmd_handler), handler_compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cmd_handler *find_handler_ex(char *line,
|
static const struct cmd_handler *find_handler_ex(char *line,
|
||||||
struct cmd_handler *config_handlers, size_t config_handlers_size,
|
const struct cmd_handler *config_handlers, size_t config_handlers_size,
|
||||||
struct cmd_handler *command_handlers, size_t command_handlers_size,
|
const struct cmd_handler *command_handlers, size_t command_handlers_size,
|
||||||
struct cmd_handler *handlers, size_t handlers_size) {
|
const struct cmd_handler *handlers, size_t handlers_size) {
|
||||||
struct cmd_handler *handler = NULL;
|
const struct cmd_handler *handler = NULL;
|
||||||
if (config->reading) {
|
if (config->reading) {
|
||||||
handler = find_handler(line, config_handlers, config_handlers_size);
|
handler = find_handler(line, config_handlers, config_handlers_size);
|
||||||
} else if (config->active) {
|
} 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);
|
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),
|
return find_handler_ex(line, config_handlers, sizeof(config_handlers),
|
||||||
command_handlers, sizeof(command_handlers),
|
command_handlers, sizeof(command_handlers),
|
||||||
handlers, sizeof(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) {
|
if (!handler) {
|
||||||
list_add(res_list, cmd_results_new(CMD_INVALID,
|
list_add(res_list, cmd_results_new(CMD_INVALID,
|
||||||
"Unknown/invalid command '%s'", argv[0]));
|
"Unknown/invalid command '%s'", argv[0]));
|
||||||
|
@ -370,7 +370,7 @@ struct cmd_results *config_command(char *exec, char **new_block) {
|
||||||
|
|
||||||
// Determine the command handler
|
// Determine the command handler
|
||||||
sway_log(SWAY_INFO, "Config command: %s", exec);
|
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) {
|
if (!handler || !handler->handle) {
|
||||||
const char *error = handler
|
const char *error = handler
|
||||||
? "Command '%s' is shimmed, but unimplemented"
|
? "Command '%s' is shimmed, but unimplemented"
|
||||||
|
@ -418,12 +418,12 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *config_subcommand(char **argv, int argc,
|
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);
|
char *command = join_args(argv, argc);
|
||||||
sway_log(SWAY_DEBUG, "Subcommand: %s", command);
|
sway_log(SWAY_DEBUG, "Subcommand: %s", command);
|
||||||
free(command);
|
free(command);
|
||||||
|
|
||||||
struct cmd_handler *handler = find_handler(argv[0], handlers,
|
const struct cmd_handler *handler = find_handler(argv[0], handlers,
|
||||||
handlers_size);
|
handlers_size);
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return cmd_results_new(CMD_INVALID,
|
return cmd_results_new(CMD_INVALID,
|
||||||
|
@ -453,7 +453,7 @@ struct cmd_results *config_commands_command(char *exec) {
|
||||||
goto cleanup;
|
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) {
|
if (!handler && strcmp(cmd, "*") != 0) {
|
||||||
results = cmd_results_new(CMD_INVALID,
|
results = cmd_results_new(CMD_INVALID,
|
||||||
"Unknown/invalid command '%s'", cmd);
|
"Unknown/invalid command '%s'", cmd);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
// Must be in alphabetical order for bsearch
|
// Must be in alphabetical order for bsearch
|
||||||
static struct cmd_handler bar_handlers[] = {
|
static const struct cmd_handler bar_handlers[] = {
|
||||||
{ "bindcode", bar_cmd_bindcode },
|
{ "bindcode", bar_cmd_bindcode },
|
||||||
{ "binding_mode_indicator", bar_cmd_binding_mode_indicator },
|
{ "binding_mode_indicator", bar_cmd_binding_mode_indicator },
|
||||||
{ "bindsym", bar_cmd_bindsym },
|
{ "bindsym", bar_cmd_bindsym },
|
||||||
|
@ -41,7 +41,7 @@ static struct cmd_handler bar_handlers[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Must be in alphabetical order for bsearch
|
// 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 },
|
{ "id", bar_cmd_id },
|
||||||
{ "swaybar_command", bar_cmd_swaybar_command },
|
{ "swaybar_command", bar_cmd_swaybar_command },
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
// Must be in alphabetical order for bsearch
|
// 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 },
|
{ "active_workspace", bar_colors_cmd_active_workspace },
|
||||||
{ "background", bar_colors_cmd_background },
|
{ "background", bar_colors_cmd_background },
|
||||||
{ "binding_mode", bar_colors_cmd_binding_mode },
|
{ "binding_mode", bar_colors_cmd_binding_mode },
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
|
||||||
// must be in order for the bsearch
|
// 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 },
|
{ "accel_profile", input_cmd_accel_profile },
|
||||||
{ "calibration_matrix", input_cmd_calibration_matrix },
|
{ "calibration_matrix", input_cmd_calibration_matrix },
|
||||||
{ "click_method", input_cmd_click_method },
|
{ "click_method", input_cmd_click_method },
|
||||||
|
@ -40,7 +40,7 @@ static struct cmd_handler input_handlers[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// must be in order for the bsearch
|
// 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_capslock", input_cmd_xkb_capslock },
|
||||||
{ "xkb_numlock", input_cmd_xkb_numlock },
|
{ "xkb_numlock", input_cmd_xkb_numlock },
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
|
||||||
// Must be in order for the bsearch
|
// Must be in order for the bsearch
|
||||||
static struct cmd_handler mode_handlers[] = {
|
static const struct cmd_handler mode_handlers[] = {
|
||||||
{ "bindcode", cmd_bindcode },
|
{ "bindcode", cmd_bindcode },
|
||||||
{ "bindswitch", cmd_bindswitch },
|
{ "bindswitch", cmd_bindswitch },
|
||||||
{ "bindsym", cmd_bindsym },
|
{ "bindsym", cmd_bindsym },
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
// must be in order for the bsearch
|
// 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 },
|
{ "adaptive_sync", output_cmd_adaptive_sync },
|
||||||
{ "background", output_cmd_background },
|
{ "background", output_cmd_background },
|
||||||
{ "bg", output_cmd_background },
|
{ "bg", output_cmd_background },
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
|
|
||||||
// must be in order for the bsearch
|
// must be in order for the bsearch
|
||||||
// these handlers perform actions on the seat
|
// 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 },
|
{ "cursor", seat_cmd_cursor },
|
||||||
};
|
};
|
||||||
|
|
||||||
// must be in order for the bsearch
|
// must be in order for the bsearch
|
||||||
// these handlers alter the seat config
|
// these handlers alter the seat config
|
||||||
static struct cmd_handler seat_handlers[] = {
|
static const struct cmd_handler seat_handlers[] = {
|
||||||
{ "attach", seat_cmd_attach },
|
{ "attach", seat_cmd_attach },
|
||||||
{ "fallback", seat_cmd_fallback },
|
{ "fallback", seat_cmd_fallback },
|
||||||
{ "hide_cursor", seat_cmd_hide_cursor },
|
{ "hide_cursor", seat_cmd_hide_cursor },
|
||||||
|
|
Loading…
Reference in a new issue