]> git.neil.brown.name Git - wiggle.git/commitdiff
General cleanups
authorNeil Brown <neilb@suse.de>
Mon, 7 May 2012 21:59:21 +0000 (07:59 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 7 May 2012 21:59:21 +0000 (07:59 +1000)
- spelling fixes
- remove ifdefed-out code
- white space adjustments
- etc

Signed-off-by: NeilBrown <neilb@suse.de>
14 files changed:
Makefile
ReadMe.c
TODO
bestmatch.c
diff.c
extract.c
load.c
merge2.c
patch_depends.c
split.c
version [deleted file]
vpatch.c
wiggle.c
wiggle.h

index 6945c1e3dfdfb6920786dfd4d72b849a8c630cd8..2e2b190f50cc1bbf994b3edb2886f424cc030933 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ wiggle.man : wiggle.1
        nroff -man wiggle.1 > wiggle.man
 
 clean:
-       rm -f *.o *.man wiggle .version* demo.patch
+       rm -f *.o *.man wiggle .version* demo.patch version
        find . -name core -o -name '*.tmp*' -o -name .tmp | xargs rm -f
 
 install : wiggle wiggle.1
index 5e401077b581258ac911fcd431c7b5590b7b0c77..d754edf35434a8607e6ce483c161fa0bb5d0896d 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -34,7 +34,6 @@ 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 */
 
-
 struct option long_options[] = {
        {"browse",      0, 0, 'B'},
        {"extract",     0, 0, 'x'},
diff --git a/TODO b/TODO
index e65f73457669af63a78427a8c643705fe2e0d385..57b1f4c44684e92ee5639bce617528487dc80e87 100644 (file)
--- a/TODO
+++ b/TODO
@@ -12,7 +12,7 @@
 
   best guess only included if there is one.
 
-- search show go to right column and highlight
+- search should go to right column and highlight
 - do we always recenter top when we split - what if near but not at bottom
 - side-by-side sometimes shows last line of a chunk with
   the next chunk
index 1b94bec1d9272df74335b731fa0ca5414f525611..ce1ed0559ada74ab10d5e5d73031b5872335d8ba 100644 (file)
@@ -36,7 +36,7 @@
  * We walk the whole matrix in a breadth first fashion following a
  * 'front' on which x+y is constant.  Along this front we examine each
  * diagonal.  For each point we calculate a 'value' for the match so
- * far.  This will be in some particlar chunk.  For each chunk we
+ * far.  This will be in some particular chunk.  For each chunk we
  * separately record the best value found so far, and where it was.
  * To choose a new value for each point we calculate based on the
  * previous value on each neighbouring diagonal and on this diagonal.
@@ -300,19 +300,6 @@ static struct csl *csl_join(struct csl *c1, struct csl *c2)
        return rv;
 }
 
-#if 0
-static void printword(struct elmnt e)
-{
-       if (e.start[0])
-               printf("%.*s", e.len, e.start);
-       else {
-               int a, b, c;
-               sscanf(e.start+1, "%d %d %d", &a, &b, &c);
-               printf("*** %d,%d **** %d\n", b, c, a);
-       }
-}
-#endif
-
 /*
  * Reduce a file by discarding less interesting words
  * Words that end with a newline are interesting (so all words
diff --git a/diff.c b/diff.c
index 51d842167b70251a85b08bbe34f89d637164f11e..f664d573a42fbadd8e5e44550a70db5a33493e6e 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -577,7 +577,6 @@ struct csl *diff_partial(struct file a, struct file b,
        return csl;
 }
 
-
 #ifdef MAIN
 
 main(int argc, char *argv[])
index f7ee0dcccf8d8d68868992fd70bbff51d996d414..5cb8ad239008477892db760cc7dc9c3f450ef0a4 100644 (file)
--- a/extract.c
+++ b/extract.c
 
 /*
  * split patch or merge files.
- *
  */
 
 #include       "wiggle.h"
 #include       <stdlib.h>
 
+/* skip 'cp' past the new '\n', or all the way to 'end' */
 static void skip_eol(char **cp, char *end)
 {
        char *c = *cp;
@@ -41,6 +41,9 @@ static void skip_eol(char **cp, char *end)
        *cp = c;
 }
 
+/* copy one line, or to end, from 'cp' into the stream, extending
+ * the stream.
+ */
 static void copyline(struct stream *s, char **cp, char *end)
 {
        char *from = *cp;
diff --git a/load.c b/load.c
index 1da2b6fba867351a4f16067988b28e93929f7cae..5978dd749ab45415fbf78030e3b138e0588e1276 100644 (file)
--- a/load.c
+++ b/load.c
@@ -63,6 +63,7 @@ static void join_streams(struct stream list[], int cnt)
                memcpy(c, list[i].body, list[i].len);
                c += list[i].len;
                list[i].len = 0;
+               free(list[i].body);
        }
        c[0] = 0;
 }
