aboutsummaryrefslogtreecommitdiff
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 9fae6a35..6f786035 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -36,7 +36,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
}
}
return error_name ?
- cmd_results_new(CMD_INVALID, name, "Invalid %s command "
+ cmd_results_new(CMD_INVALID, "Invalid %s command "
"(expected %s%d argument%s, got %d)",
name, error_name, val, val != 1 ? "s" : "", argc)
: NULL;
@@ -228,8 +228,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
char *error = NULL;
struct criteria *criteria = criteria_parse(head, &error);
if (!criteria) {
- list_add(res_list, cmd_results_new(CMD_INVALID, head,
- "%s", error));
+ list_add(res_list, cmd_results_new(CMD_INVALID, "%s", error));
free(error);
goto cleanup;
}
@@ -265,8 +264,8 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
}
struct cmd_handler *handler = find_handler(argv[0], NULL, 0);
if (!handler) {
- list_add(res_list, cmd_results_new(CMD_INVALID, cmd,
- "Unknown/invalid command"));
+ list_add(res_list, cmd_results_new(CMD_INVALID,
+ "Unknown/invalid command '%s'", argv[0]));
free_argv(argc, argv);
goto cleanup;
}
@@ -323,20 +322,20 @@ struct cmd_results *config_command(char *exec, char **new_block) {
// Check for empty lines
if (!argc) {
- results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup;
}
// Check for the start of a block
if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
*new_block = join_args(argv, argc - 1);
- results = cmd_results_new(CMD_BLOCK, NULL, NULL);
+ results = cmd_results_new(CMD_BLOCK, NULL);
goto cleanup;
}
// Check for the end of a block
if (strcmp(argv[argc - 1], "}") == 0) {
- results = cmd_results_new(CMD_BLOCK_END, NULL, NULL);
+ results = cmd_results_new(CMD_BLOCK_END, NULL);
goto cleanup;
}
@@ -348,7 +347,7 @@ struct cmd_results *config_command(char *exec, char **new_block) {
argv = split_args(temp, &argc);
free(temp);
if (!argc) {
- results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup;
}
}
@@ -357,11 +356,10 @@ struct cmd_results *config_command(char *exec, char **new_block) {
wlr_log(WLR_INFO, "Config command: %s", exec);
struct cmd_handler *handler = find_handler(argv[0], NULL, 0);
if (!handler || !handler->handle) {
- char *input = argv[0] ? argv[0] : "(empty)";
- char *error = handler
- ? "This command is shimmed, but unimplemented"
- : "Unknown/invalid command";
- results = cmd_results_new(CMD_INVALID, input, error);
+ const char *error = handler
+ ? "Command '%s' is shimmed, but unimplemented"
+ : "Unknown/invalid command '%s'";
+ results = cmd_results_new(CMD_INVALID, error, argv[0]);
goto cleanup;
}
@@ -410,14 +408,14 @@ struct cmd_results *config_subcommand(char **argv, int argc,
struct cmd_handler *handler = find_handler(argv[0], handlers,
handlers_size);
if (!handler) {
- char *input = argv[0] ? argv[0] : "(empty)";
- return cmd_results_new(CMD_INVALID, input, "Unknown/invalid command");
+ return cmd_results_new(CMD_INVALID,
+ "Unknown/invalid command '%s'", argv[0]);
}
if (handler->handle) {
return handler->handle(argc - 1, argv + 1);
}
- return cmd_results_new(CMD_INVALID, argv[0],
- "This command is shimmed, but unimplemented");
+ return cmd_results_new(CMD_INVALID,
+ "The command '%s' is shimmed, but unimplemented", argv[0]);
}
struct cmd_results *config_commands_command(char *exec) {
@@ -425,7 +423,7 @@ struct cmd_results *config_commands_command(char *exec) {
int argc;
char **argv = split_args(exec, &argc);
if (!argc) {
- results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ results = cmd_results_new(CMD_SUCCESS, NULL);
goto cleanup;
}
@@ -433,13 +431,14 @@ struct cmd_results *config_commands_command(char *exec) {
char *cmd = argv[0];
if (strcmp(cmd, "}") == 0) {
- results = cmd_results_new(CMD_BLOCK_END, NULL, NULL);
+ results = cmd_results_new(CMD_BLOCK_END, NULL);
goto cleanup;
}
struct cmd_handler *handler = find_handler(cmd, NULL, 0);
if (!handler && strcmp(cmd, "*") != 0) {
- results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command");
+ results = cmd_results_new(CMD_INVALID,
+ "Unknown/invalid command '%s'", cmd);
goto cleanup;
}
@@ -464,7 +463,7 @@ struct cmd_results *config_commands_command(char *exec) {
}
}
if (j == sizeof(context_names) / sizeof(context_names[0])) {
- results = cmd_results_new(CMD_INVALID, cmd,
+ results = cmd_results_new(CMD_INVALID,
"Invalid command context %s", argv[i]);
goto cleanup;
}
@@ -482,7 +481,7 @@ struct cmd_results *config_commands_command(char *exec) {
if (!policy) {
policy = alloc_command_policy(cmd);
if (!sway_assert(policy, "Unable to allocate security policy")) {
- results = cmd_results_new(CMD_INVALID, cmd,
+ results = cmd_results_new(CMD_INVALID,
"Unable to allocate memory");
goto cleanup;
}
@@ -493,7 +492,7 @@ struct cmd_results *config_commands_command(char *exec) {
wlr_log(WLR_INFO, "Set command policy for %s to %d",
policy->command, policy->context);
- results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ results = cmd_results_new(CMD_SUCCESS, NULL);
cleanup:
free_argv(argc, argv);
@@ -501,14 +500,13 @@ cleanup:
}
struct cmd_results *cmd_results_new(enum cmd_status status,
- const char *input, const char *format, ...) {
+ const char *format, ...) {
struct cmd_results *results = malloc(sizeof(struct cmd_results));
if (!results) {
wlr_log(WLR_ERROR, "Unable to allocate command results");
return NULL;
}
results->status = status;
- // NOTE: `input` argument is unused, remove
if (format) {
char *error = malloc(256);
va_list args;
@@ -557,20 +555,19 @@ char *cmd_results_to_json(list_t *res_list) {
*
* return error object, or NULL if color is valid.
*/
-struct cmd_results *add_color(const char *name,
- char *buffer, const char *color) {
+struct cmd_results *add_color(char *buffer, const char *color) {
int len = strlen(color);
if (len != 7 && len != 9) {
- return cmd_results_new(CMD_INVALID, name,
+ return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color);
}
if (color[0] != '#') {
- return cmd_results_new(CMD_INVALID, name,
+ return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color);
}
for (int i = 1; i < len; ++i) {
if (!isxdigit(color[i])) {
- return cmd_results_new(CMD_INVALID, name,
+ return cmd_results_new(CMD_INVALID,
"Invalid color definition %s", color);
}
}