diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-08-12 00:32:13 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-08-18 17:25:06 +0100 |
commit | e81cc8a5754386d9484b84cf97ab2f8755c35294 (patch) | |
tree | a3a9f64d0e179b07f94e2fff1484f5099f440432 /sway/commands | |
parent | commands: handle quoted exec command (diff) | |
download | sway-e81cc8a5754386d9484b84cf97ab2f8755c35294.tar.gz sway-e81cc8a5754386d9484b84cf97ab2f8755c35294.tar.zst sway-e81cc8a5754386d9484b84cf97ab2f8755c35294.zip |
commands: saner workspace number handling
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/move.c | 7 | ||||
-rw-r--r-- | sway/commands/rename.c | 8 | ||||
-rw-r--r-- | sway/commands/workspace.c | 7 |
3 files changed, 19 insertions, 3 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index f5eb9124..33d1ee4a 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _XOPEN_SOURCE 500 | 1 | #define _XOPEN_SOURCE 500 |
2 | #include <ctype.h> | ||
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
@@ -124,7 +125,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
124 | return cmd_results_new(CMD_INVALID, "move", | 125 | return cmd_results_new(CMD_INVALID, "move", |
125 | expected_syntax); | 126 | expected_syntax); |
126 | } | 127 | } |
127 | ws_name = strdup(argv[3]); | 128 | if (!isdigit(argv[3][0])) { |
129 | return cmd_results_new(CMD_INVALID, "move", | ||
130 | "Invalid workspace number '%s'", argv[3]); | ||
131 | } | ||
132 | ws_name = join_args(argv + 3, argc - 3); | ||
128 | ws = workspace_by_number(ws_name); | 133 | ws = workspace_by_number(ws_name); |
129 | } else { | 134 | } else { |
130 | ws_name = join_args(argv + 2, argc - 2); | 135 | ws_name = join_args(argv + 2, argc - 2); |
diff --git a/sway/commands/rename.c b/sway/commands/rename.c index c69bbdac..21d2aa64 100644 --- a/sway/commands/rename.c +++ b/sway/commands/rename.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _XOPEN_SOURCE 500 | 1 | #define _XOPEN_SOURCE 500 |
2 | #include <ctype.h> | ||
2 | #include <string.h> | 3 | #include <string.h> |
3 | #include <strings.h> | 4 | #include <strings.h> |
4 | #include "log.h" | 5 | #include "log.h" |
@@ -34,6 +35,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
34 | } | 35 | } |
35 | } else if (strcasecmp(argv[1], "number") == 0) { | 36 | } else if (strcasecmp(argv[1], "number") == 0) { |
36 | // 'rename workspace number x to new_name' | 37 | // 'rename workspace number x to new_name' |
38 | if (!isdigit(argv[2][0])) { | ||
39 | return cmd_results_new(CMD_INVALID, "rename", | ||
40 | "Invalid workspace number '%s'", argv[2]); | ||
41 | } | ||
37 | workspace = workspace_by_number(argv[2]); | 42 | workspace = workspace_by_number(argv[2]); |
38 | while (argn < argc && strcasecmp(argv[argn], "to") != 0) { | 43 | while (argn < argc && strcasecmp(argv[argn], "to") != 0) { |
39 | ++argn; | 44 | ++argn; |
@@ -67,7 +72,8 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
67 | strcasecmp(new_name, "next_on_output") == 0 || | 72 | strcasecmp(new_name, "next_on_output") == 0 || |
68 | strcasecmp(new_name, "prev_on_output") == 0 || | 73 | strcasecmp(new_name, "prev_on_output") == 0 || |
69 | strcasecmp(new_name, "back_and_forth") == 0 || | 74 | strcasecmp(new_name, "back_and_forth") == 0 || |
70 | strcasecmp(new_name, "current") == 0) { | 75 | strcasecmp(new_name, "current") == 0 || |
76 | strcasecmp(new_name, "number") == 0) { | ||
71 | free(new_name); | 77 | free(new_name); |
72 | return cmd_results_new(CMD_INVALID, "rename", | 78 | return cmd_results_new(CMD_INVALID, "rename", |
73 | "Cannot use special workspace name '%s'", argv[argn]); | 79 | "Cannot use special workspace name '%s'", argv[argn]); |
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f5558bb4..ceb4cd6e 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _XOPEN_SOURCE 500 | 1 | #define _XOPEN_SOURCE 500 |
2 | #include <ctype.h> | ||
2 | #include <string.h> | 3 | #include <string.h> |
3 | #include <strings.h> | 4 | #include <strings.h> |
4 | #include "sway/commands.h" | 5 | #include "sway/commands.h" |
@@ -60,9 +61,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
60 | struct sway_container *ws = NULL; | 61 | struct sway_container *ws = NULL; |
61 | if (strcasecmp(argv[0], "number") == 0) { | 62 | if (strcasecmp(argv[0], "number") == 0) { |
62 | if (argc < 2) { | 63 | if (argc < 2) { |
63 | cmd_results_new(CMD_INVALID, "workspace", | 64 | return cmd_results_new(CMD_INVALID, "workspace", |
64 | "Expected workspace number"); | 65 | "Expected workspace number"); |
65 | } | 66 | } |
67 | if (!isdigit(argv[1][0])) { | ||
68 | return cmd_results_new(CMD_INVALID, "workspace", | ||
69 | "Invalid workspace number '%s'", argv[1]); | ||
70 | } | ||
66 | if (!(ws = workspace_by_number(argv[1]))) { | 71 | if (!(ws = workspace_by_number(argv[1]))) { |
67 | char *name = join_args(argv + 1, argc - 1); | 72 | char *name = join_args(argv + 1, argc - 1); |
68 | ws = workspace_create(NULL, name); | 73 | ws = workspace_create(NULL, name); |