/* XXX: FIXME: the following variables should be static, but gcc currently
* creates a much bigger object if we do this. [which version of gcc? --vda] */
+/* 4.x, IIRC also 3.x --bernhard */
/* This is the default number of lines of context. */
int context = 3;
int status;
const char *label2;
struct stat stb1, stb2;
char **dl;
-USE_FEATURE_DIFF_DIR(static int dl_count;)
+USE_FEATURE_DIFF_DIR(int dl_count;)
struct cand {
int x;
static int len[2];
static int pref, suff; /* length of prefix and suffix */
static int slen[2];
-static int anychange;
+static smallint anychange;
static long *ixnew; /* will be overlaid on file[1] */
static long *ixold; /* will be overlaid on klist */
static struct cand *clist; /* merely a free storage pot for candidates */
static void print_status(int val, char *path1, char *path2, char *entry)
{
- const char *const _entry = entry ? entry : "";
- char *_path1 = entry ? concat_path_file(path1, _entry) : path1;
- char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
+ const char * const _entry = entry ? entry : "";
+ char * const _path1 = entry ? concat_path_file(path1, _entry) : path1;
+ char * const _path2 = entry ? concat_path_file(path2, _entry) : path2;
switch (val) {
case D_ONLY:
free(_path2);
}
}
-
-
+static void fiddle_sum(int *sum, int t)
+{
+ *sum = (int)(*sum * 127 + t);
+}
/*
* Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
*/
sum = 1;
space = 0;
if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
- if (FLAG_i)
- for (i = 0; (t = getc(f)) != '\n'; i++) {
- if (t == EOF) {
- if (i == 0)
- return 0;
- break;
- }
- sum = sum * 127 + t;
- } else
- for (i = 0; (t = getc(f)) != '\n'; i++) {
- if (t == EOF) {
- if (i == 0)
- return 0;
- break;
- }
- sum = sum * 127 + t;
+ for (i = 0; (t = getc(f)) != '\n'; i++) {
+ if (t == EOF) {
+ if (i == 0)
+ return 0;
+ break;
}
+ fiddle_sum(&sum, t);
+ }
} else {
for (i = 0;;) {
switch (t = getc(f)) {
i++;
space = 0;
}
- sum = sum * 127 + t;
+ fiddle_sum(&sum, t);
i++;
continue;
case EOF:
int i, j;
for (pref = 0; pref < len[0] && pref < len[1] &&
- file[0][pref + 1].value == file[1][pref + 1].value; pref++);
+ file[0][pref + 1].value == file[1][pref + 1].value; pref++)
+ ;
for (suff = 0; suff < len[0] - pref && suff < len[1] - pref &&
file[0][len[0] - suff].value == file[1][len[1] - suff].value;
- suff++);
+ suff++)
+ ;
for (j = 0; j < 2; j++) {
sfile[j] = file[j] + pref;
slen[j] = len[j] - pref - suff;
}
-static int fetch(long *f, int a, int b, FILE * lb, int ch)
+static void fetch(long *f, int a, int b, FILE * lb, int ch)
{
int i, j, c, lastc, col, nc;
if (a > b)
- return 0;
+ return;
for (i = a; i <= b; i++) {
fseek(lb, f[i - 1], SEEK_SET);
nc = f[i] - f[i - 1];
col = 0;
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
if ((c = getc(lb)) == EOF) {
- puts("\n\\ No newline at end of file");
- return 0;
+ printf("\n\\ No newline at end of file\n");
+ return;
}
if (c == '\t' && (option_mask32 & FLAG_t)) {
do {
}
}
}
- return 0;
+ return;
}
lowc = MAX(1, cvp->c - context);
upd = MIN(len[1], context_vec_ptr->d + context);
- fputs("@@ -", stdout);
+ printf("@@ -");
uni_range(lowa, upb);
- fputs(" +", stdout);
+ printf(" +");
uni_range(lowc, upd);
- fputs(" @@", stdout);
- putchar('\n');
+ printf(" @@\n");
/*
* Output changes in "unified" diff format--the old and new lines
* 3*(number of k-candidates installed), typically about
* 6n words for files of length n.
*/
-static int diffreg(char *ofile1, char *ofile2, int flags)
+static unsigned diffreg(char * ofile1, char * ofile2, int flags)
{
char *file1 = ofile1;
char *file2 = ofile2;
- FILE *f1 = stdin;
- FILE *f2 = stdin;
- int rval = D_SAME;
+ FILE *f1 = stdin, *f2 = stdin;
+ unsigned rval;
int i;
anychange = 0;
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
+
+ rval = D_SAME;
+
if (LONE_DASH(file1) && LONE_DASH(file2))
goto closem;
if (rval == D_SAME)
rval = D_DIFFER;
}
- if (f1 != NULL)
- fclose(f1);
- if (f2 != NULL)
- fclose(f2);
+ fclose_if_not_stdin(f1);
+ fclose_if_not_stdin(f2);
if (file1 != ofile1)
free(file1);
if (file2 != ofile2)
int flags = D_HEADER;
int val;
- char *fullpath1 = xasprintf("%s/%s", dir1, path1);
- char *fullpath2 = xasprintf("%s/%s", dir2, path2);
+ char *fullpath1 = concat_path_file(dir1, path1);
+ char *fullpath2 = concat_path_file(dir2, path2);
if (stat(fullpath1, &stb1) != 0) {
flags |= D_EMPTY1;
memset(&stb1, 0, sizeof(stb1));
- fullpath1 = xasprintf("%s/%s", dir1, path2);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(fullpath1);
+ fullpath1 = concat_path_file(dir1, path2);
}
if (stat(fullpath2, &stb2) != 0) {
flags |= D_EMPTY2;
memset(&stb2, 0, sizeof(stb2));
stb2.st_mode = stb1.st_mode;
- fullpath2 = xasprintf("%s/%s", dir2, path1);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(fullpath2);
+ fullpath2 = concat_path_file(dir2, path1);
}
if (stb1.st_mode == 0)
int diff_main(int argc, char **argv)
{
- int gotstdin = 0;
+ smallint gotstdin = 0;
char *U_opt;
char *f1, *f2;
llist_t *L_arg = NULL;
f2 = concat_path_file(f2, f1);
xstat(f2, &stb2);
}
+/* XXX: FIXME: */
/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
* This can be fixed (volunteers?) */
if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))