@@ -79,6 +80,7 @@ static struct stream load_regular(int fd)
                if (read(fd, s.body, s.len) != s.len) {
                        free(s.body);
                        s.body = NULL;
+                       die();
                }
        } else
                die();
index c25b2d8d4e465a604284318653b1b5e3c2396283..a7945e2b156e5eeded107286324b2e3f101a8c9f 100644 (file)
--- a/merge2.c
+++ b/merge2.c
@@ -214,7 +214,6 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf,
        return cnt;
 }
 
-
 struct ci make_merger(struct file af, struct file bf, struct file cf,
                      struct csl *csl1, struct csl *csl2, int words,
                      int ignore_already)
index c4cb004ad978026fed701fad28d0001518b96d64..86724ea42f32ea0f096cc1a420299034b0dec66d 100644 (file)
@@ -16,8 +16,6 @@
  *
  */
 
-
-
 struct chunk {
        struct patch *patch;    /* the patch this chunk is from */
        struct file *file;      /* the file this chunk patches */
@@ -38,8 +36,6 @@ struct patch {
        struct patch *next;     /* previous patch that was loaded */
 } *patches = NULL;
 
-
-
 void report(void)
 {
        struct patch *p;
@@ -78,7 +74,6 @@ void add_depends(struct patch *new, struct patch *old)
        new->depends[new->cnt-1] = old;
 }
 
-
 void add_chunk(struct patch *p, struct file *f, int os, int oe, int ns, int ne)
 {
        struct chunk *c = malloc(sizeof(struct chunk));
diff --git a/split.c b/split.c
index f38ba04405e72d7247be7be49be5992768b4f166..50a4b4fbb3e066200370560f2fc9dfe3a7bda8e3 100644 (file)
--- a/split.c
+++ b/split.c
@@ -23,7 +23,7 @@
  */
 
 /*
- * Split a stream into words or line
+ * Split a stream into words or lines
  *
  * A word is one of:
  *    string of [A-Za-z0-9_]
@@ -114,6 +114,8 @@ struct file split_stream(struct stream s, int type)
 
        cnt = split_internal(c, end, type, NULL);
        f.list = malloc(cnt*sizeof(struct elmnt));
+       if (!f.list)
+               die();
 
        f.elcnt = split_internal(c, end, type, f.list);
        return f;
diff --git a/version b/version
deleted file mode 100644 (file)
index aec258d..0000000
--- a/version
+++ /dev/null
@@ -1 +0,0 @@
-0.8
index 36ecb16428d451c7c376b2d180a4fb833a3c4f5a..fbd6bf78bea31a7e2098b82cade453f44c096997 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -116,7 +116,7 @@ static void help_window(char *page1[], char *page2[])
                rows = 15;
        }
 
-       /* Draw a bow around the 'help' area */
+       /* Draw a border around the 'help' area */
        (void)attrset(A_STANDOUT);
        for (c = left; c < left+cols; c++) {
                mvaddch(top-1, c, '-');
@@ -223,7 +223,6 @@ static void help_window(char *page1[], char *page2[])
        }
 }
 
-
 /* Type names are needed for tracing only. */
 static char *typenames[] = {
        [End] = "End",
@@ -252,7 +251,6 @@ static char *typenames[] = {
 #define WIGGLED 64 /* a conflict that was successfully resolved */
 #define CONFLICTED 128 /* a conflict that was not successfully resolved */
 
-
 /* Displaying a Merge.
  * The first step is to linearise the merge.  The merge in inherently
  * parallel with before/after streams.  However much of the whole document
@@ -544,7 +542,6 @@ static int check_line(struct mpos pos, struct file fm, struct file fb,
        struct elmnt e;
        int unmatched = 0;
 
-
        do {
                if (m[pos.p.m].type == Changed)
                        rv |= CHANGED | CHANGES;
@@ -941,7 +938,7 @@ static char *orig_help[] = {
        NULL
 };
 static char *result_help[] = {
-       "This is the 'result' view which show just the",
+       "This is the 'result' view which shows just the",
        "result of applying the patch.  When a conflict",
        "occurred this view does not show the full conflict",
        "but only the 'after' part of the patch.  To see",
@@ -1088,7 +1085,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
        char **modehelp = merge_help;
 
        int row, start = 0;
-       int trow; /* screen-row while searching.  If we cannot find, 
+       int trow; /* screen-row while searching.  If we cannot find,
                   * we forget this number */
        int col = 0, target = 0;
        struct mpos pos;  /* current point */
@@ -1139,6 +1136,7 @@ static void merge_window(struct plist *p, FILE *f, int reverse)
                        sm = load_file(p->file);
                }
        }
+       /* FIXME check for errors in the stream */
        fm = split_stream(sm, ByWord);
        fb = split_stream(sb, ByWord);
        fa = split_stream(sa, ByWord);
index d9b26b6176e0a2359df86b945226ce2e3aff76e7..79fb7500b68f4fe7103fddc85e78cb128d24ea52 100644 (file)
--- a/wiggle.c
+++ b/wiggle.c
@@ -31,7 +31,7 @@
  *
  * Wiggle can also read patch and merge files.  Unlike 'merge' it does not
  * need to be given three separate files, but can be given a file and a patch
- * and it will extract the pieces of the two two other files that it needs from
+ * and it will extract the pieces of the two other files that it needs from
  * the patch.
  *
  * Wiggle performs one of three core function:
  *   --diff -d       report differences between two files
  *   --merge -m      merge the changes between two files into a third file
  *
+ * This is also a --browse (-B) mode which provides interactive access
+ * to the merger.
+ *
  * To perform these, wiggle requires 1, 2, or 3 input streams respectively.
- * I can get there from individual files, from a diff (unified or context) or
+ * I can get these from individual files, from a diff (unified or context) or
  * from a merge file.
  *
  * For 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
+ * Difference calculation and merging is performed on lines (-l) or words (-w).
+ * Each 'word' is either 1/all alphnumeric (or '_'), 2/ all space or tab,
+ * or 3/ any other single character.
+ *
+ * In the case of -w, an initial diff is computed based on non-trivial words
+ * which includes alhpanumeric words and newlines.
  *
  * 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
@@ -111,36 +117,6 @@ static void printsep(struct elmnt e1, struct elmnt e2)
        printf("@@ -%d,%d +%d,%d @@\n", b, c, e, f);
 }
 
