aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/pw.c b/pw.c
index aaaeea0..1a1e5ea 100644
--- a/pw.c
+++ b/pw.c
@@ -801,9 +801,15 @@ static execode execute(pwstate *pw, char *cmd, char *resbuf,
size_t size, int count)
{
execode res = exec_failed;
- char *arg = cmd + 2 + strspn(cmd + 2, " \t");
+ char cmdbuf[16];
+ int cmdlen = 0;
+ int ntok = sscanf(cmd + 1, "%15[a-z]%n", cmdbuf, &cmdlen);
+ char *arg = cmd + 1 + cmdlen;
- if (cmd[0] == ':') switch (cmd[1]) {
+ if (*arg == ' ')
+ arg++;
+
+ if (cmd[0] == ':' && ntok == 1 && cmdlen == 1) switch (cmd[1]) {
case 'w': case 'a':
if (arg[0] == 0) {
snprintf(resbuf, size, "file name required!");
@@ -989,7 +995,7 @@ static execode execute(pwstate *pw, char *cmd, char *resbuf,
rflg = gr->flags;
fputs(((gr->flags & REG_EXTENDED)) ? ":E\n" : ":B\n", f);
}
- fputs(gr->inv ? ":v" : ":g", f);
+ fputs(gr->inv ? ":v " : ":g ", f);
fputs(gr->pat, f);
putc('\n', f);
}
@@ -1027,9 +1033,9 @@ static execode execute(pwstate *pw, char *cmd, char *resbuf,
res = exec_ok;
break;
default:
- snprintf(resbuf, size, "bad command");
+ goto badcmd;
break;
- } else {
+ } else if (cmd[0] == '?' || cmd[0] == '/') {
int trig = count > 0 ? count - 1 : count;
if (trig < pw->maxlines && trig < maxtrig)
@@ -1082,6 +1088,9 @@ static execode execute(pwstate *pw, char *cmd, char *resbuf,
}
}
}
+ } else {
+badcmd:
+ snprintf(resbuf, size, "unrecognized command");
}
return res;