mirror of
https://github.com/swaywm/sway.git
synced 2024-11-17 13:42:36 +00:00
Merge pull request #250 from sce/initial_support_for_criteria_strings
Initial support for criteria strings
This commit is contained in:
commit
8ad8ceeeb9
|
@ -1401,17 +1401,34 @@ struct cmd_results *handle_command(char *_exec) {
|
||||||
|
|
||||||
head = exec;
|
head = exec;
|
||||||
do {
|
do {
|
||||||
// Handle criteria
|
// Extract criteria (valid for this command list only).
|
||||||
|
criteria = NULL;
|
||||||
if (*head == '[') {
|
if (*head == '[') {
|
||||||
|
++head;
|
||||||
criteria = argsep(&head, "]");
|
criteria = argsep(&head, "]");
|
||||||
if (head) {
|
if (head) {
|
||||||
++head;
|
++head;
|
||||||
// TODO handle criteria
|
// TODO handle criteria
|
||||||
} else {
|
} else {
|
||||||
results = cmd_results_new(CMD_INVALID, NULL, "Unmatched [");
|
if (!results) {
|
||||||
|
results = cmd_results_new(CMD_INVALID, criteria, "Unmatched [");
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
// Skip leading whitespace
|
// Skip leading whitespace
|
||||||
head += strspn(head, whitespace);
|
head += strspn(head, whitespace);
|
||||||
|
|
||||||
|
// TODO: it will yield unexpected results to execute commands
|
||||||
|
// (on any view) that where meant for certain views only.
|
||||||
|
if (!results) {
|
||||||
|
int len = strlen(criteria) + strlen(head) + 4;
|
||||||
|
char *tmp = malloc(len);
|
||||||
|
snprintf(tmp, len, "[%s] %s", criteria, head);
|
||||||
|
results = cmd_results_new(CMD_INVALID, tmp,
|
||||||
|
"Can't handle criteria string: Refusing to execute command");
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
// Split command list
|
// Split command list
|
||||||
cmdlist = argsep(&head, ";");
|
cmdlist = argsep(&head, ";");
|
||||||
|
|
|
@ -117,6 +117,7 @@ char **split_args(const char *start, int *argc) {
|
||||||
bool in_token = false;
|
bool in_token = false;
|
||||||
bool in_string = false;
|
bool in_string = false;
|
||||||
bool in_char = false;
|
bool in_char = false;
|
||||||
|
bool in_brackets = false; // brackets are used for critera
|
||||||
bool escaped = false;
|
bool escaped = false;
|
||||||
const char *end = start;
|
const char *end = start;
|
||||||
if (start) {
|
if (start) {
|
||||||
|
@ -129,10 +130,14 @@ char **split_args(const char *start, int *argc) {
|
||||||
in_string = !in_string;
|
in_string = !in_string;
|
||||||
} else if (*end == '\'' && !in_string && !escaped) {
|
} else if (*end == '\'' && !in_string && !escaped) {
|
||||||
in_char = !in_char;
|
in_char = !in_char;
|
||||||
|
} else if (*end == '[' && !in_string && !in_char && !in_brackets && !escaped) {
|
||||||
|
in_brackets = true;
|
||||||
|
} else if (*end == ']' && !in_string && !in_char && in_brackets && !escaped) {
|
||||||
|
in_brackets = false;
|
||||||
} else if (*end == '\\') {
|
} else if (*end == '\\') {
|
||||||
escaped = !escaped;
|
escaped = !escaped;
|
||||||
} else if (*end == '\0' || (!in_string && !in_char && !escaped
|
} else if (*end == '\0' || (!in_string && !in_char && !in_brackets
|
||||||
&& strchr(whitespace, *end))) {
|
&& !escaped && strchr(whitespace, *end))) {
|
||||||
goto add_token;
|
goto add_token;
|
||||||
}
|
}
|
||||||
if (*end != '\\') {
|
if (*end != '\\') {
|
||||||
|
|
Loading…
Reference in a new issue