2018-04-24 06:59:49 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/criteria.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
2018-05-13 00:16:36 +02:00
|
|
|
#include "stringop.h"
|
2018-04-24 06:59:49 +02:00
|
|
|
|
|
|
|
struct cmd_results *cmd_assign(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
|
|
|
if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
// Create criteria
|
|
|
|
char *err_str = NULL;
|
|
|
|
struct criteria *criteria = criteria_parse(argv[0], &err_str);
|
|
|
|
if (!criteria) {
|
2023-02-28 16:24:03 +01:00
|
|
|
error = cmd_results_new(CMD_INVALID, "%s", err_str);
|
2018-05-13 00:16:36 +02:00
|
|
|
free(err_str);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-08-12 01:38:19 +02:00
|
|
|
--argc; ++argv;
|
2018-04-24 06:59:49 +02:00
|
|
|
|
|
|
|
if (strncmp(*argv, "→", strlen("→")) == 0) {
|
2018-08-12 01:38:19 +02:00
|
|
|
if (argc < 2) {
|
2018-07-01 16:17:28 +02:00
|
|
|
free(criteria);
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID, "Missing workspace");
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|
2018-08-12 01:38:19 +02:00
|
|
|
--argc;
|
2018-05-13 00:16:36 +02:00
|
|
|
++argv;
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (strcmp(*argv, "output") == 0) {
|
|
|
|
criteria->type = CT_ASSIGN_OUTPUT;
|
2018-08-12 01:38:19 +02:00
|
|
|
--argc; ++argv;
|
2018-05-13 00:16:36 +02:00
|
|
|
} else {
|
2018-08-12 01:38:19 +02:00
|
|
|
if (strcmp(*argv, "workspace") == 0) {
|
|
|
|
--argc; ++argv;
|
|
|
|
}
|
|
|
|
if (strcmp(*argv, "number") == 0) {
|
|
|
|
--argc; ++argv;
|
|
|
|
if (argv[0][0] < '0' || argv[0][0] > '9') {
|
|
|
|
free(criteria);
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2018-08-12 01:38:19 +02:00
|
|
|
"Invalid workspace number '%s'", argv[0]);
|
|
|
|
}
|
|
|
|
criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
|
|
|
|
} else {
|
|
|
|
criteria->type = CT_ASSIGN_WORKSPACE;
|
|
|
|
}
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-12 01:38:19 +02:00
|
|
|
criteria->target = join_args(argv, argc);
|
2018-05-09 06:23:20 +02:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
list_add(config->criteria, criteria);
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
|
2018-05-13 00:16:36 +02:00
|
|
|
criteria->target);
|
|
|
|
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-04-24 06:59:49 +02:00
|
|
|
}
|