-
-#if 0
-/* Remove any entries from the common-sublist that are
- * just spaces, tabs, or newlines
- */
-static void cleanlist(struct file a, struct file b, struct csl *list)
-{
-       struct csl *new = 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++) {
-                               char c = a.list[ap].start[i];
-                               if (isalnum(c))
-                                       break;
-                       }
-                       if (i != a.list[ap].len)
-                               break;
-               }
-               if (ap == list->a+list->len)
-                       list++;
-               else
-                       *new++ = *list++;
-       }
-       *new = *list;
-}
-#endif
-
 int main(int argc, char *argv[])
 {
        int opt;
@@ -161,6 +137,7 @@ int main(int argc, char *argv[])
        FILE *outfile = stdout;
        char *helpmsg;
        char *base0;
+       struct ci ci;
 
        struct stream f, flist[3];
        struct file fl[3];
@@ -171,13 +148,7 @@ int main(int argc, char *argv[])
                base0++;
        else
                base0 = argv[0];
-#if 0
-       /* The name 'vpatch' seems to be used elsewhere */
-       if (strcmp(base0, "vpatch") == 0) {
-               Cmd = base0;
-               mode = 'B';
-       }
-#endif
+
        while ((opt = getopt_long(argc, argv,
                                  short_options(mode), long_options,
                                  &option_index)) != -1)
@@ -706,29 +677,21 @@ int main(int argc, char *argv[])
                        csl1 = diff(fl[0], fl[1]);
                csl2 = diff(fl[1], fl[2]);
 
-#if 0
-               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',
+                                 ignore);
+               if (!quiet && ci.conflicts)
+                       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");
+               exit_status = (ci.conflicts > 0);
 
