[BACK]Return to diffreg.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / diff

Diff for /src/usr.bin/diff/diffreg.c between version 1.67 and 1.68

version 1.67, 2007/03/18 21:12:27 version 1.68, 2007/05/29 18:24:56
Line 84 
Line 84 
   
 #include "diff.h"  #include "diff.h"
 #include "pathnames.h"  #include "pathnames.h"
   #include "xmalloc.h"
   
 /*  /*
  * diff - compare two files.   * diff - compare two files.
Line 153 
Line 154 
  */   */
   
 struct cand {  struct cand {
         int x;          int     x;
         int y;          int     y;
         int pred;          int     pred;
 };  };
   
 struct line {  struct line {
         int serial;          int     serial;
         int value;          int     value;
 } *file[2];  } *file[2];
   
 /*  /*
Line 169 
Line 170 
  * understand the highly mnemonic field names)   * understand the highly mnemonic field names)
  */   */
 struct context_vec {  struct context_vec {
         int a;                  /* start line in old file */          int     a;              /* start line in old file */
         int b;                  /* end line in old file */          int     b;              /* end line in old file */
         int c;                  /* start line in new file */          int     c;              /* start line in new file */
         int d;                  /* end line in new file */          int     d;              /* end line in new file */
 };  };
   
 static int  *J;                 /* will be overlaid on class */  static int  *J;                 /* will be overlaid on class */
Line 225 
Line 226 
 static int  stone(int *, int, int *, int *);  static int  stone(int *, int, int *, int *);
 static int  readhash(FILE *);  static int  readhash(FILE *);
 static int  files_differ(FILE *, FILE *, int);  static int  files_differ(FILE *, FILE *, int);
 static __inline int min(int, int);  
 static __inline int max(int, int);  
 static char *match_function(const long *, int, FILE *);  static char *match_function(const long *, int, FILE *);
 static char *preadline(int, size_t, off_t);  static char *preadline(int, size_t, off_t);
   
Line 374 
Line 373 
                 char *header;                  char *header;
                 char *prargv[] = { "pr", "-h", NULL, "-f", NULL };                  char *prargv[] = { "pr", "-h", NULL, "-f", NULL };
   
                 easprintf(&header, "%s %s %s", diffargs, file1, file2);                  xasprintf(&header, "%s %s %s", diffargs, file1, file2);
                 prargv[2] = header;                  prargv[2] = header;
                 fflush(stdout);                  fflush(stdout);
                 rewind(stdout);                  rewind(stdout);
Line 383 
Line 382 
                 case -1:                  case -1:
                         warnx("No more processes");                          warnx("No more processes");
                         status |= 2;                          status |= 2;
                         free(header);                          xfree(header);
                         return (D_ERROR);                          return (D_ERROR);
                 case 0:                  case 0:
                         /* child */                          /* child */
Line 403 
Line 402 
                         }                          }
                         close(pfd[0]);                          close(pfd[0]);
                         rewind(stdout);                          rewind(stdout);
                         free(header);                          xfree(header);
                 }                  }
         }          }
         prepare(0, f1, stb1.st_size);          prepare(0, f1, stb1.st_size);
