diff options
Diffstat (limited to 'editors/ed.c')
-rw-r--r-- | editors/ed.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/editors/ed.c b/editors/ed.c index 14540e566..dfe0f1a77 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 ) |
@@ -400,9 +402,6 @@ static int readLines(const char *file, int num) | |||
400 | charCount = 0; | 402 | charCount = 0; |
401 | cc = 0; | 403 | cc = 0; |
402 | 404 | ||
403 | printf("\"%s\", ", file); | ||
404 | fflush_all(); | ||
405 | |||
406 | do { | 405 | do { |
407 | cp = memchr(bufPtr, '\n', bufUsed); | 406 | cp = memchr(bufPtr, '\n', bufUsed); |
408 | 407 | ||
@@ -793,7 +792,7 @@ static void doCommands(void) | |||
793 | * 0 on ctrl-C, | 792 | * 0 on ctrl-C, |
794 | * >0 length of input string, including terminating '\n' | 793 | * >0 length of input string, including terminating '\n' |
795 | */ | 794 | */ |
796 | len = read_line_input(NULL, ": ", buf, sizeof(buf)); | 795 | len = read_line_input(NULL, prompt, buf, sizeof(buf)); |
797 | if (len <= 0) | 796 | if (len <= 0) |
798 | return; | 797 | return; |
799 | while (len && isspace(buf[--len])) | 798 | while (len && isspace(buf[--len])) |
@@ -1005,13 +1004,15 @@ int ed_main(int argc UNUSED_PARAM, char **argv) | |||
1005 | lines.next = &lines; | 1004 | lines.next = &lines; |
1006 | lines.prev = &lines; | 1005 | lines.prev = &lines; |
1007 | 1006 | ||
1008 | if (argv[1]) { | 1007 | prompt = ""; /* no prompt by default */ |
1009 | fileName = xstrdup(argv[1]); | 1008 | getopt32(argv, "p:", &prompt); |
1009 | argv += optind; | ||
1010 | |||
1011 | if (argv[0]) { | ||
1012 | fileName = xstrdup(argv[0]); | ||
1010 | if (!readLines(fileName, 1)) { | 1013 | if (!readLines(fileName, 1)) { |
1011 | return EXIT_SUCCESS; | 1014 | return EXIT_SUCCESS; |
1012 | } | 1015 | } |
1013 | if (lastNum) | ||
1014 | setCurNum(1); | ||
1015 | dirty = FALSE; | 1016 | dirty = FALSE; |
1016 | } | 1017 | } |
1017 | 1018 | ||