vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 04ea8421de978f89e546e999fa81b07d5b122f34 parent fe613e57557dbfc1b2fe68276059e2299372f275 Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 11 Nov 2016 15:21:25 +0100 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). Diffstat:
| M | vis-cmds.c | | | 20 | +++++--------------- |
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/vis-cmds.c b/vis-cmds.c @@ -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;