diff options
Diffstat (limited to 'editors/diff.c')
| -rw-r--r-- | editors/diff.c | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/editors/diff.c b/editors/diff.c index 830c15ea6..ef39623ef 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
| @@ -65,6 +65,8 @@ | |||
| 65 | #define FLAG_U (1<<12) | 65 | #define FLAG_U (1<<12) |
| 66 | #define FLAG_w (1<<13) | 66 | #define FLAG_w (1<<13) |
| 67 | 67 | ||
| 68 | #define g_read_buf bb_common_bufsiz1 | ||
| 69 | |||
| 68 | struct cand { | 70 | struct cand { |
| 69 | int x; | 71 | int x; |
| 70 | int y; | 72 | int y; |
| @@ -208,14 +210,14 @@ static void print_status(int val, char *path1, char *path2, char *entry) | |||
| 208 | free(_path2); | 210 | free(_path2); |
| 209 | } | 211 | } |
| 210 | } | 212 | } |
| 211 | static void fiddle_sum(int *sum, int t) | 213 | static ALWAYS_INLINE int fiddle_sum(int sum, int t) |
| 212 | { | 214 | { |
| 213 | *sum = (int)(*sum * 127 + t); | 215 | return sum * 127 + t; |
| 214 | } | 216 | } |
| 215 | /* | 217 | /* |
| 216 | * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578. | 218 | * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578. |
| 217 | */ | 219 | */ |
| 218 | static int readhash(FILE * f) | 220 | static int readhash(FILE *fp) |
| 219 | { | 221 | { |
| 220 | int i, t, space; | 222 | int i, t, space; |
| 221 | int sum; | 223 | int sum; |
| @@ -223,17 +225,17 @@ static int readhash(FILE * f) | |||
| 223 | sum = 1; | 225 | sum = 1; |
| 224 | space = 0; | 226 | space = 0; |
| 225 | if (!(option_mask32 & (FLAG_b | FLAG_w))) { | 227 | if (!(option_mask32 & (FLAG_b | FLAG_w))) { |
| 226 | for (i = 0; (t = getc(f)) != '\n'; i++) { | 228 | for (i = 0; (t = getc(fp)) != '\n'; i++) { |
| 227 | if (t == EOF) { | 229 | if (t == EOF) { |
| 228 | if (i == 0) | 230 | if (i == 0) |
| 229 | return 0; | 231 | return 0; |
| 230 | break; | 232 | break; |
| 231 | } | 233 | } |
| 232 | fiddle_sum(&sum, t); | 234 | sum = fiddle_sum(sum, t); |
| 233 | } | 235 | } |
| 234 | } else { | 236 | } else { |
| 235 | for (i = 0;;) { | 237 | for (i = 0;;) { |
| 236 | switch (t = getc(f)) { | 238 | switch (t = getc(fp)) { |
| 237 | case '\t': | 239 | case '\t': |
| 238 | case '\r': | 240 | case '\r': |
| 239 | case '\v': | 241 | case '\v': |
| @@ -246,7 +248,7 @@ static int readhash(FILE * f) | |||
| 246 | i++; | 248 | i++; |
| 247 | space = 0; | 249 | space = 0; |
| 248 | } | 250 | } |
| 249 | fiddle_sum(&sum, t); | 251 | sum = fiddle_sum(sum, t); |
| 250 | i++; | 252 | i++; |
| 251 | continue; | 253 | continue; |
| 252 | case EOF: | 254 | case EOF: |
| @@ -271,7 +273,7 @@ static int readhash(FILE * f) | |||
| 271 | * Check to see if the given files differ. | 273 | * Check to see if the given files differ. |
| 272 | * Returns 0 if they are the same, 1 if different, and -1 on error. | 274 | * Returns 0 if they are the same, 1 if different, and -1 on error. |
| 273 | */ | 275 | */ |
| 274 | static int files_differ(FILE * f1, FILE * f2, int flags) | 276 | static int files_differ(FILE *f1, FILE *f2, int flags) |
| 275 | { | 277 | { |
| 276 | size_t i, j; | 278 | size_t i, j; |
| 277 | 279 | ||
| @@ -281,37 +283,37 @@ static int files_differ(FILE * f1, FILE * f2, int flags) | |||
| 281 | return 1; | 283 | return 1; |
| 282 | } | 284 | } |
| 283 | while (1) { | 285 | while (1) { |
| 284 | i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1); | 286 | i = fread(g_read_buf, 1, COMMON_BUFSIZE/2, f1); |
| 285 | j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2); | 287 | j = fread(g_read_buf + COMMON_BUFSIZE/2, 1, COMMON_BUFSIZE/2, f2); |
| 286 | if (i != j) | 288 | if (i != j) |
| 287 | return 1; | 289 | return 1; |
| 288 | if (i == 0) | 290 | if (i == 0) |
| 289 | return (ferror(f1) || ferror(f2)); | 291 | return (ferror(f1) || ferror(f2)); |
| 290 | if (memcmp(bb_common_bufsiz1, | 292 | if (memcmp(g_read_buf, |
| 291 | bb_common_bufsiz1 + BUFSIZ/2, i) != 0) | 293 | g_read_buf + COMMON_BUFSIZE/2, i) != 0) |
| 292 | return 1; | 294 | return 1; |
| 293 | } | 295 | } |
| 294 | } | 296 | } |
| 295 | 297 | ||
| 296 | 298 | ||
| 297 | static void prepare(int i, FILE * fd, off_t filesize) | 299 | static void prepare(int i, FILE *fp /*, off_t filesize*/) |
| 298 | { | 300 | { |
| 299 | struct line *p; | 301 | struct line *p; |
| 300 | int h; | 302 | int h; |
| 301 | size_t j, sz; | 303 | size_t j, sz; |
| 302 | 304 | ||
| 303 | rewind(fd); | 305 | rewind(fp); |
| 304 | 306 | ||
| 305 | sz = (filesize <= FSIZE_MAX ? filesize : FSIZE_MAX) / 25; | 307 | /*sz = (filesize <= FSIZE_MAX ? filesize : FSIZE_MAX) / 25;*/ |
| 306 | if (sz < 100) | 308 | /*if (sz < 100)*/ |
| 307 | sz = 100; | 309 | sz = 100; |
| 308 | 310 | ||
| 309 | p = xmalloc((sz + 3) * sizeof(struct line)); | 311 | p = xmalloc((sz + 3) * sizeof(p[0])); |
| 310 | j = 0; | 312 | j = 0; |
| 311 | while ((h = readhash(fd))) { | 313 | while ((h = readhash(fp))) { |
| 312 | if (j == sz) { | 314 | if (j == sz) { |
| 313 | sz = sz * 3 / 2; | 315 | sz = sz * 3 / 2; |
| 314 | p = xrealloc(p, (sz + 3) * sizeof(struct line)); | 316 | p = xrealloc(p, (sz + 3) * sizeof(p[0])); |
| 315 | } | 317 | } |
| 316 | p[++j].value = h; | 318 | p[++j].value = h; |
| 317 | } | 319 | } |
| @@ -694,10 +696,10 @@ static int asciifile(FILE * f) | |||
| 694 | 696 | ||
| 695 | #if ENABLE_FEATURE_DIFF_BINARY | 697 | #if ENABLE_FEATURE_DIFF_BINARY |
| 696 | rewind(f); | 698 | rewind(f); |
| 697 | cnt = fread(bb_common_bufsiz1, 1, BUFSIZ, f); | 699 | cnt = fread(g_read_buf, 1, COMMON_BUFSIZE, f); |
| 698 | for (i = 0; i < cnt; i++) { | 700 | for (i = 0; i < cnt; i++) { |
| 699 | if (!isprint(bb_common_bufsiz1[i]) | 701 | if (!isprint(g_read_buf[i]) |
| 700 | && !isspace(bb_common_bufsiz1[i])) { | 702 | && !isspace(g_read_buf[i])) { |
| 701 | return 0; | 703 | return 0; |
| 702 | } | 704 | } |
| 703 | } | 705 | } |
| @@ -937,7 +939,7 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2) | |||
| 937 | * 3*(number of k-candidates installed), typically about | 939 | * 3*(number of k-candidates installed), typically about |
| 938 | * 6n words for files of length n. | 940 | * 6n words for files of length n. |
| 939 | */ | 941 | */ |
| 940 | static unsigned diffreg(char * ofile1, char * ofile2, int flags) | 942 | static unsigned diffreg(char *ofile1, char *ofile2, int flags) |
| 941 | { | 943 | { |
| 942 | char *file1 = ofile1; | 944 | char *file1 = ofile1; |
| 943 | char *file2 = ofile2; | 945 | char *file2 = ofile2; |
| @@ -987,8 +989,8 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags) | |||
| 987 | goto closem; | 989 | goto closem; |
| 988 | } | 990 | } |
| 989 | 991 | ||
| 990 | prepare(0, f1, stb1.st_size); | 992 | prepare(0, f1 /*, stb1.st_size*/); |
| 991 | prepare(1, f2, stb2.st_size); | 993 | prepare(1, f2 /*, stb2.st_size*/); |
| 992 | prune(); | 994 | prune(); |
| 993 | sort(sfile[0], slen[0]); | 995 | sort(sfile[0], slen[0]); |
| 994 | sort(sfile[1], slen[1]); | 996 | sort(sfile[1], slen[1]); |
