sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 95b96039755e86cf263bae342ed719e751bf0c1b
parent 67a00c86f97f672c9fbceba9ad7ac1f747cca10b
Author: Rene Kita <mail@rkta.de>
Date:   Tue, 26 Sep 2023 08:17:00 +0200

Ensure commands are followed by a blank

POSIX.1-2017 demands in Shell & Utilities under 'Commands in ed':
The e, E, f, r, and w commands shall take an optional file parameter,
separated from the command letter by one or more <blank> characters.

Ensure at least one <blank> character (as defined for the POSIX locale)
is present or error out.

Signed-off-by: Rene Kita <mail@rkta.de>

Diffstat:
Med.c | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/ed.c b/ed.c @@ -474,6 +474,24 @@ skipblank(void) back(c); } +static void +ensureblank(void) +{ + char c; + + switch ((c = input())) { + case ' ': + case '\t': + skipblank(); + case '\n': + back(c); + case EOF: + break; + default: + error("unknown command"); + } +} + static int getnum(void) { @@ -1145,10 +1163,12 @@ repeat: case 'w': trunc = 1; case 'W': + ensureblank(); deflines(nextln(0), lastln); dowrite(getfname(cmd), trunc); break; case 'r': + ensureblank(); if (nlines > 1) goto bad_address; deflines(lastln, lastln); @@ -1260,6 +1280,7 @@ repeat: quit(); break; case 'f': + ensureblank(); if (nlines > 0) goto unexpected; if (back(input()) != '\n') @@ -1271,6 +1292,7 @@ repeat: case 'E': modflag = 0; case 'e': + ensureblank(); if (nlines > 0) goto unexpected; if (modflag)