unsigned long flags;
/* -I<regex> */
+ #if 0 // unused by Vim
regex_t **ignore_regex;
size_t ignore_regex_nr;
+#endif
- /* See Documentation/diff-options.txt. */
+ /* See Documentation/diff-options.adoc. */
char **anchors;
size_t anchors_nr;
} xpparam_t;
m->indent = -1;
} else {
m->end_of_file = 0;
- m->indent = xget_indent(xdf->recs[split]);
- m->indent = get_indent(&xdf->recs[split]);
++ m->indent = xget_indent(&xdf->recs[split]);
}
m->pre_blank = 0;
m->pre_indent = -1;
for (i = split - 1; i >= 0; i--) {
- m->pre_indent = xget_indent(xdf->recs[i]);
- m->pre_indent = get_indent(&xdf->recs[i]);
++ m->pre_indent = xget_indent(&xdf->recs[i]);
if (m->pre_indent != -1)
break;
m->pre_blank += 1;
m->post_blank = 0;
m->post_indent = -1;
for (i = split + 1; i < xdf->nrec; i++) {
- m->post_indent = xget_indent(xdf->recs[i]);
- m->post_indent = get_indent(&xdf->recs[i]);
++ m->post_indent = xget_indent(&xdf->recs[i]);
if (m->post_indent != -1)
break;
m->post_blank += 1;
}
}
- static void xdl_bug(const char *msg)
++void xdl_bug(const char *msg)
+{
+ fprintf(stderr, "BUG: %s\n", msg);
+ exit(1);
+}
+
/*
* Move back and forward change groups for a consistent and pretty diff output.
* This also helps in finding joinable change groups and reducing the diff
}
}
+#if 0 // unused by Vim
static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) {
regmatch_t regmatch;
- int i;
+ size_t i;
for (i = 0; i < xpp->ignore_regex_nr; i++)
if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,
#include "xinclude.h"
- static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) {
- *rec = xdf->recs[ri]->ptr;
-
- return xdf->recs[ri]->size;
- }
-
-
- static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) {
- long size, psize = (long)strlen(pre);
- char const *rec;
-
- size = xdl_get_rec(xdf, ri, &rec);
- if (xdl_emit_diffrec(rec, size, pre, psize, ecb) < 0) {
+ static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb)
+ {
+ xrecord_t *rec = &xdf->recs[ri];
- if (xdl_emit_diffrec(rec->ptr, rec->size, pre, strlen(pre), ecb) < 0)
++ if (xdl_emit_diffrec(rec->ptr, rec->size, pre, (long)strlen(pre), ecb) < 0)
return -1;
- }
return 0;
}
++#define signed_add_overflows(a, b) \
++ ((b) > LONG_MAX - (a))
++
+ static long saturating_add(long a, long b)
+ {
+ return signed_add_overflows(a, b) ? LONG_MAX : a + b;
+ }
+
++#undef signed_add_overflows
+
/*
* Starting at the passed change atom, find the latest change atom to be included
* inside the differential hunk according to the specified configuration.
static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
char *buf, long sz)
{
- const char *rec;
- long len = xdl_get_rec(xdf, ri, &rec);
+ xrecord_t *rec = &xdf->recs[ri];
+
if (!xecfg->find_func)
- return def_ff(rec, len, buf, sz);
- return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
+ return def_ff(rec->ptr, rec->size, buf, sz);
+ return xecfg->find_func(rec->ptr, rec->size, buf, sz, xecfg->find_func_priv);
}
+#endif
+#if 0
static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
{
char dummy[1];
}
return -1;
}
+#endif
+#if 0
static int is_empty_rec(xdfile_t *xdf, long ri)
{
- const char *rec;
- long len = xdl_get_rec(xdf, ri, &rec);
+ xrecord_t *rec = &xdf->recs[ri];
+ long i = 0;
- while (len > 0 && XDL_ISSPACE(*rec)) {
- rec++;
- len--;
- }
- return !len;
+ for (; i < rec->size && XDL_ISSPACE(rec->ptr[i]); i++);
+
+ return i == rec->size;
}
+#endif
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg) {
*
*/
+// The following includes come from Vim:
+
+// defines HAVE_ATTRIBUTE_UNUSED
+#ifdef HAVE_CONFIG_H
+# ifdef VMS
+# include "config.h"
+# else
+# include "../auto/config.h"
+# endif
+#endif
+
+// Mark unused function arguments with UNUSED, so that gcc -Wunused-parameter
+// can be used to check for mistakes.
+#if defined(HAVE_ATTRIBUTE_UNUSED) || defined(__MINGW32__)
+# define UNUSED __attribute__((unused))
+#else
+# define UNUSED
+#endif
+
+#if defined(_MSC_VER)
+# define inline __inline
+#endif
+
++// Vim replacement for BUG()
++void xdl_bug(const char *msg);
++
#if !defined(XINCLUDE_H)
#define XINCLUDE_H
/*
* Scans the lines before 'i' to find a run of lines that either
- * have no match (dis[j] == 0) or have multiple matches (dis[j] > 1).
- * Note that we always call this function with dis[i] > 1, so the
- * current line (i) is already a multimatch line.
+ * have no match (action[j] == DISCARD) or have multiple matches
+ * (action[j] == INVESTIGATE). Note that we always call this
+ * function with action[i] == INVESTIGATE, so the current line
+ * (i) is already a multimatch line.
*/
for (r = 1, rdis0 = 0, rpdis0 = 1; (i - r) >= s; r++) {
- if (!dis[i - r])
+ if (action[i - r] == DISCARD)
rdis0++;
- else if (dis[i - r] == 2)
+ else if (action[i - r] == INVESTIGATE)
rpdis0++;
- else
+ else if (action[i - r] == KEEP)
break;
- BUG("Illegal value for action[i - r]");
+ else
++ xdl_bug("Illegal value for action[i - r]");
}
/*
- * If the run before the line 'i' found only multimatch lines, we
- * return 0 and hence we don't make the current line (i) discarded.
- * We want to discard multimatch lines only when they appear in the
- * middle of runs with nomatch lines (dis[j] == 0).
+ * If the run before the line 'i' found only multimatch lines,
+ * we return false and hence we don't make the current line (i)
+ * discarded. We want to discard multimatch lines only when
+ * they appear in the middle of runs with nomatch lines
+ * (action[j] == DISCARD).
*/
if (rdis0 == 0)
return 0;
for (r = 1, rdis1 = 0, rpdis1 = 1; (i + r) <= e; r++) {
- if (!dis[i + r])
+ if (action[i + r] == DISCARD)
rdis1++;
- else if (dis[i + r] == 2)
+ else if (action[i + r] == INVESTIGATE)
rpdis1++;
- else
+ else if (action[i + r] == KEEP)
break;
- BUG("Illegal value for action[i + r]");
+ else
++ xdl_bug("Illegal value for action[i + r]");
}
/*
- * If the run after the line 'i' found only multimatch lines, we
- * return 0 and hence we don't make the current line (i) discarded.
+ * If the run after the line 'i' found only multimatch lines,
+ * we return false and hence we don't make the current line (i)
+ * discarded.
*/
if (rdis1 == 0)
- return 0;
+ return false;
rdis1 += rdis0;
rpdis1 += rpdis0;