diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-11 15:21:25 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-11 15:21:25 +0100 |
| commit | 7cc570357bd8887870b5b8504cd622c4d5edabd8 (patch) | |
| tree | 14644ceafbbfbe5cccd95eb29bb75c87271e5985 | |
| parent | ec9d22a3062fa7a4acda70a50059df848474676e (diff) | |
| download | vis-7cc570357bd8887870b5b8504cd622c4d5edabd8.tar.gz vis-7cc570357bd8887870b5b8504cd622c4d5edabd8.tar.xz | |
vis: cleanup `:set option` argument parsing logic
No longer accept "no" prefix for boolean options. Reject too many option
values (use proper quoting to specify values containing spaces).
| -rw-r--r-- | vis-cmds.c | 20 |
1 files changed, 5 insertions, 15 deletions
@@ -90,23 +90,12 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor } } - if (!argv[1]) { + if (!argv[1] || argv[3]) { vis_info_show(vis, "Expecting: set option [value]"); return false; } - Arg arg; - bool invert = false; - OptionDef *opt = NULL; - - if (!strncasecmp(argv[1], "no", 2)) { - opt = map_closest(vis->options, argv[1]+2); - if (opt && opt->type == OPTION_TYPE_BOOL) - invert = true; - else - opt = NULL; - } - + OptionDef *opt = map_closest(vis->options, argv[1]); if (!opt) opt = map_closest(vis->options, argv[1]); if (!opt) { @@ -119,6 +108,7 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor return false; } + Arg arg; switch (opt->type) { case OPTION_TYPE_STRING: if (!(opt->flags & OPTION_FLAG_OPTIONAL) && !argv[2]) { @@ -134,8 +124,6 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor vis_info_show(vis, "Expecting boolean option value not: `%s'", argv[2]); return false; } - if (invert) - arg.b = !arg.b; break; case OPTION_TYPE_NUMBER: case OPTION_TYPE_UNSIGNED: @@ -146,6 +134,8 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor /* TODO: error checking? long type */ arg.u = strtoul(argv[2], NULL, 10); break; + default: + return false; } size_t opt_index = opt - options; |
