diff options
-rw-r--r-- | sway/commands.c | 21 | ||||
-rw-r--r-- | sway/stringop.c | 9 |
2 files changed, 26 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index f6d56bb4..42105d5f 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1401,17 +1401,34 @@ struct cmd_results *handle_command(char *_exec) { | |||
1401 | 1401 | ||
1402 | head = exec; | 1402 | head = exec; |
1403 | do { | 1403 | do { |
1404 | // Handle criteria | 1404 | // Extract criteria (valid for this command list only). |
1405 | criteria = NULL; | ||
1405 | if (*head == '[') { | 1406 | if (*head == '[') { |
1407 | ++head; | ||
1406 | criteria = argsep(&head, "]"); | 1408 | criteria = argsep(&head, "]"); |
1407 | if (head) { | 1409 | if (head) { |
1408 | ++head; | 1410 | ++head; |
1409 | // TODO handle criteria | 1411 | // TODO handle criteria |
1410 | } else { | 1412 | } else { |
1411 | results = cmd_results_new(CMD_INVALID, NULL, "Unmatched ["); | 1413 | if (!results) { |
1414 | results = cmd_results_new(CMD_INVALID, criteria, "Unmatched ["); | ||
1415 | } | ||
1416 | goto cleanup; | ||
1412 | } | 1417 | } |
1413 | // Skip leading whitespace | 1418 | // Skip leading whitespace |
1414 | head += strspn(head, whitespace); | 1419 | head += strspn(head, whitespace); |
1420 | |||
1421 | // TODO: it will yield unexpected results to execute commands | ||
1422 | // (on any view) that where meant for certain views only. | ||
1423 | if (!results) { | ||
1424 | int len = strlen(criteria) + strlen(head) + 4; | ||
1425 | char *tmp = malloc(len); | ||
1426 | snprintf(tmp, len, "[%s] %s", criteria, head); | ||
1427 | results = cmd_results_new(CMD_INVALID, tmp, | ||
1428 | "Can't handle criteria string: Refusing to execute command"); | ||
1429 | free(tmp); | ||
1430 | } | ||
1431 | goto cleanup; | ||
1415 | } | 1432 | } |
1416 | // Split command list | 1433 | // Split command list |
1417 | cmdlist = argsep(&head, ";"); | 1434 | cmdlist = argsep(&head, ";"); |
diff --git a/sway/stringop.c b/sway/stringop.c index fe5a97ca..efa3a207 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -117,6 +117,7 @@ char **split_args(const char *start, int *argc) { | |||
117 | bool in_token = false; | 117 | bool in_token = false; |
118 | bool in_string = false; | 118 | bool in_string = false; |
119 | bool in_char = false; | 119 | bool in_char = false; |
120 | bool in_brackets = false; // brackets are used for critera | ||
120 | bool escaped = false; | 121 | bool escaped = false; |
121 | const char *end = start; | 122 | const char *end = start; |
122 | if (start) { | 123 | if (start) { |
@@ -129,10 +130,14 @@ char **split_args(const char *start, int *argc) { | |||
129 | in_string = !in_string; | 130 | in_string = !in_string; |
130 | } else if (*end == '\'' && !in_string && !escaped) { | 131 | } else if (*end == '\'' && !in_string && !escaped) { |
131 | in_char = !in_char; | 132 | in_char = !in_char; |
133 | } else if (*end == '[' && !in_string && !in_char && !in_brackets && !escaped) { | ||
134 | in_brackets = true; | ||
135 | } else if (*end == ']' && !in_string && !in_char && in_brackets && !escaped) { | ||
136 | in_brackets = false; | ||
132 | } else if (*end == '\\') { | 137 | } else if (*end == '\\') { |
133 | escaped = !escaped; | 138 | escaped = !escaped; |
134 | } else if (*end == '\0' || (!in_string && !in_char && !escaped | 139 | } else if (*end == '\0' || (!in_string && !in_char && !in_brackets |
135 | && strchr(whitespace, *end))) { | 140 | && !escaped && strchr(whitespace, *end))) { |
136 | goto add_token; | 141 | goto add_token; |
137 | } | 142 | } |
138 | if (*end != '\\') { | 143 | if (*end != '\\') { |