diff options
-rw-r--r-- | editors/ed.c | 14 |
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 | } |