diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 9 | ||||
-rw-r--r-- | sway/stringop.c | 11 |
2 files changed, 11 insertions, 9 deletions
diff --git a/sway/commands.c b/sway/commands.c index 423b576f..09ee91e8 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -368,26 +368,27 @@ static bool cmd_mode(int argc, char **argv) { if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { return false; } - const char *mode_name = argv[0]; + bool mode_make = strcmp(argv[argc-1], "{") == 0; + const char *mode_name = join_args(argv, argc - mode_make); struct sway_mode *mode = NULL; // Find mode int i, len = config->modes->length; for (i = 0; i < len; ++i) { struct sway_mode *find = config->modes->items[i]; - if (strcasecmp(find->name, mode_name)==0) { + if (strcasecmp(find->name, mode_name) == 0) { mode = find; break; } } // Create mode if it doesnt exist - if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) { + if (!mode && mode_make) { mode = malloc(sizeof*mode); mode->name = strdup(mode_name); mode->bindings = create_list(); list_add(config->modes, mode); } if (!mode) { - sway_log(L_ERROR, "Invalide mode `%s'", mode_name); + sway_log(L_ERROR, "Unknown mode `%s'", mode_name); return false; } sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); diff --git a/sway/stringop.c b/sway/stringop.c index 7de6eded..270e673a 100644 --- a/sway/stringop.c +++ b/sway/stringop.c @@ -99,7 +99,7 @@ void free_flat_list(list_t *list) { char **split_args(const char *start, int *argc) { *argc = 0; int alloc = 2; - char **parts = malloc(sizeof(char *) * alloc); + char **argv = malloc(sizeof(char *) * alloc); bool in_token = false; bool in_string = false; bool in_char = false; @@ -132,15 +132,16 @@ char **split_args(const char *start, int *argc) { token[end - start] = '\0'; strip_quotes(token); unescape_string(token); - parts[*argc] = token; - if (++*argc == alloc) { - parts = realloc(parts, (alloc *= 2) * sizeof(char *)); + argv[*argc] = token; + if (++*argc + 1 == alloc) { + argv = realloc(argv, (alloc *= 2) * sizeof(char *)); } } in_token = false; escaped = false; } - return parts; + argv[*argc] = NULL; + return argv; } void free_argv(int argc, char **argv) { |