]> git.neil.brown.name Git - wiggle.git/commitdiff
Fix white space etc issues reported by checkpatch.pl
authorNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 11:18:29 +0000 (21:18 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 11:18:29 +0000 (21:18 +1000)
i.e. checkpatch.pl from the linux kernel.

Signed-off-by: NeilBrown <neilb@suse.de>
ReadMe.c
bestmatch.c
diff.c
extract.c
load.c
merge.c
merge2.c
split.c
vpatch.c
wiggle.c
wiggle.h

index f1efdc2bc3ce18e6b2b7c022ce48ae73a04c9e91..9c3465ad11168937f9dcffe738d3fbd794ebbc58 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -31,8 +31,8 @@
 
 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[] = {
index 08e51314a3bc429649b005c07cd257df50a6be8b..7e9a44ca65c16467b6b8c7307a58a1e3d2532621 100644 (file)
@@ -57,7 +57,7 @@
 
 
 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 */
@@ -130,22 +130,12 @@ static inline int best_val(struct v *v, int max)
                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;
 }
 
@@ -165,15 +155,14 @@ static void find_best(struct file *a, struct file *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;
@@ -183,13 +172,15 @@ static void find_best(struct file *a, struct file *b,
                                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;
@@ -200,9 +191,9 @@ static void find_best(struct file *a, struct file *b,
                                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;
                                }
@@ -219,8 +210,8 @@ static void find_best(struct file *a, struct file *b,
                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);
@@ -229,24 +220,24 @@ static void find_best(struct file *a, struct file *b,
                }
                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;
                }
@@ -257,20 +248,23 @@ static void find_best(struct file *a, struct file *b,
 
 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);
@@ -284,9 +278,9 @@ static void printword(struct elmnt e)
        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
@@ -303,27 +297,28 @@ static void printword(struct elmnt e)
 
 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;
@@ -340,57 +335,63 @@ static void remap(struct best *best, int cnt,
                  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;
@@ -406,11 +407,13 @@ static void find_best_inorder(struct file *a, struct file *b,
         * 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)
@@ -419,7 +422,7 @@ static void find_best_inorder(struct file *a, struct file *b,
        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;
@@ -427,8 +430,9 @@ static void find_best_inorder(struct file *a, struct file *b,
        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);
@@ -436,8 +440,9 @@ static void find_best_inorder(struct file *a, struct file *b,
        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);
@@ -446,7 +451,7 @@ static void find_best_inorder(struct file *a, struct file *b,
 
 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;
@@ -460,46 +465,53 @@ struct csl *pdiff(struct file a, struct file b, int chunks)
        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 {
diff --git a/diff.c b/diff.c
index cb9749795e780a901be72ed0396df14ae633c2ba..6451fce4683b61288e5325d3aada1a6124907efc 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -74,7 +74,7 @@ static int find_common(struct file *a, struct file *b,
        int ahi = *ahip;
        int blo = *blop;
        int bhi = *bhip;
-       int x,y;
+       int x, y;
 
        int best = (ahi-alo)+(bhi-blo);
        int dist;
@@ -83,25 +83,27 @@ static int find_common(struct file *a, struct file *b,
        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;
@@ -112,7 +114,8 @@ static int find_common(struct file *a, struct file *b,
                                /* 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;
@@ -132,8 +135,8 @@ static int find_common(struct file *a, struct file *b,
                        }
                }
 
-               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 {
@@ -141,15 +144,16 @@ static int find_common(struct file *a, struct file *b,
                        }
                }
 
-               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));
                        }
 
@@ -158,10 +162,10 @@ static int find_common(struct file *a, struct file *b,
                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));
                        }
@@ -185,12 +189,13 @@ static struct csl *lcsl(struct file *a, int alo, int ahi,
                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;
 
@@ -199,8 +204,8 @@ static struct csl *lcsl(struct file *a, int alo, int ahi,
                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) {
@@ -212,16 +217,17 @@ static struct csl *lcsl(struct file *a, int alo, int ahi,
                            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)
@@ -255,7 +261,9 @@ static void fixup(struct file *a, struct file *b, struct csl *list)
        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) {
@@ -279,11 +287,11 @@ static void fixup(struct file *a, struct file *b, struct csl *list)
 #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
@@ -312,14 +320,14 @@ static void fixup(struct file *a, struct file *b, struct csl *list)
                } 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) {
@@ -329,7 +337,8 @@ static void fixup(struct file *a, struct file *b, struct csl *list)
                        } else
                                list1++;
                }
-               if (list->len && list1 == list) abort();
+               if (list->len && list1 == list)
+                       abort();
        }
        // list[1] = list1[0];
 }
@@ -387,7 +396,7 @@ main(int argc, char *argv[])
        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]);
@@ -402,7 +411,7 @@ main(int argc, char *argv[])
        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]);
@@ -423,7 +432,7 @@ main(int argc, char *argv[])
                         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,
@@ -431,8 +440,8 @@ main(int argc, char *argv[])
        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);
index 4f98811410f6610a93ce9e1d96334ac722defc3f..ba42d91f3e26a14e1f363e1620903f24eaac3e86 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -37,7 +37,8 @@ static void skip_eol(char **cp, char *end)
        char *c = *cp;
        while (c < end && *c != '\n')
                c++;
-       if (c < end) c++;
+       if (c < end)
+               c++;
        *cp = c;
 }
 
@@ -57,11 +58,11 @@ static void copyline(struct stream *s, char **cp, char *end)
 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];
 
@@ -84,9 +85,9 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                 *   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;
@@ -105,15 +106,15 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                                        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++;
@@ -121,7 +122,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                                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);
@@ -130,9 +131,9 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                        }
                        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)
@@ -143,9 +144,9 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                        }
                        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)
@@ -195,7 +196,7 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
        int lineno;
        int state = 0;
        char *cp, *end;
-       struct stream r1,r2,r3;
+       struct stream r1, r2, r3;
        f1->body = NULL;
        f2->body = NULL;
 
@@ -220,10 +221,10 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                 */
                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;
@@ -256,7 +257,7 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                                        skip_eol(&peek, end);
                                }
                        } else {
-                               char *cp2= cp;
+                               char *cp2 = cp;
                                copyline(&r1, &cp2, end);
                                cp2 = cp;
                                copyline(&r2, &cp2, end);
@@ -264,8 +265,8 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                        }
                        break;
                case 1:
-                       if (len>=8 &&
-                           strncmp(cp, "|||||||", 7)==0 &&
+                       if (len >= 8 &&
+                           strncmp(cp, "|||||||", 7) == 0 &&
                            (cp[7] == ' ' || cp[7] == '\n')
                                ) {
                                state = 2;
@@ -274,8 +275,8 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                                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;
@@ -284,8 +285,8 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                                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;
@@ -294,8 +295,8 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                                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;
@@ -304,8 +305,8 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st
                                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;
diff --git a/load.c b/load.c
index c5d57bc070bc062c98f0a85f1bd1318fef84e71a..979175b60db8834aaf90a5b476db2e5b37104e25 100644 (file)
--- a/load.c
+++ b/load.c
@@ -45,11 +45,11 @@ static void join_streams(struct stream list[], int cnt)
        /* 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);
@@ -59,7 +59,7 @@ static void join_streams(struct stream list[], int cnt)
        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;
@@ -80,7 +80,8 @@ static struct stream load_regular(int fd)
                        free(s.body);
                        s.body = NULL;
                }
-       } else die();
+       } else
+               die();
        s.body[s.len] = 0;
        return s;
 }
@@ -91,7 +92,7 @@ static struct stream load_other(int fd)
        struct stream list[10];
        int i = 0;
 
-       while(1) {
+       while (1) {
                list[i].body = malloc(8192);
                if (!list[i].body)
                        die();
@@ -118,11 +119,11 @@ struct stream load_file(char *name)
 
        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;
        }
 
diff --git a/merge.c b/merge.c
index 2e817548203d44877ec97bccd9b55ca29c63c88d..6998d8253b1e42f88b235d15b9d0e5665c46b5b5 100644 (file)
--- a/merge.c
+++ b/merge.c
  * 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,
@@ -209,7 +212,8 @@ 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);
@@ -217,7 +221,8 @@ static int tripoint(struct point *here,
                        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;
@@ -227,16 +232,18 @@ static int tripoint(struct point *here,
                *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;
@@ -248,7 +255,7 @@ static int tripoint(struct point *here,
 
 static int retreat(struct csl *c1, struct csl *c2, struct point *p)
 {
-       int a,b,c;
+       int a, b, c;
        int slid = 0;
 
  retry:
@@ -258,13 +265,13 @@ static int retreat(struct csl *c1, struct csl *c2, struct point *p)
                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;
 
@@ -282,7 +289,7 @@ static int retreat(struct csl *c1, struct csl *c2, struct point *p)
                }
 
                /* 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)
@@ -321,7 +328,7 @@ static int retreat(struct csl *c1, struct csl *c2, struct point *p)
                        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)
@@ -330,7 +337,7 @@ static int retreat(struct csl *c1, struct csl *c2, struct point *p)
                }
 
                /* 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)
@@ -362,7 +369,7 @@ static int retreat(struct csl *c1, struct csl *c2, struct point *p)
 
 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
@@ -379,8 +386,8 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                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++;
                }
@@ -390,7 +397,7 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                        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)
@@ -401,8 +408,8 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                }
 
                /* 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)
@@ -421,8 +428,8 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                         * 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;
                        }
 
@@ -451,7 +458,7 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                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++;
@@ -467,7 +474,7 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
                 * 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;
@@ -487,12 +494,12 @@ static int advance(struct csl *c1, struct csl *c2, struct point *p)
 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 &&
@@ -502,12 +509,13 @@ static int point_crossed(struct point first, struct point second,
 
 
 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]);
@@ -516,7 +524,7 @@ static void print_merger(FILE *out, struct file *a, struct file *c,
                fflush(out); /* DEBUG */
 
                start.pos++;
-               if (point_crossed(start, end, cs1,cs2))
+               if (point_crossed(start, end, cs1, cs2))
                        break;
                advance(cs1, cs2, &start);
 
@@ -545,12 +553,12 @@ static int print_conflict(FILE *out, struct file *a, struct file *b, struct file
        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();
 
 
@@ -563,7 +571,7 @@ static int print_conflict(FILE *out, struct file *a, struct file *b, struct file
        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;
                }
@@ -584,7 +592,7 @@ static int print_conflict(FILE *out, struct file *a, struct file *b, struct file
        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;
                }
@@ -593,7 +601,7 @@ static int print_conflict(FILE *out, struct file *a, struct file *b, struct file
        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;
                }
@@ -601,22 +609,23 @@ static int print_conflict(FILE *out, struct file *a, struct file *b, struct file
        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.
@@ -700,7 +709,8 @@ static int next_conflict(struct point here, struct csl *start_c1, struct csl *st
                                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
                         */
@@ -719,7 +729,7 @@ static int next_conflict(struct point here, struct csl *start_c1, struct csl *st
                        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 !
@@ -752,7 +762,7 @@ static int next_conflict(struct point here, struct csl *start_c1, struct csl *st
                                        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;
@@ -762,7 +772,7 @@ static int next_conflict(struct point here, struct csl *start_c1, struct csl *st
                                        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;
@@ -787,17 +797,19 @@ static int already_applied(struct csl *cs1, struct csl *cs2,
        /* 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++;
@@ -809,10 +821,10 @@ static int already_applied(struct csl *cs1, struct csl *cs2,
 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);
 
 }
 
@@ -827,59 +839,61 @@ struct ci print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
 
 #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;
 }
index 9e6e73fc6f0885f27a1a4a6364bd2897a345497d..3d86c33b39bd909703411495cdc10d76b7c70c5e 100644 (file)
--- a/merge2.c
+++ b/merge2.c
 
 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,
@@ -61,17 +62,17 @@ 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
@@ -98,10 +99,10 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
         * 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
@@ -135,7 +136,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                         * 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)
@@ -161,7 +162,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                }
                        }
 #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;
@@ -170,7 +171,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
                        }
 #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;
@@ -190,7 +191,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                                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 */
@@ -222,29 +223,31 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
        /* 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;
@@ -260,11 +263,11 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
                                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
@@ -276,13 +279,13 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
                                        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) {
@@ -316,17 +319,19 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
                        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 &&
@@ -335,7 +340,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
        }
        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;
@@ -343,7 +348,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
 
 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--;
@@ -354,14 +359,14 @@ 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)
 {
-       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;
@@ -369,17 +374,18 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                                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
@@ -396,7 +402,7 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
 
 #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":
@@ -406,15 +412,16 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                                       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;
@@ -422,9 +429,9 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                                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;
@@ -432,9 +439,9 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                                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;
@@ -444,7 +451,7 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                                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) {
@@ -469,11 +476,12 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                               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:
@@ -485,7 +493,8 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c
                        printrange(out, c, m->c, m->cl);
                        break;
                case Conflict:
-               case End: assert(0);
+               case End:
+                       assert(0);
                }
        }
        return rv;
diff --git a/split.c b/split.c
index 42c842ddc6711a4198dd753c28f1c4f98ae7bf93..f21c642aac3a069375f575c47594696dad8011b1 100644 (file)
--- a/split.c
+++ b/split.c
@@ -63,35 +63,40 @@ static int split_internal(char *start, char *end, int type, struct elmnt *list,
                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++;
                }
index 373c8ca7565904e0add00095651a8ac8752fb4c1..253848ed8db7f3a414ac799d9fe6924d0b827878 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -52,7 +52,7 @@ static void term_init(void);
 
 
 /* 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
@@ -109,7 +109,7 @@ static void help_window(char *page1[], char *page2[])
 {
        int rows, cols;
        int top, left;
-       int r,c;
+       int r, c;
        int ch;
        char **page = page1;
        int line = 0;
@@ -129,10 +129,10 @@ static void help_window(char *page1[], char *page2[])
                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, '-');
@@ -142,17 +142,17 @@ static void help_window(char *page1[], char *page2[])
                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)
@@ -164,7 +164,7 @@ static void help_window(char *page1[], char *page2[])
                                ln++;
                                sh--;
                        }
-                       for (c=0; c<cols; c++) {
+                       for (c = 0; c < cols; c++) {
                                int chr = *ln;
                                if (chr)
                                        ln++;
@@ -173,10 +173,10 @@ static void help_window(char *page1[], char *page2[])
                                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 '?':
@@ -185,7 +185,7 @@ static void help_window(char *page1[], char *page2[])
                        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]) {
@@ -257,7 +257,7 @@ static char *typenames[] = {
 
 
 /* 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
@@ -284,7 +284,7 @@ static char *typenames[] = {
  * 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,
@@ -336,14 +336,21 @@ static int same_mpos(struct mpos a, struct mpos b)
  */
 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;
 }
@@ -359,13 +366,19 @@ static struct elmnt next_melmnt(struct mp *pos,
                                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
@@ -386,14 +399,13 @@ static struct elmnt next_melmnt(struct mp *pos,
                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];
@@ -413,7 +425,7 @@ static struct elmnt prev_melmnt(struct mp *pos,
        }
 
        pos->o--;
-       while (pos->m >=0 && pos->o < 0) {
+       while (pos->m >= 0 && pos->o < 0) {
                do {
                        pos->s--;
                        if (pos->s < 0) {
@@ -422,11 +434,17 @@ static struct elmnt prev_melmnt(struct mp *pos,
                        }
                } 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;
                        }
                }
        }
@@ -435,7 +453,7 @@ static struct elmnt prev_melmnt(struct mp *pos,
                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];
@@ -452,7 +470,7 @@ static int visible(int mode, enum mergetype type, int stream)
        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 */
@@ -460,7 +478,8 @@ static int visible(int mode, enum mergetype type, int stream)
                        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))
@@ -476,7 +495,7 @@ static int visible(int mode, enum mergetype type, int stream)
                        return a_added;
                break;
        case Conflict:
-               switch(stream) {
+               switch (stream) {
                case 0:
                        if (mode & ORIG)
                                return a_unmatched | A_REVERSE;
@@ -492,7 +511,7 @@ static int visible(int mode, enum mergetype type, int stream)
                }
                break;
        case AlreadyApplied:
-               switch(stream) {
+               switch (stream) {
                case 0:
                        if (mode & (ORIG|RESULT))
                                return a_already;
@@ -539,9 +558,10 @@ static int check_line(struct mpos pos, struct file fm, struct file fb,
                        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;
@@ -559,14 +579,14 @@ static void next_mline(struct mpos *pos, struct file fm, struct file fb,
 
                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 */
@@ -583,13 +603,17 @@ static void next_mline(struct mpos *pos, struct file fm, struct file fb,
                        } 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);
 
@@ -607,15 +631,15 @@ static void prev_mline(struct mpos *pos, struct file fm, struct file fb,
                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 */
@@ -632,13 +656,17 @@ static void prev_mline(struct mpos *pos, struct file fm, struct file fb,
                        } 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);
 }
@@ -647,7 +675,7 @@ static void prev_mline(struct mpos *pos, struct file fm, struct file fb,
 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(' ');
 }
@@ -665,15 +693,16 @@ static int mcontains(struct mpos pos,
        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;
 }
 
@@ -725,15 +754,14 @@ static void draw_mside(int mode, int row, int offset, int start, int cols,
        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 */
@@ -757,28 +785,30 @@ static void draw_mside(int mode, int row, int offset, int start, int cols,
 
        /* 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));
@@ -789,19 +819,18 @@ static void draw_mside(int mode, int row, int offset, int start, int cols,
                        }
                        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);
@@ -811,7 +840,7 @@ static void draw_mside(int mode, int row, int offset, int start, int cols,
                                        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, '?');
@@ -843,10 +872,10 @@ static void draw_mline(int mode, int row, int start, int cols,
         */
        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;
@@ -855,13 +884,13 @@ static void draw_mline(int mode, int row, int start, int cols,
                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[] = {
@@ -1042,15 +1071,15 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
        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;
@@ -1106,14 +1135,15 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
        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;
@@ -1124,7 +1154,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
 
 
                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;
@@ -1164,13 +1194,20 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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,
@@ -1197,9 +1234,10 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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) {
@@ -1210,16 +1248,18 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                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);
 
                        }
@@ -1232,58 +1272,67 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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)
@@ -1291,7 +1340,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        search_notfound = 0;
                }
                clrtoeol();
-               move(row,col-start);
+               move(row, col-start);
                c = getch();
                tmeta = meta; meta = 0;
                tnum = num; num = -1;
@@ -1305,7 +1354,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                if (cswitch >= SEARCH(' ') && cswitch <= SEARCH('~'))
                        cswitch = SEARCH(' ');
 
-               switch(cswitch) {
+               switch (cswitch) {
                case 27: /* escape */
                case META(27):
                        meta = META(0);
@@ -1315,24 +1364,26 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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':
@@ -1366,10 +1417,10 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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;
 
@@ -1405,7 +1456,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                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;
@@ -1413,10 +1464,10 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                                }
                                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);
 
@@ -1444,10 +1495,11 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                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++;
@@ -1459,12 +1511,12 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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;
@@ -1473,12 +1525,12 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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;
 
@@ -1486,10 +1538,11 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                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--;
@@ -1501,7 +1554,8 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                case 'h':
                        /* left */
                        target = col - 1;
-                       if (target < 0) target = 0;
+                       if (target < 0)
+                               target = 0;
                        break;
                case KEY_RIGHT:
                case 'l':
@@ -1551,23 +1605,25 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        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;
@@ -1637,19 +1693,21 @@ static struct plist *patch_add_file(struct plist *pl, int *np, char *file,
                /* 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);
@@ -1683,25 +1741,28 @@ static struct plist *parse_patch(FILE *f, FILE *of, int *np)
                /* 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)
@@ -1710,8 +1771,9 @@ static struct plist *parse_patch(FILE *f, FILE *of, int *np)
                *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);
 
@@ -1723,7 +1785,7 @@ static struct plist *parse_patch(FILE *f, FILE *of, int *np)
                /* 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)
@@ -1770,19 +1832,27 @@ static int common_depth(char *a, char *b)
         * 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++;
        }
@@ -1798,11 +1868,16 @@ static struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr)
        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) {
@@ -1810,7 +1885,8 @@ static struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr)
                        *curr++ = '/';
                while (*file && *file != '/')
                        *curr++ = *file++;
-               while (*file == '/') file++;
+               while (*file == '/')
+                       file++;
                *curr = '\0';
                if (*file)
                        pl = patch_add_file(pl, np, strdup(buf),
@@ -1830,7 +1906,7 @@ static struct plist *sort_patches(struct plist *pl, int *np)
        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);
@@ -1840,7 +1916,7 @@ static struct plist *sort_patches(struct plist *pl, int *np)
        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;
@@ -1877,7 +1953,7 @@ static int get_strip(char *file)
                strip++;
                file = strchr(file, '/');
                if (file)
-                       while(*file == '/')
+                       while (*file == '/')
                                file++;
        }
        return -1;
@@ -1887,7 +1963,7 @@ static int get_strip(char *file)
 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) {
@@ -1895,12 +1971,14 @@ static int set_prefix(struct plist *pl, int n, int strip)
                        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",
@@ -1943,7 +2021,7 @@ static void calc_one(struct plist *pl, FILE *f, int reverse)
                        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;
@@ -1964,7 +2042,8 @@ static void calc_one(struct plist *pl, FILE *f, int reverse)
 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;
@@ -1989,10 +2068,11 @@ static int get_next(int pos, struct plist *pl, int n, int mode,
             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;
@@ -2023,7 +2103,7 @@ static void draw_one(int row, struct plist *pl, FILE *f, int reverse)
        hdr[0] = 0;
 
        if (pl == NULL) {
-               move(row,0);
+               move(row, 0);
                clrtoeol();
                return;
        }
@@ -2035,19 +2115,23 @@ static void draw_one(int row, struct plist *pl, FILE *f, int reverse)
        } 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);
@@ -2119,38 +2203,38 @@ static void main_window(struct plist *pl, int n, FILE *f, int reverse)
         *         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;
@@ -2159,12 +2243,12 @@ static void main_window(struct plist *pl, int n, FILE *f, int reverse)
                        }
                        /* 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);
@@ -2172,10 +2256,14 @@ static void main_window(struct plist *pl, int n, FILE *f, int 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':
@@ -2202,26 +2290,32 @@ static void main_window(struct plist *pl, int n, FILE *f, int reverse)
                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);
@@ -2241,7 +2335,9 @@ static void catch(int sig)
                signal(sig, catch);
                return;
        }
-       nocbreak();nl();endwin();
+       nocbreak();
+       nl();
+       endwin();
        printf("Died on signal %d\n", sig);
        exit(2);
 }
@@ -2338,7 +2434,7 @@ int vpatch(int argc, char *argv[], int patch, int strip,
                        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);
@@ -2381,6 +2477,8 @@ int vpatch(int argc, char *argv[], int patch, int strip,
                break;
        }
 
-       nocbreak();nl();endwin();
+       nocbreak();
+       nl();
+       endwin();
        exit(0);
 }
index f467f5589f26535c72955214b763ecb088e6b406..305053f051073091e9e81786a3a77e2d6e240f4c 100644 (file)
--- a/wiggle.c
+++ b/wiggle.c
@@ -45,7 +45,8 @@
  *
  * 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.
@@ -84,7 +87,7 @@ char *Cmd = "wiggle";
 
 void die()
 {
-       fprintf(stderr,"wiggle: fatal error\n");
+       fprintf(stderr, "wiggle: fatal error\n");
        abort();
        exit(3);
 }
@@ -94,18 +97,18 @@ void printword(FILE *f, struct elmnt e)
        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);
 }
 
 
@@ -120,8 +123,8 @@ static void cleanlist(struct file a, struct file b, struct csl *list)
        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;
@@ -145,14 +148,14 @@ int main(int argc, char *argv[])
        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;
@@ -164,10 +167,13 @@ int main(int argc, char *argv[])
        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';
        }
@@ -175,14 +181,22 @@ int main(int argc, char *argv[])
        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);
@@ -200,11 +214,12 @@ int main(int argc, char *argv[])
                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);
 
@@ -214,7 +229,8 @@ int main(int argc, char *argv[])
                                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':
@@ -235,7 +251,8 @@ int main(int argc, char *argv[])
                                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' */
@@ -244,78 +261,97 @@ int main(int argc, char *argv[])
                        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);
                }
@@ -330,13 +366,16 @@ int main(int argc, char *argv[])
                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);
                        }
@@ -344,72 +383,87 @@ int main(int argc, char *argv[])
                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++;
@@ -418,7 +472,7 @@ int main(int argc, char *argv[])
                                }
                        }
                } 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);
@@ -430,14 +484,14 @@ int main(int argc, char *argv[])
                        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) {
@@ -445,82 +499,88 @@ int main(int argc, char *argv[])
                                        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;
                                                                        }
                                                                }
@@ -528,13 +588,13 @@ int main(int argc, char *argv[])
                                                                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++;
                                        }
@@ -555,7 +615,7 @@ int main(int argc, char *argv[])
                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",
@@ -568,11 +628,11 @@ int main(int argc, char *argv[])
                        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);
                        }
@@ -585,41 +645,43 @@ int main(int argc, char *argv[])
                        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') {
@@ -638,26 +700,32 @@ int main(int argc, char *argv[])
                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");
index a35698e1ff10b04b67530ddc97c4a391d0c15b13..c0c3dd65c3597ddd0be390873e38992b2dd6a727 100644 (file)
--- a/wiggle.h
+++ b/wiggle.h
@@ -44,7 +44,7 @@ static  inline int match(struct elmnt *a, struct elmnt *b)
        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)
@@ -60,7 +60,7 @@ static inline int ends_mline(struct elmnt e)
 }
 
 struct csl {
-       int a,b;
+       int a, b;
        int len;
 };
 
@@ -89,21 +89,25 @@ struct file {
  * 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);
@@ -116,10 +120,12 @@ struct ci {
        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);