commit - 7d283eeedcc17429a90e21e179a6bb5183ffe3c8
commit + cb056f1e59cb36536cf2324d2474beac1b93f1e7
blob - 3f0e7f186d7c57e9a03d09d0121817515a1fbb9d
blob + 423cac042d786ab10e56106a192677d6cc2dcb2a
--- lib/diff.h
+++ lib/diff.h
struct excludes *next;
};
-extern int Nflag, Pflag, rflag, sflag, Tflag;
-extern int diff_format, diff_context, status;
-extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats;
-extern struct stat stb1, stb2;
-extern struct excludes *excludes_list;
-extern regex_t ignore_re;
-
char *splice(char *, char *);
const struct got_error *got_diffreg(int *, char *, char *, int);
int easprintf(char **, const char *, ...);
blob - c2f476a91925fffd9c98f83da921dcdc62aadd0d
blob + 3a45cddd3fcffb2a5f04b6ace9993648e168eeac
--- lib/diffreg.c
+++ lib/diffreg.c
static int lastline;
static int lastmatchline;
-int Nflag, Pflag, rflag, sflag, Tflag;
-int diff_format, diff_context, status;
-char *start, *ifdefname, *diffargs, *label[2], *ignore_pats;
-struct stat stb1, stb2;
-
+struct diff_args {
+ int Tflag;
+ int diff_format, diff_context, status;
+ char *ifdefname, *diffargs, *label[2], *ignore_pats;
+ struct stat stb1, stb2;
+} diff_args;
/*
* chrtran points to one of 2 translation tables: cup2low if folding upper to
FILE *f1, *f2;
int i;
- diff_format = D_UNIFIED;
+ diff_args.diff_format = D_UNIFIED;
if (strcmp(file1, "-") == 0)
- fstat(STDIN_FILENO, &stb1);
- else if (stat(file1, &stb1) != 0)
+ fstat(STDIN_FILENO, &diff_args.stb1);
+ else if (stat(file1, &diff_args.stb1) != 0)
return got_error(GOT_ERR_BAD_PATH);
if (strcmp(file2, "-") == 0)
- fstat(STDIN_FILENO, &stb2);
- else if (stat(file2, &stb2) != 0)
+ fstat(STDIN_FILENO, &diff_args.stb2);
+ else if (stat(file2, &diff_args.stb2) != 0)
return got_error(GOT_ERR_BAD_PATH);
f1 = f2 = NULL;
chrtran = cup2low;
else
chrtran = clow2low;
- if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) {
- *rval = (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
+ if (S_ISDIR(diff_args.stb1.st_mode) != S_ISDIR(diff_args.stb2.st_mode)) {
+ *rval = (S_ISDIR(diff_args.stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
return NULL;
}
if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0)
if (flags & D_EMPTY1)
f1 = fopen(_PATH_DEVNULL, "r");
else {
- if (!S_ISREG(stb1.st_mode)) {
+ if (!S_ISREG(diff_args.stb1.st_mode)) {
if ((f1 = opentemp(file1)) == NULL ||
- fstat(fileno(f1), &stb1) < 0) {
- status |= 2;
+ fstat(fileno(f1), &diff_args.stb1) < 0) {
+ diff_args.status |= 2;
goto closem;
}
} else if (strcmp(file1, "-") == 0)
f1 = fopen(file1, "r");
}
if (f1 == NULL) {
- status |= 2;
+ diff_args.status |= 2;
goto closem;
}
if (flags & D_EMPTY2)
f2 = fopen(_PATH_DEVNULL, "r");
else {
- if (!S_ISREG(stb2.st_mode)) {
+ if (!S_ISREG(diff_args.stb2.st_mode)) {
if ((f2 = opentemp(file2)) == NULL ||
- fstat(fileno(f2), &stb2) < 0) {
- status |= 2;
+ fstat(fileno(f2), &diff_args.stb2) < 0) {
+ diff_args.status |= 2;
goto closem;
}
} else if (strcmp(file2, "-") == 0)
f2 = fopen(file2, "r");
}
if (f2 == NULL) {
- status |= 2;
+ diff_args.status |= 2;
goto closem;
}
break;
default:
/* error */
- status |= 2;
+ diff_args.status |= 2;
goto closem;
}
if ((flags & D_FORCEASCII) == 0 &&
(!asciifile(f1) || !asciifile(f2))) {
*rval = D_BINARY;
- status |= 1;
+ diff_args.status |= 1;
goto closem;
}
- prepare(0, f1, stb1.st_size, flags);
- prepare(1, f2, stb2.st_size, flags);
+ prepare(0, f1, diff_args.stb1.st_size, flags);
+ prepare(1, f2, diff_args.stb2.st_size, flags);
prune();
sort(sfile[0], slen[0]);
output(file1, f1, file2, f2, flags);
closem:
if (anychange) {
- status |= 1;
+ diff_args.status |= 1;
if (*rval == D_SAME)
*rval = D_DIFFER;
}
char buf1[BUFSIZ], buf2[BUFSIZ];
size_t i, j;
- if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size ||
- (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
+ if ((flags & (D_EMPTY1|D_EMPTY2)) || diff_args.stb1.st_size != diff_args.stb2.st_size ||
+ (diff_args.stb1.st_mode & S_IFMT) != (diff_args.stb2.st_mode & S_IFMT))
return (1);
for (;;) {
i = fread(buf1, 1, sizeof(buf1), f1);
m = len[0];
J[0] = 0;
J[m + 1] = len[1] + 1;
- if (diff_format != D_EDIT) {
+ if (diff_args.diff_format != D_EDIT) {
for (i0 = 1; i0 <= m; i0 = i1 + 1) {
while (i0 <= m && J[i0] == J[i0 - 1] + 1)
i0++;
}
if (m == 0)
change(file1, f1, file2, f2, 1, 0, 1, len[1], &flags);
- if (diff_format == D_IFDEF) {
+ if (diff_args.diff_format == D_IFDEF) {
for (;;) {
#define c i0
if ((c = getc(f1)) == EOF)
#undef c
}
if (anychange != 0) {
- if (diff_format == D_CONTEXT)
+ if (diff_args.diff_format == D_CONTEXT)
dump_context_vec(f1, f2, flags);
- else if (diff_format == D_UNIFIED)
+ else if (diff_args.diff_format == D_UNIFIED)
dump_unified_vec(f1, f2, flags);
}
}
int i;
restart:
- if (diff_format != D_IFDEF && a > b && c > d)
+ if (diff_args.diff_format != D_IFDEF && a > b && c > d)
return;
- if (ignore_pats != NULL) {
+ if (diff_args.ignore_pats != NULL) {
char *line;
/*
* All lines in the change, insert, or delete must
}
proceed:
if (*pflags & D_HEADER) {
- diff_output("%s %s %s\n", diffargs, file1, file2);
+ diff_output("%s %s %s\n", diff_args.diffargs, file1, file2);
*pflags &= ~D_HEADER;
}
- if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) {
+ if (diff_args.diff_format == D_CONTEXT || diff_args.diff_format == D_UNIFIED) {
/*
* Allocate change records as needed.
*/
*/
print_header(file1, file2);
anychange = 1;
- } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 &&
- c > context_vec_ptr->d + (2 * diff_context) + 1) {
+ } else if (a > context_vec_ptr->b + (2 * diff_args.diff_context) + 1 &&
+ c > context_vec_ptr->d + (2 * diff_args.diff_context) + 1) {
/*
* If this change is more than 'diff_context' lines from the
* previous change, dump the record and reset it.
*/
- if (diff_format == D_CONTEXT)
+ if (diff_args.diff_format == D_CONTEXT)
dump_context_vec(f1, f2, *pflags);
else
dump_unified_vec(f1, f2, *pflags);
}
if (anychange == 0)
anychange = 1;
- switch (diff_format) {
+ switch (diff_args.diff_format) {
case D_BRIEF:
return;
case D_NORMAL:
case D_EDIT:
range(a, b, ",");
diff_output("%c", a > b ? 'a' : c > d ? 'd' : 'c');
- if (diff_format == D_NORMAL)
+ if (diff_args.diff_format == D_NORMAL)
range(c, d, ",");
diff_output("\n");
break;
}
break;
}
- if (diff_format == D_NORMAL || diff_format == D_IFDEF) {
+ if (diff_args.diff_format == D_NORMAL || diff_args.diff_format == D_IFDEF) {
fetch(ixold, a, b, f1, '<', 1, *pflags);
- if (a <= b && c <= d && diff_format == D_NORMAL)
+ if (a <= b && c <= d && diff_args.diff_format == D_NORMAL)
diff_output("---\n");
}
- i = fetch(ixnew, c, d, f2, diff_format == D_NORMAL ? '>' : '\0', 0, *pflags);
- if (i != 0 && diff_format == D_EDIT) {
+ i = fetch(ixnew, c, d, f2, diff_args.diff_format == D_NORMAL ? '>' : '\0', 0, *pflags);
+ if (i != 0 && diff_args.diff_format == D_EDIT) {
/*
* A non-zero return value for D_EDIT indicates that the
* last line printed was a bare dot (".") that has been
c += i;
goto restart;
}
- if ((diff_format == D_EDIT || diff_format == D_REVERSE) && c <= d)
+ if ((diff_args.diff_format == D_EDIT || diff_args.diff_format == D_REVERSE) && c <= d)
diff_output(".\n");
if (inifdef) {
- diff_output("#endif /* %s */\n", ifdefname);
+ diff_output("#endif /* %s */\n", diff_args.ifdefname);
inifdef = 0;
}
}
* When doing #ifdef's, copy down to current line
* if this is the first file, so that stuff makes it to output.
*/
- if (diff_format == D_IFDEF && oldfile) {
+ if (diff_args.diff_format == D_IFDEF && oldfile) {
long curpos = ftell(lb);
/* print through if append (a>b), else to (nb: 0 vs 1 orig) */
nc = f[a > b ? b : a - 1] - curpos;
}
if (a > b)
return (0);
- if (diff_format == D_IFDEF) {
+ if (diff_args.diff_format == D_IFDEF) {
if (inifdef) {
diff_output("#else /* %s%s */\n",
- oldfile == 1 ? "!" : "", ifdefname);
+ oldfile == 1 ? "!" : "", diff_args.ifdefname);
} else {
if (oldfile)
- diff_output("#ifndef %s\n", ifdefname);
+ diff_output("#ifndef %s\n", diff_args.ifdefname);
else
- diff_output("#ifdef %s\n", ifdefname);
+ diff_output("#ifdef %s\n", diff_args.ifdefname);
}
inifdef = 1 + oldfile;
}
for (i = a; i <= b; i++) {
fseek(lb, f[i - 1], SEEK_SET);
nc = f[i] - f[i - 1];
- if (diff_format != D_IFDEF && ch != '\0') {
+ if (diff_args.diff_format != D_IFDEF && ch != '\0') {
diff_output("%c", ch);
- if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT
- || diff_format == D_UNIFIED))
+ if (diff_args.Tflag && (diff_args.diff_format == D_NORMAL || diff_args.diff_format == D_CONTEXT
+ || diff_args.diff_format == D_UNIFIED))
diff_output("\t");
- else if (diff_format != D_UNIFIED)
+ else if (diff_args.diff_format != D_UNIFIED)
diff_output(" ");
}
col = 0;
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
if ((c = getc(lb)) == EOF) {
- if (diff_format == D_EDIT || diff_format == D_REVERSE ||
- diff_format == D_NREVERSE)
+ if (diff_args.diff_format == D_EDIT || diff_args.diff_format == D_REVERSE ||
+ diff_args.diff_format == D_NREVERSE)
warnx("No newline at end of file");
else
diff_output("\n\\ No newline at end of "
diff_output(" ");
} while (++col & 7);
} else {
- if (diff_format == D_EDIT && j == 1 && c == '\n'
+ if (diff_args.diff_format == D_EDIT && j == 1 && c == '\n'
&& lastc == '.') {
/*
* Don't print a bare "." line
return;
b = d = 0; /* gcc */
- lowa = MAXIMUM(1, cvp->a - diff_context);
- upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
- lowc = MAXIMUM(1, cvp->c - diff_context);
- upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
+ lowa = MAXIMUM(1, cvp->a - diff_args.diff_context);
+ upb = MINIMUM(len[0], context_vec_ptr->b + diff_args.diff_context);
+ lowc = MAXIMUM(1, cvp->c - diff_args.diff_context);
+ upd = MINIMUM(len[1], context_vec_ptr->d + diff_args.diff_context);
diff_output("***************");
if ((flags & D_PROTOTYPE)) {
return;
b = d = 0; /* gcc */
- lowa = MAXIMUM(1, cvp->a - diff_context);
- upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
- lowc = MAXIMUM(1, cvp->c - diff_context);
- upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
+ lowa = MAXIMUM(1, cvp->a - diff_args.diff_context);
+ upb = MINIMUM(len[0], context_vec_ptr->b + diff_args.diff_context);
+ lowc = MAXIMUM(1, cvp->c - diff_args.diff_context);
+ upd = MINIMUM(len[1], context_vec_ptr->d + diff_args.diff_context);
diff_output("@@ -");
uni_range(lowa, upb);
static void
print_header(const char *file1, const char *file2)
{
- if (label[0] != NULL)
- diff_output("%s %s\n", diff_format == D_CONTEXT ? "***" : "---",
- label[0]);
+ if (diff_args.label[0] != NULL)
+ diff_output("%s %s\n", diff_args.diff_format == D_CONTEXT ? "***" : "---",
+ diff_args.label[0]);
else
- diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---",
- file1, ctime(&stb1.st_mtime));
- if (label[1] != NULL)
- diff_output("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++",
- label[1]);
+ diff_output("%s %s\t%s", diff_args.diff_format == D_CONTEXT ? "***" : "---",
+ file1, ctime(&diff_args.stb1.st_mtime));
+ if (diff_args.label[1] != NULL)
+ diff_output("%s %s\n", diff_args.diff_format == D_CONTEXT ? "---" : "+++",
+ diff_args.label[1]);
else
- diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++",
- file2, ctime(&stb2.st_mtime));
+ diff_output("%s %s\t%s", diff_args.diff_format == D_CONTEXT ? "---" : "+++",
+ file2, ctime(&diff_args.stb2.st_mtime));
}