Line 414 
Line 413 
   
         member = (int *)file[1];          member = (int *)file[1];
         equiv(sfile[0], slen[0], sfile[1], slen[1], member);          equiv(sfile[0], slen[0], sfile[1], slen[1], member);
         member = erealloc(member, (slen[1] + 2) * sizeof(int));          member = xrealloc(member, slen[1] + 2, sizeof(int));
   
         class = (int *)file[0];          class = (int *)file[0];
         unsort(sfile[0], slen[0], class);          unsort(sfile[0], slen[0], class);
         class = erealloc(class, (slen[0] + 2) * sizeof(int));          class = xrealloc(class, slen[0] + 2, sizeof(int));
   
         klist = emalloc((slen[0] + 2) * sizeof(int));          klist = xmalloc((slen[0] + 2) * sizeof(int));
         clen = 0;          clen = 0;
         clistlen = 100;          clistlen = 100;
         clist = emalloc(clistlen * sizeof(struct cand));          clist = xmalloc(clistlen * sizeof(struct cand));
         i = stone(class, slen[0], member, klist);          i = stone(class, slen[0], member, klist);
         free(member);          xfree(member);
         free(class);          xfree(class);
   
         J = erealloc(J, (len[0] + 2) * sizeof(int));          J = xrealloc(J, len[0] + 2, sizeof(int));
         unravel(klist[i]);          unravel(klist[i]);
         free(clist);          xfree(clist);
         free(klist);          xfree(klist);
   
         ixold = erealloc(ixold, (len[0] + 2) * sizeof(long));          ixold = xrealloc(ixold, len[0] + 2, sizeof(long));
         ixnew = erealloc(ixnew, (len[1] + 2) * sizeof(long));          ixnew = xrealloc(ixnew, len[1] + 2, sizeof(long));
         check(file1, f1, file2, f2);          check(file1, f1, file2, f2);
         output(file1, f1, file2, f2, (flags & D_HEADER));          output(file1, f1, file2, f2, (flags & D_HEADER));
         if (ostdout != -1) {          if (ostdout != -1) {
Line 461 
Line 460 
         if (f2 != NULL)          if (f2 != NULL)
                 fclose(f2);                  fclose(f2);
         if (file1 != ofile1)          if (file1 != ofile1)
                 free(file1);                  xfree(file1);
         if (file2 != ofile2)          if (file2 != ofile2)
                 free(file2);                  xfree(file2);
         return (rval);          return (rval);
 }  }
   
Line 543 
Line 542 
                 tail = file;                  tail = file;
         else          else
                 tail++;                  tail++;
         easprintf(&buf, "%s/%s", dir, tail);          xasprintf(&buf, "%s/%s", dir, tail);
         return (buf);          return (buf);
 }  }
   
Line 560 
Line 559 
         if (sz < 100)          if (sz < 100)
                 sz = 100;                  sz = 100;
   
         p = emalloc((sz + 3) * sizeof(struct line));          p = xmalloc((sz + 3) * sizeof(struct line));
         for (j = 0; (h = readhash(fd));) {          for (j = 0; (h = readhash(fd));) {
                 if (j == sz) {                  if (j == sz) {
                         sz = sz * 3 / 2;                          sz = sz * 3 / 2;
                         p = erealloc(p, (sz + 3) * sizeof(struct line));                          p = xrealloc(p, sz + 3, sizeof(struct line));
                 }                  }
                 p[++j].value = h;                  p[++j].value = h;
         }          }
