From 907b0ba539549c6dc97959d058f0f149fd9161d5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 3 Oct 2020 20:29:36 +1000 Subject: [PATCH] Add "wiggle_" prefix to all exported names. All global names visible in libwiggle now start 'wiggle_'. This makes conflicts less likely. Signed-off-by: NeilBrown --- bestmatch.c | 28 ++++----- diff.c | 26 ++++---- extract.c | 20 +++--- load.c | 30 ++++----- merge2.c | 20 +++--- parse.c | 12 ++-- patch_depends.c | 2 +- split.c | 10 +-- utils.c | 18 +++--- vpatch.c | 150 +++++++++++++++++++++---------------------- wiggle.c | 164 ++++++++++++++++++++++++------------------------ wiggle.h | 54 ++++++++-------- 12 files changed, 267 insertions(+), 267 deletions(-) diff --git a/bestmatch.c b/bestmatch.c index eb35592..6d1bcbd 100644 --- a/bestmatch.c +++ b/bestmatch.c @@ -175,7 +175,7 @@ static void find_best(struct file *a, struct file *b, int klo, khi, k; int f; - struct v *valloc = xmalloc(sizeof(struct v)*((ahi-alo)+(bhi-blo)+5)); + struct v *valloc = wiggle_xmalloc(sizeof(struct v)*((ahi-alo)+(bhi-blo)+5)); struct v *v = valloc + (bhi-alo+2); k = klo = khi = alo-blo; @@ -301,7 +301,7 @@ static struct file reduce(struct file orig) return orig; rv.elcnt = cnt; - rv.list = xmalloc(cnt*sizeof(struct elmnt)); + rv.list = wiggle_xmalloc(cnt*sizeof(struct elmnt)); cnt = 0; for (i = 0; i < orig.elcnt; i++) if (!is_skipped(orig.list[i])) @@ -432,10 +432,10 @@ static void find_best_inorder(struct file *a, struct file *b, } } -struct csl *pdiff(struct file a, struct file b, int chunks) +struct csl *wiggle_pdiff(struct file a, struct file b, int chunks) { struct csl *csl1, *csl2; - struct best *best = xmalloc(sizeof(struct best)*(chunks+1)); + struct best *best = wiggle_xmalloc(sizeof(struct best)*(chunks+1)); int i; struct file asmall, bsmall; int xmin; @@ -460,7 +460,7 @@ struct csl *pdiff(struct file a, struct file b, int chunks) if (best[i].val > 0) { /* If we there are any newlines in the hunk before * ylo, then extend xlo back that many newlines if - * possible and diff_partial the extended regions. + * possible and wiggle_diff_partial the extended regions. */ int lines = 0; int ylo = best[i].ylo; @@ -477,23 +477,23 @@ struct csl *pdiff(struct file a, struct file b, int chunks) } while (xlo > xmin && !ends_line(a.list[xlo-1])) xlo--; - csl2 = diff_partial(a, b, + csl2 = wiggle_diff_partial(a, b, xlo, best[i].xlo, ylo, best[i].ylo); - csl1 = csl_join(csl1, csl2); + csl1 = wiggle_csl_join(csl1, csl2); } - /* Now diff_partial the good bit of the hunk with the + /* Now wiggle_diff_partial the good bit of the hunk with the * good match */ - csl2 = diff_partial(a, b, + csl2 = wiggle_diff_partial(a, b, best[i].xlo, best[i].xhi, best[i].ylo, best[i].yhi); - csl1 = csl_join(csl1, csl2); + csl1 = wiggle_csl_join(csl1, csl2); /* Now if there are newlines at the end of the * hunk that weren't matched, find as many in - * original and diff_partial those bits + * original and wiggle_diff_partial those bits */ lines = 0; yhi = best[i].yhi; @@ -511,10 +511,10 @@ struct csl *pdiff(struct file a, struct file b, int chunks) lines -= !!ends_line(a.list[xhi]); xhi++; } - csl2 = diff_partial(a, b, + csl2 = wiggle_diff_partial(a, b, best[i].xhi, xhi, best[i].yhi, yhi); - csl1 = csl_join(csl1, csl2); + csl1 = wiggle_csl_join(csl1, csl2); xmin = xhi; } } else { @@ -526,7 +526,7 @@ struct csl *pdiff(struct file a, struct file b, int chunks) csl2->a = a.elcnt; csl2->b = b.elcnt; } else { - csl1 = xmalloc(sizeof(*csl1)); + csl1 = wiggle_xmalloc(sizeof(*csl1)); csl1->len = 0; csl1->a = a.elcnt; csl1->b = b.elcnt; diff --git a/diff.c b/diff.c index 954d3d6..2772b21 100644 --- a/diff.c +++ b/diff.c @@ -595,13 +595,13 @@ static struct file filter_unique(struct file f, struct file ref) int fi, cnt; struct file sorted; - sorted.list = xmalloc(sizeof(sorted.list[0]) * ref.elcnt); + sorted.list = wiggle_xmalloc(sizeof(sorted.list[0]) * ref.elcnt); sorted.elcnt = ref.elcnt; memcpy(sorted.list, ref.list, sizeof(sorted.list[0]) * sorted.elcnt); qsort(sorted.list, sorted.elcnt, sizeof(sorted.list[0]), elcmp); - n.list = xmalloc(sizeof(n.list[0]) * f.elcnt); + n.list = wiggle_xmalloc(sizeof(n.list[0]) * f.elcnt); n.elcnt = 0; cnt = 0; for (fi = 0; fi < f.elcnt; fi++) { @@ -653,7 +653,7 @@ static void remap(struct csl *csl, int which, struct file from, struct file to) * The final element in the list will have 'len' == 0 and will point * beyond the end of the files. */ -struct csl *diff(struct file a, struct file b, int shortest) +struct csl *wiggle_diff(struct file a, struct file b, int shortest) { struct v *v; struct cslb cslb = {}; @@ -666,7 +666,7 @@ struct csl *diff(struct file a, struct file b, int shortest) af = filter_unique(a, b); bf = filter_unique(b, a); - v = xmalloc(sizeof(struct v)*(af.elcnt+bf.elcnt+2)); + v = wiggle_xmalloc(sizeof(struct v)*(af.elcnt+bf.elcnt+2)); v += bf.elcnt+1; lcsl(&af, 0, af.elcnt, @@ -685,12 +685,12 @@ struct csl *diff(struct file a, struct file b, int shortest) /* Alternate entry point - find the common-sub-list in two * subranges of files. */ -struct csl *diff_partial(struct file a, struct file b, +struct csl *wiggle_diff_partial(struct file a, struct file b, int alo, int ahi, int blo, int bhi) { struct v *v; struct cslb cslb = {}; - v = xmalloc(sizeof(struct v)*(ahi-alo+bhi-blo+2)); + v = wiggle_xmalloc(sizeof(struct v)*(ahi-alo+bhi-blo+2)); v += bhi-alo+1; lcsl(&a, alo, ahi, @@ -702,7 +702,7 @@ struct csl *diff_partial(struct file a, struct file b, return cslb.csl; } -struct csl *csl_join(struct csl *c1, struct csl *c2) +struct csl *wiggle_csl_join(struct csl *c1, struct csl *c2) { int cnt1, cnt2; int offset = 0; @@ -736,7 +736,7 @@ struct csl *csl_join(struct csl *c1, struct csl *c2) * line up. So don't do a full diff, but rather find the hunk * headers and diff the bits between them. */ -struct csl *diff_patch(struct file a, struct file b, int shortest) +struct csl *wiggle_diff_patch(struct file a, struct file b, int shortest) { int ap, bp; struct csl *csl = NULL; @@ -744,7 +744,7 @@ struct csl *diff_patch(struct file a, struct file b, int shortest) a.list[0].start[0] != '\0' || b.list[0].start[0] != '\0') /* this is not a patch */ - return diff(a, b, shortest); + return wiggle_diff(a, b, shortest); ap = 0; bp = 0; while (ap < a.elcnt && bp < b.elcnt) { @@ -760,8 +760,8 @@ struct csl *diff_patch(struct file a, struct file b, int shortest) bp++; while (bp < b.elcnt && b.list[bp].start[0] != '\0'); - cs = diff_partial(a, b, alo, ap, blo, bp); - csl = csl_join(csl, cs); + cs = wiggle_diff_partial(a, b, alo, ap, blo, bp); + csl = wiggle_csl_join(csl, cs); } return csl; } @@ -772,7 +772,7 @@ main(int argc, char *argv[]) { struct file a, b; struct csl *csl; - struct elmnt *lst = xmalloc(argc*sizeof(*lst)); + struct elmnt *lst = wiggle_xmalloc(argc*sizeof(*lst)); int arg; struct v *v; int ln; @@ -804,7 +804,7 @@ main(int argc, char *argv[]) arg++; } - csl = diff(a, b, 1); + csl = wiggle_diff(a, b, 1); fixup(&a, &b, csl); while (csl && csl->len) { int i; diff --git a/extract.c b/extract.c index ac61421..feaafd4 100644 --- a/extract.c +++ b/extract.c @@ -56,7 +56,7 @@ static void copyline(struct stream *s, char **cp, char *end) *cp = from; } -int split_patch(struct stream f, struct stream *f1, struct stream *f2) +int wiggle_split_patch(struct stream f, struct stream *f1, struct stream *f2) { struct stream r1, r2; int chunks = 0; @@ -70,8 +70,8 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) f1->body = f2->body = NULL; - r1.body = xmalloc(f.len); - r2.body = xmalloc(f.len); + r1.body = wiggle_xmalloc(f.len); + r2.body = wiggle_xmalloc(f.len); r1.len = r2.len = 0; func[0] = 0; @@ -165,7 +165,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) state = 0; } else { fprintf(stderr, "%s: bad context patch at line %d\n", - Cmd, lineno); + wiggle_Cmd, lineno); return 0; } break; @@ -179,7 +179,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) state = 0; } else { fprintf(stderr, "%s: bad context patch/2 at line %d\n", - Cmd, lineno); + wiggle_Cmd, lineno); return 0; } break; @@ -207,7 +207,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) acnt --; bcnt--; } else { fprintf(stderr, "%s: bad unified patch at line %d\n", - Cmd, lineno); + wiggle_Cmd, lineno); return 0; } if (acnt <= 0 && bcnt <= 0) @@ -225,7 +225,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) /* * extract parts of a "diff3 -m" or "wiggle -m" output */ -int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct stream *f3) +int wiggle_split_merge(struct stream f, struct stream *f1, struct stream *f2, struct stream *f3) { int state = 0; char *cp, *end; @@ -233,9 +233,9 @@ int split_merge(struct stream f, struct stream *f1, struct stream *f2, struct st f1->body = NULL; f2->body = NULL; - r1.body = xmalloc(f.len); - r2.body = xmalloc(f.len); - r3.body = xmalloc(f.len); + r1.body = wiggle_xmalloc(f.len); + r2.body = wiggle_xmalloc(f.len); + r3.body = wiggle_xmalloc(f.len); r1.len = r2.len = r3.len = 0; cp = f.body; diff --git a/load.c b/load.c index 59cc354..b2a8e5f 100644 --- a/load.c +++ b/load.c @@ -54,7 +54,7 @@ static void join_streams(struct stream list[], int cnt) c = realloc(list[0].body, len+1); if (c == NULL) - die("memory allocation"); + wiggle_die("memory allocation"); list[0].body = c; c += list[0].len; @@ -68,32 +68,32 @@ static void join_streams(struct stream list[], int cnt) c[0] = 0; } -static struct stream load_regular(int fd) +static struct stream wiggle_load_regular(int fd) { struct stat stb; struct stream s; fstat(fd, &stb); s.len = stb.st_size; - s.body = xmalloc(s.len+1); + s.body = wiggle_xmalloc(s.len+1); if (read(fd, s.body, s.len) != s.len) - die("file read"); + wiggle_die("file read"); s.body[s.len] = 0; return s; } -static struct stream load_other(int fd) +static struct stream wiggle_load_other(int fd) { struct stream list[10]; int i = 0; while (1) { - list[i].body = xmalloc(8192); + list[i].body = wiggle_xmalloc(8192); list[i].len = read(fd, list[i].body, 8192); if (list[i].len < 0) - die("file read"); + wiggle_die("file read"); if (list[i].len == 0) break; i++; @@ -106,21 +106,21 @@ static struct stream load_other(int fd) return list[0]; } -struct stream load_segment(FILE *f, +struct stream wiggle_load_segment(FILE *f, unsigned int start, unsigned int end) { struct stream s; s.len = end - start; - s.body = xmalloc(s.len+1); + s.body = wiggle_xmalloc(s.len+1); fseek(f, start, 0); if (fread(s.body, 1, s.len, f) != (size_t)s.len) - die("file read"); + wiggle_die("file read"); /* ensure string is 'nul' terminated - for sscanf */ s.body[s.len] = 0; return s; } -struct stream load_file(char *name) +struct stream wiggle_load_file(char *name) { struct stream s; struct stat stb; @@ -134,7 +134,7 @@ struct stream load_file(char *name) &prefix_len) >= 2 && prefix_len > 0) { FILE *f = fopen(name + prefix_len, "r"); if (f) { - s = load_segment(f, start, end); + s = wiggle_load_segment(f, start, end); fclose(f); } else { s.body = NULL; @@ -148,13 +148,13 @@ struct stream load_file(char *name) if (fd < 0) return s; } - check_dir(name, fd); + wiggle_check_dir(name, fd); if (fstat(fd, &stb) == 0) { if (S_ISREG(stb.st_mode)) - s = load_regular(fd); + s = wiggle_load_regular(fd); else - s = load_other(fd); + s = wiggle_load_other(fd); } close(fd); } diff --git a/merge2.c b/merge2.c index 24ccd73..98b04b6 100644 --- a/merge2.c +++ b/merge2.c @@ -63,7 +63,7 @@ static int check_alreadyapplied(struct file af, struct file cf, af.list[m->a+i].len) != 0) return 0; } - if (do_trace) { + if (wiggle_do_trace) { printf("already applied %d,%d,%d - %d,%d,%d\n", m->a, m->b, m->c, m->al, m->bl, m->cl); printf(" %.10s - %.10s\n", af.list[m->a].start, @@ -89,7 +89,7 @@ static int is_cutpoint(struct merge m, (m.c == 0 || ends_line(cf.list[m.c-1]))); } -int isolate_conflicts(struct file af, struct file bf, struct file cf, +int wiggle_isolate_conflicts(struct file af, struct file bf, struct file cf, struct csl *csl1, struct csl *csl2, int words, struct merge *m, int show_wiggles, int *wigglesp) @@ -426,7 +426,7 @@ 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 ci wiggle_make_merger(struct file af, struct file bf, struct file cf, struct csl *csl1, struct csl *csl2, int words, int ignore_already, int show_wiggles) { @@ -449,7 +449,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf, /* maybe a bit of slack at each end */ l = l * 4 + 10; - rv.merger = xmalloc(sizeof(struct merge)*l); + rv.merger = wiggle_xmalloc(sizeof(struct merge)*l); a = b = c = c1 = c2 = 0; i = 0; @@ -612,7 +612,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf, rv.merger[i+1].type != End) rv.merger[i].type = Conflict; } - rv.conflicts = isolate_conflicts(af, bf, cf, csl1, csl2, words, + rv.conflicts = wiggle_isolate_conflicts(af, bf, cf, csl1, csl2, words, rv.merger, show_wiggles, &rv.wiggles); return rv; } @@ -623,7 +623,7 @@ static int printrange(FILE *out, struct file *f, int start, int len, int lines = 0; while (len > 0 && start < f->elcnt) { struct elmnt e = f->list[start]; - printword(out, e); + wiggle_printword(out, e); if (e.start[e.plen-1] == '\n' && offset > 0) lines++; @@ -637,7 +637,7 @@ static int printrange(FILE *out, struct file *f, int start, int len, static const char *conflict_types[] = { "", " border"," conflict"," wiggle" }; -int print_merge(FILE *out, struct file *a, struct file *b, struct file *c, +int wiggle_print_merge(FILE *out, struct file *a, struct file *b, struct file *c, int words, struct merge *merger, struct merge *mpos, int streampos, int offsetpos) { @@ -649,7 +649,7 @@ int print_merge(FILE *out, struct file *a, struct file *b, struct file *c, for (m = merger; m->type != End ; m++) { struct merge *cm; - if (do_trace) + if (wiggle_do_trace) printf("[%s: %d-%d,%d-%d,%d-%d%s(%d,%d)]\n", m->type==Unmatched ? "Unmatched" : m->type==Unchanged ? "Unchanged" : @@ -680,7 +680,7 @@ int print_merge(FILE *out, struct file *a, struct file *b, struct file *c, if (m == mpos) rv = lineno; - if (do_trace) + if (wiggle_do_trace) for (cm = m; cm->in_conflict; cm++) { printf("{%s: %d-%d,%d-%d,%d-%d%s(%d,%d)}%s\n", cm->type==Unmatched?"Unmatched": @@ -875,7 +875,7 @@ int print_merge(FILE *out, struct file *a, struct file *b, struct file *c, if (m->type == End) break; - if (do_trace) { + if (wiggle_do_trace) { printf("<<%s: %d-%d,%d-%d,%d-%d%s(%d,%d)>>\n", m->type==Unmatched?"Unmatched": m->type==Unchanged?"Unchanged": diff --git a/parse.c b/parse.c index 3ef8649..c56fa4c 100644 --- a/parse.c +++ b/parse.c @@ -56,7 +56,7 @@ static int get_strip(char *file) } -int set_prefix(struct plist *pl, int n, int strip) +int wiggle_set_prefix(struct plist *pl, int n, int strip) { int i; for (i = 0; i < 4 && i < n && strip < 0; i++) @@ -64,7 +64,7 @@ int set_prefix(struct plist *pl, int n, int strip) if (strip < 0) { fprintf(stderr, "%s: Cannot find files to patch: please specify --strip\n", - Cmd); + wiggle_Cmd); return 0; } for (i = 0; i < n; i++) { @@ -78,7 +78,7 @@ int set_prefix(struct plist *pl, int n, int strip) } if (p == NULL) { fprintf(stderr, "%s: cannot strip %d segments from %s\n", - Cmd, strip, pl[i].file); + wiggle_Cmd, strip, pl[i].file); return 0; } memmove(pl[i].file, p, strlen(p)+1); @@ -206,7 +206,7 @@ static struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr) return pl; } -struct plist *sort_patches(struct plist *pl, int *np) +struct plist *wiggle_sort_patches(struct plist *pl, int *np) { /* sort the patches, add directory names, and re-sort */ char curr[1024]; @@ -246,7 +246,7 @@ struct plist *sort_patches(struct plist *pl, int *np) return pl; } -struct plist *parse_patch(FILE *f, FILE *of, int *np) +struct plist *wiggle_parse_patch(FILE *f, FILE *of, int *np) { /* read a multi-file patch from 'f' and record relevant * details in a plist. @@ -321,7 +321,7 @@ struct plist *parse_patch(FILE *f, FILE *of, int *np) return plist; } -void plist_free(struct plist *pl, int num) +void wiggle_plist_free(struct plist *pl, int num) { int i; for (i = 0; i < num ; i++) diff --git a/patch_depends.c b/patch_depends.c index 9b3600c..17d6cda 100644 --- a/patch_depends.c +++ b/patch_depends.c @@ -76,7 +76,7 @@ void add_depends(struct patch *new, struct patch *old) void add_chunk(struct patch *p, struct file *f, int os, int oe, int ns, int ne) { - struct chunk *c = xmalloc(sizeof(struct chunk)); + struct chunk *c = wiggle_xmalloc(sizeof(struct chunk)); c->patch = p; c->file = f; c->old_start = os; diff --git a/split.c b/split.c index a9d66b0..2fa99b3 100644 --- a/split.c +++ b/split.c @@ -48,7 +48,7 @@ #include "ccan/hash/hash.h" -static int split_internal(char *start, char *end, int type, +static int wiggle_split_internal(char *start, char *end, int type, struct elmnt *list) { int cnt = 0; @@ -125,7 +125,7 @@ static int split_internal(char *start, char *end, int type, return cnt; } -struct file split_stream(struct stream s, int type) +struct file wiggle_split_stream(struct stream s, int type) { int cnt; struct file f; @@ -139,9 +139,9 @@ struct file split_stream(struct stream s, int type) end = s.body+s.len; c = s.body; - cnt = split_internal(c, end, type, NULL); - f.list = xmalloc(cnt*sizeof(struct elmnt)); + cnt = wiggle_split_internal(c, end, type, NULL); + f.list = wiggle_xmalloc(cnt*sizeof(struct elmnt)); - f.elcnt = split_internal(c, end, type, f.list); + f.elcnt = wiggle_split_internal(c, end, type, f.list); return f; } diff --git a/utils.c b/utils.c index 37e9a32..6984c15 100644 --- a/utils.c +++ b/utils.c @@ -28,11 +28,11 @@ #include #include -char *Cmd = "wiggle"; +char *wiggle_Cmd = "wiggle"; -int do_trace = 0; +int wiggle_do_trace = 0; -void *xmalloc(int size) +void *wiggle_xmalloc(int size) { void *rv = malloc(size); if (size && !rv) { @@ -43,7 +43,7 @@ void *xmalloc(int size) return rv; } -void printword(FILE *f, struct elmnt e) +void wiggle_printword(FILE *f, struct elmnt e) { if (e.start[0]) fprintf(f, "%.*s", e.plen + e.prefix, @@ -55,21 +55,21 @@ void printword(FILE *f, struct elmnt e) } } -void die(char *reason) +void wiggle_die(char *reason) { - fprintf(stderr, "%s: fatal error: %s failure\n", Cmd, reason); + fprintf(stderr, "%s: fatal error: %s failure\n", wiggle_Cmd, reason); exit(3); } -void check_dir(char *name, int fd) +void wiggle_check_dir(char *name, int fd) { struct stat st; if (fstat(fd, &st) != 0) { - fprintf(stderr, "%s: fatal: %s is strange\n", Cmd, name); + fprintf(stderr, "%s: fatal: %s is strange\n", wiggle_Cmd, name); exit(3); } if (S_ISDIR(st.st_mode)) { - fprintf(stderr, "%s: %s is a directory\n", Cmd, name); + fprintf(stderr, "%s: %s is a directory\n", wiggle_Cmd, name); exit(3); } } diff --git a/vpatch.c b/vpatch.c index abbb4c6..5bd8f52 100644 --- a/vpatch.c +++ b/vpatch.c @@ -1295,8 +1295,8 @@ static void *memdup(void *a, int len) static int save_merge(struct file a, struct file b, struct file c, struct merge *merger, char *file, int backup) { - char *replacename = xmalloc(strlen(file) + 20); - char *orignew = xmalloc(strlen(file) + 20); + char *replacename = wiggle_xmalloc(strlen(file) + 20); + char *orignew = wiggle_xmalloc(strlen(file) + 20); int fd; FILE *outfile; int err = 0; @@ -1312,8 +1312,8 @@ static int save_merge(struct file a, struct file b, struct file c, goto out; } outfile = fdopen(fd, "w"); - lineno = print_merge(outfile, &a, &b, &c, 0, merger, - NULL, 0, 0); + lineno = wiggle_print_merge(outfile, &a, &b, &c, 0, merger, + NULL, 0, 0); fclose(outfile); if (backup && rename(file, orignew) != 0) err = -2; @@ -1361,8 +1361,8 @@ static int save_tmp_merge(struct file a, struct file b, struct file c, return -1; } outfile = fdopen(fd, "w"); - lineno = print_merge(outfile, &a, &b, &c, 0, merger, - mpos, streampos, offsetpos); + lineno = wiggle_print_merge(outfile, &a, &b, &c, 0, merger, + mpos, streampos, offsetpos); fclose(outfile); *filep = fname; return lineno; @@ -1472,17 +1472,17 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, #define prepare_merge(ch) \ do { \ /* FIXME check for errors in the stream */ \ - fm = split_stream(sm, ByWord | ignore_blanks); \ - fb = split_stream(sb, ByWord | ignore_blanks); \ - fa = split_stream(sa, ByWord | ignore_blanks); \ + fm = wiggle_split_stream(sm, ByWord | ignore_blanks); \ + fb = wiggle_split_stream(sb, ByWord | ignore_blanks); \ + fa = wiggle_split_stream(sa, ByWord | ignore_blanks); \ \ if (ch && !just_diff) \ - csl1 = pdiff(fm, fb, ch); \ + csl1 = wiggle_pdiff(fm, fb, ch); \ else \ - csl1 = diff(fm, fb, 1); \ - csl2 = diff_patch(fb, fa, 1); \ + csl1 = wiggle_diff(fm, fb, 1); \ + csl2 = wiggle_diff_patch(fb, fa, 1); \ \ - ci = make_merger(fm, fb, fa, csl1, csl2, 0, 1, 0); \ + ci = wiggle_make_merger(fm, fb, fa, csl1, csl2, 0, 1, 0); \ for (i = 0; ci.merger[i].type != End; i++) \ ci.merger[i].oldtype = ci.merger[i].type; \ } while(0) @@ -1495,39 +1495,39 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, if (f == NULL) { if (!p->is_merge) { /* three separate files */ - sb = load_file(p->before); - sa = load_file(p->after); + sb = wiggle_load_file(p->before); + sa = wiggle_load_file(p->after); if (just_diff) sm = sb; else - sm = load_file(p->file); + sm = wiggle_load_file(p->file); } else { /* One merge file */ - sp = load_file(p->file); + sp = wiggle_load_file(p->file); if (reverse) - split_merge(sp, &sm, &sa, &sb); + wiggle_split_merge(sp, &sm, &sa, &sb); else - split_merge(sp, &sm, &sb, &sa); + wiggle_split_merge(sp, &sm, &sb, &sa); free(sp.body); } ch = 0; } else { - sp = load_segment(f, p->start, p->end); + sp = wiggle_load_segment(f, p->start, p->end); if (p->is_merge) { if (reverse) - split_merge(sp, &sm, &sa, &sb); + wiggle_split_merge(sp, &sm, &sa, &sb); else - split_merge(sp, &sm, &sb, &sa); + wiggle_split_merge(sp, &sm, &sb, &sa); ch = 0; } else { if (reverse) - ch = split_patch(sp, &sa, &sb); + ch = wiggle_split_patch(sp, &sa, &sb); else - ch = split_patch(sp, &sb, &sa); + ch = wiggle_split_patch(sp, &sb, &sa); if (just_diff) sm = sb; else - sm = load_file(p->file); + sm = wiggle_load_file(p->file); } free(sp.body); } @@ -1864,7 +1864,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, break; if (answer) { p->wiggles = 0; - p->conflicts = isolate_conflicts( + p->conflicts = wiggle_isolate_conflicts( fm, fb, fa, csl1, csl2, 0, ci.merger, 0, &p->wiggles); p->chunks = p->conflicts; @@ -1910,15 +1910,15 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, endwin(); free_stuff(); do_edit(tempname, lineno); - sp = load_file(tempname); + sp = wiggle_load_file(tempname); unlink(tempname); - split_merge(sp, &sm, &sb, &sa); + wiggle_split_merge(sp, &sm, &sb, &sa); if (sp.len == sm.len && memcmp(sp.body, sm.body, sm.len) == 0 && !p->is_merge) { /* no conflicts left, so display diff */ free(sm.body); - sm = load_file(p->file); + sm = wiggle_load_file(p->file); free(sb.body); sb = sm; sb.body = memdup(sm.body, sm.len); @@ -2332,7 +2332,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, ci.merger[curs.pos.m].type = ci.merger[curs.pos.m].oldtype; else ci.merger[curs.pos.m].type = next; - p->conflicts = isolate_conflicts( + p->conflicts = wiggle_isolate_conflicts( fm, fb, fa, csl1, csl2, 0, ci.merger, 0, &p->wiggles); refresh = 1; @@ -2350,7 +2350,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, ci.merger[curs.pos.m].type = ci.merger[curs.pos.m].oldtype; else ci.merger[curs.pos.m].type = Changed; - p->conflicts = isolate_conflicts( + p->conflicts = wiggle_isolate_conflicts( fm, fb, fa, csl1, csl2, 0, ci.merger, 0, &p->wiggles); refresh = 1; @@ -2367,7 +2367,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, break; } while (!ends_line(e) || visible(mode & (RESULT|AFTER), ci.merger, &tpos) < 0); - p->conflicts = isolate_conflicts( + p->conflicts = wiggle_isolate_conflicts( fm, fb, fa, csl1, csl2, 0, ci.merger, 0, &p->wiggles); refresh = 1; @@ -2389,7 +2389,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace, !same_mpos(anchor->pos, pos) || anchor->searchlen != searchlen || !same_mp(anchor->curs.pos, curs.pos)) { - struct search_anchor *a = xmalloc(sizeof(*a)); + struct search_anchor *a = wiggle_xmalloc(sizeof(*a)); a->pos = pos; a->row = row; a->start = start; @@ -2452,23 +2452,23 @@ static void calc_one(struct plist *pl, FILE *f, int reverse, int ignore_blanks, int just_diff) { struct stream s1, s2; - struct stream s = load_segment(f, pl->start, pl->end); + struct stream s = wiggle_load_segment(f, pl->start, pl->end); struct stream sf; if (pl->is_merge) { if (reverse) - split_merge(s, &sf, &s2, &s1); + wiggle_split_merge(s, &sf, &s2, &s1); else - split_merge(s, &sf, &s1, &s2); + wiggle_split_merge(s, &sf, &s1, &s2); pl->chunks = 0; } else { if (reverse) - pl->chunks = split_patch(s, &s2, &s1); + pl->chunks = wiggle_split_patch(s, &s2, &s1); else - pl->chunks = split_patch(s, &s1, &s2); + pl->chunks = wiggle_split_patch(s, &s1, &s2); if (just_diff) sf = s1; else - sf = load_file(pl->file); + sf = wiggle_load_file(pl->file); } if (sf.body == NULL || s1.body == NULL || s1.body == NULL) { pl->wiggles = pl->conflicts = -1; @@ -2476,15 +2476,15 @@ static void calc_one(struct plist *pl, FILE *f, int reverse, struct file ff, fp1, fp2; struct csl *csl1, *csl2; struct ci ci; - ff = split_stream(sf, ByWord | ignore_blanks); - fp1 = split_stream(s1, ByWord | ignore_blanks); - fp2 = split_stream(s2, ByWord | ignore_blanks); + ff = wiggle_split_stream(sf, ByWord | ignore_blanks); + fp1 = wiggle_split_stream(s1, ByWord | ignore_blanks); + fp2 = wiggle_split_stream(s2, ByWord | ignore_blanks); if (pl->chunks && !just_diff) - csl1 = pdiff(ff, fp1, pl->chunks); + csl1 = wiggle_pdiff(ff, fp1, pl->chunks); else - csl1 = diff(ff, fp1, 1); - csl2 = diff_patch(fp1, fp2, 1); - ci = make_merger(ff, fp1, fp2, csl1, csl2, 0, 1, 0); + csl1 = wiggle_diff(ff, fp1, 1); + csl2 = wiggle_diff_patch(fp1, fp2, 1); + ci = wiggle_make_merger(ff, fp1, fp2, csl1, csl2, 0, 1, 0); pl->wiggles = ci.wiggles; pl->conflicts = ci.conflicts; free(ci.merger); @@ -2624,19 +2624,19 @@ static int save_one(FILE *f, struct plist *pl, int reverse, struct csl *csl1, *csl2; struct ci ci; int chunks; - sp = load_segment(f, pl->start, + sp = wiggle_load_segment(f, pl->start, pl->end); if (reverse) - chunks = split_patch(sp, &sa, &sb); + chunks = wiggle_split_patch(sp, &sa, &sb); else - chunks = split_patch(sp, &sb, &sa); - fb = split_stream(sb, ByWord | ignore_blanks); - fa = split_stream(sa, ByWord | ignore_blanks); - sm = load_file(pl->file); - fm = split_stream(sm, ByWord | ignore_blanks); - csl1 = pdiff(fm, fb, chunks); - csl2 = diff_patch(fb, fa, 1); - ci = make_merger(fm, fb, fa, csl1, csl2, 0, 1, 0); + chunks = wiggle_split_patch(sp, &sb, &sa); + fb = wiggle_split_stream(sb, ByWord | ignore_blanks); + fa = wiggle_split_stream(sa, ByWord | ignore_blanks); + sm = wiggle_load_file(pl->file); + fm = wiggle_split_stream(sm, ByWord | ignore_blanks); + csl1 = wiggle_pdiff(fm, fb, chunks); + csl2 = wiggle_diff_patch(fb, fa, 1); + ci = wiggle_make_merger(fm, fb, fa, csl1, csl2, 0, 1, 0); return save_merge(fm, fb, fa, ci.merger, pl->file, backup); } @@ -2985,7 +2985,7 @@ static void main_window(struct plist *pl, int np, FILE *f, int reverse, else { /* rename foo.porig to foo, and clear is_merge */ char *file = pl[pos].file; - char *orignew = xmalloc(strlen(file) + 20); + char *orignew = wiggle_xmalloc(strlen(file) + 20); strcpy(orignew, file); strcat(orignew, ".porig"); if (rename(orignew, file) == 0) { @@ -3031,7 +3031,7 @@ static void catch(int sig) if (sig != SIGBUS && sig != SIGSEGV) exit(2); else - /* Otherwise return and die */ + /* Otherwise return and wiggle_die */ signal(sig, NULL); } @@ -3129,7 +3129,7 @@ int vpatch(int argc, char *argv[], int patch, int strip, switch (argc) { default: - fprintf(stderr, "%s: too many file names given.\n", Cmd); + fprintf(stderr, "%s: too many file names given.\n", wiggle_Cmd); exit(1); case 0: /* stdin is a patch or diff */ @@ -3137,46 +3137,46 @@ int vpatch(int argc, char *argv[], int patch, int strip, /* cannot seek, so need to copy to a temp file */ f = tmpfile(); if (!f) { - fprintf(stderr, "%s: Cannot create temp file\n", Cmd); + fprintf(stderr, "%s: Cannot create temp file\n", wiggle_Cmd); exit(1); } - pl = parse_patch(stdin, f, &num_patches); + pl = wiggle_parse_patch(stdin, f, &num_patches); in = f; } else { - pl = parse_patch(stdin, NULL, &num_patches); + pl = wiggle_parse_patch(stdin, NULL, &num_patches); in = fdopen(dup(0), "r"); } /* use stderr for keyboard input */ dup2(2, 0); if (!just_diff && - set_prefix(pl, num_patches, strip) == 0) { - fprintf(stderr, "%s: aborting\n", Cmd); + wiggle_set_prefix(pl, num_patches, strip) == 0) { + fprintf(stderr, "%s: aborting\n", wiggle_Cmd); exit(2); } - pl = sort_patches(pl, &num_patches); + pl = wiggle_sort_patches(pl, &num_patches); main_window(pl, num_patches, in, reverse, replace, ignore_blanks, just_diff, backup); - plist_free(pl, num_patches); + wiggle_plist_free(pl, num_patches); fclose(in); break; case 1: /* a patch/diff, a .rej, or a merge file */ f = fopen(argv[0], "r"); if (!f) { - fprintf(stderr, "%s: cannot open %s\n", Cmd, argv[0]); + fprintf(stderr, "%s: cannot open %s\n", wiggle_Cmd, argv[0]); exit(1); } - check_dir(argv[0], fileno(f)); + wiggle_check_dir(argv[0], fileno(f)); if (patch) { - pl = parse_patch(f, NULL, &num_patches); - if (!just_diff && set_prefix(pl, num_patches, strip) == 0) { - fprintf(stderr, "%s: aborting\n", Cmd); + pl = wiggle_parse_patch(f, NULL, &num_patches); + if (!just_diff && wiggle_set_prefix(pl, num_patches, strip) == 0) { + fprintf(stderr, "%s: aborting\n", wiggle_Cmd); exit(2); } - pl = sort_patches(pl, &num_patches); + pl = wiggle_sort_patches(pl, &num_patches); main_window(pl, num_patches, f, reverse, replace, ignore_blanks, just_diff, backup); - plist_free(pl, num_patches); + wiggle_plist_free(pl, num_patches); } else if (strlen(argv[0]) > 4 && strcmp(argv[0]+strlen(argv[0])-4, ".rej") == 0) { char *origname = strdup(argv[0]); @@ -3199,10 +3199,10 @@ int vpatch(int argc, char *argv[], int patch, int strip, } f = fopen(argv[1], "r"); if (!f) { - fprintf(stderr, "%s: cannot open %s\n", Cmd, argv[0]); + fprintf(stderr, "%s: cannot open %s\n", wiggle_Cmd, argv[0]); exit(1); } - check_dir(argv[1], fileno(f)); + wiggle_check_dir(argv[1], fileno(f)); show_merge(argv[0], f, reverse, 0, NULL, NULL, replace, outfilename, selftest, ignore_blanks, just_diff, backup); diff --git a/wiggle.c b/wiggle.c index e7444a8..c529486 100644 --- a/wiggle.c +++ b/wiggle.c @@ -107,39 +107,39 @@ static int extract(int argc, char *argv[], int ispatch, int which) if (argc == 0) { fprintf(stderr, - "%s: no file given for --extract\n", Cmd); + "%s: no file given for --extract\n", wiggle_Cmd); return 2; } if (argc > 1) { fprintf(stderr, - "%s: only give one file for --extract\n", Cmd); + "%s: only give one file for --extract\n", wiggle_Cmd); return 2; } - f = load_file(argv[0]); + f = wiggle_load_file(argv[0]); if (f.body == NULL) { fprintf(stderr, - "%s: cannot load file '%s' - %s\n", Cmd, + "%s: cannot load file '%s' - %s\n", wiggle_Cmd, argv[0], strerror(errno)); return 2; } if (ispatch) { - if (split_patch(f, &flist[0], &flist[1]) == 0) { + if (wiggle_split_patch(f, &flist[0], &flist[1]) == 0) { fprintf(stderr, - "%s: No chunk found in patch: %s\n", Cmd, + "%s: No chunk found in patch: %s\n", wiggle_Cmd, argv[0]); return 0; } } else { - if (!split_merge(f, &flist[0], &flist[1], &flist[2])) { + if (!wiggle_split_merge(f, &flist[0], &flist[1], &flist[2])) { fprintf(stderr, - "%s: merge file %s looks bad.\n", Cmd, + "%s: merge file %s looks bad.\n", wiggle_Cmd, argv[0]); return 2; } } if (flist[which-'1'].body == NULL) { fprintf(stderr, - "%s: %s has no -%c component.\n", Cmd, + "%s: %s has no -%c component.\n", wiggle_Cmd, argv[0], which); return 2; } else { @@ -160,7 +160,7 @@ static int do_diff_lines(struct file fl[2], struct csl *csl) if (a < csl->a) { if (fl[0].list[a].start[0]) { printf("-"); - printword(stdout, + wiggle_printword(stdout, fl[0].list[a]); } a++; @@ -168,7 +168,7 @@ static int do_diff_lines(struct file fl[2], struct csl *csl) } else if (b < csl->b) { if (fl[1].list[b].start[0]) { printf("+"); - printword(stdout, + wiggle_printword(stdout, fl[1].list[b]); } b++; @@ -179,7 +179,7 @@ static int do_diff_lines(struct file fl[2], struct csl *csl) fl[1].list[b]); else { printf(" "); - printword(stdout, + wiggle_printword(stdout, fl[0].list[a]); } a++; @@ -215,7 +215,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) if (sol) { printf("-"); for (; a < csl->a ; a++) { - printword(stdout, fl[0].list[a]); + wiggle_printword(stdout, fl[0].list[a]); if (ends_line(fl[0].list[a])) { a++; break; @@ -229,7 +229,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) do { if (sol) printf("|"); - printword(stdout, fl[0].list[a]); + wiggle_printword(stdout, fl[0].list[a]); sol = ends_line(fl[0].list[a]); a++; } while (a < csl->a); @@ -249,7 +249,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) if (sol) { printf("+"); for (; b < csl->b ; b++) { - printword(stdout, fl[1].list[b]); + wiggle_printword(stdout, fl[1].list[b]); if (ends_line(fl[1].list[b])) { b++; break; @@ -263,7 +263,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) do { if (sol) printf("|"); - printword(stdout, fl[1].list[b]); + wiggle_printword(stdout, fl[1].list[b]); sol = ends_line(fl[1].list[b]); b++; } while (b < csl->b); @@ -281,7 +281,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) if (fl[0].list[a].start[0]) { printf(" "); for (; a < csl->a+csl->len; a++, b++) { - printword(stdout, fl[0].list[a]); + wiggle_printword(stdout, fl[0].list[a]); if (ends_line(fl[0].list[a])) { a++, b++; break; @@ -295,7 +295,7 @@ static int do_diff_words(struct file fl[2], struct csl *csl) printf("|"); } if (!sol) { - printword(stdout, fl[0].list[a]); + wiggle_printword(stdout, fl[0].list[a]); if (ends_line(fl[0].list[a])) sol = 1; a++; @@ -320,62 +320,62 @@ static int do_diff(int argc, char *argv[], int obj, int ispatch, switch (argc) { case 0: - fprintf(stderr, "%s: no file given for --diff\n", Cmd); + fprintf(stderr, "%s: no file given for --diff\n", wiggle_Cmd); return 2; case 1: - f = load_file(argv[0]); + f = wiggle_load_file(argv[0]); if (f.body == NULL) { fprintf(stderr, - "%s: cannot load file '%s' - %s\n", Cmd, + "%s: cannot load file '%s' - %s\n", wiggle_Cmd, argv[0], strerror(errno)); return 2; } chunks1 = chunks2 = - split_patch(f, &flist[0], &flist[1]); + wiggle_split_patch(f, &flist[0], &flist[1]); if (!flist[0].body || !flist[1].body) { fprintf(stderr, - "%s: couldn't parse patch %s\n", Cmd, + "%s: couldn't parse patch %s\n", wiggle_Cmd, argv[0]); return 2; } break; case 2: - flist[0] = load_file(argv[0]); + flist[0] = wiggle_load_file(argv[0]); if (flist[0].body == NULL) { fprintf(stderr, - "%s: cannot load file '%s' - %s\n", Cmd, + "%s: cannot load file '%s' - %s\n", wiggle_Cmd, argv[0], strerror(errno)); return 2; } if (ispatch) { - f = load_file(argv[1]); + f = wiggle_load_file(argv[1]); if (f.body == NULL) { fprintf(stderr, - "%s: cannot load patch '%s' - %s\n", Cmd, + "%s: cannot load patch '%s' - %s\n", wiggle_Cmd, argv[1], strerror(errno)); return 2; } if (which == '2') chunks2 = chunks3 = - split_patch(f, &flist[2], + wiggle_split_patch(f, &flist[2], &flist[1]); else chunks2 = chunks3 = - split_patch(f, &flist[1], + wiggle_split_patch(f, &flist[1], &flist[2]); } else - flist[1] = load_file(argv[1]); + flist[1] = wiggle_load_file(argv[1]); if (flist[1].body == NULL) { fprintf(stderr, - "%s: cannot load file '%s' - %s\n", Cmd, + "%s: cannot load file '%s' - %s\n", wiggle_Cmd, argv[1], strerror(errno)); return 2; } break; default: fprintf(stderr, - "%s: too many files given for --diff\n", Cmd); + "%s: too many files given for --diff\n", wiggle_Cmd); return 2; } if (reverse) { @@ -383,20 +383,20 @@ static int do_diff(int argc, char *argv[], int obj, int ispatch, flist[0] = flist[1]; flist[1] = f; } - fl[0] = split_stream(flist[0], obj); - fl[1] = split_stream(flist[1], obj); + fl[0] = wiggle_split_stream(flist[0], obj); + fl[1] = wiggle_split_stream(flist[1], obj); if (!(obj & WholeWord) && fl[0].elcnt > 50000 && fl[1].elcnt > 50000) { /* Too big - use fewer words if possible */ free(fl[0].list); free(fl[1].list); obj |= WholeWord; - fl[0] = split_stream(flist[0], obj); - fl[1] = split_stream(flist[1], obj); + fl[0] = wiggle_split_stream(flist[0], obj); + fl[1] = wiggle_split_stream(flist[1], obj); } if (chunks2 && !chunks1) - csl = pdiff(fl[0], fl[1], chunks2); + csl = wiggle_pdiff(fl[0], fl[1], chunks2); else - csl = diff_patch(fl[0], fl[1], shortest); + csl = wiggle_diff_patch(fl[0], fl[1], shortest); if ((obj & ByMask) == ByLine) { if (!chunks1) printf("@@ -1,%d +1,%d @@\n", @@ -438,16 +438,16 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, switch (argc) { case 0: - fprintf(stderr, "%s: no files given for --merge\n", Cmd); + fprintf(stderr, "%s: no files given for --merge\n", wiggle_Cmd); return 2; case 3: case 2: case 1: for (i = 0; i < argc; i++) { - flist[i] = load_file(argv[i]); + flist[i] = wiggle_load_file(argv[i]); if (flist[i].body == NULL) { fprintf(stderr, "%s: cannot load file '%s' - %s\n", - Cmd, + wiggle_Cmd, argv[i], strerror(errno)); return 2; } @@ -455,22 +455,22 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, break; default: fprintf(stderr, "%s: too many files given for --merge\n", - Cmd); + wiggle_Cmd); return 2; } switch (argc) { case 1: /* a merge file */ f = flist[0]; - if (!split_merge(f, &flist[0], &flist[1], &flist[2])) { + if (!wiggle_split_merge(f, &flist[0], &flist[1], &flist[2])) { fprintf(stderr, "%s: merge file %s looks bad.\n", - Cmd, + wiggle_Cmd, argv[0]); return 2; } break; case 2: /* a file and a patch */ f = flist[1]; - chunks2 = chunks3 = split_patch(f, &flist[1], &flist[2]); + chunks2 = chunks3 = wiggle_split_patch(f, &flist[1], &flist[2]); break; case 3: /* three separate files */ break; @@ -483,7 +483,7 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, for (i = 0; i < 3; i++) { if (flist[i].body == NULL) { - fprintf(stderr, "%s: file %d missing\n", Cmd, i); + fprintf(stderr, "%s: file %d missing\n", wiggle_Cmd, i); return 2; } } @@ -491,20 +491,20 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, outfile = fopen(outfilename, "w"); if (!outfile) { fprintf(stderr, "%s: could not create %s\n", - Cmd, outfilename); + wiggle_Cmd, outfilename); return 2; } } else if (replace) { int fd; - replacename = xmalloc(strlen(argv[0]) + 20); - orignew = xmalloc(strlen(argv[0]) + 20); + replacename = wiggle_xmalloc(strlen(argv[0]) + 20); + orignew = wiggle_xmalloc(strlen(argv[0]) + 20); strcpy(replacename, argv[0]); strcpy(orignew, argv[0]); strcat(orignew, ".porig"); if (open(orignew, O_RDONLY) >= 0 || errno != ENOENT) { fprintf(stderr, "%s: %s already exists\n", - Cmd, + wiggle_Cmd, orignew); free(replacename); free(orignew); @@ -515,7 +515,7 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, if (fd == -1) { fprintf(stderr, "%s: could not create temporary file for %s\n", - Cmd, + wiggle_Cmd, replacename); free(replacename); free(orignew); @@ -528,9 +528,9 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, blanks |= ByLine; else blanks |= ByWord; - fl[0] = split_stream(flist[0], blanks); - fl[1] = split_stream(flist[1], blanks); - fl[2] = split_stream(flist[2], blanks); + fl[0] = wiggle_split_stream(flist[0], blanks); + fl[1] = wiggle_split_stream(flist[1], blanks); + fl[2] = wiggle_split_stream(flist[2], blanks); if (!(blanks & WholeWord) && fl[1].elcnt > 50000 && (fl[0].elcnt > 50000 || fl[2].elcnt > 50000)) { @@ -539,20 +539,20 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, free(fl[1].list); free(fl[2].list); blanks |= WholeWord; - fl[0] = split_stream(flist[0], blanks); - fl[1] = split_stream(flist[1], blanks); - fl[2] = split_stream(flist[2], blanks); + fl[0] = wiggle_split_stream(flist[0], blanks); + fl[1] = wiggle_split_stream(flist[1], blanks); + fl[2] = wiggle_split_stream(flist[2], blanks); } if (chunks2 && !chunks1) - csl1 = pdiff(fl[0], fl[1], chunks2); + csl1 = wiggle_pdiff(fl[0], fl[1], chunks2); else - csl1 = diff(fl[0], fl[1], shortest); - csl2 = diff_patch(fl[1], fl[2], shortest); + csl1 = wiggle_diff(fl[0], fl[1], shortest); + csl2 = wiggle_diff_patch(fl[1], fl[2], shortest); - ci = make_merger(fl[0], fl[1], fl[2], csl1, csl2, + ci = wiggle_make_merger(fl[0], fl[1], fl[2], csl1, csl2, obj == 'w', ignore, show_wiggles > 1); - print_merge(outfile, &fl[0], &fl[1], &fl[2], + wiggle_print_merge(outfile, &fl[0], &fl[1], &fl[2], obj == 'w', ci.merger, NULL, 0, 0); if (!quiet && ci.conflicts) fprintf(stderr, @@ -573,7 +573,7 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, if (stat(argv[0], &statbuf) != 0) { fprintf(stderr, "%s: failed to stat original file. - %s\n", - Cmd, strerror(errno)); + wiggle_Cmd, strerror(errno)); free(replacename); free(orignew); return 2; @@ -581,7 +581,7 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, if (fchmod(fileno(outfile), statbuf.st_mode) != 0) { fprintf(stderr, "%s: failed to change permission of new file. - %s\n", - Cmd, strerror(errno)); + wiggle_Cmd, strerror(errno)); free(replacename); free(orignew); return 2; @@ -593,7 +593,7 @@ static int do_merge(int argc, char *argv[], int obj, int blanks, else { fprintf(stderr, "%s: failed to move new file into place.\n", - Cmd); + wiggle_Cmd); free(replacename); free(orignew); return 2; @@ -622,27 +622,27 @@ static int multi_merge(int argc, char *argv[], int obj, int blanks, if (!replace) { fprintf(stderr, "%s: -p in merge mode requires -r\n", - Cmd); + wiggle_Cmd); return 2; } if (argc != 1) { fprintf(stderr, "%s: -p in merge mode requires exactly one file\n", - Cmd); + wiggle_Cmd); return 2; } filename = argv[0]; f = fopen(filename, "r"); if (!f) { fprintf(stderr, "%s: cannot open %s\n", - Cmd, filename); + wiggle_Cmd, filename); return 2; } - check_dir(filename, fileno(f)); - pl = parse_patch(f, NULL, &num_patches); + wiggle_check_dir(filename, fileno(f)); + pl = wiggle_parse_patch(f, NULL, &num_patches); fclose(f); - if (set_prefix(pl, num_patches, strip) == 0) { - fprintf(stderr, "%s: aborting\n", Cmd); + if (wiggle_set_prefix(pl, num_patches, strip) == 0) { + fprintf(stderr, "%s: aborting\n", wiggle_Cmd); return 2; } for (i = 0; i < num_patches; i++) { @@ -683,7 +683,7 @@ int main(int argc, char *argv[]) trace = getenv("WIGGLE_TRACE"); if (trace && *trace) - do_trace = 1; + wiggle_do_trace = 1; while ((opt = getopt_long(argc, argv, short_options, long_options, @@ -732,7 +732,7 @@ int main(int argc, char *argv[]) } fprintf(stderr, "%s: mode is '%c' - cannot set to '%c'\n", - Cmd, mode, opt); + wiggle_Cmd, mode, opt); exit(2); case NON_SPACE: @@ -750,7 +750,7 @@ int main(int argc, char *argv[]) continue; } fprintf(stderr, - "%s: cannot select both words and lines.\n", Cmd); + "%s: cannot select both words and lines.\n", wiggle_Cmd); exit(2); case 'r': @@ -790,7 +790,7 @@ int main(int argc, char *argv[]) continue; } fprintf(stderr, - "%s: can only select one of -1, -2, -3\n", Cmd); + "%s: can only select one of -1, -2, -3\n", wiggle_Cmd); exit(2); case 'p': /* 'patch' or 'strip' */ @@ -824,36 +824,36 @@ int main(int argc, char *argv[]) if (obj && mode == 'x') { fprintf(stderr, "%s: cannot specify --line or --word with --extract\n", - Cmd); + wiggle_Cmd); exit(2); } if (mode != 'm' && !obj) obj = 'w'; if (ispatch && outfile) { fprintf(stderr, "%s: --output incompatible with --patch\n", - Cmd); + wiggle_Cmd); exit(2); } if (replace && mode != 'm') { fprintf(stderr, - "%s: --replace or --output only allowed with --merge\n", Cmd); + "%s: --replace or --output only allowed with --merge\n", wiggle_Cmd); exit(2); } if (mode == 'x' && !which) { fprintf(stderr, - "%s: must specify -1, -2 or -3 with --extract\n", Cmd); + "%s: must specify -1, -2 or -3 with --extract\n", wiggle_Cmd); exit(2); } if (mode != 'x' && mode != 'd' && which) { fprintf(stderr, "%s: -1, -2 or -3 only allowed with --extract or --diff\n", - Cmd); + wiggle_Cmd); exit(2); } if (ispatch && which == '3') { fprintf(stderr, - "%s: cannot extract -3 from a patch.\n", Cmd); + "%s: cannot extract -3 from a patch.\n", wiggle_Cmd); exit(2); } diff --git a/wiggle.h b/wiggle.h index 90e71f2..2757e7a 100644 --- a/wiggle.h +++ b/wiggle.h @@ -141,54 +141,54 @@ struct plist { char *before, *after; }; -extern struct plist *sort_patches(struct plist *pl, int *np); -extern void plist_free(struct plist *pl, int num); -extern struct plist *parse_patch(FILE *f, FILE *of, int *np); -extern struct stream load_segment(FILE *f, unsigned int start, +extern struct plist *wiggle_sort_patches(struct plist *pl, int *np); +extern void wiggle_plist_free(struct plist *pl, int num); +extern struct plist *wiggle_parse_patch(FILE *f, FILE *of, int *np); +extern struct stream wiggle_load_segment(FILE *f, unsigned int start, unsigned int end); -extern int set_prefix(struct plist *pl, int n, int strip); -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*, +extern int wiggle_set_prefix(struct plist *pl, int n, int strip); +extern struct stream wiggle_load_file(char *name); +extern int wiggle_split_patch(struct stream, struct stream*, struct stream*); +extern int wiggle_split_merge(struct stream, struct stream*, struct stream*, struct stream*); -extern struct file split_stream(struct stream s, int type); -extern struct csl *pdiff(struct file a, struct file b, int chunks); -extern struct csl *diff(struct file a, struct file b, int shortest); -extern struct csl *diff_patch(struct file a, struct file b, int shortest); -extern struct csl *diff_partial(struct file a, struct file b, +extern struct file wiggle_split_stream(struct stream s, int type); +extern struct csl *wiggle_pdiff(struct file a, struct file b, int chunks); +extern struct csl *wiggle_diff(struct file a, struct file b, int shortest); +extern struct csl *wiggle_diff_patch(struct file a, struct file b, int shortest); +extern struct csl *wiggle_diff_partial(struct file a, struct file b, int alo, int ahi, int blo, int bhi); extern struct csl *worddiff(struct stream f1, struct stream f2, struct file *fl1p, struct file *fl2p); -extern struct csl *csl_join(struct csl *c1, struct csl *c2); +extern struct csl *wiggle_csl_join(struct csl *c1, struct csl *c2); struct ci { int conflicts, wiggles, ignored; struct merge *merger; }; -extern int print_merge(FILE *out, +extern int wiggle_print_merge(FILE *out, struct file *a, struct file *b, struct file *c, int words, struct merge *merger, struct merge *mpos, int streampos, int offsetpos); -extern void printword(FILE *f, struct elmnt e); +extern void wiggle_printword(FILE *f, struct elmnt e); -extern int isolate_conflicts(struct file af, struct file bf, struct file cf, - struct csl *csl1, struct csl *csl2, int words, - struct merge *m, int show_wiggles, int *wigglesp); -extern struct ci make_merger(struct file a, struct file b, struct file c, - struct csl *c1, struct csl *c2, int words, - int ignore_already, int show_wiggles); +extern int wiggle_isolate_conflicts(struct file af, struct file bf, struct file cf, + struct csl *csl1, struct csl *csl2, int words, + struct merge *m, int show_wiggles, int *wigglesp); +extern struct ci wiggle_make_merger(struct file a, struct file b, struct file c, + struct csl *c1, struct csl *c2, int words, + int ignore_already, int show_wiggles); -extern void die(char *reason); -extern void check_dir(char *name, int fd); -extern void *xmalloc(int len); -extern int do_trace; +extern void wiggle_die(char *reason); +extern void wiggle_check_dir(char *name, int fd); +extern void *wiggle_xmalloc(int len); +extern int wiggle_do_trace; extern int vpatch(int argc, char *argv[], int patch, int strip, int reverse, int replace, char *outfile, int selftest, int ignore_blanks, int backup); -extern char *Cmd; +extern char *wiggle_Cmd; extern char Version[]; extern char short_options[]; extern struct option long_options[]; -- 2.39.5