-                       ci = print_merge2(outfile, &fl[0], &fl[1], &fl[2],
-                                         csl1, csl2, obj == 'w',
-                                         ignore);
-                       if (!quiet && ci.conflicts)
-                               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");
-                       exit_status = (ci.conflicts > 0);
-               }
                if (replace) {
                        fclose(outfile);
                        if (rename(argv[optind], orignew) == 0 &&
index 56a6151ea03bb79a89b823ab6ca41f36c136ad57..53b001fa061c6ae967f8db743431c36b9ad45198 100644 (file)
--- a/wiggle.h
+++ b/wiggle.h
@@ -32,7 +32,15 @@ struct stream {
        int len;
 };
 
-
+/* an 'elmnt' is a word or a line from the file.
+ * 'start' points into a 'body' in a stream.
+ * When a stream is made of 'diff' hunks, there is a special
+ * elmnt at the start of each hunk which starts with '\0' and
+ * records the line offsets of the hunk.  These are 20 bytes long.
+ * "\0\d{5} \d{5} \d{5}\n\0"
+ * The 3 numbers are: chunk number, starting line, number if lines.
+ * An element with len==0 marks EOF.
+ */
 struct elmnt {
        char *start;
        int hash;
@@ -47,6 +55,11 @@ static  inline int match(struct elmnt *a, struct elmnt *b)
                strncmp(a->start, b->start, a->len) == 0;
 }
 
+/* end-of-line is important for narrowing conflicts.
+ * In line mode, every element is a line and 'ends a line'
+ * In word mode, the newline element and the diff-hunk element
+ * end a line.
+ */
 static inline int ends_line(struct elmnt e)
 {
        if (e.len == 20 && e.start[0] == 0)
@@ -84,7 +97,7 @@ struct file {
  * Actually... it is possibly for a 'Changed' section to bound
  * a conflict as it indicates a successful match of A and B.
  * For line-wise merges, any Changed or Unchanged section bounds a conflict
- * For word-wise merges, and Changed or Unchanged section that matches
+ * For word-wise merges, any Changed or Unchanged section that matches
  * a newline, or immediately follows a newline (in all files) can bound
  * a conflict.
  */
@@ -120,10 +133,6 @@ 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,
                              struct csl *c1, struct csl *c2,
@@ -156,5 +165,7 @@ extern char HelpBrowse[];
 
 extern void cleanlist(struct file a, struct file b, struct csl *list);
 
-#define        ByLine  0
-#define        ByWord  1
+enum {
+       ByLine,
+       ByWord,
+};