diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-06 16:07:08 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-06 16:07:08 +0000 |
| commit | bc142140180c517dcb1c8bb59bdf9110f0a1422e (patch) | |
| tree | 12b66ed0a02fe336acabde21a0063194cd01404d /coreutils | |
| parent | 5fb0fecc1f934c414627931509cd993616c1f46f (diff) | |
| download | busybox-w32-bc142140180c517dcb1c8bb59bdf9110f0a1422e.tar.gz busybox-w32-bc142140180c517dcb1c8bb59bdf9110f0a1422e.tar.bz2 busybox-w32-bc142140180c517dcb1c8bb59bdf9110f0a1422e.zip | |
- patch from Rob Sullivan to add support for -L
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/diff.c | 100 |
1 files changed, 64 insertions, 36 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c index a45916dc7..2c89a66e4 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
| @@ -88,15 +88,16 @@ static unsigned long cmd_flags; | |||
| 88 | #define FLAG_b (1<<1) | 88 | #define FLAG_b (1<<1) |
| 89 | #define FLAG_d (1<<2) | 89 | #define FLAG_d (1<<2) |
| 90 | #define FLAG_i (1<<3) | 90 | #define FLAG_i (1<<3) |
| 91 | #define FLAG_N (1<<4) | 91 | #define FLAG_L (1<<4) |
| 92 | #define FLAG_q (1<<5) | 92 | #define FLAG_N (1<<5) |
| 93 | #define FLAG_r (1<<6) | 93 | #define FLAG_q (1<<6) |
| 94 | #define FLAG_s (1<<7) | 94 | #define FLAG_r (1<<7) |
| 95 | #define FLAG_S (1<<8) | 95 | #define FLAG_s (1<<8) |
| 96 | #define FLAG_t (1<<9) | 96 | #define FLAG_S (1<<9) |
| 97 | #define FLAG_T (1<<10) | 97 | #define FLAG_t (1<<10) |
| 98 | #define FLAG_U (1<<11) | 98 | #define FLAG_T (1<<11) |
| 99 | #define FLAG_w (1<<12) | 99 | #define FLAG_U (1<<12) |
| 100 | #define FLAG_w (1<<13) | ||
| 100 | 101 | ||
| 101 | int context, status; | 102 | int context, status; |
| 102 | char *start, *label[2]; | 103 | char *start, *label[2]; |
| @@ -376,7 +377,6 @@ static int isqrt(int n) { | |||
| 376 | return (x); | 377 | return (x); |
| 377 | } | 378 | } |
| 378 | 379 | ||
| 379 | |||
| 380 | static int newcand(int x, int y, int pred) | 380 | static int newcand(int x, int y, int pred) |
| 381 | { | 381 | { |
| 382 | struct cand *q; | 382 | struct cand *q; |
| @@ -422,10 +422,10 @@ static int stone(int *a, int n, int *b, int *c) | |||
| 422 | int i, k, y, j, l; | 422 | int i, k, y, j, l; |
| 423 | int oldc, tc, oldl; | 423 | int oldc, tc, oldl; |
| 424 | u_int numtries; | 424 | u_int numtries; |
| 425 | #ifdef CONFIG_FEATURE_DIFF_MINIMAL | 425 | #if ENABLE_FEATURE_DIFF_MINIMAL |
| 426 | const u_int bound = (cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n)); | 426 | const u_int bound = (cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n)); |
| 427 | #else | 427 | #else |
| 428 | const u_int bound = MAX(256, isqrt(n)); | 428 | const u_int bound = MAX(256, isqrt(n)); |
| 429 | #endif | 429 | #endif |
| 430 | k = 0; | 430 | k = 0; |
| 431 | c[0] = newcand(0, 0, 0); | 431 | c[0] = newcand(0, 0, 0); |
| @@ -672,7 +672,7 @@ static int fetch(long *f, int a, int b, FILE *lb, int ch) | |||
| 672 | 672 | ||
| 673 | static int asciifile(FILE *f) | 673 | static int asciifile(FILE *f) |
| 674 | { | 674 | { |
| 675 | #ifdef CONFIG_FEATURE_DIFF_BINARY | 675 | #if ENABLE_FEATURE_DIFF_BINARY |
| 676 | unsigned char buf[BUFSIZ]; | 676 | unsigned char buf[BUFSIZ]; |
| 677 | int i, cnt; | 677 | int i, cnt; |
| 678 | #endif | 678 | #endif |
| @@ -680,14 +680,16 @@ static int asciifile(FILE *f) | |||
| 680 | if ((cmd_flags & FLAG_a) || f == NULL) | 680 | if ((cmd_flags & FLAG_a) || f == NULL) |
| 681 | return (1); | 681 | return (1); |
| 682 | 682 | ||
| 683 | #ifdef CONFIG_FEATURE_DIFF_BINARY | 683 | #if ENABLE_FEATURE_DIFF_BINARY |
| 684 | rewind(f); | 684 | rewind(f); |
| 685 | cnt = fread(buf, 1, sizeof(buf), f); | 685 | cnt = fread(buf, 1, sizeof(buf), f); |
| 686 | for (i = 0; i < cnt; i++) | 686 | for (i = 0; i < cnt; i++) { |
| 687 | if (!isprint(buf[i]) && !isspace(buf[i])) | 687 | if (!isprint(buf[i]) && !isspace(buf[i])) { |
| 688 | return (0); | 688 | return (0); |
| 689 | } | ||
| 690 | } | ||
| 689 | #endif | 691 | #endif |
| 690 | return (1); | 692 | return (1); |
| 691 | } | 693 | } |
| 692 | 694 | ||
| 693 | /* dump accumulated "unified" diff changes */ | 695 | /* dump accumulated "unified" diff changes */ |
| @@ -837,7 +839,10 @@ static void change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, i | |||
| 837 | 839 | ||
| 838 | static void output(char *file1, FILE *f1, char *file2, FILE *f2) | 840 | static void output(char *file1, FILE *f1, char *file2, FILE *f2) |
| 839 | { | 841 | { |
| 840 | int m, i0, i1, j0, j1; | 842 | |
| 843 | /* Note that j0 and j1 can't be used as they are defined in math.h. | ||
| 844 | * This also allows the rather amusing variable 'j00'... */ | ||
| 845 | int m, i0, i1, j00, j01; | ||
| 841 | 846 | ||
| 842 | rewind(f1); | 847 | rewind(f1); |
| 843 | rewind(f2); | 848 | rewind(f2); |
| @@ -847,13 +852,13 @@ static void output(char *file1, FILE *f1, char *file2, FILE *f2) | |||
| 847 | for (i0 = 1; i0 <= m; i0 = i1 + 1) { | 852 | for (i0 = 1; i0 <= m; i0 = i1 + 1) { |
| 848 | while (i0 <= m && J[i0] == J[i0 - 1] + 1) | 853 | while (i0 <= m && J[i0] == J[i0 - 1] + 1) |
| 849 | i0++; | 854 | i0++; |
| 850 | j0 = J[i0 - 1] + 1; | 855 | j00 = J[i0 - 1] + 1; |
| 851 | i1 = i0 - 1; | 856 | i1 = i0 - 1; |
| 852 | while (i1 < m && J[i1 + 1] == 0) | 857 | while (i1 < m && J[i1 + 1] == 0) |
| 853 | i1++; | 858 | i1++; |
| 854 | j1 = J[i1 + 1] - 1; | 859 | j01 = J[i1 + 1] - 1; |
| 855 | J[i1] = j1; | 860 | J[i1] = j01; |
| 856 | change(file1, f1, file2, f2, i0, i1, j0, j1); | 861 | change(file1, f1, file2, f2, i0, i1, j00, j01); |
| 857 | } | 862 | } |
| 858 | if (m == 0) { | 863 | if (m == 0) { |
| 859 | change(file1, f1, file2, f2, 1, 0, 1, len[1]); | 864 | change(file1, f1, file2, f2, 1, 0, 1, len[1]); |
| @@ -1064,7 +1069,7 @@ static void do_diff (char *dir1, char *path1, char *dir2, char *path2) { | |||
| 1064 | } | 1069 | } |
| 1065 | #endif | 1070 | #endif |
| 1066 | 1071 | ||
| 1067 | #ifdef CONFIG_FEATURE_DIFF_DIR | 1072 | #if ENABLE_FEATURE_DIFF_DIR |
| 1068 | static int dir_strcmp(const void *p1, const void *p2) { | 1073 | static int dir_strcmp(const void *p1, const void *p2) { |
| 1069 | return strcmp(*(char * const *)p1, *(char * const *)p2); | 1074 | return strcmp(*(char * const *)p1, *(char * const *)p2); |
| 1070 | } | 1075 | } |
| @@ -1196,13 +1201,36 @@ static void diffdir (char *p1, char *p2) { | |||
| 1196 | 1201 | ||
| 1197 | 1202 | ||
| 1198 | 1203 | ||
| 1199 | extern int diff_main(int argc, char **argv) { | 1204 | int diff_main(int argc, char **argv) { |
| 1200 | char *ep; | 1205 | char *ep; |
| 1201 | int gotstdin = 0; | 1206 | int gotstdin = 0; |
| 1202 | 1207 | ||
| 1203 | char *U_opt; | 1208 | char *U_opt; |
| 1204 | cmd_flags = bb_getopt_ulflags(argc, argv, "abdiNqrsS:tTU:wu", &start, &U_opt); | 1209 | llist_t *L_arg = NULL; |
| 1205 | 1210 | bb_opt_complementally = "L::"; | |
| 1211 | cmd_flags = bb_getopt_ulflags(argc, argv, "abdiL:NqrsS:tTU:wu", &L_arg, &start, &U_opt); | ||
| 1212 | |||
| 1213 | if (cmd_flags & FLAG_L) { | ||
| 1214 | while (L_arg) { | ||
| 1215 | if (label[0] == NULL) | ||
| 1216 | label[0] = L_arg->data; | ||
| 1217 | else if (label[1] == NULL) | ||
| 1218 | label[1] = L_arg->data; | ||
| 1219 | else | ||
| 1220 | bb_show_usage(); | ||
| 1221 | |||
| 1222 | L_arg = L_arg->link; | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | /* If both label[0] and label[1] were set, they need to be swapped. */ | ||
| 1226 | if (label[0] && label[1]) { | ||
| 1227 | char *tmp; | ||
| 1228 | tmp = label[1]; | ||
| 1229 | label[1] = label[0]; | ||
| 1230 | label[0] = tmp; | ||
| 1231 | } | ||
| 1232 | } | ||
| 1233 | |||
| 1206 | context = 3; /* This is the default number of lines of context. */ | 1234 | context = 3; /* This is the default number of lines of context. */ |
| 1207 | if (cmd_flags & FLAG_U) { | 1235 | if (cmd_flags & FLAG_U) { |
| 1208 | context = strtol(U_opt, &ep, 10); | 1236 | context = strtol(U_opt, &ep, 10); |
| @@ -1235,23 +1263,23 @@ extern int diff_main(int argc, char **argv) { | |||
| 1235 | if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) | 1263 | if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) |
| 1236 | bb_error_msg_and_die("Can't compare - to a directory"); | 1264 | bb_error_msg_and_die("Can't compare - to a directory"); |
| 1237 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { | 1265 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
| 1238 | #ifdef CONFIG_FEATURE_DIFF_DIR | 1266 | #if ENABLE_FEATURE_DIFF_DIR |
| 1239 | diffdir(argv[0], argv[1]); | 1267 | diffdir(argv[0], argv[1]); |
| 1240 | #else | 1268 | #else |
| 1241 | bb_error_msg_and_die("Directory comparison not supported"); | 1269 | bb_error_msg_and_die("Directory comparison not supported"); |
| 1242 | #endif | 1270 | #endif |
| 1243 | } | 1271 | } |
| 1244 | else { | 1272 | else { |
| 1245 | if (S_ISDIR(stb1.st_mode)) { | 1273 | if (S_ISDIR(stb1.st_mode)) { |
| 1246 | argv[0] = concat_path_file(argv[0], argv[1]); | 1274 | argv[0] = concat_path_file(argv[0], argv[1]); |
| 1247 | if (stat(argv[0], &stb1) < 0) | 1275 | if (stat(argv[0], &stb1) < 0) |
| 1248 | bb_perror_msg_and_die("Couldn't stat %s", argv[0]); | 1276 | bb_perror_msg_and_die("Couldn't stat %s", argv[0]); |
| 1249 | } | 1277 | } |
| 1250 | if (S_ISDIR(stb2.st_mode)) { | 1278 | if (S_ISDIR(stb2.st_mode)) { |
| 1251 | argv[1] = concat_path_file(argv[1], argv[0]); | 1279 | argv[1] = concat_path_file(argv[1], argv[0]); |
| 1252 | if (stat(argv[1], &stb2) < 0) | 1280 | if (stat(argv[1], &stb2) < 0) |
| 1253 | bb_perror_msg_and_die("Couldn't stat %s", argv[1]); | 1281 | bb_perror_msg_and_die("Couldn't stat %s", argv[1]); |
| 1254 | } | 1282 | } |
| 1255 | print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], NULL); | 1283 | print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], NULL); |
| 1256 | } | 1284 | } |
| 1257 | exit(status); | 1285 | exit(status); |
