1 #include <strings.h>
2 #include "sway/commands.h"
3 #include "sway/config.h"
4 
output_cmd_position(int argc,char ** argv)5 struct cmd_results *output_cmd_position(int argc, char **argv) {
6 	if (!config->handler_context.output_config) {
7 		return cmd_results_new(CMD_FAILURE, "Missing output config");
8 	}
9 	if (!argc) {
10 		return cmd_results_new(CMD_INVALID, "Missing position argument.");
11 	}
12 
13 	char *end;
14 	config->handler_context.output_config->x = strtol(*argv, &end, 10);
15 	if (*end) {
16 		// Format is 1234,4321
17 		if (*end != ',') {
18 			return cmd_results_new(CMD_INVALID, "Invalid position x.");
19 		}
20 		++end;
21 		config->handler_context.output_config->y = strtol(end, &end, 10);
22 		if (*end) {
23 			return cmd_results_new(CMD_INVALID, "Invalid position y.");
24 		}
25 	} else {
26 		// Format is 1234 4321 (legacy)
27 		argc--; argv++;
28 		if (!argc) {
29 			return cmd_results_new(CMD_INVALID, "Missing position argument (y).");
30 		}
31 		config->handler_context.output_config->y = strtol(*argv, &end, 10);
32 		if (*end) {
33 			return cmd_results_new(CMD_INVALID, "Invalid position y.");
34 		}
35 	}
36 
37 	config->handler_context.leftovers.argc = argc - 1;
38 	config->handler_context.leftovers.argv = argv + 1;
39 	return NULL;
40 }
41 
42