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

Diff for /src/usr.bin/rcs/diff3.c between version 1.29 and 1.30

version 1.29, 2010/07/23 08:31:19 version 1.30, 2010/07/23 21:46:05
Line 126 
Line 126 
 static int eflag = 3;   /* default -E for compatibility with former RCS */  static int eflag = 3;   /* default -E for compatibility with former RCS */
 static int oflag = 1;   /* default -E for compatibility with former RCS */  static int oflag = 1;   /* default -E for compatibility with former RCS */
 static int debug  = 0;  static int debug  = 0;
 static char f1mark[256], f3mark[256];   /* markers for -E and -X */  static char f1mark[MAXPATHLEN], f3mark[MAXPATHLEN];     /* markers for -E and -X */
   
 static int duplicate(struct range *, struct range *);  static int duplicate(struct range *, struct range *);
 static int edit(struct diff *, int, int);  static int edit(struct diff *, int, int);
Line 166 
Line 166 
         if ((flags & MERGE_EFLAG) && !(flags & MERGE_OFLAG))          if ((flags & MERGE_EFLAG) && !(flags & MERGE_OFLAG))
                 oflag = 0;                  oflag = 0;
   
         if ((b1 = rcs_buf_load(av[0], BUF_AUTOEXT)) == NULL)          if ((b1 = buf_load(av[0], BUF_AUTOEXT)) == NULL)
                 goto out;                  goto out;
         if ((b2 = rcs_buf_load(av[1], BUF_AUTOEXT)) == NULL)          if ((b2 = buf_load(av[1], BUF_AUTOEXT)) == NULL)
                 goto out;                  goto out;
         if ((b3 = rcs_buf_load(av[2], BUF_AUTOEXT)) == NULL)          if ((b3 = buf_load(av[2], BUF_AUTOEXT)) == NULL)
                 goto out;                  goto out;
   
         d1 = rcs_buf_alloc(128, BUF_AUTOEXT);          d1 = buf_alloc(128, BUF_AUTOEXT);
         d2 = rcs_buf_alloc(128, BUF_AUTOEXT);          d2 = buf_alloc(128, BUF_AUTOEXT);
         diffb = rcs_buf_alloc(128, BUF_AUTOEXT);          diffb = buf_alloc(128, BUF_AUTOEXT);
   
         (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
         (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);
         (void)xasprintf(&path3, "%s/diff3.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path3, "%s/diff3.XXXXXXXXXX", rcs_tmpdir);
   
         rcs_buf_write_stmp(b1, path1);          buf_write_stmp(b1, path1);
         rcs_buf_write_stmp(b2, path2);          buf_write_stmp(b2, path2);
         rcs_buf_write_stmp(b3, path3);          buf_write_stmp(b3, path3);
   
         rcs_buf_free(b2);          buf_free(b2);
         b2 = NULL;          b2 = NULL;
   
         if ((diffreg(path1, path3, d1, D_FORCEASCII) == D_ERROR) ||          if ((diffreg(path1, path3, d1, D_FORCEASCII) == D_ERROR) ||
             (diffreg(path2, path3, d2, D_FORCEASCII) == D_ERROR)) {              (diffreg(path2, path3, d2, D_FORCEASCII) == D_ERROR)) {
                 rcs_buf_free(diffb);                  buf_free(diffb);
                 diffb = NULL;                  diffb = NULL;
                 goto out;                  goto out;
         }          }
   
         (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", rcs_tmpdir);
         rcs_buf_write_stmp(d1, dp13);          buf_write_stmp(d1, dp13);
   
         rcs_buf_free(d1);          buf_free(d1);
         d1 = NULL;          d1 = NULL;
   
         (void)xasprintf(&dp23, "%s/d23.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&dp23, "%s/d23.XXXXXXXXXX", rcs_tmpdir);
         rcs_buf_write_stmp(d2, dp23);          buf_write_stmp(d2, dp23);
   
         rcs_buf_free(d2);          buf_free(d2);
         d2 = NULL;          d2 = NULL;
   
         argc = 0;          argc = 0;
Line 217 
Line 217 
   
         diff3_conflicts = diff3_internal(argc, argv, av[0], av[2]);          diff3_conflicts = diff3_internal(argc, argv, av[0], av[2]);
         if (diff3_conflicts < 0) {          if (diff3_conflicts < 0) {
                 rcs_buf_free(diffb);                  buf_free(diffb);
                 diffb = NULL;                  diffb = NULL;
                 goto out;                  goto out;
         }          }
   
         plen = rcs_buf_len(diffb);          plen = buf_len(diffb);
         patch = rcs_buf_release(diffb);          patch = buf_release(diffb);
         dlen = rcs_buf_len(b1);          dlen = buf_len(b1);
         data = rcs_buf_release(b1);          data = buf_release(b1);
   
         if ((diffb = rcs_patchfile(data, dlen, patch, plen, ed_patch_lines)) == NULL)          if ((diffb = rcs_patchfile(data, dlen, patch, plen, ed_patch_lines)) == NULL)
                 goto out;                  goto out;
Line 235 
Line 235 
   
 out:  out:
         if (b2 != NULL)          if (b2 != NULL)
                 rcs_buf_free(b2);                  buf_free(b2);
         if (b3 != NULL)          if (b3 != NULL)
                 rcs_buf_free(b3);                  buf_free(b3);
         if (d1 != NULL)          if (d1 != NULL)
                 rcs_buf_free(d1);                  buf_free(d1);
         if (d2 != NULL)          if (d2 != NULL)
                 rcs_buf_free(d2);                  buf_free(d2);
   
         (void)unlink(path1);          (void)unlink(path1);
         (void)unlink(path2);          (void)unlink(path2);
Line 287 
Line 287 
         rcsnum_tostr(rev1, r1, sizeof(r1));          rcsnum_tostr(rev1, r1, sizeof(r1));
         rcsnum_tostr(rev2, r2, sizeof(r2));          rcsnum_tostr(rev2, r2, sizeof(r2));
   
         if ((b1 = rcs_buf_load(workfile, BUF_AUTOEXT)) == NULL)          if ((b1 = buf_load(workfile, BUF_AUTOEXT)) == NULL)
                 goto out;                  goto out;
   
         if (!(flags & QUIET))          if (!(flags & QUIET))
Line 300 
Line 300 
         if ((b3 = rcs_getrev(rf, rev2)) == NULL)          if ((b3 = rcs_getrev(rf, rev2)) == NULL)
                 goto out;                  goto out;
   
         d1 = rcs_buf_alloc(128, BUF_AUTOEXT);          d1 = buf_alloc(128, BUF_AUTOEXT);
         d2 = rcs_buf_alloc(128, BUF_AUTOEXT);          d2 = buf_alloc(128, BUF_AUTOEXT);
         diffb = rcs_buf_alloc(128, BUF_AUTOEXT);          diffb = buf_alloc(128, BUF_AUTOEXT);
   
         (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
         (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);
         (void)xasprintf(&path3, "%s/diff3.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&path3, "%s/diff3.XXXXXXXXXX", rcs_tmpdir);
   
         rcs_buf_write_stmp(b1, path1);          buf_write_stmp(b1, path1);
         rcs_buf_write_stmp(b2, path2);          buf_write_stmp(b2, path2);
         rcs_buf_write_stmp(b3, path3);          buf_write_stmp(b3, path3);
   
         rcs_buf_free(b2);          buf_free(b2);
         b2 = NULL;          b2 = NULL;
   
         if ((diffreg(path1, path3, d1, D_FORCEASCII) == D_ERROR) ||          if ((diffreg(path1, path3, d1, D_FORCEASCII) == D_ERROR) ||
             (diffreg(path2, path3, d2, D_FORCEASCII) == D_ERROR)) {              (diffreg(path2, path3, d2, D_FORCEASCII) == D_ERROR)) {
                 rcs_buf_free(diffb);                  buf_free(diffb);
                 diffb = NULL;                  diffb = NULL;
                 goto out;                  goto out;
         }          }
   
         (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", rcs_tmpdir);
         rcs_buf_write_stmp(d1, dp13);          buf_write_stmp(d1, dp13);
   
         rcs_buf_free(d1);          buf_free(d1);
         d1 = NULL;          d1 = NULL;
   
         (void)xasprintf(&dp23, "%s/d23.XXXXXXXXXX", rcs_tmpdir);          (void)xasprintf(&dp23, "%s/d23.XXXXXXXXXX", rcs_tmpdir);
         rcs_buf_write_stmp(d2, dp23);          buf_write_stmp(d2, dp23);
   
         rcs_buf_free(d2);          buf_free(d2);
         d2 = NULL;          d2 = NULL;
   
         argc = 0;          argc = 0;
Line 344 
Line 344 
   
         diff3_conflicts = diff3_internal(argc, argv, workfile, r2);          diff3_conflicts = diff3_internal(argc, argv, workfile, r2);
         if (diff3_conflicts < 0) {          if (diff3_conflicts < 0) {
                 rcs_buf_free(diffb);                  buf_free(diffb);
                 diffb = NULL;                  diffb = NULL;
                 goto out;                  goto out;
         }          }
   
         plen = rcs_buf_len(diffb);          plen = buf_len(diffb);
         patch = rcs_buf_release(diffb);          patch = buf_release(diffb);
         dlen = rcs_buf_len(b1);          dlen = buf_len(b1);
         data = rcs_buf_release(b1);          data = buf_release(b1);
   
         if ((diffb = rcs_patchfile(data, dlen, patch, plen, ed_patch_lines)) == NULL)          if ((diffb = rcs_patchfile(data, dlen, patch, plen, ed_patch_lines)) == NULL)
                 goto out;                  goto out;
Line 362 
Line 362 
   
 out:  out:
         if (b2 != NULL)          if (b2 != NULL)
                 rcs_buf_free(b2);                  buf_free(b2);
         if (b3 != NULL)          if (b3 != NULL)
                 rcs_buf_free(b3);                  buf_free(b3);
         if (d1 != NULL)          if (d1 != NULL)
                 rcs_buf_free(d1);                  buf_free(d1);
         if (d2 != NULL)          if (d2 != NULL)
                 rcs_buf_free(d2);                  buf_free(d2);
   
         (void)unlink(path1);          (void)unlink(path1);
         (void)unlink(path2);          (void)unlink(path2);
Line 449 
Line 449 
                 /* Skip blank lines */                  /* Skip blank lines */
                 if (lp->l_len < 2)                  if (lp->l_len < 2)
                         continue;                          continue;
   
                 /* NUL-terminate line buffer for strtol() safety. */                  /* NUL-terminate line buffer for strtol() safety. */
                 tmp = lp->l_line[lp->l_len - 1];                  tmp = lp->l_line[lp->l_len - 1];
                 lp->l_line[lp->l_len - 1] = '\0';                  lp->l_line[lp->l_len - 1] = '\0';
   
                 /* len - 1 is NUL terminator so we use len - 2 for 'op' */                  /* len - 1 is NUL terminator so we use len - 2 for 'op' */
                 op = lp->l_line[lp->l_len - 2];                  op = lp->l_line[lp->l_len - 2];
                 start = (int)strtol(lp->l_line, &ep, 10);                  start = (int)strtol(lp->l_line, &ep, 10);
   
                 /* Restore the last byte of the buffer */                  /* Restore the last byte of the buffer */
                 lp->l_line[lp->l_len - 1] = tmp;                  lp->l_line[lp->l_len - 1] = tmp;
   
                 if (op == 'a') {                  if (op == 'a') {
                         if (start > dlines->l_nblines ||                          if (start > dlines->l_nblines ||
                             start < 0 || *ep != 'a')                              start < 0 || *ep != 'a')
Line 585 
Line 589 
                 (*dd)[i].old.from = (*dd)[i-1].old.to;                  (*dd)[i].old.from = (*dd)[i-1].old.to;
                 (*dd)[i].new.from = (*dd)[i-1].new.to;                  (*dd)[i].new.from = (*dd)[i-1].new.to;
         }          }
   
         (void)fclose(fp[0]);          (void)fclose(fp[0]);
   
         return (i);          return (i);
Line 903 
Line 908 
                 (void)fseek(fp[2], (long)de[n].new.from, SEEK_SET);                  (void)fseek(fp[2], (long)de[n].new.from, SEEK_SET);
                 for (k = de[n].new.to-de[n].new.from; k > 0; k-= j) {                  for (k = de[n].new.to-de[n].new.from; k > 0; k-= j) {
                         j = k > BUFSIZ ? BUFSIZ : k;                          j = k > BUFSIZ ? BUFSIZ : k;
                         if (fread(block, 1, (size_t)j,                          if (fread(block, 1, j, fp[2]) != j)
                             fp[2]) != (size_t)j)  
                                 return (-1);                                  return (-1);
                         block[j] = '\0';                          block[j] = '\0';
                         diff_output("%s", block);                          diff_output("%s", block);

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30