diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-06 11:28:19 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-06 11:28:19 +0000 |
commit | 5fb0fecc1f934c414627931509cd993616c1f46f (patch) | |
tree | 0a369c0151f7ada1aca1ed0ece6ae86400584961 | |
parent | cc4003f778bd1e861968dcf0cbcdd7428414c67b (diff) | |
download | busybox-w32-5fb0fecc1f934c414627931509cd993616c1f46f.tar.gz busybox-w32-5fb0fecc1f934c414627931509cd993616c1f46f.tar.bz2 busybox-w32-5fb0fecc1f934c414627931509cd993616c1f46f.zip |
- shrink it a little bit and make it buildable with gcc-2.95
text data bss dec hex filename
7332 4 92 7428 1d04 diff.o-gcc-4.2-HEAD.orig
7185 4 92 7281 1c71 diff.o-gcc-4.2-HEAD.new
7336 4 92 7432 1d08 diff.o-gcc-4.1-HEAD.orig
7148 4 92 7244 1c4c diff.o-gcc-4.1-HEAD.new
7485 4 92 7581 1d9d diff.o-gcc-4.0.orig
7318 4 92 7414 1cf6 diff.o-gcc-4.0.new
7511 4 92 7607 1db7 diff.o-gcc-3.4.orig
7252 4 92 7348 1cb4 diff.o-gcc-3.4.new
8214 4 92 8310 2076 diff.o-gcc-3.3.orig
7882 4 92 7978 1f2a diff.o-gcc-3.3.new
- - - - - diff.o-gcc-2.95.orig
8238 8 88 8334 208e diff.o-gcc-2.95.new
-rw-r--r-- | coreutils/diff.c | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c index b1345f8d0..a45916dc7 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -154,47 +154,48 @@ static void print_only(const char *path, size_t dirlen, const char *entry) | |||
154 | 154 | ||
155 | static void print_status(int val, char *path1, char *path2, char *entry) | 155 | static void print_status(int val, char *path1, char *path2, char *entry) |
156 | { | 156 | { |
157 | const char * const _entry = entry ? entry : ""; | ||
158 | char *_path1 = entry ? concat_path_file(path1, _entry) : path1; | ||
159 | char *_path2 = entry ? concat_path_file(path2, _entry) : path2; | ||
157 | switch (val) { | 160 | switch (val) { |
158 | case D_ONLY: | 161 | case D_ONLY: |
159 | print_only(path1, strlen(path1), entry); | 162 | print_only(path1, strlen(path1), entry); |
160 | break; | 163 | break; |
161 | case D_COMMON: | 164 | case D_COMMON: |
162 | printf("Common subdirectories: %s%s and %s%s\n", | 165 | printf("Common subdirectories: %s and %s\n", _path1, _path2); |
163 | path1, entry ? entry : "", path2, entry ? entry : ""); | ||
164 | break; | 166 | break; |
165 | case D_BINARY: | 167 | case D_BINARY: |
166 | printf("Binary files %s%s and %s%s differ\n", | 168 | printf("Binary files %s and %s differ\n", _path1, _path2); |
167 | path1, entry ? entry : "", path2, entry ? entry : ""); | ||
168 | break; | 169 | break; |
169 | case D_DIFFER: | 170 | case D_DIFFER: |
170 | if (cmd_flags & FLAG_q) | 171 | if (cmd_flags & FLAG_q) |
171 | printf("Files %s%s and %s%s differ\n", | 172 | printf("Files %s and %s differ\n", _path1, _path2); |
172 | path1, entry ? entry : "", | ||
173 | path2, entry ? entry : ""); | ||
174 | break; | 173 | break; |
175 | case D_SAME: | 174 | case D_SAME: |
176 | if (cmd_flags & FLAG_s) | 175 | if (cmd_flags & FLAG_s) |
177 | printf("Files %s%s and %s%s are identical\n", | 176 | printf("Files %s and %s are identical\n", _path1, _path2); |
178 | path1, entry ? entry : "", | ||
179 | path2, entry ? entry : ""); | ||
180 | break; | 177 | break; |
181 | case D_MISMATCH1: | 178 | case D_MISMATCH1: |
182 | printf("File %s%s is a directory while file %s%s is a regular file\n", | 179 | printf("File %s is a directory while file %s is a regular file\n", |
183 | path1, entry ? entry : "", path2, entry ? entry : ""); | 180 | _path1, _path2); |
184 | break; | 181 | break; |
185 | case D_MISMATCH2: | 182 | case D_MISMATCH2: |
186 | printf("File %s%s is a regular file while file %s%s is a directory\n", | 183 | printf("File %s is a regular file while file %s is a directory\n", |
187 | path1, entry ? entry : "", path2, entry ? entry : ""); | 184 | _path1, _path2); |
188 | break; | 185 | break; |
189 | case D_SKIPPED1: | 186 | case D_SKIPPED1: |
190 | printf("File %s%s is not a regular file or directory and was skipped\n", | 187 | printf("File %s is not a regular file or directory and was skipped\n", |
191 | path1, entry ? entry : ""); | 188 | _path1); |
192 | break; | 189 | break; |
193 | case D_SKIPPED2: | 190 | case D_SKIPPED2: |
194 | printf("File %s%s is not a regular file or directory and was skipped\n", | 191 | printf("File %s is not a regular file or directory and was skipped\n", |
195 | path2, entry ? entry : ""); | 192 | _path2); |
196 | break; | 193 | break; |
197 | } | 194 | } |
195 | if (entry) { | ||
196 | free(_path1); | ||
197 | free(_path2); | ||
198 | } | ||
198 | } | 199 | } |
199 | 200 | ||
200 | /* | 201 | /* |
@@ -293,8 +294,8 @@ static int files_differ(FILE *f1, FILE *f2, int flags) | |||
293 | static void prepare(int i, FILE *fd, off_t filesize) | 294 | static void prepare(int i, FILE *fd, off_t filesize) |
294 | { | 295 | { |
295 | struct line *p; | 296 | struct line *p; |
296 | int j, h; | 297 | int h; |
297 | size_t sz; | 298 | size_t j, sz; |
298 | 299 | ||
299 | rewind(fd); | 300 | rewind(fd); |
300 | 301 | ||
@@ -671,13 +672,15 @@ static int fetch(long *f, int a, int b, FILE *lb, int ch) | |||
671 | 672 | ||
672 | static int asciifile(FILE *f) | 673 | static int asciifile(FILE *f) |
673 | { | 674 | { |
675 | #ifdef CONFIG_FEATURE_DIFF_BINARY | ||
676 | unsigned char buf[BUFSIZ]; | ||
677 | int i, cnt; | ||
678 | #endif | ||
674 | 679 | ||
675 | if ((cmd_flags & FLAG_a) || f == NULL) | 680 | if ((cmd_flags & FLAG_a) || f == NULL) |
676 | return (1); | 681 | return (1); |
677 | #ifdef CONFIG_FEATURE_DIFF_BINARY | ||
678 | unsigned char buf[BUFSIZ]; | ||
679 | int i, cnt; | ||
680 | 682 | ||
683 | #ifdef CONFIG_FEATURE_DIFF_BINARY | ||
681 | rewind(f); | 684 | rewind(f); |
682 | cnt = fread(buf, 1, sizeof(buf), f); | 685 | cnt = fread(buf, 1, sizeof(buf), f); |
683 | for (i = 0; i < cnt; i++) | 686 | for (i = 0; i < cnt; i++) |
@@ -730,7 +733,7 @@ static void dump_unified_vec(FILE *f1, FILE *f2) | |||
730 | ch = 'c'; | 733 | ch = 'c'; |
731 | else | 734 | else |
732 | ch = (a <= b) ? 'd' : 'a'; | 735 | ch = (a <= b) ? 'd' : 'a'; |
733 | 736 | #if 0 | |
734 | switch (ch) { | 737 | switch (ch) { |
735 | case 'c': | 738 | case 'c': |
736 | fetch(ixold, lowa, a - 1, f1, ' '); | 739 | fetch(ixold, lowa, a - 1, f1, ' '); |
@@ -746,6 +749,16 @@ static void dump_unified_vec(FILE *f1, FILE *f2) | |||
746 | fetch(ixnew, c, d, f2, '+'); | 749 | fetch(ixnew, c, d, f2, '+'); |
747 | break; | 750 | break; |
748 | } | 751 | } |
752 | #else | ||
753 | if (ch == 'c' || ch == 'd') { | ||
754 | fetch(ixold, lowa, a - 1, f1, ' '); | ||
755 | fetch(ixold, a, b, f1, '-'); | ||
756 | } | ||
757 | if (ch == 'a') | ||
758 | fetch(ixnew, lowc, c - 1, f2, ' '); | ||
759 | if (ch == 'c' || ch == 'a') | ||
760 | fetch(ixnew, c, d, f2, '+'); | ||
761 | #endif | ||
749 | lowa = b + 1; | 762 | lowa = b + 1; |
750 | lowc = d + 1; | 763 | lowc = d + 1; |
751 | } | 764 | } |
@@ -948,12 +961,9 @@ static int diffreg(char *ofile1, char *ofile2, int flags) | |||
948 | f2 = bb_xfopen(file2, "r"); | 961 | f2 = bb_xfopen(file2, "r"); |
949 | } | 962 | } |
950 | 963 | ||
951 | switch (files_differ(f1, f2, flags)) { | 964 | if ((i=files_differ(f1, f2, flags)) == 0) |
952 | case 0: | ||
953 | goto closem; | 965 | goto closem; |
954 | case 1: | 966 | else if (i != 1) {/* 1 == ok */ |
955 | break; | ||
956 | default: | ||
957 | /* error */ | 967 | /* error */ |
958 | status |= 2; | 968 | status |= 2; |
959 | goto closem; | 969 | goto closem; |
@@ -1078,10 +1088,7 @@ static int add_to_dirlist (const char *filename, | |||
1078 | static char **get_dir(char *path) { | 1088 | static char **get_dir(char *path) { |
1079 | 1089 | ||
1080 | int i; | 1090 | int i; |
1081 | 1091 | char **retval; | |
1082 | /* Reset dl_count - there's no need to free dl as bb_xrealloc does | ||
1083 | * the job nicely. */ | ||
1084 | dl_count = 0; | ||
1085 | 1092 | ||
1086 | /* If -r has been set, then the recursive_action function will be | 1093 | /* If -r has been set, then the recursive_action function will be |
1087 | * used. Unfortunately, this outputs the root directory along with | 1094 | * used. Unfortunately, this outputs the root directory along with |
@@ -1091,7 +1098,11 @@ static char **get_dir(char *path) { | |||
1091 | 1098 | ||
1092 | int path_len = strlen(path); | 1099 | int path_len = strlen(path); |
1093 | void *userdata = &path_len; | 1100 | void *userdata = &path_len; |
1094 | 1101 | ||
1102 | /* Reset dl_count - there's no need to free dl as bb_xrealloc does | ||
1103 | * the job nicely. */ | ||
1104 | dl_count = 0; | ||
1105 | |||
1095 | /* Now fill dl with a listing. */ | 1106 | /* Now fill dl with a listing. */ |
1096 | if (cmd_flags & FLAG_r) | 1107 | if (cmd_flags & FLAG_r) |
1097 | recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL, userdata); | 1108 | recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL, userdata); |
@@ -1112,7 +1123,7 @@ static char **get_dir(char *path) { | |||
1112 | qsort(dl, dl_count, sizeof(char *), dir_strcmp); | 1123 | qsort(dl, dl_count, sizeof(char *), dir_strcmp); |
1113 | 1124 | ||
1114 | /* Copy dl so that we can return it. */ | 1125 | /* Copy dl so that we can return it. */ |
1115 | char **retval = xmalloc(dl_count * sizeof(char *)); | 1126 | retval = xmalloc(dl_count * sizeof(char *)); |
1116 | for (i = 0; i < dl_count; i++) | 1127 | for (i = 0; i < dl_count; i++) |
1117 | retval[i] = bb_xstrdup(dl[i]); | 1128 | retval[i] = bb_xstrdup(dl[i]); |
1118 | 1129 | ||