From 46c52e5e2f70749803b2a3906e2da1d6d0b1fdf8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 16 May 2022 19:03:17 -0700 Subject: Change :s to :sa. --- pw.1 | 18 +++++++++++++++--- pw.c | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pw.1 b/pw.1 index 3f05bdc..c773b1c 100644 --- a/pw.1 +++ b/pw.1 @@ -589,8 +589,20 @@ letters .B a through .R z , -upper or lower case. Currently, no -command has a name more than one letter long. The command may be followed +upper or lower case. Only the first two letters of a command are significant: +for instance, the command +.B :save +is actually +.BR :sa . +Commands which are one letter long may not be written with superfluous +letters, though. For instance, +.B :grep +is not understood as +.B :g +but as the (nonexistent) command +.BR :gr . + +The command may be followed by an argument, which is separated from the command by exactly one space. If the argument does not begin with a lower-case letter, then the space may be omitted. If the command is followed by no characters at all, or @@ -744,7 +756,7 @@ Sets the display parameters, exactly in the manner of the option. Any parameters not specified are reset to their default initial values: zero in the case of character positions, off in the case of flags. -.IP "\fB:s\fP [\fIfilename\fP]" +.IP "\fB:sa\fP [\fIfilename\fP]" Save a snapshot of the configuration state to the specified file. The state is saved as a sequence of colon and trigger commands, such that the resulting file is suitable as an argument to the diff --git a/pw.c b/pw.c index 681fd6d..b675a4d 100644 --- a/pw.c +++ b/pw.c @@ -55,6 +55,8 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) +#define twocc(ch1, ch2) (((int) (ch1)) << 8 | (ch2)) + #ifdef __GNUC__ #define printf_attr(fmtpos, vargpos) __attribute__ ((format (printf, \ fmtpos, vargpos))) @@ -967,7 +969,10 @@ static execode execute(pwstate *pw, char *cmd, char *resbuf, } } break; - case 's': + default: + goto badcmd; + } else if (cmd[0] == ':' && ntok == 1) switch (twocc(cmd[1], cmd[2])) { + case twocc('s', 'a'): { int rflg = 0; FILE *f; -- cgit v1.2.3