diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-18 11:22:02 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-18 11:22:02 -0500 |
commit | 733993a651c71f7e2198d505960d6bbd31e0e107 (patch) | |
tree | e51732c5872b624e73355f9e5b3f762101f3cd0d /sway/commands/set.c | |
parent | Initial (awful) pass on xdg shell support (diff) | |
download | sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip |
Move everything to sway/old/
Diffstat (limited to 'sway/commands/set.c')
-rw-r--r-- | sway/commands/set.c | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/sway/commands/set.c b/sway/commands/set.c deleted file mode 100644 index 46fc6d38..00000000 --- a/sway/commands/set.c +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | #include <strings.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "list.h" | ||
8 | #include "stringop.h" | ||
9 | |||
10 | // sort in order of longest->shortest | ||
11 | static int compare_set_qsort(const void *_l, const void *_r) { | ||
12 | struct sway_variable const *l = *(void **)_l; | ||
13 | struct sway_variable const *r = *(void **)_r; | ||
14 | return strlen(r->name) - strlen(l->name); | ||
15 | } | ||
16 | |||
17 | struct cmd_results *cmd_set(int argc, char **argv) { | ||
18 | char *tmp; | ||
19 | struct cmd_results *error = NULL; | ||
20 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); | ||
21 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { | ||
22 | return error; | ||
23 | } | ||
24 | |||
25 | if (argv[0][0] != '$') { | ||
26 | sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); | ||
27 | |||
28 | size_t size = snprintf(NULL, 0, "$%s", argv[0]); | ||
29 | tmp = malloc(size + 1); | ||
30 | if (!tmp) { | ||
31 | return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); | ||
32 | } | ||
33 | snprintf(tmp, size+1, "$%s", argv[0]); | ||
34 | |||
35 | argv[0] = tmp; | ||
36 | } | ||
37 | |||
38 | struct sway_variable *var = NULL; | ||
39 | // Find old variable if it exists | ||
40 | int i; | ||
41 | for (i = 0; i < config->symbols->length; ++i) { | ||
42 | var = config->symbols->items[i]; | ||
43 | if (strcmp(var->name, argv[0]) == 0) { | ||
44 | break; | ||
45 | } | ||
46 | var = NULL; | ||
47 | } | ||
48 | if (var) { | ||
49 | free(var->value); | ||
50 | } else { | ||
51 | var = malloc(sizeof(struct sway_variable)); | ||
52 | if (!var) { | ||
53 | return cmd_results_new(CMD_FAILURE, "set", "Unable to allocate variable"); | ||
54 | } | ||
55 | var->name = strdup(argv[0]); | ||
56 | list_add(config->symbols, var); | ||
57 | list_qsort(config->symbols, compare_set_qsort); | ||
58 | } | ||
59 | var->value = join_args(argv + 1, argc - 1); | ||
60 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
61 | } | ||