=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rcs/diff.c,v retrieving revision 1.21 retrieving revision 1.22 diff -c -r1.21 -r1.22 *** src/usr.bin/rcs/diff.c 2007/06/28 01:26:24 1.21 --- src/usr.bin/rcs/diff.c 2007/06/28 05:01:39 1.22 *************** *** 1,4 **** ! /* $OpenBSD: diff.c,v 1.21 2007/06/28 01:26:24 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: diff.c,v 1.22 2007/06/28 05:01:39 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. *************** *** 63,69 **** --- 63,90 ---- * * @(#)diffreg.c 8.1 (Berkeley) 6/6/93 */ + + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + + #include "buf.h" + #include "diff.h" + #include "xmalloc.h" + /* + * diff - compare two files. + */ + + /* * Uses an algorithm due to Harold Stone, which finds * a pair of longest identical subsequences in the two * files. *************** *** 126,147 **** * 6n words for files of length n. */ - #include - #include - - #include - #include - #include - #include - #include - #include - #include - #include - - #include "buf.h" - #include "diff.h" - #include "xmalloc.h" - struct cand { int x; int y; --- 147,152 ---- *************** *** 228,233 **** --- 233,239 ---- static int lastmatchline; BUF *diffbuf = NULL; + /* * chrtran points to one of 2 translation tables: cup2low if folding upper to * lower case clow2low if not folding case *************** *** 364,373 **** clen = 0; clistlen = 100; clist = xcalloc(clistlen, sizeof(*clist)); ! ! if ((i = stone(class, slen[0], member, klist, flags)) < 0) ! goto closem; ! xfree(member); xfree(class); --- 370,376 ---- clen = 0; clistlen = 100; clist = xcalloc(clistlen, sizeof(*clist)); ! i = stone(class, slen[0], member, klist, flags); xfree(member); xfree(class); *************** *** 377,389 **** xfree(klist); ixold = xrealloc(ixold, len[0] + 2, sizeof(*ixold)); - ixnew = xrealloc(ixnew, len[1] + 2, sizeof(*ixnew)); check(f1, f2, flags); output(f1, f2, flags); closem: ! if (anychange == 1) { if (rval == D_SAME) rval = D_DIFFER; } --- 380,391 ---- xfree(klist); ixold = xrealloc(ixold, len[0] + 2, sizeof(*ixold)); ixnew = xrealloc(ixnew, len[1] + 2, sizeof(*ixnew)); check(f1, f2, flags); output(f1, f2, flags); closem: ! if (anychange) { if (rval == D_SAME) rval = D_DIFFER; } *************** *** 457,466 **** file[0][pref + 1].value == file[1][pref + 1].value; pref++) ; ! for (suff = 0; ! (suff < len[0] - pref) && (suff < len[1] - pref) && ! (file[0][len[0] - suff].value == ! file[1][len[1] - suff].value); suff++) ; for (j = 0; j < 2; j++) { --- 459,466 ---- file[0][pref + 1].value == file[1][pref + 1].value; pref++) ; ! for (suff = 0; suff < len[0] - pref && suff < len[1] - pref && ! file[0][len[0] - suff].value == file[1][len[1] - suff].value; suff++) ; for (j = 0; j < 2; j++) { *************** *** 513,519 **** x = n / x; x += y; x /= 2; ! } while (x - y > 1 || x - y < -1); return (x); } --- 513,519 ---- x = n / x; x += y; x /= 2; ! } while ((x - y) > 1 || (x - y) < -1); return (x); } *************** *** 521,527 **** static int stone(int *a, int n, int *b, int *c, int flags) { - int ret; int i, k, y, j, l; int oldc, tc, oldl; u_int numtries; --- 521,526 ---- *************** *** 531,539 **** MAX(256, (u_int)isqrt(n)); k = 0; ! if ((ret = newcand(0, 0, 0)) < 0) ! return (-1); ! c[0] = ret; for (i = 1; i <= n; i++) { j = a[i]; if (j == 0) --- 530,536 ---- MAX(256, (u_int)isqrt(n)); k = 0; ! c[0] = newcand(0, 0, 0); for (i = 1; i <= n; i++) { j = a[i]; if (j == 0) *************** *** 552,567 **** if (clist[c[l]].y <= y) continue; tc = c[l]; ! if ((ret = newcand(i, y, oldc)) < 0) ! return (-1); ! c[l] = ret; oldc = tc; oldl = l; numtries++; } else { ! if ((ret = newcand(i, y, oldc)) < 0) ! return (-1); ! c[l] = ret; k++; break; } --- 549,560 ---- if (clist[c[l]].y <= y) continue; tc = c[l]; ! c[l] = newcand(i, y, oldc); oldc = tc; oldl = l; numtries++; } else { ! c[l] = newcand(i, y, oldc); k++; break; } *************** *** 723,730 **** for (; j <= len[1]; j++) ixnew[j] = ctnew += skipline(f2); /* ! * if (jackpot != 0) ! * printf("jackpot\n"); */ } --- 716,723 ---- for (; j <= len[1]; j++) ixnew[j] = ctnew += skipline(f2); /* ! * if (jackpot) ! * fprintf(stderr, "jackpot\n"); */ } *************** *** 879,888 **** static void change(FILE *f1, FILE *f2, int a, int b, int c, int d, int flags) { - int i; static size_t max_context = 64; char buf[64]; struct tm *t; if (diff_format != D_IFDEF && a > b && c > d) return; --- 872,881 ---- static void change(FILE *f1, FILE *f2, int a, int b, int c, int d, int flags) { static size_t max_context = 64; char buf[64]; struct tm *t; + int i; if (diff_format != D_IFDEF && a > b && c > d) return; *************** *** 961,968 **** } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 && c > context_vec_ptr->d + (2 * diff_context) + 1) { /* ! * If this change is more than 'diff_context' lines ! * from the previous change, dump the record and reset it. */ if (diff_format == D_CONTEXT) dump_context_vec(f1, f2, flags); --- 954,961 ---- } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 && c > context_vec_ptr->d + (2 * diff_context) + 1) { /* ! * If this change is more than 'diff_context' lines from the ! * previous change, dump the record and reset it. */ if (diff_format == D_CONTEXT) dump_context_vec(f1, f2, flags); *************** *** 1106,1111 **** --- 1099,1107 ---- for (i = 0;;) { switch (t = getc(f)) { case '\t': + case '\r': + case '\v': + case '\f': case ' ': space++; continue; *************** *** 1137,1143 **** static int asciifile(FILE *f) { ! char buf[BUFSIZ]; size_t i, cnt; if (f == NULL) --- 1133,1139 ---- static int asciifile(FILE *f) { ! unsigned char buf[BUFSIZ]; size_t i, cnt; if (f == NULL) *************** *** 1153,1159 **** #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0) ! static char* match_function(const long *f, int pos, FILE *fp) { unsigned char buf[FUNCTION_CONTEXT_SIZE]; --- 1149,1155 ---- #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0) ! static char * match_function(const long *f, int pos, FILE *fp) { unsigned char buf[FUNCTION_CONTEXT_SIZE]; *************** *** 1196,1205 **** } pos--; } ! return (lastmatchline > 0) ? lastbuf : NULL; } - /* dump accumulated "context" diff changes */ static void dump_context_vec(FILE *f1, FILE *f2, int flags) --- 1192,1200 ---- } pos--; } ! return lastmatchline > 0 ? lastbuf : NULL; } /* dump accumulated "context" diff changes */ static void dump_context_vec(FILE *f1, FILE *f2, int flags) *************** *** 1220,1226 **** diff_output("***************"); if ((flags & D_PROTOTYPE)) { ! f = match_function(ixold, lowa - 1, f1); if (f != NULL) { diff_output(" "); diff_output("%s", f); --- 1215,1221 ---- diff_output("***************"); if ((flags & D_PROTOTYPE)) { ! f = match_function(ixold, lowa-1, f1); if (f != NULL) { diff_output(" "); diff_output("%s", f); *************** *** 1242,1248 **** do_output++; break; } ! if (do_output != 0) { while (cvp <= context_vec_ptr) { a = cvp->a; b = cvp->b; --- 1237,1243 ---- do_output++; break; } ! if (do_output) { while (cvp <= context_vec_ptr) { a = cvp->a; b = cvp->b; *************** *** 1278,1284 **** do_output++; break; } ! if (do_output != 0) { while (cvp <= context_vec_ptr) { a = cvp->a; b = cvp->b; --- 1273,1279 ---- do_output++; break; } ! if (do_output) { while (cvp <= context_vec_ptr) { a = cvp->a; b = cvp->b; *************** *** 1329,1335 **** uni_range(lowc, upd); diff_output(" @@"); if ((flags & D_PROTOTYPE)) { ! f = match_function(ixold, lowa - 1, f1); if (f != NULL) { diff_output(" "); diff_output("%s", f); --- 1324,1330 ---- uni_range(lowc, upd); diff_output(" @@"); if ((flags & D_PROTOTYPE)) { ! f = match_function(ixold, lowa-1, f1); if (f != NULL) { diff_output(" "); diff_output("%s", f);