Line 628 
Line 627 
         int y, x = 1;          int y, x = 1;
   
         if (n == 0)          if (n == 0)
                 return(0);                  return (0);
   
         do { /* newton was a stinker */          do { /* newton was a stinker */
                 y = x;                  y = x;
Line 647 
Line 646 
         int oldc, tc, oldl;          int oldc, tc, oldl;
         u_int numtries;          u_int numtries;
   
         const u_int bound = dflag ? UINT_MAX : max(256, isqrt(n));          const u_int bound = dflag ? UINT_MAX : MAX(256, isqrt(n));
   
         k = 0;          k = 0;
         c[0] = newcand(0, 0, 0);          c[0] = newcand(0, 0, 0);
Line 690 
Line 689 
   
         if (clen == clistlen) {          if (clen == clistlen) {
                 clistlen = clistlen * 11 / 10;                  clistlen = clistlen * 11 / 10;
                 clist = erealloc(clist, clistlen * sizeof(struct cand));                  clist = xrealloc(clist, clistlen, sizeof(struct cand));
         }          }
         q = clist + clen;          q = clist + clen;
         q->x = x;          q->x = x;
Line 878 
Line 877 
 {  {
         int *a, i;          int *a, i;
   
         a = emalloc((l + 1) * sizeof(int));          a = xmalloc((l + 1) * sizeof(int));
         for (i = 1; i <= l; i++)          for (i = 1; i <= l; i++)
                 a[f[i].serial] = f[i].value;                  a[f[i].serial] = f[i].value;
         for (i = 1; i <= l; i++)          for (i = 1; i <= l; i++)
                 b[i] = a[i];                  b[i] = a[i];
         free(a);          xfree(a);
 }  }
   
 static int  static int
Line 950 
Line 949 
         }          }
 }  }
   
 static __inline void  static void
 range(int a, int b, char *separator)  range(int a, int b, char *separator)
 {  {
         printf("%d", a > b ? b : a);          printf("%d", a > b ? b : a);
Line 958 
Line 957 
                 printf("%s%d", separator, b);                  printf("%s%d", separator, b);
 }  }
   
 static __inline void  static void
 uni_range(int a, int b)  uni_range(int a, int b)
 {  {
         if (a < b)          if (a < b)
Line 975 
Line 974 
         char *line;          char *line;
         ssize_t nr;          ssize_t nr;
   
         line = emalloc(len + 1);          line = xmalloc(len + 1);
         if ((nr = pread(fd, line, len, off)) < 0)          if ((nr = pread(fd, line, len, off)) < 0)
                 err(1, "preadline");                  err(1, "preadline");
         if (nr > 0 && line[nr-1] == '\n')          if (nr > 0 && line[nr-1] == '\n')
Line 990 
Line 989 
         int ret;          int ret;
   
         ret = regexec(&ignore_re, line, 0, NULL, 0);          ret = regexec(&ignore_re, line, 0, NULL, 0);
         free(line);          xfree(line);
         return (ret == 0);      /* if it matched, it should be ignored. */          return (ret == 0);      /* if it matched, it should be ignored. */
 }  }
   
Line 1048 
Line 1047 
                 if (context_vec_ptr == context_vec_end - 1) {                  if (context_vec_ptr == context_vec_end - 1) {
                         ptrdiff_t offset = context_vec_ptr - context_vec_start;                          ptrdiff_t offset = context_vec_ptr - context_vec_start;
                         max_context <<= 1;                          max_context <<= 1;
                         context_vec_start = erealloc(context_vec_start,                          context_vec_start = xrealloc(context_vec_start,
                             max_context * sizeof(struct context_vec));                              max_context, sizeof(struct context_vec));
                         context_vec_end = context_vec_start + max_context;                          context_vec_end = context_vec_start + max_context;
                         context_vec_ptr = context_vec_start + offset;                          context_vec_ptr = context_vec_start + offset;
                 }                  }
Line 1293 
Line 1292 
         return (1);          return (1);
 }  }
   
 static __inline int min(int a, int b)  
 {  
         return (a < b ? a : b);  
 }  
   
 static __inline int max(int a, int b)  
 {  
         return (a > b ? a : b);  
 }  
   
 #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)  #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
   
 static char *  static char *
Line 1364 
Line 1353 
                 return;                  return;
   
         b = d = 0;              /* gcc */          b = d = 0;              /* gcc */
         lowa = max(1, cvp->a - context);          lowa = MAX(1, cvp->a - context);
         upb = min(len[0], context_vec_ptr->b + context);          upb = MIN(len[0], context_vec_ptr->b + context);
         lowc = max(1, cvp->c - context);          lowc = MAX(1, cvp->c - context);
         upd = min(len[1], context_vec_ptr->d + context);          upd = MIN(len[1], context_vec_ptr->d + context);
   
         printf("***************");          printf("***************");
         if (pflag) {          if (pflag) {
Line 1469 
Line 1458 
                 return;                  return;
   
         b = d = 0;              /* gcc */          b = d = 0;              /* gcc */
         lowa = max(1, cvp->a - context);          lowa = MAX(1, cvp->a - context);
         upb = min(len[0], context_vec_ptr->b + context);          upb = MIN(len[0], context_vec_ptr->b + context);
         lowc = max(1, cvp->c - context);          lowc = MAX(1, cvp->c - context);
         upd = min(len[1], context_vec_ptr->d + context);          upd = MIN(len[1], context_vec_ptr->d + context);
   
         fputs("@@ -", stdout);          fputs("@@ -", stdout);
         uni_range(lowa, upb);          uni_range(lowa, upb);

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.68