diff options
author | taiyu <taiyu.len@gmail.com> | 2015-09-08 10:53:15 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-09-08 10:53:15 -0700 |
commit | 6388241abb7e2e66e716fc128e658d3d3419442a (patch) | |
tree | ac715db07ee07ff0226434e9a8228d187a77cb64 | |
parent | 799ff640f8c15dde5f8d65fdd71f91bab7aaa5fe (diff) |
mode supports multi token names
-rw-r--r-- | include/commands.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 9 | ||||
-rw-r--r-- | sway/stringop.c | 11 |
3 files changed, 11 insertions, 10 deletions
diff --git a/include/commands.h b/include/commands.h index e521306c..0a38ce43 100644 --- a/include/commands.h +++ b/include/commands.h @@ -13,7 +13,6 @@ struct cmd_handler { } config_type; }; -struct cmd_handler *find_handler(char *line); bool handle_command(char *command); // Handles commands during config bool config_command(char *command); 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) { |