aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/cmp.c12
-rw-r--r--editors/ed.c19
-rw-r--r--editors/sed.c3
3 files changed, 20 insertions, 14 deletions
diff --git a/editors/cmp.c b/editors/cmp.c
index e106d814e..6d2b0c6c3 100644
--- a/editors/cmp.c
+++ b/editors/cmp.c
@@ -18,12 +18,13 @@
18//kbuild:lib-$(CONFIG_CMP) += cmp.o 18//kbuild:lib-$(CONFIG_CMP) += cmp.o
19 19
20//usage:#define cmp_trivial_usage 20//usage:#define cmp_trivial_usage
21//usage: "[-ls] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" 21//usage: "[-ls] [-n NUM] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]"
22//usage:#define cmp_full_usage "\n\n" 22//usage:#define cmp_full_usage "\n\n"
23//usage: "Compare FILE1 with FILE2 (or stdin)\n" 23//usage: "Compare FILE1 with FILE2 (or stdin)\n"
24//usage: "\n -l Write the byte numbers (decimal) and values (octal)" 24//usage: "\n -l Write the byte numbers (decimal) and values (octal)"
25//usage: "\n for all differing bytes" 25//usage: "\n for all differing bytes"
26//usage: "\n -s Quiet" 26//usage: "\n -s Quiet"
27//usage: "\n -n NUM Compare at most NUM bytes"
27 28
28/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ 29/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */
29/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */ 30/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */
@@ -35,9 +36,10 @@ static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u
35// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" 36// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n"
36static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; 37static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n";
37 38
38#define OPT_STR "sl" 39#define OPT_STR "sln:+"
39#define CMP_OPT_s (1<<0) 40#define CMP_OPT_s (1<<0)
40#define CMP_OPT_l (1<<1) 41#define CMP_OPT_l (1<<1)
42#define CMP_OPT_n (1<<2)
41 43
42int cmp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 44int cmp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
43int cmp_main(int argc UNUSED_PARAM, char **argv) 45int cmp_main(int argc UNUSED_PARAM, char **argv)
@@ -50,13 +52,15 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
50 int c1, c2; 52 int c1, c2;
51 unsigned opt; 53 unsigned opt;
52 int retval = 0; 54 int retval = 0;
55 int max_count = -1;
53 56
54 opt = getopt32(argv, "^" 57 opt = getopt32(argv, "^"
55 OPT_STR 58 OPT_STR
56 "\0" "-1" 59 "\0" "-1"
57 IF_DESKTOP(":?4") 60 IF_DESKTOP(":?4")
58 IF_NOT_DESKTOP(":?2") 61 IF_NOT_DESKTOP(":?2")
59 ":l--s:s--l" 62 ":l--s:s--l",
63 &max_count
60 ); 64 );
61 argv += optind; 65 argv += optind;
62 66
@@ -95,6 +99,8 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
95 while (skip2) { getc(fp2); skip2--; } 99 while (skip2) { getc(fp2); skip2--; }
96 } 100 }
97 do { 101 do {
102 if (max_count >= 0 && --max_count < 0)
103 break;
98 c1 = getc(fp1); 104 c1 = getc(fp1);
99 c2 = getc(fp2); 105 c2 = getc(fp2);
100 ++char_pos; 106 ++char_pos;
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
diff --git a/editors/sed.c b/editors/sed.c
index 523fb8dba..73034438a 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -441,8 +441,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
441 switch (substr[idx]) { 441 switch (substr[idx]) {
442 /* Replace all occurrences */ 442 /* Replace all occurrences */
443 case 'g': 443 case 'g':
444 if (match[0] != '^') 444 sed_cmd->which_match = 0;
445 sed_cmd->which_match = 0;
446 break; 445 break;
447 /* Print pattern space */ 446 /* Print pattern space */
448 case 'p': 447 case 'p':