aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/rename.c
diff options
context:
space:
mode:
authorLibravatar M Stoeckl <code@mstoeckl.com>2019-01-10 18:27:21 -0500
committerLibravatar M Stoeckl <code@mstoeckl.com>2019-01-14 08:05:29 -0500
commit2a684cad5fc8e12a8e47a7fd00e2b7c66b43afb0 (patch)
tree56332b9c150459beb5aef94605372ef179ec8854 /sway/commands/rename.c
parentRemove 'input' field of IPC command return json (diff)
downloadsway-2a684cad5fc8e12a8e47a7fd00e2b7c66b43afb0.tar.gz
sway-2a684cad5fc8e12a8e47a7fd00e2b7c66b43afb0.tar.zst
sway-2a684cad5fc8e12a8e47a7fd00e2b7c66b43afb0.zip
Remove now-unused "input" argument of cmd_results_new
Patch tested by compiling with `__attribute__ ((format (printf, 2, 3)))` applied to `cmd_results_new`. String usage constants have been converted from pointers to arrays when encountered. General handler format strings were sometimes modified to include the old input string, especially for unknown command errors.
Diffstat (limited to 'sway/commands/rename.c')
-rw-r--r--sway/commands/rename.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/sway/commands/rename.c b/sway/commands/rename.c
index 491dbab0..a68302c4 100644
--- a/sway/commands/rename.c
+++ b/sway/commands/rename.c
@@ -10,7 +10,7 @@
10#include "sway/tree/container.h" 10#include "sway/tree/container.h"
11#include "sway/tree/workspace.h" 11#include "sway/tree/workspace.h"
12 12
13static const char* expected_syntax = 13static const char expected_syntax[] =
14 "Expected 'rename workspace <old_name> to <new_name>' or " 14 "Expected 'rename workspace <old_name> to <new_name>' or "
15 "'rename workspace to <new_name>'"; 15 "'rename workspace to <new_name>'";
16 16
@@ -20,11 +20,11 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
20 return error; 20 return error;
21 } 21 }
22 if (!root->outputs->length) { 22 if (!root->outputs->length) {
23 return cmd_results_new(CMD_INVALID, "rename", 23 return cmd_results_new(CMD_INVALID,
24 "Can't run this command while there's no outputs connected."); 24 "Can't run this command while there's no outputs connected.");
25 } 25 }
26 if (strcasecmp(argv[0], "workspace") != 0) { 26 if (strcasecmp(argv[0], "workspace") != 0) {
27 return cmd_results_new(CMD_INVALID, "rename", expected_syntax); 27 return cmd_results_new(CMD_INVALID, expected_syntax);
28 } 28 }
29 29
30 int argn = 1; 30 int argn = 1;
@@ -36,7 +36,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
36 } else if (strcasecmp(argv[1], "number") == 0) { 36 } else if (strcasecmp(argv[1], "number") == 0) {
37 // 'rename workspace number x to new_name' 37 // 'rename workspace number x to new_name'
38 if (!isdigit(argv[2][0])) { 38 if (!isdigit(argv[2][0])) {
39 return cmd_results_new(CMD_INVALID, "rename", 39 return cmd_results_new(CMD_INVALID,
40 "Invalid workspace number '%s'", argv[2]); 40 "Invalid workspace number '%s'", argv[2]);
41 } 41 }
42 workspace = workspace_by_number(argv[2]); 42 workspace = workspace_by_number(argv[2]);
@@ -56,14 +56,14 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
56 } 56 }
57 57
58 if (!workspace) { 58 if (!workspace) {
59 return cmd_results_new(CMD_INVALID, "rename", 59 return cmd_results_new(CMD_INVALID,
60 "There is no workspace with that name"); 60 "There is no workspace with that name");
61 } 61 }
62 62
63 ++argn; // move past "to" 63 ++argn; // move past "to"
64 64
65 if (argn >= argc) { 65 if (argn >= argc) {
66 return cmd_results_new(CMD_INVALID, "rename", expected_syntax); 66 return cmd_results_new(CMD_INVALID, expected_syntax);
67 } 67 }
68 68
69 char *new_name = join_args(argv + argn, argc - argn); 69 char *new_name = join_args(argv + argn, argc - argn);
@@ -75,17 +75,16 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
75 strcasecmp(new_name, "current") == 0 || 75 strcasecmp(new_name, "current") == 0 ||
76 strcasecmp(new_name, "number") == 0) { 76 strcasecmp(new_name, "number") == 0) {
77 free(new_name); 77 free(new_name);
78 return cmd_results_new(CMD_INVALID, "rename", 78 return cmd_results_new(CMD_INVALID,
79 "Cannot use special workspace name '%s'", argv[argn]); 79 "Cannot use special workspace name '%s'", argv[argn]);
80 } 80 }
81 struct sway_workspace *tmp_workspace = workspace_by_name(new_name); 81 struct sway_workspace *tmp_workspace = workspace_by_name(new_name);
82 if (tmp_workspace) { 82 if (tmp_workspace) {
83 free(new_name); 83 free(new_name);
84 if (tmp_workspace == workspace) { 84 if (tmp_workspace == workspace) {
85 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 85 return cmd_results_new(CMD_SUCCESS, NULL);
86 } else { 86 } else {
87 return cmd_results_new(CMD_INVALID, "rename", 87 return cmd_results_new(CMD_INVALID, "Workspace already exists");
88 "Workspace already exists");
89 } 88 }
90 } 89 }
91 90
@@ -96,5 +95,5 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
96 output_sort_workspaces(workspace->output); 95 output_sort_workspaces(workspace->output);
97 ipc_event_workspace(NULL, workspace, "rename"); 96 ipc_event_workspace(NULL, workspace, "rename");
98 97
99 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 98 return cmd_results_new(CMD_SUCCESS, NULL);
100} 99}