diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/cmp.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/editors/cmp.c b/editors/cmp.c index e106d81..9eaff2b 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -18,12 +18,13 @@ //kbuild:lib-$(CONFIG_CMP) += cmp.o //usage:#define cmp_trivial_usage -//usage: "[-ls] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" +//usage: "[-ls] [-n NUM] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" //usage:#define cmp_full_usage "\n\n" //usage: "Compare FILE1 with FILE2 (or stdin)\n" //usage: "\n -l Write the byte numbers (decimal) and values (octal)" //usage: "\n for all differing bytes" //usage: "\n -s Quiet" +//usage: "\n -n NUM Compare at most NUM bytes" /* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ /* 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 // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; -#define OPT_STR "sl" +#define OPT_STR "sln:" #define CMP_OPT_s (1<<0) #define CMP_OPT_l (1<<1) +#define CMP_OPT_n (1<<2) int cmp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int cmp_main(int argc UNUSED_PARAM, char **argv) @@ -50,13 +52,15 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) int c1, c2; unsigned opt; int retval = 0; + int max_count = -1; opt = getopt32(argv, "^" OPT_STR - "\0" "-1" + "\0" "-1:n+" IF_DESKTOP(":?4") IF_NOT_DESKTOP(":?2") - ":l--s:s--l" + ":l--s:s--l", + &max_count ); argv += optind; @@ -95,6 +99,8 @@ int cmp_main(int argc UNUSED_PARAM, char **argv) while (skip2) { getc(fp2); skip2--; } } do { + if (max_count >= 0 && --max_count < 0) + break; c1 = getc(fp1); c2 = getc(fp2); ++char_pos; |