vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit c532f7e163f2af962f689d4f4f6574654d0e4357
parent 92d4b3f7e84e86edb0f67f44e3b50af5c03b9916
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 12 Apr 2017 17:39:01 +0200

sam: reject command names containing digits or ending with a hyphen

The current implementation will also reject consecutive hyphens.

Diffstat:
Msam.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sam.c b/sam.c @@ -605,12 +605,17 @@ static void parse_argv(const char **s, const char *argv[], size_t maxarg) { } } +static bool valid_cmdname(const char *s) { + unsigned char c = (unsigned char)*s; + return c && !isspace(c) && !isdigit(c) && (!ispunct(c) || (c == '-' && valid_cmdname(s+1))); +} + static char *parse_cmdname(const char **s) { Buffer buf; buffer_init(&buf); skip_spaces(s); - while (**s && !isspace((unsigned char)**s) && (!ispunct((unsigned char)**s) || **s == '-')) + while (valid_cmdname(*s)) buffer_append(&buf, (*s)++, 1); buffer_terminate(&buf);