aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-11-21 12:24:45 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-12-17 22:35:25 +0100
commitbfd8738154747d16f66ccfde3036dc21d39c7cec (patch)
tree90436ec94c1ce7533248ddf07b091d54d11275f5
parent579894bfd28ffb38f7dabc7862d4e7ebfade2865 (diff)
downloadbusybox-w32-bfd8738154747d16f66ccfde3036dc21d39c7cec.tar.gz
busybox-w32-bfd8738154747d16f66ccfde3036dc21d39c7cec.tar.bz2
busybox-w32-bfd8738154747d16f66ccfde3036dc21d39c7cec.zip
ed: add support for -p command-line option as mandated by POSIX
The POSIX.1-2008 specification of ed(1) mandates two command-line options: -p (for specifying a prompt string) and -s (to suppress writing of byte counts). This commit adds support for the former. Furthermore, it also changes the default prompt string to an empty string (instead of ": ") since this is also mandated by POSIX: -p string Use string as the prompt string when in command mode. By default, there shall be no prompt string. function old new delta ed_main 112 144 +32 packed_usage 34074 34097 +23 doCommands 1889 1887 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 55/-2) Total: 53 bytes Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/ed.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/editors/ed.c b/editors/ed.c
index 14540e566..18faba5a4 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -18,7 +18,7 @@
18 18
19//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) 19//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
20 20
21//usage:#define ed_trivial_usage "[FILE]" 21//usage:#define ed_trivial_usage "[-p PROMPT] [FILE]"
22//usage:#define ed_full_usage "" 22//usage:#define ed_full_usage ""
23 23
24#include "libbb.h" 24#include "libbb.h"
@@ -48,6 +48,7 @@ struct globals {
48 char *bufBase; 48 char *bufBase;
49 char *bufPtr; 49 char *bufPtr;
50 char *fileName; 50 char *fileName;
51 const char *prompt;
51 LINE lines; 52 LINE lines;
52 smallint dirty; 53 smallint dirty;
53 int marks[26]; 54 int marks[26];
@@ -57,6 +58,7 @@ struct globals {
57#define bufBase (G.bufBase ) 58#define bufBase (G.bufBase )
58#define bufPtr (G.bufPtr ) 59#define bufPtr (G.bufPtr )
59#define fileName (G.fileName ) 60#define fileName (G.fileName )
61#define prompt (G.prompt )
60#define curNum (G.curNum ) 62#define curNum (G.curNum )
61#define lastNum (G.lastNum ) 63#define lastNum (G.lastNum )
62#define bufUsed (G.bufUsed ) 64#define bufUsed (G.bufUsed )
@@ -793,7 +795,7 @@ static void doCommands(void)
793 * 0 on ctrl-C, 795 * 0 on ctrl-C,
794 * >0 length of input string, including terminating '\n' 796 * >0 length of input string, including terminating '\n'
795 */ 797 */
796 len = read_line_input(NULL, ": ", buf, sizeof(buf)); 798 len = read_line_input(NULL, prompt, buf, sizeof(buf));
797 if (len <= 0) 799 if (len <= 0)
798 return; 800 return;
799 while (len && isspace(buf[--len])) 801 while (len && isspace(buf[--len]))
@@ -1005,8 +1007,12 @@ int ed_main(int argc UNUSED_PARAM, char **argv)
1005 lines.next = &lines; 1007 lines.next = &lines;
1006 lines.prev = &lines; 1008 lines.prev = &lines;
1007 1009
1008 if (argv[1]) { 1010 prompt = ""; /* no prompt by default */
1009 fileName = xstrdup(argv[1]); 1011 getopt32(argv, "p:", &prompt);
1012 argv += optind;
1013
1014 if (argv[0]) {
1015 fileName = xstrdup(argv[0]);
1010 if (!readLines(fileName, 1)) { 1016 if (!readLines(fileName, 1)) {
1011 return EXIT_SUCCESS; 1017 return EXIT_SUCCESS;
1012 } 1018 }