i.e. checkpatch.pl from the linux kernel.
Signed-off-by: NeilBrown <neilb@suse.de>
char Version[] = "wiggle 0.8 2010-03-24 GPL-2+ http://neil.brown.name/wiggle/\n";
-char short_options1[]="xdmwlrhi123pVRvqB"; /* not mode B */
-char short_options2[]="xdmwlrhi123p::VRvqB"; /* mode B */
+char short_options1[] = "xdmwlrhi123pVRvqB"; /* not mode B */
+char short_options2[] = "xdmwlrhi123p::VRvqB"; /* mode B */
struct option long_options[] = {
struct v {
- int x,y; /* location of start of match */
+ int x, y; /* location of start of match */
int val; /* value of match from x,y to here */
int k; /* diagonal of last match - if val > 0 */
int inmatch; /* 1 if last point was a match */
return max*3-1+v->inmatch+v->val;
}
-#ifdef OLDSTUFF
-#if 0
-#define value(v,kk,xx) (v.l ? (v.l - abs(kk-v.k)): -3)
-#else
-# if 0
-# define value(v,kk,xx) (v.l ? (v.l - (xx-v.x)/2): -3)
-# else
-# define value(v,kk,xx) (v.l ? (v.l - (xx-v.x)*2/v.l): -3)
-# endif
-#endif
-#endif
struct best {
- int xlo,ylo,xhi,yhi,val;
+ int xlo, ylo, xhi, yhi, val;
};
-static inline int min(int a, int b) {
+static inline int min(int a, int b)
+{
return a < b ? a : b;
}
v[k].c = -1;
while (f < ahi+bhi) {
- int x,y;
+ int x, y;
f++;
-
#if 0
if (f == ahi+bhi)
- printf("f %d klo %d khi %d\n", f,klo,khi);
+ printf("f %d klo %d khi %d\n", f, klo, khi);
#endif
- for (k=klo+1; k <= khi-1 ; k+=2) {
+ for (k = klo+1; k <= khi-1 ; k += 2) {
struct v vnew, vnew2;
x = (k+f)/2;
y = x-k;
update_value(&vnew, 0, k, x);
#if 0
printf("new %d,%d %d,%d (%d) ...",
- vnew.x, vy(vnew), x, y, value(vnew,k,x));
+ vnew.x, vy(vnew), x, y, value(vnew, k, x));
#endif
- if (vnew.c < 0) abort();
+ if (vnew.c < 0)
+ abort();
if (vnew.val > best[vnew.c].val) {
#if 0
printf("New best for %d at %d,%d %d,%d, val %d\n",
- vnew.c, vnew.x, vnew.y,x,y,vnew.val);
+ vnew.c, vnew.x, vnew.y,
+ x, y, vnew.val);
#endif
best[vnew.c].xlo = vnew.x;
best[vnew.c].ylo = vnew.y;
v[k] = vnew;
} else {
vnew = v[k+1];
- update_value(&vnew, -1, k,x);
+ update_value(&vnew, -1, k, x);
/* might cross a chunk boundary */
- if (b->list[y-1].len && b->list[y-1].start[0]==0) {
+ if (b->list[y-1].len && b->list[y-1].start[0] == 0) {
vnew.c = atoi(b->list[y-1].start+1);
vnew.val = 0;
}
klo--;
v[klo] = v[klo+1];
x = (klo+f)/2; y = x-klo;
- update_value(&v[klo],-1,klo,x);
- if (y<=bhi && b->list[y-1].len && b->list[y-1].start[0]==0) {
+ update_value(&v[klo], -1, klo, x);
+ if (y <= bhi && b->list[y-1].len && b->list[y-1].start[0] == 0) {
v[klo].c = atoi(b->list[y-1].start+1);
#if 0
printf("entered %d at %d,%d\n", v[klo].c, x, y);
}
while (klo+2 < (ahi-bhi) &&
(y > bhi ||
- (best_val(&v[klo], min(ahi-x,bhi-y)) < best[v[klo].c].val &&
- best_val(&v[klo+1], min(ahi-x,bhi-y+1)) < best[v[klo+1].c].val
+ (best_val(&v[klo], min(ahi-x, bhi-y)) < best[v[klo].c].val &&
+ best_val(&v[klo+1], min(ahi-x, bhi-y+1)) < best[v[klo+1].c].val
)
)) {
- klo+=2;
+ klo += 2;
x = (klo+f)/2; y = x-klo;
}
khi++;
v[khi] = v[khi-1];
x = (khi+f)/2; y = x - khi;
- update_value(&v[khi],-1,khi,x);
- while(khi-2 > (ahi-bhi) &&
- (x > ahi ||
- (best_val(&v[khi], min(ahi-x,bhi-y)) < best[v[khi].c].val &&
- best_val(&v[khi-1], min(ahi-x+1,bhi-y)) < best[v[khi].c].val
- )
- )) {
+ update_value(&v[khi], -1, khi, x);
+ while (khi-2 > (ahi-bhi) &&
+ (x > ahi ||
+ (best_val(&v[khi], min(ahi-x, bhi-y)) < best[v[khi].c].val &&
+ best_val(&v[khi-1], min(ahi-x+1, bhi-y)) < best[v[khi].c].val
+ )
+ )) {
khi -= 2;
x = (khi+f)/2; y = x - khi;
}
static struct csl *csl_join(struct csl *c1, struct csl *c2)
{
- struct csl *c,*cd, *rv;
+ struct csl *c, *cd, *rv;
int cnt;
+
if (c1 == NULL)
return c2;
if (c2 == NULL)
return c1;
cnt = 1; /* the sentinal */
- for (c=c1; c->len; c++) cnt++;
- for (c=c2; c->len; c++) cnt++;
+ for (c = c1; c->len; c++)
+ cnt++;
+ for (c = c2; c->len; c++)
+ cnt++;
cd = rv = malloc(sizeof(*rv)*cnt);
- for (c=c1; c->len; c++)
+ for (c = c1; c->len; c++)
*cd++ = *c;
- for (c=c2; c->len; c++)
+ for (c = c2; c->len; c++)
*cd++ = *c;
cd->len = 0;
free(c1);
if (e.start[0])
printf("%.*s", e.len, e.start);
else {
- int a,b,c;
+ int a, b, c;
sscanf(e.start+1, "%d %d %d", &a, &b, &c);
- printf("*** %d,%d **** %d\n", b,c,a);
+ printf("*** %d,%d **** %d\n", b, c, a);
}
}
#endif
static inline int is_skipped(struct elmnt e)
{
- return !( ends_line(e) ||
- isalnum(e.start[0]) ||
- e.start[0] == '_');
+ return !(ends_line(e) ||
+ isalnum(e.start[0]) ||
+ e.start[0] == '_');
}
static struct file reduce(struct file orig)
{
- int cnt=0;
+ int cnt = 0;
int i;
struct file rv;
- for (i=0; i<orig.elcnt; i++)
+ for (i = 0; i < orig.elcnt; i++)
if (!is_skipped(orig.list[i]))
cnt++;
- if (cnt == orig.elcnt) return orig;
+ if (cnt == orig.elcnt)
+ return orig;
rv.elcnt = cnt;
rv.list = malloc(cnt*sizeof(struct elmnt));
cnt = 0;
- for (i=0; i<orig.elcnt; i++)
+ for (i = 0; i < orig.elcnt; i++)
if (!is_skipped(orig.list[i]))
rv.list[cnt++] = orig.list[i];
return rv;
struct file a2, struct file b2)
{
int b;
- int pa,pb;
- pa=pb=0;
+ int pa, pb;
+
+ pa = pb = 0;
- if (a1.elcnt == 0 && a2.elcnt == 0) return;
+ if (a1.elcnt == 0 && a2.elcnt == 0)
+ return;
- for (b=1; b<cnt; b++)
- if (best[b].val>0) {
+ for (b = 1; b < cnt; b++)
+ if (best[b].val > 0) {
#if 0
printf("best %d,%d %d,%d\n",
- best[b].xlo,best[b].ylo,
- best[b].xhi,best[b].yhi);
+ best[b].xlo, best[b].ylo,
+ best[b].xhi, best[b].yhi);
#endif
- while (pa<a2.elcnt &&
+ while (pa < a2.elcnt &&
a2.list[pa].start != a1.list[best[b].xlo].start)
pa++;
- if (pa == a2.elcnt) abort();
- while (pb<b2.elcnt &&
+ if (pa == a2.elcnt)
+ abort();
+ while (pb < b2.elcnt &&
b2.list[pb].start != b1.list[best[b].ylo].start)
pb++;
- if (pb == b2.elcnt) abort();
+ if (pb == b2.elcnt)
+ abort();
/* pa,pb is the start of this best bit. Step
* backward over ignored words
*/
- while (pa>0 && is_skipped(a2.list[pa-1]))
+ while (pa > 0 && is_skipped(a2.list[pa-1]))
pa--;
- while (pb>0 && is_skipped(b2.list[pb-1]))
+ while (pb > 0 && is_skipped(b2.list[pb-1]))
pb--;
#if 0
- printf("-> %d,%d\n", pa,pb);
+ printf("-> %d,%d\n", pa, pb);
#endif
best[b].xlo = pa;
best[b].ylo = pb;
- while (pa<a2.elcnt &&
+ while (pa < a2.elcnt &&
a2.list[pa-1].start != a1.list[best[b].xhi-1].start)
pa++;
- if (pa == a2.elcnt && best[b].xhi != a1.elcnt) abort();
- while (pb<b2.elcnt &&
+ if (pa == a2.elcnt && best[b].xhi != a1.elcnt)
+ abort();
+ while (pb < b2.elcnt &&
b2.list[pb-1].start != b1.list[best[b].yhi-1].start)
pb++;
- if (pb == b2.elcnt && best[b].yhi != b1.elcnt) abort();
+ if (pb == b2.elcnt && best[b].yhi != b1.elcnt)
+ abort();
/* now step pa,pb forward over ignored words */
- while (pa<a2.elcnt && is_skipped(a2.list[pa]))
+ while (pa < a2.elcnt && is_skipped(a2.list[pa]))
pa++;
- while (pb<b2.elcnt && is_skipped(b2.list[pb]))
+ while (pb < b2.elcnt && is_skipped(b2.list[pb]))
pb++;
#if 0
- printf("-> %d,%d\n", pa,pb);
+ printf("-> %d,%d\n", pa, pb);
#endif
best[b].xhi = pa;
best[b].yhi = pb;
* recurse either side of that
*/
int i;
- int bad=0;
- int bestval, bestpos=0;
- for (i=bestlo; i<besthi; i++) best[i].val = 0;
- find_best(a,b,alo,ahi,blo,bhi,best);
- for (i=bestlo+1; i<besthi; i++)
+ int bad = 0;
+ int bestval, bestpos = 0;
+
+ for (i = bestlo; i < besthi; i++)
+ best[i].val = 0;
+ find_best(a, b, alo, ahi, blo, bhi, best);
+ for (i = bestlo + 1; i < besthi; i++)
if (best[i-1].val > 0 &&
best[i].val > 0 &&
best[i-1].xhi >= best[i].xlo)
if (!bad)
return;
bestval = 0;
- for (i=bestlo; i<besthi; i++)
+ for (i = bestlo; i < besthi; i++)
if (best[i].val > bestval) {
bestval = best[i].val;
bestpos = i;
if (bestpos > bestlo) {
/* move top down below chunk marker */
int y = best[bestpos].ylo;
- while (b->list[y].start[0]) y--;
- find_best_inorder(a,b,
+ while (b->list[y].start[0])
+ y--;
+ find_best_inorder(a, b,
alo, best[bestpos].xlo,
blo, y,
best, bestlo, bestpos);
if (bestpos < besthi-1) {
/* move bottom up to chunk marker */
int y = best[bestpos].yhi;
- while (b->list[y].start[0]) y++;
- find_best_inorder(a,b,
+ while (b->list[y].start[0])
+ y++;
+ find_best_inorder(a, b,
best[bestpos].xhi, ahi,
y, bhi,
best, bestpos+1, besthi);
struct csl *pdiff(struct file a, struct file b, int chunks)
{
- int alo,ahi,blo,bhi;
+ int alo, ahi, blo, bhi;
struct csl *csl1, *csl2;
struct best *best = malloc(sizeof(struct best)*(chunks+1));
int i;
bhi = bsmall.elcnt;
/* printf("start: %d,%d %d,%d\n", alo,blo,ahi,bhi); */
- for (i=0; i<chunks+1; i++)
+ for (i = 0; i < chunks+1; i++)
best[i].val = 0;
- find_best_inorder(&asmall,&bsmall,
- 0, asmall.elcnt, 0, bsmall.elcnt,
- best, 1, chunks+1);
+ find_best_inorder(&asmall, &bsmall,
+ 0, asmall.elcnt, 0, bsmall.elcnt,
+ best, 1, chunks+1);
#if 0
-/* for(i=0; i<b.elcnt;i++) { printf("%d: ", i); printword(b.list[i]); }*/
- for (i=1; i<=chunks; i++) {
- printf("end: %d,%d %d,%d\n", best[i].xlo,best[i].ylo,best[i].xhi,best[i].yhi);
- printf("<"); printword(bsmall.list[best[i].ylo]); printf("><");
- printword(bsmall.list[best[i].yhi-1]);printf(">\n");
+/* for(i=0; i < b.elcnt;i++) { printf("%d: ", i); printword(b.list[i]); }*/
+ for (i = 1; i <= chunks; i++) {
+ printf("end: %d,%d %d,%d\n", best[i].xlo, best[i].ylo,
+ best[i].xhi, best[i].yhi);
+ printf("<");
+ printword(bsmall.list[best[i].ylo]);
+ printf("><");
+ printword(bsmall.list[best[i].yhi-1]);
+ printf(">\n");
}
#endif
- remap(best,chunks+1,asmall,bsmall,a,b);
+ remap(best, chunks+1, asmall, bsmall, a, b);
#if 0
-/* for(i=0; i<b.elcnt;i++) { printf("%d: ", i); printword(b.list[i]); }*/
- for (i=1; i<=chunks; i++)
- printf("end: %d,%d %d,%d\n", best[i].xlo,best[i].ylo,best[i].xhi,best[i].yhi);
- printf("small: a %d b %d --- normal: a %d b %d\n", asmall.elcnt, bsmall.elcnt, a.elcnt, b.elcnt);
+/* for(i=0; i < b.elcnt;i++) { printf("%d: ", i); printword(b.list[i]); }*/
+ for (i = 1; i <= chunks; i++)
+ printf("end: %d,%d %d,%d\n", best[i].xlo, best[i].ylo,
+ best[i].xhi, best[i].yhi);
+ printf("small: a %d b %d --- normal: a %d b %d\n", asmall.elcnt,
+ bsmall.elcnt, a.elcnt, b.elcnt);
#endif
csl1 = NULL;
- for (i=1; i<=chunks; i++)
- if (best[i].val>0) {
+ for (i = 1; i <= chunks; i++)
+ if (best[i].val > 0) {
#if 0
int j;
printf("Before:\n");
- for (j=best[i].xlo; j<best[i].xhi; j++)
+ for (j = best[i].xlo; j < best[i].xhi; j++)
printword(a.list[j]);
printf("After:\n");
- for (j=best[i].ylo; j<best[i].yhi; j++)
+ for (j = best[i].ylo; j < best[i].yhi; j++)
printword(b.list[j]);
#endif
- csl2 = diff_partial(a,b,
- best[i].xlo,best[i].xhi,
- best[i].ylo,best[i].yhi);
- csl1 = csl_join(csl1,csl2);
+ csl2 = diff_partial(a, b,
+ best[i].xlo, best[i].xhi,
+ best[i].ylo, best[i].yhi);
+ csl1 = csl_join(csl1, csl2);
}
if (csl1) {
- for (csl2=csl1; csl2->len; csl2++);
+ for (csl2 = csl1; csl2->len; csl2++)
+ ;
csl2->a = a.elcnt;
csl2->b = b.elcnt;
} else {
int ahi = *ahip;
int blo = *blop;
int bhi = *bhip;
- int x,y;
+ int x, y;
int best = (ahi-alo)+(bhi-blo);
int dist;
v[klo].x = alo;
v[klo].l = 0;
- while(1) {
+ while (1) {
- for (k=klo ; k <= khi ; k+= 2) {
+ for (k = klo ; k <= khi ; k += 2) {
int snake = 0;
struct v vnew = v[k];
x = v[k].x;
y = x-k;
- if (y > bhi) abort();
+ if (y > bhi)
+ abort();
while (x < ahi && y < bhi &&
match(&a->list[x], &b->list[y])
) {
x++;
y++;
- snake=1;
+ snake = 1;
}
vnew.x = x;
vnew.l += snake;
dist = (ahi-x)+(bhi-y);
- if (dist < best) best = dist;
+ if (dist < best)
+ best = dist;
if (x+y >= mid &&
v[k].x+v[k].x-k <= mid) {
vnew.md = k;
/* OK! We have arrived.
* We crossed the midpoint at or after v[k].xm,v[k].ym
*/
- if (x != ahi) abort();
+ if (x != ahi)
+ abort();
x = (v[k].md+mid)/2;
y = x-v[k].md;
*alop = x;
}
}
- for (k=klo+1; k <= khi-1 ; k+= 2) {
- if (v[k-1].x+1 >= v[k+1].x ) {
+ for (k = klo+1; k <= khi-1 ; k += 2) {
+ if (v[k-1].x+1 >= v[k+1].x) {
v[k] = v[k-1];
v[k].x++;
} else {
}
}
- x = v[klo].x; y = x -(klo-1);
+ x = v[klo].x; y = x - (klo-1);
dist = abs((ahi-x)-(bhi-y));
if (dist <= best) {
v[klo-1] = v[klo];
- klo --;
+ klo--;
} else
while (dist > best) {
- klo ++;
- x = v[klo].x; y = x -(klo-1);
+ klo++;
+ x = v[klo].x;
+ y = x - (klo-1);
dist = abs((ahi-x)-(bhi-y));
}
if (dist <= best) {
v[khi+1] = v[khi];
v[khi+1].x++;
- khi ++;
+ khi++;
} else
while (dist > best) {
- khi --;
+ khi--;
x = v[khi].x+1; y = x - (khi+1);
dist = abs((ahi-x)-(bhi-y));
}
return csl;
- k = find_common(a,b,
+ k = find_common(a, b,
&alo1, &ahi1,
&blo1, &bhi1,
(ahi+bhi+alo+blo)/2,
v);
- if (k != ahi-bhi) abort();
+ if (k != ahi-bhi)
+ abort();
len = v[k].l;
csl->len = 0;
}
if (len) {
- csl = lcsl(a,alo,alo1,
- b,blo,blo1,
+ csl = lcsl(a, alo, alo1,
+ b, blo, blo1,
csl, v);
if (ahi1 > alo1) {
csl->b+csl->len == blo1) {
csl->len += ahi1-alo1;
} else {
- if (csl->len) csl++;
+ if (csl->len)
+ csl++;
csl->len = ahi1-alo1;
csl->a = alo1;
csl->b = blo1;
csl[1].len = 0;
}
}
- csl = lcsl(a,ahi1,ahi,
- b,bhi1,bhi,
- csl,v);
+ csl = lcsl(a, ahi1, ahi,
+ b, bhi1, bhi,
+ csl, v);
}
if (rv) {
if (csl->len)
struct csl *list1, *orig;
int lasteol = -1;
int found_end = 0;
- if (!list) return;
+
+ if (!list)
+ return;
orig = list;
list1 = list+1;
while (list->len) {
#if 0
printword(stderr, a->list[list1->a-1]);
printf("fixup %d,%d %d : %d,%d %d\n",
- list->a,list->b,list->len,
- list1->a,list1->b,list1->len);
+ list->a, list->b, list->len,
+ list1->a, list1->b, list1->len);
#endif
if (ends_line(a->list[list->a+list->len-1])
- && a->list[list->a+list->len-1].len==1
+ && a->list[list->a+list->len-1].len == 1
&& lasteol == -1
) {
#if 0
} else {
if (lasteol >= 0) {
/* printf("seek %d\n", lasteol);*/
- while (list1->a <= lasteol && (list1->len>1 ||
+ while (list1->a <= lasteol && (list1->len > 1 ||
(found_end && list1->len > 0))) {
list1->a++;
list1->b++;
list1->len--;
list->len++;
}
- lasteol=-1;
+ lasteol = -1;
}
*++list = *list1;
if (found_end) {
} else
list1++;
}
- if (list->len && list1 == list) abort();
+ if (list->len && list1 == list)
+ abort();
}
// list[1] = list1[0];
}
arg = 1;
a.elcnt = 0;
a.list = lst;
- while (argv[arg] && strcmp(argv[arg],"--")) {
+ while (argv[arg] && strcmp(argv[arg], "--")) {
lst->hash = 0;
lst->start = argv[arg];
lst->len = strlen(argv[arg]);
arg++;
b.elcnt = 0;
b.list = lst;
- while (argv[arg] && strcmp(argv[arg],"--")) {
+ while (argv[arg] && strcmp(argv[arg], "--")) {
lst->hash = 0;
lst->start = argv[arg];
lst->len = strlen(argv[arg]);
v);
printf("ln=%d (%d,%d) -> (%d,%d)\n", ln,
- alo,blo,ahi,bhi);
+ alo, blo, ahi, bhi);
#else
csl = lcsl(&a, 0, a.elcnt,
&b, 0, b.elcnt,
fixup(&a, &b, csl);
while (csl && csl->len) {
int i;
- printf("%d,%d for %d:\n", csl->a,csl->b,csl->len);
- for (i=0; i<csl->len; i++) {
+ printf("%d,%d for %d:\n", csl->a, csl->b, csl->len);
+ for (i = 0; i < csl->len; i++) {
printf(" %.*s (%.*s)\n",
a.list[csl->a+i].len, a.list[csl->a+i].start,
b.list[csl->b+i].len, b.list[csl->b+i].start);
char *c = *cp;
while (c < end && *c != '\n')
c++;
- if (c < end) c++;
+ if (c < end)
+ c++;
*cp = c;
}
int split_patch(struct stream f, struct stream *f1, struct stream *f2)
{
struct stream r1, r2;
- int chunks=0;
+ int chunks = 0;
char *cp, *end;
int state = 0;
- int acnt=0, bcnt=0;
- int a,b,c,d;
+ int acnt = 0, bcnt = 0;
+ int a, b, c, d;
int lineno = 0;
char before[100], after[100];
* 3 unified
*/
lineno++;
- switch(state) {
+ switch (state) {
case 0:
- if (sscanf(cp, "@@ -%s +%s @@", before, after)==2) {
+ if (sscanf(cp, "@@ -%s +%s @@", before, after) == 2) {
int ok = 1;
if (sscanf(before, "%d,%d", &a, &b) == 2)
acnt = b;
state = 3;
else
state = 0;
- } else if (sscanf(cp, "*** %d,%d ****", &a, &b)==2) {
+ } else if (sscanf(cp, "*** %d,%d ****", &a, &b) == 2) {
acnt = b-a+1;
state = 1;
- } else if (sscanf(cp, "--- %d,%d ----", &c, &d)==2) {
+ } else if (sscanf(cp, "--- %d,%d ----", &c, &d) == 2) {
bcnt = d-c+1;
state = 2;
}
skip_eol(&cp, end);
- if (state==1 || state == 3) {
+ if (state == 1 || state == 3) {
char buf[20];
buf[0] = 0;
chunks++;
memcpy(r1.body+r1.len, buf, 20);
r1.len += 20;
}
- if (state==2 || state == 3) {
+ if (state == 2 || state == 3) {
char buf[20];
buf[0] = 0;
sprintf(buf+1, "%5d %5d %5d\n", chunks, c, bcnt);
}
break;
case 1:
- if ((*cp == ' ' || *cp=='!' || *cp == '-' || *cp == '+')
+ if ((*cp == ' ' || *cp == '!' || *cp == '-' || *cp == '+')
&& cp[1] == ' ') {
- cp+=2;
+ cp += 2;
copyline(&r1, &cp, end);
acnt--;
if (acnt == 0)
}
break;
case 2:
- if ((*cp == ' ' || *cp=='!' || *cp == '-' || *cp == '+')
+ if ((*cp == ' ' || *cp == '!' || *cp == '-' || *cp == '+')
&& cp[1] == ' ') {
- cp+= 2;
+ cp += 2;
copyline(&r2, &cp, end);
bcnt--;
if (bcnt == 0)
int lineno;
int state = 0;
char *cp, *end;
- struct stream r1,r2,r3;
+ struct stream r1, r2, r3;
f1->body = NULL;
f2->body = NULL;
*/
int len = end-cp;
lineno++;
- switch(state) {
+ switch (state) {
case 0:
- if (len>=8 &&
- strncmp(cp, "<<<<<<<", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, "<<<<<<<", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
char *peek;
skip_eol(&peek, end);
}
} else {
- char *cp2= cp;
+ char *cp2 = cp;
copyline(&r1, &cp2, end);
cp2 = cp;
copyline(&r2, &cp2, end);
}
break;
case 1:
- if (len>=8 &&
- strncmp(cp, "|||||||", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, "|||||||", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
state = 2;
copyline(&r1, &cp, end);
break;
case 2:
- if (len>=8 &&
- strncmp(cp, "=======", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, "=======", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
state = 3;
copyline(&r2, &cp, end);
break;
case 3:
- if (len>=8 &&
- strncmp(cp, ">>>>>>>", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, ">>>>>>>", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
state = 0;
copyline(&r3, &cp, end);
break;
case 4:
- if (len>=8 &&
- strncmp(cp, "=======", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, "=======", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
state = 5;
copyline(&r2, &cp, end);
break;
case 5:
- if (len>=8 &&
- strncmp(cp, ">>>>>>>", 7)==0 &&
+ if (len >= 8 &&
+ strncmp(cp, ">>>>>>>", 7) == 0 &&
(cp[7] == ' ' || cp[7] == '\n')
) {
state = 0;
/* join all the streams in the list (upto body=NULL)
* into one by re-allocing list[0].body and copying
*/
- int len=0;
+ int len = 0;
int i;
char *c;
- for (i=0; i<cnt ; i++)
+ for (i = 0; i < cnt ; i++)
len += list[i].len;
c = realloc(list[0].body, len+1);
list[0].body = c;
c += list[0].len;
list[0].len = len;
- for (i=1; i<cnt; i++) {
+ for (i = 1; i < cnt; i++) {
memcpy(c, list[i].body, list[i].len);
c += list[i].len;
list[i].len = 0;
free(s.body);
s.body = NULL;
}
- } else die();
+ } else
+ die();
s.body[s.len] = 0;
return s;
}
struct stream list[10];
int i = 0;
- while(1) {
+ while (1) {
list[i].body = malloc(8192);
if (!list[i].body)
die();
s.body = NULL;
s.len = 0;
- if (strcmp(name, "-")==0)
+ if (strcmp(name, "-") == 0)
fd = 0;
else {
fd = open(name, O_RDONLY);
- if (fd <0)
+ if (fd < 0)
return s;
}
* At the end of the file, c1 will be the EOF match in A-B, c2 will be the
* EOF match in B-C, !in_a and pos == [c2]->b
*/
-struct point { int pos, in_a; int c1,c2; };
+struct point {
+ int pos, in_a;
+ int c1, c2;
+};
static int tripoint(struct point *here,
*a = here->pos;
if (here->c1 < 0) {
- if (*a) return 0;
+ if (*a)
+ return 0;
*b = 0;
} else if (c1->a <= *a && c1->a+c1->len >= *a)
*b = c1->b + (*a - c1->a);
return 0;
if (here->c2 < 0) {
- if (*b) return 0;
+ if (*b)
+ return 0;
*c = 0;
} else if (c2->a <= *b && c2->a + c2->len >= *b)
*c = c2->b + *b - c2->a;
*c = here->pos;
if (here->c2 < 0) {
- if (*c) return 0;
+ if (*c)
+ return 0;
*b = 0;
- } else if (c2->b <= *c && c2->b +c2->len >= *c)
+ } else if (c2->b <= *c && c2->b + c2->len >= *c)
*b = c2->a + *c - c2->b;
else
return 0;
if (here->c1 < 0) {
- if (*b) return 0;
+ if (*b)
+ return 0;
*a = 0;
} else if (c1->b <= *b && c1->b + c1->len >= *b)
*a = c1->a + *b - c1->b;
static int retreat(struct csl *c1, struct csl *c2, struct point *p)
{
- int a,b,c;
+ int a, b, c;
int slid = 0;
retry:
while ((p->c1 == 0 && a == 0) ||
(p->c1 > 0 && c1[p->c1-1].a + c1[p->c1-1].len >= a)) {
if (!slid)
- if ( a >= c1[p->c1].a)
+ if (a >= c1[p->c1].a)
break;
p->c1--;
}
/* if we aren't in a co-incidence, just return */
- if (p->c1 >=0 &&
+ if (p->c1 >= 0 &&
c1[p->c1].a > a)
return 1;
}
/* check if this is a conflict */
- if ((p->c2>=0 && c2[p->c2].a > b))
+ if ((p->c2 >= 0 && c2[p->c2].a > b))
return 2;
if (p->c2 == -1)
b = 0;
else
b = c2[p->c2].a + c - c2[p->c2].b;
- while ((p->c1==0 && b == 0) ||
+ while ((p->c1 == 0 && b == 0) ||
(p->c1 > 0 && c1[p->c1-1].b + c1[p->c1-1].len >= b)) {
if (!slid)
if (b >= c1[p->c1].b)
}
/* check if this is a conflict */
- if ((p->c1>=0 && c1[p->c1].b > b))
+ if ((p->c1 >= 0 && c1[p->c1].b > b))
return 2;
if (p->c1 == -1)
static int advance(struct csl *c1, struct csl *c2, struct point *p)
{
- int a,b,c;
+ int a, b, c;
int slid = 0;
/* make next char at point is the 'right' one, either in a or c.
* This might involve move p->c1 and p->c2 forward
while ((p->c1 == -1 || c1[p->c1].len) &&
c1[p->c1+1].a <= a) {
if (!slid)
- if ((p->c1== -1 && a ==0) ||
- (p->c1>=0 && a <= c1[p->c1].a+c1[p->c1].len))
+ if ((p->c1 == -1 && a == 0) ||
+ (p->c1 >= 0 && a <= c1[p->c1].a+c1[p->c1].len))
break;
p->c1++;
}
return 1;
/* advance c2 to last coincidence containing or before pos->b */
- b = c1[p->c1].b + a- c1[p->c1].a;
+ b = c1[p->c1].b + a - c1[p->c1].a;
while ((p->c2 == -1 || c2[p->c2].len) &&
c2[p->c2+1].a <= b) {
if (!slid)
}
/* check if this is a conflict */
- if ((p->c2 == -1 && b >0) ||
- (p->c2>=0 && c2[p->c2].a + c2[p->c2].len < b))
+ if ((p->c2 == -1 && b > 0) ||
+ (p->c2 >= 0 && c2[p->c2].a + c2[p->c2].len < b))
return 2;
if (p->c2 == -1)
* if we've slid, make sure not to skip over
* the stuff in c2.
*/
- if(slid && p->c2 != -1 && c2[p->c2].a == b &&
- c2[p->c2].b > c2[p->c2].a) {
+ if (slid && p->c2 != -1 && c2[p->c2].a == b &&
+ c2[p->c2].b > c2[p->c2].a) {
c -= c2[p->c2].b - c2[p->c2].a;
}
while ((p->c1 == -1 || c1[p->c1].len) &&
c1[p->c1+1].b <= b) {
if (!slid)
- if ((p->c1 == -1 && b ==0) ||
+ if ((p->c1 == -1 && b == 0) ||
(p->c1 >= 0 && b <= c1[p->c1].b+c1[p->c1].len))
break;
p->c1++;
* If it is the end of an A-B coincidence but not EOF,
* slide down to A
*/
- if (a == c1[p->c1].a+ c1[p->c1].len &&
+ if (a == c1[p->c1].a + c1[p->c1].len &&
c1[p->c1].len) {
p->in_a = 1;
p->pos = a;
static int point_crossed(struct point first, struct point second,
struct csl *cs1, struct csl *cs2)
{
- int a1,b1,c1;
- int a2,b2,c2;
+ int a1, b1, c1;
+ int a2, b2, c2;
- if (tripoint(&first, cs1,cs2, &a1,&b1,&c1) &&
- tripoint(&second, cs1,cs2, &a2,&b2,&c2))
- return a1>=a2 && b1>=b2 && c1>=c2;
+ if (tripoint(&first, cs1, cs2, &a1, &b1, &c1) &&
+ tripoint(&second, cs1, cs2, &a2, &b2, &c2))
+ return a1 >= a2 && b1 >= b2 && c1 >= c2;
return 0;
/*
return first.in_a == second.in_a &&
static void print_merger(FILE *out, struct file *a, struct file *c,
- struct csl *cs1, struct csl *cs2,
- struct point start, struct point end)
+ struct csl *cs1, struct csl *cs2,
+ struct point start, struct point end)
{
- while (!point_crossed(start, end, cs1,cs2)) {
+ while (!point_crossed(start, end, cs1, cs2)) {
#if 0
- printf("%c %d (%d,%d)\n", start.in_a?'A':'C', start.pos, start.c1,start.c2);
+ printf("%c %d (%d,%d)\n", start.in_a ? 'A' : 'C', start.pos,
+ start.c1, start.c2);
#endif
if (start.in_a)
printword(out, a->list[start.pos]);
fflush(out); /* DEBUG */
start.pos++;
- if (point_crossed(start, end, cs1,cs2))
+ if (point_crossed(start, end, cs1, cs2))
break;
advance(cs1, cs2, &start);
int bi;
#if 0
- if (point_same(start,end))
+ if (point_same(start, end))
return 0; /* no conflict here !! */
#endif
- if (!tripoint(&start, c1,c2, &astart, &bstart, &cstart))
+ if (!tripoint(&start, c1, c2, &astart, &bstart, &cstart))
abort();
- if (!tripoint(&end, c1,c2, &aend, &bend, &cend))
+ if (!tripoint(&end, c1, c2, &aend, &bend, &cend))
abort();
bi = bstart;
while (bi < bend && start.c1 >= 0 && bi >= c1[start.c1].b && bi < c1[start.c1].b + c1[start.c1].len) {
bi++;
- if (words || at_sol(b,bi)) {
+ if (words || at_sol(b, bi)) {
astart += bi-bstart;
bstart = bi;
}
bi = bstart;
while (bi < bend && start.c2 >= 0 && bi >= c2[start.c2].a && bi < c2[start.c2].a + c2[start.c2].len) {
bi++;
- if (words || at_sol(b,bi)) {
+ if (words || at_sol(b, bi)) {
cstart += bi-bstart;
bstart = bi;
}
bi = bend;
while (bi > bstart && bi > c2[end.c2].a) {
bi--;
- if (words || at_sol(b,bi)) {
+ if (words || at_sol(b, bi)) {
cend -= bend-bi;
bend = bi;
}
if (astart >= aend && bstart >= bend && cstart >= cend)
return 0;
- fputs(words?"<<<---":"<<<<<<<\n", out);
+ fputs(words ? "<<<---" : "<<<<<<<\n", out);
print_range(out, a, astart, aend);
- fputs(words?"|||":"|||||||\n", out);
+ fputs(words ? "|||" : "|||||||\n", out);
print_range(out, b, bstart, bend);
- fputs(words?"===":"=======\n", out);
+ fputs(words ? "===" : "=======\n", out);
print_range(out, c, cstart, cend);
- fputs(words?"--->>>":">>>>>>>\n", out);
+ fputs(words ? "--->>>" : ">>>>>>>\n", out);
return 1;
}
static int end_of_file(struct point p, struct csl *c1, struct csl *c2)
{
- return advance(c1,c2,&p)==0;
+ return advance(c1, c2, &p) == 0;
}
-static int next_conflict(struct point here, struct csl *start_c1, struct csl *start_c2,
+static int next_conflict(struct point here,
+ struct csl *start_c1, struct csl *start_c2,
struct point *start, struct point *end)
{
/* We want to find the start and end of the 'next' conflict.
c1++;
if (c2->len)
c2++;
- } else if (c2->len ==0 || (c1->len && c1->b+c1->len < c2->a+c2->len)) {
+ } else if (c2->len == 0 ||
+ (c1->len && c1->b+c1->len < c2->a+c2->len)) {
/* c1 ends earlier. If the new start of c1 is
* beyond the current end of c2, we have a conflict
*/
if (c2->a > c1->b+c1->len)
conflict_found = 1;
}
- if ((c1->len == 0 && c2->len ==0) ||
+ if ((c1->len == 0 && c2->len == 0) ||
(c1->b+c1->len >= c2->a && c2->a+c2->len >= c1->b)
) {
/* double coincidence !
start->in_a = 0;
start->pos = c2[start->c2].b+c2[start->c2].len;
}
- retreat(c1,c2, start);
+ retreat(c1, c2, start);
if (c1[end->c1].b <= c2[end->c2].a) {
end->in_a = 0;
end->pos = c2[end->c2].b +
c1[end->c1].b - c2[end->c2].a;
}
- advance(c1,c2, end);
+ advance(c1, c2, end);
return 1;
}
start->c1 = c1-start_c1;
/* check if this conflict reflects and already-applied change
* i.e. the section in a matches the section in b
*/
- int a1,b1,c1;
- int a2,b2,c2;
+ int a1, b1, c1;
+ int a2, b2, c2;
- if (!tripoint(&start,cs1,cs2,&a1,&b1,&c1))
+ if (!tripoint(&start, cs1, cs2, &a1, &b1, &c1))
abort();
- if (!tripoint(&end,cs1,cs2,&a2,&b2,&c2))
+ if (!tripoint(&end, cs1, cs2, &a2, &b2, &c2))
abort();
- if (a1==a2 && b1==b2) return 0;
- if ((a2-a1) != (c2-c1)) return 0;
+ if (a1 == a2 && b1 == b2)
+ return 0;
+ if ((a2-a1) != (c2-c1))
+ return 0;
- while (a1<a2) {
+ while (a1 < a2) {
if (!match(&a->list[a1], &c->list[c1]))
return 0;
a1++;
static int Startofline(struct point p, struct csl *cs1, struct csl *cs2,
struct file *a, struct file *b, struct file *c)
{
- int a1,b1,c1;
+ int a1, b1, c1;
return
- tripoint(&p,cs1,cs2,&a1,&b1,&c1) &&
- at_sol(a,a1) && at_sol(b,b1) && at_sol(c,c1);
+ tripoint(&p, cs1, cs2, &a1, &b1, &c1) &&
+ at_sol(a, a1) && at_sol(b, b1) && at_sol(c, c1);
}
#if 0
{ int i;
- for (i=0; c1[i].len; i++) printf("%2d c1 %d:%d %d\n", i, c1[i].a,c1[i].b,c1[i].len);
- printf("%2d c1 %d:%d END\n", i, c1[i].a,c1[i].b);
- for (i=0; c2[i].len; i++) printf("%2d c2 %d:%d %d\n", i, c2[i].a,c2[i].b,c2[i].len);
- printf("%2d c2 %d:%d END\n", i, c2[i].a,c2[i].b);
+ for (i = 0; c1[i].len; i++)
+ printf("%2d c1 %d:%d %d\n", i, c1[i].a, c1[i].b, c1[i].len);
+ printf("%2d c1 %d:%d END\n", i, c1[i].a, c1[i].b);
+ for (i = 0; c2[i].len; i++)
+ printf("%2d c2 %d:%d %d\n", i, c2[i].a, c2[i].b, c2[i].len);
+ printf("%2d c2 %d:%d END\n", i, c2[i].a, c2[i].b);
}
#endif
/* end_last is a forward looking point */
end_last.pos = 0;
end_last.in_a = 1;
end_last.c1 = end_last.c2 = -1;
- advance(c1,c2, &end_last);
+ advance(c1, c2, &end_last);
/* start_last is a backward looking point */
start_last.pos = 0;
start_last.in_a = 1;
start_last.c1 = start_last.c2 = 0;
- retreat(c1,c2, &start_last);
+ retreat(c1, c2, &start_last);
while (!end_of_file(end_last, c1, c2)) {
next_conflict(end_last, c1, c2, &start_next, &end_next);
- while (already_applied(c1,c2,start_next,end_next,a,b,c)) {
+ while (already_applied(c1, c2, start_next, end_next, a, b, c)) {
rv.ignored++;
- next_conflict(end_next, c1,c2,&start_next,&end_next);
+ next_conflict(end_next, c1, c2, &start_next, &end_next);
}
#if 0
printf("start %d %d (%d,%d) end %d %d (%d,%d)\n",
start_next.in_a, start_next.pos, start_next.c1, start_next.c2,
end_next.in_a, end_next.pos, end_next.c1, end_next.c2);
#endif
- while (!point_crossed(end_last, start_next,c1,c2) &&
- !(words || Startofline(end_last, c1,c2, a,b,c))) {
+ while (!point_crossed(end_last, start_next, c1, c2) &&
+ !(words || Startofline(end_last, c1, c2, a, b, c))) {
end_last.pos++;
- advance(c1,c2, &end_last);
+ advance(c1, c2, &end_last);
}
- while (!point_crossed(end_last, start_next, c1,c2) &&
- !(words || Startofline(start_next, c1,c2, a,b,c))) {
+ while (!point_crossed(end_last, start_next, c1, c2) &&
+ !(words || Startofline(start_next, c1, c2, a, b, c))) {
start_next.pos--;
- retreat(c1,c2, &start_next);
+ retreat(c1, c2, &start_next);
}
- if (point_crossed(end_last, start_next, c1,c2)) {
+ if (point_crossed(end_last, start_next, c1, c2)) {
end_last = end_next;
continue;
}
- if (print_conflict(out, a,b,c, c1,c2, start_last, end_last, words))
+ if (print_conflict(out, a, b, c, c1, c2, start_last, end_last, words))
rv.conflicts++;
- print_merger(out, a,c, c1,c2, end_last, start_next);
+ print_merger(out, a, c, c1, c2, end_last, start_next);
start_last = start_next;
end_last = end_next;
}
- if (print_conflict(out,a,b,c, c1,c2, start_last, end_last, words))
+ if (print_conflict(out, a, b, c, c1, c2, start_last, end_last, words))
rv.conflicts++;
return rv;
}
static inline int min(int a, int b)
{
- return a<b?a:b;
+ return a < b ? a : b;
}
static inline void assert(int a)
{
- if (!a) abort();
+ if (!a)
+ abort();
}
static int check_alreadyapplied(struct file af, struct file cf,
int i;
if (m->al != m->cl)
return 0;
- for (i=0; i<m->al; i++) {
+ for (i = 0; i < m->al; i++) {
if (af.list[m->a+i].len != cf.list[m->c+i].len)
return 0;
if (strncmp(af.list[m->a+i].start,
cf.list[m->c+i].start,
- af.list[m->a+i].len)!= 0)
+ af.list[m->a+i].len) != 0)
return 0;
}
#if 0
printf("already applied %d,%d,%d - %d,%d,%d\n",
- m->a,m->b,m->c,m->al,m->bl,m->cl);
+ m->a, m->b, m->c, m->al, m->bl, m->cl);
printf(" %.10s - %.10s\n", af.list[m->a].start,
cf.list[m->c].start);
#endif
* a newline.
*
*/
- int i,j,k;
+ int i, j, k;
int cnt = 0;
- for (i=0; m[i].type != End; i++)
+ for (i = 0; m[i].type != End; i++)
if (m[i].type == Conflict) {
/* We have a conflict here.
* First search backwards for an Unchanged marking
* might be after the last newline, if there
* is one, or might be at the start
*/
- for (k=m[j].al; k>0; k--)
+ for (k = m[j].al; k > 0; k--)
if (ends_line(af.list[m[j].a+k-1]))
break;
if (k > 0)
}
}
#if 0
- if (j>=0 && m[j].in_conflict && m[j].type == Unchanged &&
+ if (j >= 0 && m[j].in_conflict && m[j].type == Unchanged &&
m[j].hi == m[j].lo) {
/* nothing to separate conflicts, merge them */
m[j].lo = 0;
}
#endif
/* now the forward search */
- for (j=i+1; m[j].type != End; j++) {
+ for (j = i+1; m[j].type != End; j++) {
m[j].in_conflict = 1;
if (m[j].type == Unchanged || m[j].type == Changed) {
m[j].hi = m[j].al;
for (k = 0 ; k < m[j].al ; k++)
if (ends_line(af.list[m[j].a+k]))
break;
- if (k<m[j].al)
+ if (k < m[j].al)
m[j].lo = k+1;
else
/* no start-of-line found */
/* find the wiggles and conflicts between csl1 and csl2
*/
struct ci rv;
- int i,l;
- int a,b,c,c1,c2;
+ int i, l;
+ int a, b, c, c1, c2;
int wiggle_found = 0;
rv.conflicts = rv.wiggles = rv.ignored = 0;
- for (i=0; csl1[i].len; i++);
+ for (i = 0; csl1[i].len; i++)
+ ;
l = i;
- for (i=0; csl2[i].len; i++);
+ for (i = 0; csl2[i].len; i++)
+ ;
l += i;
/* maybe a bit of slack at each end */
- l = l* 4 + 10;
+ l = l * 4 + 10;
rv.merger = malloc(sizeof(struct merge)*l);
if (!rv.merger)
return rv;
- a=b=c=c1=c2 = 0;
+ a = b = c = c1 = c2 = 0;
i = 0;
while (1) {
int match1, match2;
- match1 = (a>=csl1[c1].a && b >= csl1[c1].b); /* c1 doesn't match */
- match2 = (b>=csl2[c2].a && c >= csl2[c2].b);
+ match1 = (a >= csl1[c1].a && b >= csl1[c1].b); /* c1 doesn't match */
+ match2 = (b >= csl2[c2].a && c >= csl2[c2].b);
rv.merger[i].a = a;
rv.merger[i].b = b;
rv.merger[i].al = csl1[c1].a - a;
rv.merger[i].bl = 0;
rv.merger[i].cl = 0;
- wiggle_found ++;
+ wiggle_found++;
} else {
int newb;
int j;
- assert(b<csl1[c1].b);
+ assert(b < csl1[c1].b);
/* some Extraneous text */
/* length is min of unmatched on left
* and matched on right
min(csl1[c1].b - b,
csl2[c2].len - (b-csl2[c2].a));
newb = b+rv.merger[i].bl;
- for (j=b; j<newb; j++) {
+ for (j = b; j < newb; j++) {
if (bf.list[j].start[0] == '\0') {
if (wiggle_found > 1)
rv.wiggles++;
wiggle_found = 0;
} else
- wiggle_found ++;
+ wiggle_found++;
}
}
} else if (match1 && !match2) {
rv.merger[i].cl = csl2[c2].b - c;
rv.merger[i].bl = min(csl1[c1].b, csl2[c2].a) - b;
if (ignore_already &&
- check_alreadyapplied(af,cf,&rv.merger[i]))
- rv.ignored ++;
+ check_alreadyapplied(af, cf, &rv.merger[i]))
+ rv.ignored++;
}
a += rv.merger[i].al;
b += rv.merger[i].bl;
c += rv.merger[i].cl;
i++;
- while (csl1[c1].a + csl1[c1].len <= a && csl1[c1].len) c1++;
+ while (csl1[c1].a + csl1[c1].len <= a && csl1[c1].len)
+ c1++;
assert(csl1[c1].b + csl1[c1].len >= b);
- while (csl2[c2].b + csl2[c2].len <= c && csl2[c2].len) c2++;
+ while (csl2[c2].b + csl2[c2].len <= c && csl2[c2].len)
+ c2++;
assert(csl2[c2].a + csl2[c2].len >= b);
if (csl1[c1].len == 0 && csl2[c2].len == 0 &&
a == csl1[c1].a && b == csl1[c1].b &&
}
rv.merger[i].type = End;
rv.merger[i].in_conflict = 0;
- rv.conflicts = isolate_conflicts(af,bf,cf,csl1,csl2,words,rv.merger);
+ rv.conflicts = isolate_conflicts(af, bf, cf, csl1, csl2, words, rv.merger);
if (wiggle_found)
rv.wiggles++;
return rv;
static void printrange(FILE *out, struct file *f, int start, int len)
{
- while (len> 0) {
+ while (len > 0) {
printword(out, f->list[start]);
start++;
len--;
struct csl *c1, struct csl *c2,
int words, int ignore_already)
{
- struct ci rv = make_merger(*a, *b, *c, c1, c2,
+ struct ci rv = make_merger(*a, *b, *c, c1, c2,
words, ignore_already);
struct merge *m;
- for (m=rv.merger; m->type != End ; m++) {
+ for (m = rv.merger; m->type != End ; m++) {
struct merge *cm;
#if 1
- static int v= -1;
+ static int v = -1;
if (v == -1) {
if (getenv("WiggleVerbose"))
v = 1;
v = 0;
}
if (v)
- printf("[%s: %d-%d,%d-%d,%d-%d%s(%d,%d)]\n",
- m->type==Unmatched?"Unmatched":
- m->type==Unchanged?"Unchanged":
- m->type==Extraneous?"Extraneous":
- m->type==Changed?"Changed":
- m->type==AlreadyApplied?"AlreadyApplied":
- m->type==Conflict?"Conflict":"unknown",
- m->a, m->a+m->al-1,
- m->b, m->b+m->bl-1,
- m->c, m->c+m->cl-1, m->in_conflict?" in_conflict":"",
- m->lo, m->hi);
+ printf("[%s: %d-%d,%d-%d,%d-%d%s(%d,%d)]\n",
+ m->type==Unmatched ? "Unmatched" :
+ m->type==Unchanged ? "Unchanged" :
+ m->type==Extraneous ? "Extraneous" :
+ m->type==Changed ? "Changed" :
+ m->type==AlreadyApplied ? "AlreadyApplied" :
+ m->type==Conflict ? "Conflict":"unknown",
+ m->a, m->a+m->al-1,
+ m->b, m->b+m->bl-1,
+ m->c, m->c+m->cl-1,
+ m->in_conflict ? " in_conflict" : "",
+ m->lo, m->hi);
#endif
while (m->in_conflict) {
/* need to print from 'hi' to 'lo' of next
#if 1
if (v)
- for (cm=m; cm->in_conflict; cm++) {
+ for (cm = m; cm->in_conflict; cm++) {
printf("{%s: %d-%d,%d-%d,%d-%d%s(%d,%d)}\n",
cm->type==Unmatched?"Unmatched":
cm->type==Unchanged?"Unchanged":
cm->type==Conflict?"Conflict":"unknown",
cm->a, cm->a+cm->al-1,
cm->b, cm->b+cm->bl-1,
- cm->c, cm->c+cm->cl-1, cm->in_conflict?" in_conflict":"",
+ cm->c, cm->c+cm->cl-1,
+ cm->in_conflict ? " in_conflict" : "",
cm->lo, cm->hi);
- if ((cm->type == Unchanged ||cm->type == Changed) && cm != m && cm->lo < cm->hi)
+ if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi)
break;
}
#endif
- fputs(words?"<<<---":"<<<<<<<\n", out);
- for (cm=m; cm->in_conflict; cm++) {
+ fputs(words ? "<<<---" : "<<<<<<<\n", out);
+ for (cm = m; cm->in_conflict; cm++) {
if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) {
printrange(out, a, cm->a, cm->lo);
break;
printrange(out, a, cm->a+st1, cm->al-st1);
st1 = 0;
}
- fputs(words?"|||":"|||||||\n", out);
+ fputs(words ? "|||" : "|||||||\n", out);
st1 = st;
- for (cm=m; cm->in_conflict; cm++) {
+ for (cm = m; cm->in_conflict; cm++) {
if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) {
printrange(out, b, cm->b, cm->lo);
break;
printrange(out, b, cm->b+st1, cm->bl-st1);
st1 = 0;
}
- fputs(words?"===":"=======\n", out);
+ fputs(words ? "===" : "=======\n", out);
st1 = st;
- for (cm=m; cm->in_conflict; cm++) {
+ for (cm = m; cm->in_conflict; cm++) {
if (cm->type == Unchanged && cm != m && cm->lo < cm->hi) {
printrange(out, c, cm->c, cm->lo);
break;
printrange(out, c, cm->c+st1, cm->cl-st1);
st1 = 0;
}
- fputs(words?"--->>>":">>>>>>>\n", out);
+ fputs(words ? "--->>>" : ">>>>>>>\n", out);
m = cm;
if (m->in_conflict && m->type == Unchanged
&& m->hi >= m->al) {
m->type==Conflict?"Conflict":"unknown",
m->a, m->a+m->al-1,
m->b, m->b+m->bl-1,
- m->c, m->c+m->cl-1, m->in_conflict?" in_conflict":"",
+ m->c, m->c+m->cl-1,
+ m->in_conflict ? " in_conflict" : "",
m->lo, m->hi);
}
#endif
- switch(m->type) {
+ switch (m->type) {
case Unchanged:
case AlreadyApplied:
case Unmatched:
printrange(out, c, m->c, m->cl);
break;
case Conflict:
- case End: assert(0);
+ case End:
+ assert(0);
}
}
return rv;
if (*cp == '\0' && cp+19 < end && cp[18] == '\n') {
/* special word */
cp += 20;
- } else switch(type) {
+ } else switch (type) {
case ByLine:
while (cp < end && *cp != '\n')
cp++;
- if (cp<end) cp++;
+ if (cp < end)
+ cp++;
break;
case ByWord:
case ApproxWord:
if (isalnum(*cp) || *cp == '_') {
- do cp++;
- while (cp<end && (isalnum(*cp) || *cp == '_'));
+ do
+ cp++;
+ while (cp < end && (isalnum(*cp) || *cp == '_'));
} else if (*cp == ' ' || *cp == '\t') {
- do cp++;
- while (cp<end && (*cp == ' ' || *cp == '\t'));
+ do
+ cp++;
+ while (cp < end && (*cp == ' ' || *cp == '\t'));
} else
cp++;
break;
}
- if (type != ApproxWord || *start =='\0' ||
+ if (type != ApproxWord || *start == '\0' ||
(isalnum(*start) || *start == '_')) {
if (list) {
- if (reverse) list--;
+ if (reverse)
+ list--;
list->start = start;
list->len = cp-start;
if (*start)
list->hash = hash_mem(start, list->len, BITS_PER_LONG);
else
list->hash = atoi(start+1);
- if (!reverse) list++;
+ if (!reverse)
+ list++;
}
cnt++;
}
/* plist stores a list of patched files in an array
- * Each entry identifies a file, the range of the
+ * Each entry identifies a file, the range of the
* original patch which applies to this file, some
* statistics concerning how many conflicts etc, and
* some linkage information so the list can be viewed
{
int rows, cols;
int top, left;
- int r,c;
+ int r, c;
int ch;
char **page = page1;
int line = 0;
top = 3;
rows = rows - 6;
} else {
- top = (rows-15)/2 -1;
+ top = (rows-15)/2 - 1;
rows = 15;
}
-
+
(void)attrset(A_STANDOUT);
for (c = left; c < left+cols; c++) {
mvaddch(top-1, c, '-');
mvaddch(r, left-1, '|');
mvaddch(r, left+cols, '|');
}
- mvaddch(top-1,left-1,'/');
- mvaddch(top-1,left+cols, '\\');
+ mvaddch(top-1, left-1, '/');
+ mvaddch(top-1, left+cols, '\\');
mvaddch(top+rows, left-1, '\\');
mvaddch(top+rows, left+cols, '/');
mvaddstr(top-1, left + cols/2 - 2, "HELP");
mvaddstr(top+rows, left+cols/2 - 16, "Press SPACE for more, ? for help");
(void)attrset(A_NORMAL);
-
- while(1) {
+
+ while (1) {
char **lnp = page + line;
- for (r=0; r < rows; r++) {
+ for (r = 0; r < rows; r++) {
char *ln = *lnp;
int sh = shift;
if (ln)
ln++;
sh--;
}
- for (c=0; c<cols; c++) {
+ for (c = 0; c < cols; c++) {
int chr = *ln;
if (chr)
ln++;
mvaddch(top+r, left+c, chr);
}
}
- move(top+rows-1,left);
+ move(top+rows-1, left);
ch = getch();
- switch(ch) {
+ switch (ch) {
case 'q':
return;
case '?':
break;
case ' ':
case '\r':
- for (r=0; r < rows-2; r++)
+ for (r = 0; r < rows-2; r++)
if (page[line])
line++;
if (!page[line]) {
/* Displaying a Merge.
- * The first step is to linearise the merge. The merge in inherently
+ * The first step is to linearise the merge. The merge in inherently
* parallel with before/after streams. However much of the whole document
* is linear as normally much of the original in unchanged.
* All parallelism comes from the patch. This normally produces two
* This is all encoded in 'struct mpos'.
*
* Each location may or may not be visible depending on certain
- * display options.
+ * display options.
*
* Also, some locations might be 'invalid' in that they don't need to be displayed.
* For example when the patch leaves a section of the original unchanged,
*/
static int stream_valid(int s, enum mergetype type)
{
- switch(type) {
- case End: return 1;
- case Unmatched: return s == 0;
- case Unchanged: return s == 0;
- case Extraneous: return s == 2;
- case Changed: return s != 1;
- case Conflict: return 1;
- case AlreadyApplied: return 1;
+ switch (type) {
+ case End:
+ return 1;
+ case Unmatched:
+ return s == 0;
+ case Unchanged:
+ return s == 0;
+ case Extraneous:
+ return s == 2;
+ case Changed:
+ return s != 1;
+ case Conflict:
+ return 1;
+ case AlreadyApplied:
+ return 1;
}
return 0;
}
struct merge *m)
{
pos->o++;
- while(1) {
- int l=0; /* Length remaining in current merge section */
+ while (1) {
+ int l = 0; /* Length remaining in current merge section */
if (pos->m >= 0)
- switch(pos->s) {
- case 0: l = m[pos->m].al; break;
- case 1: l = m[pos->m].bl; break;
- case 2: l = m[pos->m].cl; break;
+ switch (pos->s) {
+ case 0:
+ l = m[pos->m].al;
+ break;
+ case 1:
+ l = m[pos->m].bl;
+ break;
+ case 2:
+ l = m[pos->m].cl;
+ break;
}
if (pos->o >= l) {
/* Offset has reached length, choose new stream or
e.start = NULL; e.len = 0;
return e;
}
- switch(pos->s) {
+ switch (pos->s) {
default: /* keep compiler happy */
case 0:
if (pos->lineno & 1)
- pos->lineno ++;
+ pos->lineno++;
if (ends_mline(fm.list[m[pos->m].a + pos->o]))
- pos->lineno ++;
-
+ pos->lineno++;
return fm.list[m[pos->m].a + pos->o];
case 1: return fb.list[m[pos->m].b + pos->o];
case 2: return fa.list[m[pos->m].c + pos->o];
}
pos->o--;
- while (pos->m >=0 && pos->o < 0) {
+ while (pos->m >= 0 && pos->o < 0) {
do {
pos->s--;
if (pos->s < 0) {
}
} while (pos->m >= 0 &&
!stream_valid(pos->s, m[pos->m].type));
- if (pos->m>=0) {
- switch(pos->s) {
- case 0: pos->o = m[pos->m].al-1; break;
- case 1: pos->o = m[pos->m].bl-1; break;
- case 2: pos->o = m[pos->m].cl-1; break;
+ if (pos->m >= 0) {
+ switch (pos->s) {
+ case 0:
+ pos->o = m[pos->m].al-1;
+ break;
+ case 1:
+ pos->o = m[pos->m].bl-1;
+ break;
+ case 2:
+ pos->o = m[pos->m].cl-1;
+ break;
}
}
}
e.start = NULL; e.len = 0;
return e;
}
- switch(pos->s) {
+ switch (pos->s) {
default: /* keep compiler happy */
case 0: return fm.list[m[pos->m].a + pos->o];
case 1: return fb.list[m[pos->m].b + pos->o];
if (mode == 0)
return -1;
/* mode can be any combination of ORIG RESULT BEFORE AFTER */
- switch(type) {
+ switch (type) {
case End: /* The END is always visible */
return A_NORMAL;
case Unmatched: /* Visible in ORIG and RESULT */
return a_unmatched;
break;
case Unchanged: /* visible everywhere, but only show stream 0 */
- if (stream == 0) return a_common;
+ if (stream == 0)
+ return a_common;
break;
case Extraneous: /* stream 2 is visible in BEFORE and AFTER */
if ((mode & (BEFORE|AFTER))
return a_added;
break;
case Conflict:
- switch(stream) {
+ switch (stream) {
case 0:
if (mode & ORIG)
return a_unmatched | A_REVERSE;
}
break;
case AlreadyApplied:
- switch(stream) {
+ switch (stream) {
case 0:
if (mode & (ORIG|RESULT))
return a_already;
rv |= WIGGLED;
else if (m[pos.p.m].type == Unmatched)
unmatched = 1;
- e = prev_melmnt(&pos.p, fm,fb,fa,m);
+ e = prev_melmnt(&pos.p, fm, fb, fa, m);
} while (e.start != NULL &&
- (!ends_mline(e) || visible(mode, m[pos.p.m].type, pos.p.s)==-1));
+ (!ends_mline(e)
+ || visible(mode, m[pos.p.m].type, pos.p.s) == -1));
if (unmatched && (rv & CHANGES))
rv |= WIGGLED;
prv = pos->p;
while (1) {
- struct elmnt e = next_melmnt(&pos->p, fm,fb,fa,m);
+ struct elmnt e = next_melmnt(&pos->p, fm, fb, fa, m);
if (e.start == NULL)
break;
if (ends_mline(e) &&
visible(mode, m[pos->p.m].type, pos->p.s) >= 0)
break;
}
- mode2 = check_line(*pos, fm,fb,fa,m,mode);
+ mode2 = check_line(*pos, fm, fb, fa, m, mode);
if ((mode2 & CHANGES) && pos->state == 0) {
/* Just entered a diff-set */
} else {
/* time for another pass */
pos->p = pos->lo;
- pos->state ++;
+ pos->state++;
}
}
mask = ORIG|RESULT|BEFORE|AFTER|CHANGES|CHANGED;
- switch(pos->state) {
- case 1: mask &= ~(RESULT|AFTER); break;
- case 2: mask &= ~(ORIG|BEFORE); break;
+ switch (pos->state) {
+ case 1:
+ mask &= ~(RESULT|AFTER);
+ break;
+ case 2:
+ mask &= ~(ORIG|BEFORE);
+ break;
}
} while (visible(mode&mask, m[pos->p.m].type, pos->p.s) < 0);
prv = pos->p;
if (pos->p.m < 0)
return;
- while(1) {
- struct elmnt e = prev_melmnt(&pos->p, fm,fb,fa,m);
+ while (1) {
+ struct elmnt e = prev_melmnt(&pos->p, fm, fb, fa, m);
if (e.start == NULL)
break;
if (ends_mline(e) &&
visible(mode, m[pos->p.m].type, pos->p.s) >= 0)
break;
}
- mode2 = check_line(*pos, fm,fb,fa,m,mode);
+ mode2 = check_line(*pos, fm, fb, fa, m, mode);
if ((mode2 & CHANGES) && pos->state == 0) {
/* Just entered a diff-set */
} else {
/* time for another pass */
pos->p = pos->hi;
- pos->state --;
+ pos->state--;
}
}
mask = ORIG|RESULT|BEFORE|AFTER|CHANGES|CHANGED;
- switch(pos->state) {
- case 1: mask &= ~(RESULT|AFTER); break;
- case 2: mask &= ~(ORIG|BEFORE); break;
+ switch (pos->state) {
+ case 1:
+ mask &= ~(RESULT|AFTER);
+ break;
+ case 2:
+ mask &= ~(ORIG|BEFORE);
+ break;
}
} while (visible(mode&mask, m[pos->p.m].type, pos->p.s) < 0);
}
static void blank(int row, int start, int cols, unsigned int attr)
{
(void)attrset(attr);
- move(row,start);
+ move(row, start);
while (cols-- > 0)
addch(' ');
}
struct elmnt e;
int len = strlen(search);
do {
- e = prev_melmnt(&pos.p, fm,fb,fa,m);
+ e = prev_melmnt(&pos.p, fm, fb, fa, m);
if (e.start) {
int i;
- for (i=0; i<e.len; i++)
- if (strncmp(e.start+i, search, len)==0)
+ for (i = 0; i < e.len; i++)
+ if (strncmp(e.start+i, search, len) == 0)
return 1;
}
} while (e.start != NULL &&
- (!ends_mline(e) || visible(mode, m[pos.p.m].type, pos.p.s)==-1));
+ (!ends_mline(e)
+ || visible(mode, m[pos.p.m].type, pos.p.s) == -1));
return 0;
}
int col = 0;
char tag;
- switch(pos.state) {
+ switch (pos.state) {
case 0: /* unchanged line */
tag = ' ';
break;
case 1: /* 'before' text */
tag = '-';
- if ((mode & ORIG) && (mode & CONFLICTED)) {
+ if ((mode & ORIG) && (mode & CONFLICTED))
tag = '|';
- }
mode &= (ORIG|BEFORE);
break;
case 2: /* the 'after' part */
/* find previous visible newline, or start of file */
do
- e = prev_melmnt(&pos.p, fm,fb,fa,m);
+ e = prev_melmnt(&pos.p, fm, fb, fa, m);
while (e.start != NULL &&
(!ends_mline(e) ||
- visible(mode, m[pos.p.m].type, pos.p.s)==-1));
+ visible(mode, m[pos.p.m].type, pos.p.s) == -1));
while (1) {
unsigned char *c;
int l;
- e = next_melmnt(&pos.p, fm,fb,fa,m);
+ e = next_melmnt(&pos.p, fm, fb, fa, m);
if (e.start == NULL ||
(ends_mline(e) && visible(mode, m[pos.p.m].type, pos.p.s) != -1)) {
- if (colp) *colp = col;
- if (col < start) col = start;
+ if (colp)
+ *colp = col;
+ if (col < start)
+ col = start;
if (e.start && e.start[0] == 0) {
char b[40];
struct elmnt e1;
if (pos.p.s == 2 && m[pos.p.m].type == Extraneous) {
- int A,B,C,D,E,F;
+ int A, B, C, D, E, F;
e1 = fb.list[m[pos.p.m].b + pos.p.o];
sscanf(e1.start+1, "%d %d %d", &A, &B, &C);
sscanf(e.start+1, "%d %d %d", &D, &E, &F);
- sprintf(b, "@@ -%d,%d +%d,%d @@\n", B,C,E,F);
+ sprintf(b, "@@ -%d,%d +%d,%d @@\n", B, C, E, F);
(void)attrset(a_sep);
} else {
(void)attrset(visible(mode, m[pos.p.m].type, pos.p.s));
}
blank(row, col-start+offset, start+cols-col,
e.start
- ?(unsigned)visible(mode, m[pos.p.m].type, pos.p.s)
- :A_NORMAL );
+ ? (unsigned)visible(mode, m[pos.p.m].type, pos.p.s)
+ : A_NORMAL);
return;
}
- if (visible(mode, m[pos.p.m].type, pos.p.s) == -1) {
+ if (visible(mode, m[pos.p.m].type, pos.p.s) == -1)
continue;
- }
if (e.start[0] == 0)
continue;
(void)attrset(visible(mode, m[pos.p.m].type, pos.p.s));
c = (unsigned char *)e.start;
l = e.len;
- while(l) {
+ while (l) {
if (*c >= ' ' && *c != 0x7f) {
if (col >= start && col < start+cols)
mvaddch(row, col-start+offset, *c);
if (col >= start && col < start+cols)
mvaddch(row, col-start+offset, ' ');
col++;
- } while ((col&7)!= 0);
+ } while ((col&7) != 0);
} else {
if (col >= start && col < start+cols)
mvaddch(row, col-start+offset, '?');
*/
int lcols, rcols;
- mode |= check_line(pos, fm,fb,fa,m,mode);
+ mode |= check_line(pos, fm, fb, fa, m, mode);
- if ( (mode & (BEFORE|AFTER)) &&
- (mode & (ORIG|RESULT))) {
+ if ((mode & (BEFORE|AFTER)) &&
+ (mode & (ORIG|RESULT))) {
lcols = (cols-1)/2;
rcols = cols - lcols - 1;
mvaddch(row, lcols, '|');
draw_mside(mode&~(BEFORE|AFTER), row, 0, start, lcols,
- fm,fb,fa,m, pos, target, colp);
+ fm, fb, fa, m, pos, target, colp);
draw_mside(mode&~(ORIG|RESULT), row, lcols+1, start, rcols,
- fm,fb,fa,m, pos, 0, NULL);
+ fm, fb, fa, m, pos, 0, NULL);
} else
draw_mside(mode, row, 0, start, cols,
- fm,fb,fa,m, pos, target, colp);
+ fm, fb, fa, m, pos, target, colp);
}
static char *merge_help[] = {
char *modename = "merge";
char **modehelp = merge_help;
- int row,start = 0;
+ int row, start = 0;
int trow;
- int col=0, target=0;
+ int col = 0, target = 0;
struct mpos pos;
struct mpos tpos, toppos, botpos;
struct mpos vpos, tvpos;
int botrow = 0;
int meta = 0, tmeta;
- int num= -1, tnum;
+ int num = -1, tnum;
char search[80];
unsigned int searchlen = 0;
int search_notfound = 0;
pos.p.o = -1; /* offset */
pos.p.lineno = 1;
pos.state = 0;
- next_mline(&pos, fm,fb,fa,ci.merger, mode);
+ next_mline(&pos, fm, fb, fa, ci.merger, mode);
vpos = pos;
- while(1) {
+ while (1) {
if (refresh == 2) {
clear();
sprintf(buf, "File: %s%s Mode: %s\n",
- p->file,reverse?" - reversed":"", modename);
- (void)attrset(A_BOLD); mvaddstr(0,0,buf);
+ p->file, reverse ? " - reversed" : "", modename);
+ (void)attrset(A_BOLD);
+ mvaddstr(0, 0, buf);
clrtoeol();
(void)attrset(A_NORMAL);
refresh = 1;
if (mode == (ORIG|RESULT)) {
- int cmode = check_line(pos, fm,fb,fa,ci.merger, mode);
+ int cmode = check_line(pos, fm, fb, fa, ci.merger, mode);
if (splitrow < 0 && (cmode & (WIGGLED|CONFLICTED))) {
splitrow = (rows+1)/2;
lastrow = splitrow - 1;
char *e, e2[7];
int i;
switch (vpos.p.s) {
- case 0: e = fm.list[ci.merger[vpos.p.m].a + vpos.p.o].start; break;
- case 1: e = fb.list[ci.merger[vpos.p.m].b + vpos.p.o].start; break;
- case 2: e = fa.list[ci.merger[vpos.p.m].c + vpos.p.o].start; break;
+ case 0:
+ e = fm.list[ci.merger[vpos.p.m].a + vpos.p.o].start;
+ break;
+ case 1:
+ e = fb.list[ci.merger[vpos.p.m].b + vpos.p.o].start;
+ break;
+ case 2:
+ e = fa.list[ci.merger[vpos.p.m].c + vpos.p.o].start;
+ break;
}
- for (i=0; i<6; i++) {
+ for (i = 0; i < 6; i++) {
e2[i] = e[i];
- if (e2[i] < 32 || e2[i] >= 127) e2[i] = '?';
+ if (e2[i] < 32 || e2[i] >= 127)
+ e2[i] = '?';
}
sprintf(b, "st=%d str=%d o=%d m=%d mt=%s(%d,%d,%d) ic=%d <%.3s>", vpos.state,
vpos.p.s, vpos.p.o,
start -= 8;
refresh = 1;
}
- if (start < 0) start = 0;
+ if (start < 0)
+ start = 0;
retry:
- draw_mline(mode, row, start, cols, fm,fb,fa,ci.merger,
+ draw_mline(mode, row, start, cols, fm, fb, fa, ci.merger,
pos, target, &col);
if (col > cols+start) {
if (col < start) {
start -= 8;
refresh = 1;
- if (start < 0) start = 0;
+ if (start < 0)
+ start = 0;
goto retry;
}
if (refresh) {
refresh = 0;
tpos = pos;
- for (i=row-1; i>=1 && tpos.p.m >= 0; ) {
- prev_mline(&tpos, fm,fb,fa,ci.merger, mode);
- draw_mline(mode, i--, start, cols, fm,fb,fa,ci.merger,
+ for (i = row-1; i >= 1 && tpos.p.m >= 0; ) {
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
+ draw_mline(mode, i--, start, cols,
+ fm, fb, fa, ci.merger,
tpos, 0, NULL);
}
while (i >= 1)
blank(i--, 0, cols, a_void);
tpos = pos;
- for (i=row; i<= lastrow && ci.merger[tpos.p.m].type != End; ) {
- draw_mline(mode, i++, start, cols, fm,fb,fa,ci.merger,
+ for (i = row; i <= lastrow && ci.merger[tpos.p.m].type != End; ) {
+ draw_mline(mode, i++, start, cols,
+ fm, fb, fa, ci.merger,
tpos, 0, NULL);
- next_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
}
botpos = tpos; botrow = i;
- while (i<=lastrow)
+ while (i <= lastrow)
blank(i++, 0, cols, a_void);
}
-
+
if (splitrow >= 0) {
struct mpos spos = pos;
int smode = BEFORE|AFTER;
int srow = (rows + splitrow)/2;
if (visible(smode, ci.merger[spos.p.m].type,
spos.p.s) < 0)
- prev_mline(&spos, fm,fb,fa,ci.merger, smode);
+ prev_mline(&spos, fm, fb, fa, ci.merger, smode);
/* Now hi/lo might be wrong, so lets fix it. */
tpos = spos;
while (spos.p.m >= 0 && spos.state != 0)
- prev_mline(&spos, fm,fb,fa,ci.merger, smode);
+ prev_mline(&spos, fm, fb, fa, ci.merger, smode);
while (!same_mpos(spos, tpos))
- next_mline(&spos, fm,fb,fa,ci.merger, smode);
-
+ next_mline(&spos, fm, fb, fa, ci.merger, smode);
+
(void)attrset(a_sep);
- for (i=0; i<cols; i++)
+ for (i = 0; i < cols; i++)
mvaddstr(splitrow, i, "-");
tpos = spos;
- for (i=srow-1; i>splitrow; i-- ) {
- prev_mline(&tpos, fm,fb,fa,ci.merger, smode);
- draw_mline(smode, i, start, cols, fm,fb,fa,ci.merger,
+ for (i = srow-1; i > splitrow; i--) {
+ prev_mline(&tpos, fm, fb, fa, ci.merger, smode);
+ draw_mline(smode, i, start, cols, fm, fb, fa, ci.merger,
tpos, 0, NULL);
}
while (i > splitrow)
blank(i--, 0, cols, a_void);
tpos = spos;
- for (i=srow; i<rows && ci.merger[tpos.p.m].type != End; i++) {
- draw_mline(smode, i, start, cols, fm, fb,fa,ci.merger,
+ for (i = srow;
+ i < rows && ci.merger[tpos.p.m].type != End;
+ i++) {
+ draw_mline(smode, i, start, cols, fm, fb, fa, ci.merger,
tpos, 0, NULL);
- next_mline(&tpos, fm,fb,fa,ci.merger, smode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, smode);
}
}
#define META(c) ((c)|0x1000)
#define SEARCH(c) ((c)|0x2000)
- move(rows,0);
+ move(rows, 0);
(void)attrset(A_NORMAL);
- if (num>=0) { char buf[10]; sprintf(buf, "%d ", num); addstr(buf);}
- if (meta & META(0)) addstr("ESC...");
+ if (num >= 0) {
+ char buf[10];
+ sprintf(buf, "%d ", num);
+ addstr(buf);
+ }
+ if (meta & META(0))
+ addstr("ESC...");
if (meta & SEARCH(0)) {
- if (searchdir) addstr("Backwards ");
+ if (searchdir)
+ addstr("Backwards ");
addstr("Search: ");
addstr(search);
if (search_notfound)
search_notfound = 0;
}
clrtoeol();
- move(row,col-start);
+ move(row, col-start);
c = getch();
tmeta = meta; meta = 0;
tnum = num; num = -1;
if (cswitch >= SEARCH(' ') && cswitch <= SEARCH('~'))
cswitch = SEARCH(' ');
- switch(cswitch) {
+ switch (cswitch) {
case 27: /* escape */
case META(27):
meta = META(0);
tpos = pos; row++;
do {
pos = tpos; row--;
- prev_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (tpos.p.m >= 0);
if (row <= 0)
row = 0;
break;
case META('>'): /* end of file */
case 'G':
- if (tnum >=0) goto start;
+ if (tnum >= 0)
+ goto start;
tpos = pos; row--;
do {
pos = tpos; row++;
- next_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (ci.merger[tpos.p.m].type != End);
if (row >= lastrow)
row = lastrow;
break;
case '0': /* actually '0'...'9' */
- if (tnum < 0) tnum = 0;
+ if (tnum < 0)
+ tnum = 0;
num = tnum*10 + (c-'0');
break;
case 'q':
tpos = pos; trow = row;
if (searchdir) {
trow--;
- prev_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
} else {
trow++;
- next_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
}
goto search_again;
search_again:
search_notfound = 1;
do {
- if (mcontains(tpos, fm,fb,fa,ci.merger,mode,search)) {
+ if (mcontains(tpos, fm, fb, fa, ci.merger, mode, search)) {
pos = tpos;
row = trow;
search_notfound = 0;
}
if (searchdir) {
trow--;
- prev_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
} else {
trow++;
- next_mline(&tpos, fm,fb,fa,ci.merger,mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
}
} while (tpos.p.m >= 0 && ci.merger[tpos.p.m].type != End);
case 'n':
case 'N'-64:
case KEY_DOWN:
- if (tnum < 0) tnum = 1;
+ if (tnum < 0)
+ tnum = 1;
for (; tnum > 0 ; tnum--) {
tpos = pos;
- next_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
if (ci.merger[tpos.p.m].type != End) {
pos = tpos;
row++;
tpos = pos; row--;
do {
pos = tpos; row++;
- next_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (pos.state != 0 && ci.merger[tpos.p.m].type != End);
tpos = pos; row--;
do {
pos = tpos; row++;
- next_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ next_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (pos.state == 0 && ci.merger[tpos.p.m].type != End);
break;
tpos = pos; row++;
do {
pos = tpos; row--;
- prev_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (tpos.state == 0 && tpos.p.m >= 0);
tpos = pos; row++;
do {
pos = tpos; row--;
- prev_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
} while (tpos.state != 0 && tpos.p.m >= 0);
break;
case 'p':
case 'P'-64:
case KEY_UP:
- if (tnum < 0) tnum = 1;
+ if (tnum < 0)
+ tnum = 1;
for (; tnum > 0 ; tnum--) {
tpos = pos;
- prev_mline(&tpos, fm,fb,fa,ci.merger, mode);
+ prev_mline(&tpos, fm, fb, fa, ci.merger, mode);
if (tpos.p.m >= 0) {
pos = tpos;
row--;
case 'h':
/* left */
target = col - 1;
- if (target < 0) target = 0;
+ if (target < 0)
+ target = 0;
break;
case KEY_RIGHT:
case 'l':
break;
case 'H':
- if (start > 0) start--;
+ if (start > 0)
+ start--;
target = start + 1;
refresh = 1;
break;
case 'L':
- if (start < cols) start++;
+ if (start < cols)
+ start++;
target = start + 1;
refresh = 1;
break;
case '<':
- prev_melmnt(&tvpos.p, fm,fb,fa,ci.merger);
+ prev_melmnt(&tvpos.p, fm, fb, fa, ci.merger);
if (tvpos.p.m >= 0)
vpos = tvpos;
break;
case '>':
- next_melmnt(&tvpos.p, fm,fb,fa,ci.merger);
+ next_melmnt(&tvpos.p, fm, fb, fa, ci.merger);
if (ci.merger[tvpos.p.m].type != End)
vpos = tvpos;
break;
/* leading '/' are bad... */
file++;
- if (n==0)
+ if (n == 0)
asize = 0;
- else if (n<=16)
+ else if (n <= 16)
asize = 16;
- else if ((n&(n-1))==0)
+ else if ((n&(n-1)) == 0)
asize = n;
else
asize = n+1; /* not accurate, but not too large */
if (asize <= n) {
/* need to extend array */
struct plist *npl;
- if (asize < 16) asize = 16;
- else asize += asize;
+ if (asize < 16)
+ asize = 16;
+ else
+ asize += asize;
npl = realloc(pl, asize * sizeof(struct plist));
if (!npl) {
fprintf(stderr, "malloc failed - skipping %s\n", file);
/* first, find the start of a patch: "\n+++ "
* grab the file name and scan to the end of a line
*/
- char *target="\n+++ ";
- char *target2="\n--- ";
+ char *target = "\n+++ ";
+ char *target2 = "\n--- ";
char *pos = target;
int c;
char name[1024];
unsigned start, end;
- while (*pos && (c=fgetc(f)) != EOF ) {
- if (of) fputc(c, of);
+ while (*pos && (c = fgetc(f)) != EOF) {
+ if (of)
+ fputc(c, of);
if (c == *pos)
pos++;
- else pos = target;
+ else
+ pos = target;
}
if (c == EOF)
break;
assert(c == ' ');
/* now read a file name */
pos = name;
- while ((c=fgetc(f)) != EOF && c != '\t' && c != '\n' && c != ' ' &&
+ while ((c = fgetc(f)) != EOF
+ && c != '\t' && c != '\n' && c != ' ' &&
pos - name < 1023) {
*pos++ = c;
if (of)
*pos = 0;
if (c == EOF)
break;
- if (of) fputc(c, of);
- while (c != '\n' && (c=fgetc(f)) != EOF)
+ if (of)
+ fputc(c, of);
+ while (c != '\n' && (c = fgetc(f)) != EOF)
if (of)
fputc(c, of);
/* now skip to end - "\n--- " */
pos = target2+1;
- while (*pos && (c=fgetc(f)) != EOF) {
+ while (*pos && (c = fgetc(f)) != EOF) {
if (of)
fputc(c, of);
if (c == *pos)
* in common
*/
int depth = 0;
- while(1) {
+ while (1) {
char *c;
int al, bl;
c = strchr(a, '/');
- if (c) al = c-a; else al = strlen(a);
+ if (c)
+ al = c-a;
+ else
+ al = strlen(a);
c = strchr(b, '/');
- if (c) bl = c-b; else bl = strlen(b);
- if (al == 0 || al != bl || strncmp(a,b,al) != 0)
+ if (c)
+ bl = c-b;
+ else
+ bl = strlen(b);
+ if (al == 0 || al != bl || strncmp(a, b, al) != 0)
return depth;
- a+= al;
- while (*a=='/') a++;
- b+= bl;
- while(*b=='/') b++;
+ a += al;
+ while (*a == '/')
+ a++;
+ b += bl;
+ while (*b == '/')
+ b++;
depth++;
}
while (d) {
char *c = strchr(file, '/');
int l;
- if (c) l = c-file; else l = strlen(file);
+ if (c)
+ l = c-file;
+ else
+ l = strlen(file);
file += l;
curr += l;
- while (*file == '/') file++;
- while (*curr == '/') curr++;
+ while (*file == '/')
+ file++;
+ while (*curr == '/')
+ curr++;
d--;
}
while (*file) {
*curr++ = '/';
while (*file && *file != '/')
*curr++ = *file++;
- while (*file == '/') file++;
+ while (*file == '/')
+ file++;
*curr = '\0';
if (*file)
pl = patch_add_file(pl, np, strdup(buf),
qsort(pl, *np, sizeof(struct plist), pl_cmp);
curr[0] = 0;
n = *np;
- for (i=0; i<n; i++)
+ for (i = 0; i < n; i++)
pl = add_dir(pl, np, pl[i].file, curr);
qsort(pl, *np, sizeof(struct plist), pl_cmp);
curr[0] = 0;
prevnode[0] = -1;
prev = "";
- for (i=0; i<n; i++) {
+ for (i = 0; i < n; i++) {
int d = common_depth(prev, pl[i].file);
if (d == 0)
pl[i].parent = -1;
strip++;
file = strchr(file, '/');
if (file)
- while(*file == '/')
+ while (*file == '/')
file++;
}
return -1;
static int set_prefix(struct plist *pl, int n, int strip)
{
int i;
- for(i=0; i<4 && i<n && strip < 0; i++)
+ for (i = 0; i < 4 && i < n && strip < 0; i++)
strip = get_strip(pl[i].file);
if (strip < 0) {
Cmd);
return 0;
}
- for (i=0; i<n; i++) {
+ for (i = 0; i < n; i++) {
char *p = pl[i].file;
int j;
- for (j=0; j<strip; j++) {
- if (p) p = strchr(p,'/');
- while (p && *p == '/') p++;
+ for (j = 0; j < strip; j++) {
+ if (p)
+ p = strchr(p, '/');
+ while (p && *p == '/')
+ p++;
}
if (p == NULL) {
fprintf(stderr, "%s: cannot strip %d segments from %s\n",
csl1 = pdiff(ff, fp1, pl->chunks);
else
csl1 = diff(ff, fp1);
- csl2 = diff(fp1,fp2);
+ csl2 = diff(fp1, fp2);
ci = make_merger(ff, fp1, fp2, csl1, csl2, 0, 1);
pl->wiggles = ci.wiggles;
pl->conflicts = ci.conflicts;
static int get_prev(int pos, struct plist *pl, int n, int mode)
{
int found = 0;
- if (pos == -1) return pos;
+ if (pos == -1)
+ return pos;
do {
if (pl[pos].prev == -1)
return pl[pos].parent;
FILE *f, int reverse)
{
int found = 0;
- if (pos == -1) return pos;
+ if (pos == -1)
+ return pos;
do {
if (pl[pos].open) {
- if (pos +1 < n)
+ if (pos + 1 < n)
pos = pos+1;
else
return -1;
hdr[0] = 0;
if (pl == NULL) {
- move(row,0);
+ move(row, 0);
clrtoeol();
return;
}
} else {
if (pl->chunks > 99)
strcpy(hdr, "XX");
- else sprintf(hdr, "%2d", pl->chunks);
+ else
+ sprintf(hdr, "%2d", pl->chunks);
if (pl->wiggles > 99)
strcpy(hdr+2, " XX");
- else sprintf(hdr+2, " %2d", pl->wiggles);
+ else
+ sprintf(hdr+2, " %2d", pl->wiggles);
if (pl->conflicts > 99)
strcpy(hdr+5, " XX ");
- else sprintf(hdr+5, " %2d ", pl->conflicts);
+ else
+ sprintf(hdr+5, " %2d ", pl->conflicts);
}
if (pl->end)
strcpy(hdr+9, "= ");
else if (pl->open)
strcpy(hdr+9, "+ ");
- else strcpy(hdr+9, "- ");
+ else
+ strcpy(hdr+9, "- ");
mvaddstr(row, 0, hdr);
mvaddstr(row, 11, pl->file);
* mode
*
*/
- int pos=0; /* position in file */
- int row=1; /* position on screen */
+ int pos = 0; /* position in file */
+ int row = 1; /* position on screen */
int rows = 0; /* size of screen in rows */
int cols = 0;
int tpos, i;
int refresh = 2;
- int c=0;
+ int c = 0;
int mode = 0; /* 0=all, 1= only wiggled, 2=only conflicted */
term_init();
pl = sort_patches(pl, &n);
- while(1) {
+ while (1) {
if (refresh == 2) {
clear(); (void)attrset(0);
attron(A_BOLD);
- mvaddstr(0,0,"Ch Wi Co Patched Files");
- move(2,0);
+ mvaddstr(0, 0, "Ch Wi Co Patched Files");
+ move(2, 0);
attroff(A_BOLD);
refresh = 1;
}
- if (row <1 || row >= rows)
+ if (row < 1 || row >= rows)
refresh = 1;
if (refresh) {
refresh = 0;
getmaxyx(stdscr, rows, cols);
- if (row >= rows +3)
+ if (row >= rows + 3)
row = (rows+1)/2;
if (row >= rows)
row = rows-1;
tpos = pos;
- for (i=row; i>1; i--) {
+ for (i = row; i > 1; i--) {
tpos = get_prev(tpos, pl, n, mode);
if (tpos == -1) {
row = row - i + 1;
}
/* Ok, row and pos could be trustworthy now */
tpos = pos;
- for (i=row; i>=1; i--) {
+ for (i = row; i >= 1; i--) {
draw_one(i, &pl[tpos], f, reverse);
tpos = get_prev(tpos, pl, n, mode);
}
tpos = pos;
- for (i=row+1; i<rows; i++) {
+ for (i = row+1; i < rows; i++) {
tpos = get_next(tpos, pl, n, mode, f, reverse);
if (tpos >= 0)
draw_one(i, &pl[tpos], f, reverse);
draw_one(i, NULL, f, reverse);
}
}
- {char bb[20]; sprintf(bb,"%d", c); mvaddstr(0, 70, bb); clrtoeol();}
+ {char bb[20];
+ sprintf(bb, "%d", c);
+ mvaddstr(0, 70, bb);
+ clrtoeol();
+ }
move(row, 9);
c = getch();
- switch(c) {
+ switch (c) {
case 'j':
case 'n':
case 'N':
case ' ':
case 13:
if (pl[pos].end == 0) {
- pl[pos].open = ! pl[pos].open;
+ pl[pos].open = !pl[pos].open;
refresh = 1;
} else {
/* diff_window(&pl[pos], f); */
- merge_window(&pl[pos],f,reverse);
+ merge_window(&pl[pos], f, reverse);
refresh = 2;
}
break;
case 27: /* escape */
- mvaddstr(0,70,"ESC..."); clrtoeol();
+ mvaddstr(0, 70, "ESC..."); clrtoeol();
c = getch();
- switch(c) {
+ switch (c) {
}
break;
case 'q':
return;
- case 'A': mode = 0; refresh = 1; break;
- case 'W': mode = 1; refresh = 1; break;
- case 'C': mode = 2; refresh = 1; break;
+ case 'A':
+ mode = 0; refresh = 1;
+ break;
+ case 'W':
+ mode = 1; refresh = 1;
+ break;
+ case 'C':
+ mode = 2; refresh = 1;
+ break;
case '?':
help_window(main_help, NULL);
signal(sig, catch);
return;
}
- nocbreak();nl();endwin();
+ nocbreak();
+ nl();
+ endwin();
printf("Died on signal %d\n", sig);
exit(2);
}
in = fdopen(dup(0), "r");
}
/* use stderr for keyboard input */
- dup2(2,0);
+ dup2(2, 0);
if (set_prefix(pl, num_patches, strip) == 0) {
fprintf(stderr, "%s: aborting\n", Cmd);
exit(2);
break;
}
- nocbreak();nl();endwin();
+ nocbreak();
+ nl();
+ endwin();
exit(0);
}
*
* For merge:
* If one file is given, it is a merge file (output of 'merge').
- * If two files are given, the second is assumed to be a patch, the first is a normal file.
+ * If two files are given, the second is assumed to be a patch,
+ * the first is a normal file.
* If three files are given, they are taken to be normal files.
*
* For diff:
* If two files are given, they are normal files.
*
* For extract:
- * Only one file can be given. -p indicates it is a patch, otherwise it is a merge.
+ * Only one file can be given. -p indicates it is a patch,
+ * otherwise it is a merge.
* One of the flags -1 -2 or -3 must also be given and they indicate which
* part of the patch or merge to extract.
*
* Difference calculate and merging is performed on lines (-l) or words (-w).
* In the case of -w, an initial diff is computed based on non-trivial words.
* i.e. spaces are ignored
- * This diff is computed from the ends of the file and is used to find a suitable
- * starting point and range. Then a more precise diff is computed over that
- * restricted range
+ *
+ * This diff is computed from the ends of the file and is used to find
+ * a suitable starting point and range. Then a more precise diff is
+ * computed over that restricted range
*
* Other options available are:
* --replace -r replace first file with result of merge.
void die()
{
- fprintf(stderr,"wiggle: fatal error\n");
+ fprintf(stderr, "wiggle: fatal error\n");
abort();
exit(3);
}
if (e.start[0])
fprintf(f, "%.*s", e.len, e.start);
else {
- int a,b,c;
+ int a, b, c;
sscanf(e.start+1, "%d %d %d", &a, &b, &c);
- fprintf(f, "*** %d,%d **** %d\n", b,c,a);
+ fprintf(f, "*** %d,%d **** %d\n", b, c, a);
}
}
static void printsep(struct elmnt e1, struct elmnt e2)
{
- int a,b,c,d,e,f;
+ int a, b, c, d, e, f;
sscanf(e1.start+1, "%d %d %d", &a, &b, &c);
sscanf(e2.start+1, "%d %d %d", &d, &e, &f);
- printf("@@ -%d,%d +%d,%d @@\n", b,c,e,f);
+ printf("@@ -%d,%d +%d,%d @@\n", b, c, e, f);
}
while (list->len) {
int i;
int ap;
- for( ap = list->a; ap< list->a+list->len; ap++) {
- for (i=0; i<a.list[ap].len; i++) {
+ for (ap = list->a; ap < list->a+list->len; ap++) {
+ for (i = 0; i < a.list[ap].len; i++) {
char c = a.list[ap].start[i];
if (isalnum(c))
break;
int mode = 0;
int obj = 0;
int replace = 0;
- char *replacename=NULL, *orignew=NULL;
+ char *replacename = NULL, *orignew = NULL;
int which = 0;
int ispatch = 0;
int reverse = 0;
- int verbose=0, quiet=0;
+ int verbose = 0, quiet = 0;
int i;
int strip = -1;
- int chunks1=0, chunks2=0, chunks3=0;
+ int chunks1 = 0, chunks2 = 0, chunks3 = 0;
int exit_status = 0;
int ignore = 1;
FILE *outfile = stdout;
struct csl *csl1, *csl2;
base0 = strrchr(argv[0], '/');
- if (base0) base0++; else base0=argv[0];
+ if (base0)
+ base0++;
+ else
+ base0 = argv[0];
#if 0
/* The name 'vpatch' seems to be used elsewhere */
- if (strcmp(base0, "vpatch")==0) {
+ if (strcmp(base0, "vpatch") == 0) {
Cmd = base0;
mode = 'B';
}
while ((opt = getopt_long(argc, argv,
short_options(mode), long_options,
&option_index)) != -1)
- switch(opt) {
+ switch (opt) {
case 'h':
helpmsg = Help;
- switch(mode) {
- case 'x': helpmsg = HelpExtract; break;
- case 'd': helpmsg = HelpDiff; break;
- case 'm': helpmsg = HelpMerge; break;
- case 'B': helpmsg = HelpBrowse; break;
+ switch (mode) {
+ case 'x':
+ helpmsg = HelpExtract;
+ break;
+ case 'd':
+ helpmsg = HelpDiff;
+ break;
+ case 'm':
+ helpmsg = HelpMerge;
+ break;
+ case 'B':
+ helpmsg = HelpBrowse;
+ break;
}
fputs(helpmsg, stderr);
exit(0);
case 'x':
case 'd':
case 'm':
- if (mode ==0){
+ if (mode == 0) {
mode = opt;
continue;
}
- fprintf(stderr, "wiggle: mode is '%c' - cannot set to '%c'\n",
+ fprintf(stderr,
+ "wiggle: mode is '%c' - cannot set to '%c'\n",
mode, opt);
exit(2);
obj = opt;
continue;
}
- fprintf(stderr, "wiggle: cannot select both words and lines.\n");
+ fprintf(stderr,
+ "wiggle: cannot select both words and lines.\n");
exit(2);
case 'r':
which = opt;
continue;
}
- fprintf(stderr, "wiggle: can only select one of -1, -2, -3\n");
+ fprintf(stderr,
+ "wiggle: can only select one of -1, -2, -3\n");
exit(2);
case 'p': /* 'patch' or 'strip' */
ispatch = 1;
continue;
- case 'v': verbose++; continue;
- case 'q': quiet=1 ; continue;
+ case 'v':
+ verbose++;
+ continue;
+ case 'q':
+ quiet = 1;
+ continue;
}
if (!mode)
mode = 'm';
if (mode == 'B') {
- vpatch(argc-optind, argv+optind, ispatch, strip, reverse, replace);
+ vpatch(argc-optind, argv+optind, ispatch,
+ strip, reverse, replace);
/* should not return */
exit(1);
}
if (obj && mode == 'x') {
- fprintf(stderr,"wiggle: cannot specify --line or --word with --extract\n");
+ fprintf(stderr,
+ "wiggle: cannot specify --line or --word with --extract\n");
exit(2);
}
- if (mode != 'm' && !obj) obj = 'w';
+ if (mode != 'm' && !obj)
+ obj = 'w';
if (replace && mode != 'm') {
- fprintf(stderr, "wiggle: --replace only allowed with --merge\n");
+ fprintf(stderr,
+ "wiggle: --replace only allowed with --merge\n");
exit(2);
}
if (mode == 'x' && !which) {
- fprintf(stderr, "wiggle: must specify -1, -2 or -3 with --extract\n");
+ fprintf(stderr,
+ "wiggle: must specify -1, -2 or -3 with --extract\n");
exit(2);
}
if (mode != 'x' && mode != 'd' && which) {
- fprintf(stderr, "wiggle: -1, -2 or -3 only allowed with --extract or --diff\n");
+ fprintf(stderr,
+ "wiggle: -1, -2 or -3 only allowed with --extract or --diff\n");
exit(2);
}
if (ispatch && (mode != 'x' && mode != 'd')) {
- fprintf(stderr, "wiggle: --patch only allowed with --extract or --diff\n");
+ fprintf(stderr,
+ "wiggle: --patch only allowed with --extract or --diff\n");
exit(2);
}
if (ispatch && which == '3') {
- fprintf(stderr, "wiggle: cannot extract -3 from a patch.\n");
+ fprintf(stderr,
+ "wiggle: cannot extract -3 from a patch.\n");
exit(2);
}
- switch(mode) {
+ switch (mode) {
case 'x':
/* extract a branch of a diff or diff3 or merge output
* We need one file
*/
if (optind == argc) {
- fprintf(stderr, "wiggle: no file given for --extract\n");
+ fprintf(stderr,
+ "wiggle: no file given for --extract\n");
exit(2);
}
if (optind < argc-1) {
- fprintf(stderr, "wiggle: only give one file for --extract\n");
+ fprintf(stderr,
+ "wiggle: only give one file for --extract\n");
exit(2);
}
f = load_file(argv[optind]);
- if (f.body==NULL) {
- fprintf(stderr, "wiggle: cannot load file '%s' - %s\n",
+ if (f.body == NULL) {
+ fprintf(stderr,
+ "wiggle: cannot load file '%s' - %s\n",
argv[optind], strerror(errno));
exit(2);
}
if (ispatch)
- chunks1 = chunks2 = split_patch(f, &flist[0], &flist[1]);
+ chunks1 = chunks2 =
+ split_patch(f, &flist[0], &flist[1]);
else {
if (!split_merge(f, &flist[0], &flist[1], &flist[2])) {
- fprintf(stderr, "wiggle: merge file %s looks bad.\n",
+ fprintf(stderr,
+ "wiggle: merge file %s looks bad.\n",
argv[optind]);
exit(2);
}
}
if (flist[which-'1'].body == NULL) {
- fprintf(stderr, "wiggle: %s has no -%c component.\n",
+ fprintf(stderr,
+ "wiggle: %s has no -%c component.\n",
argv[optind], which);
exit(2);
} else {
- if (write(1, flist[which-'1'].body, flist[which-'1'].len)
+ if (write(1, flist[which-'1'].body,
+ flist[which-'1'].len)
!= flist[which-'1'].len)
exit(2);
}
case 1:
f = load_file(argv[optind]);
if (f.body == NULL) {
- fprintf(stderr, "wiggle: cannot load file '%s' - %s\n",
+ fprintf(stderr,
+ "wiggle: cannot load file '%s' - %s\n",
argv[optind], strerror(errno));
exit(2);
}
- chunks1 = chunks2 = split_patch(f, &flist[0], &flist[1]);
+ chunks1 = chunks2 =
+ split_patch(f, &flist[0], &flist[1]);
if (!flist[0].body || !flist[1].body) {
- fprintf(stderr, "wiggle: couldn't parse patch %s\n",
+ fprintf(stderr,
+ "wiggle: couldn't parse patch %s\n",
argv[optind]);
exit(2);
}
case 2:
flist[0] = load_file(argv[optind]);
if (flist[0].body == NULL) {
- fprintf(stderr, "wiggle: cannot load file '%s' - %s\n",
+ fprintf(stderr,
+ "wiggle: cannot load file '%s' - %s\n",
argv[optind], strerror(errno));
exit(2);
}
if (ispatch) {
f = load_file(argv[optind+1]);
if (f.body == NULL) {
- fprintf(stderr, "wiggle: cannot load patch '%s' - %s\n",
+ fprintf(stderr,
+ "wiggle: cannot load patch"
+ " '%s' - %s\n",
argv[optind], strerror(errno));
exit(2);
}
if (which == '2')
- chunks2 = chunks3 = split_patch(f, &flist[2], &flist[1]);
+ chunks2 = chunks3 =
+ split_patch(f, &flist[2],
+ &flist[1]);
else
- chunks2 = chunks3 = split_patch(f, &flist[1], &flist[2]);
+ chunks2 = chunks3 =
+ split_patch(f, &flist[1],
+ &flist[2]);
} else
flist[1] = load_file(argv[optind+1]);
if (flist[1].body == NULL) {
- fprintf(stderr, "wiggle: cannot load file '%s' - %s\n",
+ fprintf(stderr,
+ "wiggle: cannot load file"
+ " '%s' - %s\n",
argv[optind+1], strerror(errno));
exit(2);
}
break;
default:
- fprintf(stderr, "wiggle: too many files given for --diff\n");
+ fprintf(stderr,
+ "wiggle: too many files given for --diff\n");
exit(2);
}
if (reverse) {
- f=flist[1];
+ f = flist[1];
flist[1] = flist[2];
- flist[2]= f;
+ flist[2] = f;
}
if (obj == 'l') {
- int a,b;
+ int a, b;
fl[0] = split_stream(flist[0], ByLine, 0);
fl[1] = split_stream(flist[1], ByLine, 0);
- if (chunks2 && ! chunks1)
+ if (chunks2 && !chunks1)
csl1 = pdiff(fl[0], fl[1], chunks2);
else
csl1 = diff(fl[0], fl[1]);
if (!chunks1)
- printf("@@ -1,%d +1,%d @@\n", fl[0].elcnt, fl[1].elcnt);
+ printf("@@ -1,%d +1,%d @@\n",
+ fl[0].elcnt, fl[1].elcnt);
a = b = 0;
- while (a<fl[0].elcnt || b < fl[1].elcnt) {
+ while (a < fl[0].elcnt || b < fl[1].elcnt) {
if (a < csl1->a) {
if (fl[0].list[a].start[0]) {
printf("-");
- printword(stdout, fl[0].list[a]);
+ printword(stdout,
+ fl[0].list[a]);
}
a++;
exit_status++;
} else if (b < csl1->b) {
if (fl[1].list[b].start[0]) {
printf("+");
- printword(stdout, fl[1].list[b]);
+ printword(stdout,
+ fl[1].list[b]);
}
b++;
exit_status++;
} else {
if (fl[0].list[a].start[0] == '\0')
- printsep(fl[0].list[a], fl[1].list[b]);
+ printsep(fl[0].list[a],
+ fl[1].list[b]);
else {
printf(" ");
- printword(stdout, fl[0].list[a]);
+ printword(stdout,
+ fl[0].list[a]);
}
a++;
b++;
}
}
} else {
- int a,b;
+ int a, b;
int sol = 1; /* start of line */
fl[0] = split_stream(flist[0], ByWord, 0);
fl[1] = split_stream(flist[1], ByWord, 0);
if (!chunks1) {
/* count lines in each file */
int l1, l2, i;
- l1=l2=0;
- for (i=0;i<fl[0].elcnt;i++)
+ l1 = l2 = 0;
+ for (i = 0 ; i < fl[0].elcnt ; i++)
if (ends_line(fl[0].list[i]))
l1++;
- for (i=0;i<fl[1].elcnt;i++)
+ for (i = 0 ; i < fl[1].elcnt ; i++)
if (ends_line(fl[1].list[i]))
l2++;
- printf("@@ -1,%d +1,%d @@\n", l1,l2);
+ printf("@@ -1,%d +1,%d @@\n", l1, l2);
}
a = b = 0;
while (a < fl[0].elcnt || b < fl[1].elcnt) {
exit_status++;
if (sol) {
int a1;
- /* If we remove a whole line, output +line
- * else clear sol and retry */
+ /* If we remove a
+ * whole line, output
+ * +line else clear
+ * sol and retry */
sol = 0;
- for (a1=a; a1<csl1->a;a1++)
+ for (a1 = a; a1 < csl1->a ; a1++)
if (ends_line(fl[0].list[a1])) {
- sol=1;
+ sol = 1;
break;
}
if (sol) {
printf("-");
- for (; a<csl1->a; a++) {
+ for (; a < csl1->a ; a++) {
printword(stdout, fl[0].list[a]);
if (ends_line(fl[0].list[a])) {
a++;
break;
}
}
- } else printf("|");
+ } else
+ printf("|");
}
if (!sol) {
printf("<<<--");
do {
- if (sol) printf("|");
+ if (sol)
+ printf("|");
printword(stdout, fl[0].list[a]);
sol = ends_line(fl[0].list[a]);
a++;
} while (a < csl1->a);
- printf("%s-->>>", sol?"|":"");
- sol=0;
+ printf("%s-->>>", sol ? "|" : "");
+ sol = 0;
}
} else if (b < csl1->b) {
exit_status++;
if (sol) {
int b1;
sol = 0;
- for (b1=b; b1<csl1->b;b1++)
- if(ends_line(fl[1].list[b1])) {
- sol=1;
+ for (b1 = b; b1 < csl1->b; b1++)
+ if (ends_line(fl[1].list[b1])) {
+ sol = 1;
break;
}
if (sol) {
printf("+");
- for(; b<csl1->b ; b++) {
+ for (; b < csl1->b ; b++) {
printword(stdout, fl[1].list[b]);
- if(ends_line(fl[1].list[b])) {
+ if (ends_line(fl[1].list[b])) {
b++;
break;
}
}
- } else printf("|");
+ } else
+ printf("|");
}
if (!sol) {
printf("<<<++");
do {
- if (sol) printf("|");
+ if (sol)
+ printf("|");
printword(stdout, fl[1].list[b]);
sol = ends_line(fl[1].list[b]);
b++;
} while (b < csl1->b);
- printf("%s++>>>",sol?"|":"");
- sol=0;
+ printf("%s++>>>", sol ? "|" : "");
+ sol = 0;
}
} else {
if (sol) {
int a1;
sol = 0;
- for (a1=a; a1<csl1->a+csl1->len; a1++)
+ for (a1 = a; a1 < csl1->a+csl1->len; a1++)
if (ends_line(fl[0].list[a1]))
- sol=1;
+ sol = 1;
if (sol) {
if (fl[0].list[a].start[0]) {
printf(" ");
- for(; a<csl1->a+csl1->len; a++,b++) {
+ for (; a < csl1->a+csl1->len; a++, b++) {
printword(stdout, fl[0].list[a]);
if (ends_line(fl[0].list[a])) {
- a++,b++;
+ a++, b++;
break;
}
}
printsep(fl[0].list[a], fl[1].list[b]);
a++; b++;
}
- }
- else printf("|");
+ } else
+ printf("|");
}
if (!sol) {
printword(stdout, fl[0].list[a]);
if (ends_line(fl[0].list[a]))
- sol=1;
+ sol = 1;
a++;
b++;
}
case 3:
case 2:
case 1:
- for (i=0; i< argc-optind; i++) {
+ for (i = 0; i < argc-optind; i++) {
flist[i] = load_file(argv[optind+i]);
if (flist[i].body == NULL) {
fprintf(stderr, "wiggle: cannot load file '%s' - %s\n",
fprintf(stderr, "wiggle: too many files given for --merge\n");
exit(2);
}
- switch(argc-optind) {
+ switch (argc-optind) {
case 1: /* a merge file */
f = flist[0];
if (!split_merge(f, &flist[0], &flist[1], &flist[2])) {
- fprintf(stderr,"wiggle: merge file %s looks bad.\n",
+ fprintf(stderr, "wiggle: merge file %s looks bad.\n",
argv[optind]);
exit(2);
}
break;
}
if (reverse) {
- f=flist[1];
+ f = flist[1];
flist[1] = flist[2];
- flist[2]= f;
+ flist[2] = f;
}
- for (i=0; i<3; i++) {
- if (flist[i].body==NULL) {
+ for (i = 0; i < 3; i++) {
+ if (flist[i].body == NULL) {
fprintf(stderr, "wiggle: file %d missing\n", i);
exit(2);
}
}
if (replace) {
int fd;
- replacename = malloc(strlen(argv[optind])+ 20);
- if (!replacename) die();
- orignew = malloc(strlen(argv[optind])+20);
- if (!orignew) die();
+ replacename = malloc(strlen(argv[optind]) + 20);
+ if (!replacename)
+ die();
+ orignew = malloc(strlen(argv[optind]) + 20);
+ if (!orignew)
+ die();
strcpy(replacename, argv[optind]);
strcpy(orignew, argv[optind]);
strcat(orignew, ".porig");
if (open(orignew, O_RDONLY) >= 0 ||
errno != ENOENT) {
- fprintf(stderr,"wiggle: %s already exists\n",
+ fprintf(stderr, "wiggle: %s already exists\n",
orignew);
exit(2);
}
- strcat(replacename,"XXXXXX");
+ strcat(replacename, "XXXXXX");
fd = mkstemp(replacename);
if (fd == -1) {
- fprintf(stderr,"wiggle: could not create temporary file for %s\n",
+ fprintf(stderr,
+ "wiggle: could not create temporary file for %s\n",
replacename);
exit(2);
}
outfile = fdopen(fd, "w");
-
}
if (obj == 'l') {
csl2 = diff(fl[1], fl[2]);
#if 0
- cleanlist(fl[0],fl[1],csl1);
- cleanlist(fl[1],fl[2],csl2);
+ cleanlist(fl[0], fl[1], csl1);
+ cleanlist(fl[1], fl[2], csl2);
#endif
{
struct ci ci;
ci = print_merge2(outfile, &fl[0], &fl[1], &fl[2],
- csl1, csl2, obj=='w',
+ csl1, csl2, obj == 'w',
ignore);
if (!quiet && ci.conflicts)
- fprintf(stderr, "%d unresolved conflict%s found\n", ci.conflicts, ci.conflicts==1?"":"s");
+ fprintf(stderr,
+ "%d unresolved conflict%s found\n",
+ ci.conflicts,
+ ci.conflicts == 1 ? "" : "s");
if (!quiet && ci.ignored)
- fprintf(stderr, "%d already-applied change%s ignored\n", ci.ignored, ci.ignored==1?"":"s");
+ fprintf(stderr,
+ "%d already-applied change%s ignored\n",
+ ci.ignored,
+ ci.ignored == 1 ? "" : "s");
exit_status = (ci.conflicts > 0);
}
if (replace) {
fclose(outfile);
- if (rename(argv[optind], orignew) ==0 &&
- rename(replacename, argv[optind]) ==0)
+ if (rename(argv[optind], orignew) == 0 &&
+ rename(replacename, argv[optind]) == 0)
/* all ok */;
else {
fprintf(stderr, "wiggle: failed to move new file into place.\n");
return
a->hash == b->hash &&
a->len == b->len &&
- strncmp(a->start, b->start, a->len)==0;
+ strncmp(a->start, b->start, a->len) == 0;
}
static inline int ends_line(struct elmnt e)
}
struct csl {
- int a,b;
+ int a, b;
int len;
};
* a conflict.
*/
struct merge {
- enum mergetype {End, Unmatched, Unchanged, Extraneous, Changed, Conflict, AlreadyApplied} type;
- int a,b,c; /* start of ranges */
+ enum mergetype {
+ End, Unmatched, Unchanged, Extraneous,
+ Changed, Conflict, AlreadyApplied,
+ } type;
+ int a, b, c; /* start of ranges */
int al, bl, cl; /* length of ranges */
int c1, c2; /* this or next commonsequence */
int in_conflict;
- int lo,hi; /* region of a Changed or Unchanged that is not involved
+ int lo, hi; /* region of a Changed or Unchanged that is not involved
* in a conflict.
- * These are distances from start of the "before" section, not
- * indexes into any file
+ * These are distances from start of the "before" section,
+ * not indexes into any file.
*/
};
extern struct stream load_file(char *name);
extern int split_patch(struct stream, struct stream*, struct stream*);
-extern int split_merge(struct stream, struct stream*, struct stream*, struct stream*);
+extern int split_merge(struct stream, struct stream*, struct stream*,
+ struct stream*);
extern struct file split_stream(struct stream s, int type, int reverse);
extern struct csl *pdiff(struct file a, struct file b, int chunks);
extern struct csl *diff(struct file a, struct file b);
int conflicts, wiggles, ignored;
struct merge *merger;
};
-extern struct ci print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
- struct csl *c1, struct csl *c2,
- int words);
-extern struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c,
+extern struct ci print_merge(FILE *out,
+ struct file *a, struct file *b, struct file *c,
+ struct csl *c1, struct csl *c2,
+ int words);
+extern struct ci print_merge2(FILE *out,
+ struct file *a, struct file *b, struct file *c,
struct csl *c1, struct csl *c2,
int words, int ignore_already);
extern void printword(FILE *f, struct elmnt e);