diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/sway/commands.c b/sway/commands.c index 3f416afc..37c7169a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -18,41 +18,28 @@ | |||
18 | 18 | ||
19 | // Returns error object, or NULL if check succeeds. | 19 | // Returns error object, or NULL if check succeeds. |
20 | struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) { | 20 | struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) { |
21 | struct cmd_results *error = NULL; | 21 | const char *error_name = NULL; |
22 | switch (type) { | 22 | switch (type) { |
23 | case EXPECTED_MORE_THAN: | ||
24 | if (argc > val) { | ||
25 | return NULL; | ||
26 | } | ||
27 | error = cmd_results_new(CMD_INVALID, name, "Invalid %s command " | ||
28 | "(expected more than %d argument%s, got %d)", | ||
29 | name, val, (char*[2]){"s", ""}[argc==1], argc); | ||
30 | break; | ||
31 | case EXPECTED_AT_LEAST: | 23 | case EXPECTED_AT_LEAST: |
32 | if (argc >= val) { | 24 | if (argc < val) { |
33 | return NULL; | 25 | error_name = "at least "; |
34 | } | 26 | } |
35 | error = cmd_results_new(CMD_INVALID, name, "Invalid %s command " | ||
36 | "(expected at least %d argument%s, got %d)", | ||
37 | name, val, (char*[2]){"s", ""}[argc==1], argc); | ||
38 | break; | 27 | break; |
39 | case EXPECTED_LESS_THAN: | 28 | case EXPECTED_AT_MOST: |
40 | if (argc < val) { | 29 | if (argc > val) { |
41 | return NULL; | 30 | error_name = "at most "; |
42 | }; | 31 | } |
43 | error = cmd_results_new(CMD_INVALID, name, "Invalid %s command " | ||
44 | "(expected less than %d argument%s, got %d)", | ||
45 | name, val, (char*[2]){"s", ""}[argc==1], argc); | ||
46 | break; | 32 | break; |
47 | case EXPECTED_EQUAL_TO: | 33 | case EXPECTED_EQUAL_TO: |
48 | if (argc == val) { | 34 | if (argc != val) { |
49 | return NULL; | 35 | error_name = ""; |
50 | }; | 36 | } |
51 | error = cmd_results_new(CMD_INVALID, name, "Invalid %s command " | ||
52 | "(expected %d arguments, got %d)", name, val, argc); | ||
53 | break; | ||
54 | } | 37 | } |
55 | return error; | 38 | return error_name ? |
39 | cmd_results_new(CMD_INVALID, name, "Invalid %s command " | ||
40 | "(expected %s%d argument%s, got %d)", | ||
41 | name, error_name, val, val != 1 ? "s" : "", argc) | ||
42 | : NULL; | ||
56 | } | 43 | } |
57 | 44 | ||
58 | void apply_seat_config(struct seat_config *seat_config) { | 45 | void apply_seat_config(struct seat_config *seat_config) { |