diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-21 22:30:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-21 22:30:14 +0000 |
commit | 9a1fa8cf07f66cc2585d8ff11eb07d6f5ca0e2b2 (patch) | |
tree | 7c47c189138b55be3f4871a5932f1a1679181925 | |
parent | 7c139b477882a06a86c31928d997d43c696dbc62 (diff) | |
download | busybox-w32-9a1fa8cf07f66cc2585d8ff11eb07d6f5ca0e2b2.tar.gz busybox-w32-9a1fa8cf07f66cc2585d8ff11eb07d6f5ca0e2b2.tar.bz2 busybox-w32-9a1fa8cf07f66cc2585d8ff11eb07d6f5ca0e2b2.zip |
cmp: support 3rd and 4th arguments if DESKTOP=y (needed for gcc build)
-rw-r--r-- | coreutils/cmp.c | 39 | ||||
-rw-r--r-- | include/usage.h | 2 |
2 files changed, 29 insertions, 12 deletions
diff --git a/coreutils/cmp.c b/coreutils/cmp.c index 0aebd4b4d..cff118279 100644 --- a/coreutils/cmp.c +++ b/coreutils/cmp.c | |||
@@ -34,9 +34,9 @@ static FILE *cmp_xfopen_input(const char * const filename) | |||
34 | } | 34 | } |
35 | 35 | ||
36 | static const char fmt_eof[] = "cmp: EOF on %s\n"; | 36 | static const char fmt_eof[] = "cmp: EOF on %s\n"; |
37 | static const char fmt_differ[] = "%s %s differ: char %d, line %d\n"; | 37 | static const char fmt_differ[] = "%s %s differ: char %"OFF_FMT"d, line %d\n"; |
38 | // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%d %o %o\n" | 38 | // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"d %o %o\n" |
39 | static const char fmt_l_opt[] = "%.0s%.0s%d %3o %3o\n"; | 39 | static const char fmt_l_opt[] = "%.0s%.0s%"OFF_FMT"d %3o %3o\n"; |
40 | 40 | ||
41 | static const char opt_chars[] = "sl"; | 41 | static const char opt_chars[] = "sl"; |
42 | #define CMP_OPT_s (1<<0) | 42 | #define CMP_OPT_s (1<<0) |
@@ -47,27 +47,40 @@ int cmp_main(int argc, char **argv) | |||
47 | { | 47 | { |
48 | FILE *fp1, *fp2, *outfile = stdout; | 48 | FILE *fp1, *fp2, *outfile = stdout; |
49 | const char *filename1, *filename2 = "-"; | 49 | const char *filename1, *filename2 = "-"; |
50 | USE_DESKTOP(off_t skip1 = 0, skip2 = 0;) | ||
51 | off_t char_pos = 0; | ||
52 | int line_pos = 1; /* Hopefully won't overflow... */ | ||
50 | const char *fmt; | 53 | const char *fmt; |
51 | int c1, c2, char_pos = 0, line_pos = 1; | 54 | int c1, c2; |
52 | unsigned opt; | 55 | unsigned opt; |
53 | int retval = 0; | 56 | int retval = 0; |
54 | 57 | ||
55 | xfunc_error_retval = 2; /* 1 is returned if files are different. */ | 58 | xfunc_error_retval = 2; /* 1 is returned if files are different. */ |
56 | 59 | ||
60 | opt_complementary = "?:-1" | ||
61 | USE_DESKTOP(":?4") | ||
62 | SKIP_DESKTOP(":?2") | ||
63 | ":l--s:s--l"; | ||
57 | opt = getopt32(argc, argv, opt_chars); | 64 | opt = getopt32(argc, argv, opt_chars); |
65 | argv += optind; | ||
58 | 66 | ||
59 | if (((opt & (CMP_OPT_s|CMP_OPT_l)) == (CMP_OPT_s|CMP_OPT_l)) | 67 | filename1 = *argv; |
60 | || (((unsigned int)(--argc - optind)) > 1)) | 68 | fp1 = cmp_xfopen_input(filename1); |
61 | bb_show_usage(); | ||
62 | |||
63 | fp1 = cmp_xfopen_input(filename1 = *(argv += optind)); | ||
64 | 69 | ||
65 | if (*++argv) { | 70 | if (*++argv) { |
66 | filename2 = *argv; | 71 | filename2 = *argv; |
72 | #if ENABLE_DESKTOP | ||
73 | if (*++argv) { | ||
74 | skip1 = XATOOFF(*argv); | ||
75 | if (*++argv) { | ||
76 | skip2 = XATOOFF(*argv); | ||
77 | } | ||
78 | } | ||
79 | #endif | ||
67 | } | 80 | } |
68 | fp2 = cmp_xfopen_input(filename2); | ||
69 | 81 | ||
70 | if (fp1 == fp2) { /* Paranioa check... stdin == stdin? */ | 82 | fp2 = cmp_xfopen_input(filename2); |
83 | if (fp1 == fp2) { /* Paranoia check... stdin == stdin? */ | ||
71 | /* Note that we don't bother reading stdin. Neither does gnu wc. | 84 | /* Note that we don't bother reading stdin. Neither does gnu wc. |
72 | * But perhaps we should, so that other apps down the chain don't | 85 | * But perhaps we should, so that other apps down the chain don't |
73 | * get the input. Consider 'echo hello | (cmp - - && cat -)'. | 86 | * get the input. Consider 'echo hello | (cmp - - && cat -)'. |
@@ -80,6 +93,10 @@ int cmp_main(int argc, char **argv) | |||
80 | else | 93 | else |
81 | fmt = fmt_differ; | 94 | fmt = fmt_differ; |
82 | 95 | ||
96 | #if ENABLE_DESKTOP | ||
97 | while (skip1) { getc(fp1); skip1--; } | ||
98 | while (skip2) { getc(fp2); skip2--; } | ||
99 | #endif | ||
83 | do { | 100 | do { |
84 | c1 = getc(fp1); | 101 | c1 = getc(fp1); |
85 | c2 = getc(fp2); | 102 | c2 = getc(fp2); |
diff --git a/include/usage.h b/include/usage.h index db38504b8..66f8638f5 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -377,7 +377,7 @@ | |||
377 | "Clear screen" | 377 | "Clear screen" |
378 | 378 | ||
379 | #define cmp_trivial_usage \ | 379 | #define cmp_trivial_usage \ |
380 | "[-l] [-s] FILE1 [FILE2]" | 380 | "[-l] [-s] FILE1 [FILE2" USE_DESKTOP(" [SKIP1 [SKIP2]") "]]" |
381 | #define cmp_full_usage \ | 381 | #define cmp_full_usage \ |
382 | "Compares FILE1 vs stdin if FILE2 is not specified" \ | 382 | "Compares FILE1 vs stdin if FILE2 is not specified" \ |
383 | "\n\nOptions:\n" \ | 383 | "\n\nOptions:\n" \ |