mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 00:55:11 +00:00
- FIXME: someone broke diff -r
- minor shrinkage i had lying around text data bss dec hex filename 7002 8 88 7098 1bba diff.o.orig 6936 8 81 7025 1b71 diff.o
This commit is contained in:
parent
5568b722d4
commit
7ae93f0fe7
@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
/* XXX: FIXME: the following variables should be static, but gcc currently
|
/* 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] */
|
* 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. */
|
/* This is the default number of lines of context. */
|
||||||
int context = 3;
|
int context = 3;
|
||||||
int status;
|
int status;
|
||||||
@ -75,7 +76,7 @@ const char *label1;
|
|||||||
const char *label2;
|
const char *label2;
|
||||||
struct stat stb1, stb2;
|
struct stat stb1, stb2;
|
||||||
char **dl;
|
char **dl;
|
||||||
USE_FEATURE_DIFF_DIR(static int dl_count;)
|
USE_FEATURE_DIFF_DIR(int dl_count;)
|
||||||
|
|
||||||
struct cand {
|
struct cand {
|
||||||
int x;
|
int x;
|
||||||
@ -108,7 +109,7 @@ static int clen;
|
|||||||
static int len[2];
|
static int len[2];
|
||||||
static int pref, suff; /* length of prefix and suffix */
|
static int pref, suff; /* length of prefix and suffix */
|
||||||
static int slen[2];
|
static int slen[2];
|
||||||
static int anychange;
|
static smallint anychange;
|
||||||
static long *ixnew; /* will be overlaid on file[1] */
|
static long *ixnew; /* will be overlaid on file[1] */
|
||||||
static long *ixold; /* will be overlaid on klist */
|
static long *ixold; /* will be overlaid on klist */
|
||||||
static struct cand *clist; /* merely a free storage pot for candidates */
|
static struct cand *clist; /* merely a free storage pot for candidates */
|
||||||
@ -129,9 +130,9 @@ static void print_only(const char *path, size_t dirlen, const char *entry)
|
|||||||
|
|
||||||
static void print_status(int val, char *path1, char *path2, char *entry)
|
static void print_status(int val, char *path1, char *path2, char *entry)
|
||||||
{
|
{
|
||||||
const char *const _entry = entry ? entry : "";
|
const char * const _entry = entry ? entry : "";
|
||||||
char *_path1 = entry ? concat_path_file(path1, _entry) : path1;
|
char * const _path1 = entry ? concat_path_file(path1, _entry) : path1;
|
||||||
char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
|
char * const _path2 = entry ? concat_path_file(path2, _entry) : path2;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case D_ONLY:
|
case D_ONLY:
|
||||||
@ -173,8 +174,10 @@ static void print_status(int val, char *path1, char *path2, char *entry)
|
|||||||
free(_path2);
|
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.
|
* Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
|
||||||
*/
|
*/
|
||||||
@ -186,23 +189,14 @@ static int readhash(FILE * f)
|
|||||||
sum = 1;
|
sum = 1;
|
||||||
space = 0;
|
space = 0;
|
||||||
if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
|
if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
|
||||||
if (FLAG_i)
|
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
if (t == EOF) {
|
||||||
if (t == EOF) {
|
if (i == 0)
|
||||||
if (i == 0)
|
return 0;
|
||||||
return 0;
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
fiddle_sum(&sum, t);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0;;) {
|
for (i = 0;;) {
|
||||||
switch (t = getc(f)) {
|
switch (t = getc(f)) {
|
||||||
@ -218,7 +212,7 @@ static int readhash(FILE * f)
|
|||||||
i++;
|
i++;
|
||||||
space = 0;
|
space = 0;
|
||||||
}
|
}
|
||||||
sum = sum * 127 + t;
|
fiddle_sum(&sum, t);
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
@ -298,10 +292,12 @@ static void prune(void)
|
|||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
for (pref = 0; pref < len[0] && pref < len[1] &&
|
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 &&
|
for (suff = 0; suff < len[0] - pref && suff < len[1] - pref &&
|
||||||
file[0][len[0] - suff].value == file[1][len[1] - suff].value;
|
file[0][len[0] - suff].value == file[1][len[1] - suff].value;
|
||||||
suff++);
|
suff++)
|
||||||
|
;
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
sfile[j] = file[j] + pref;
|
sfile[j] = file[j] + pref;
|
||||||
slen[j] = len[j] - pref - suff;
|
slen[j] = len[j] - pref - suff;
|
||||||
@ -621,12 +617,12 @@ static void uni_range(int a, int b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
int i, j, c, lastc, col, nc;
|
||||||
|
|
||||||
if (a > b)
|
if (a > b)
|
||||||
return 0;
|
return;
|
||||||
for (i = a; i <= b; i++) {
|
for (i = a; i <= b; i++) {
|
||||||
fseek(lb, f[i - 1], SEEK_SET);
|
fseek(lb, f[i - 1], SEEK_SET);
|
||||||
nc = f[i] - f[i - 1];
|
nc = f[i] - f[i - 1];
|
||||||
@ -638,8 +634,8 @@ static int fetch(long *f, int a, int b, FILE * lb, int ch)
|
|||||||
col = 0;
|
col = 0;
|
||||||
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
|
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
|
||||||
if ((c = getc(lb)) == EOF) {
|
if ((c = getc(lb)) == EOF) {
|
||||||
puts("\n\\ No newline at end of file");
|
printf("\n\\ No newline at end of file\n");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if (c == '\t' && (option_mask32 & FLAG_t)) {
|
if (c == '\t' && (option_mask32 & FLAG_t)) {
|
||||||
do {
|
do {
|
||||||
@ -651,7 +647,7 @@ static int fetch(long *f, int a, int b, FILE * lb, int ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -695,12 +691,11 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
|
|||||||
lowc = MAX(1, cvp->c - context);
|
lowc = MAX(1, cvp->c - context);
|
||||||
upd = MIN(len[1], context_vec_ptr->d + context);
|
upd = MIN(len[1], context_vec_ptr->d + context);
|
||||||
|
|
||||||
fputs("@@ -", stdout);
|
printf("@@ -");
|
||||||
uni_range(lowa, upb);
|
uni_range(lowa, upb);
|
||||||
fputs(" +", stdout);
|
printf(" +");
|
||||||
uni_range(lowc, upd);
|
uni_range(lowc, upd);
|
||||||
fputs(" @@", stdout);
|
printf(" @@\n");
|
||||||
putchar('\n');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output changes in "unified" diff format--the old and new lines
|
* Output changes in "unified" diff format--the old and new lines
|
||||||
@ -894,13 +889,12 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
|
|||||||
* 3*(number of k-candidates installed), typically about
|
* 3*(number of k-candidates installed), typically about
|
||||||
* 6n words for files of length n.
|
* 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 *file1 = ofile1;
|
||||||
char *file2 = ofile2;
|
char *file2 = ofile2;
|
||||||
FILE *f1 = stdin;
|
FILE *f1 = stdin, *f2 = stdin;
|
||||||
FILE *f2 = stdin;
|
unsigned rval;
|
||||||
int rval = D_SAME;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
anychange = 0;
|
anychange = 0;
|
||||||
@ -908,6 +902,9 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
|
|||||||
|
|
||||||
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
|
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
|
||||||
return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
|
return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
|
||||||
|
|
||||||
|
rval = D_SAME;
|
||||||
|
|
||||||
if (LONE_DASH(file1) && LONE_DASH(file2))
|
if (LONE_DASH(file1) && LONE_DASH(file2))
|
||||||
goto closem;
|
goto closem;
|
||||||
|
|
||||||
@ -980,10 +977,8 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
|
|||||||
if (rval == D_SAME)
|
if (rval == D_SAME)
|
||||||
rval = D_DIFFER;
|
rval = D_DIFFER;
|
||||||
}
|
}
|
||||||
if (f1 != NULL)
|
fclose_if_not_stdin(f1);
|
||||||
fclose(f1);
|
fclose_if_not_stdin(f2);
|
||||||
if (f2 != NULL)
|
|
||||||
fclose(f2);
|
|
||||||
if (file1 != ofile1)
|
if (file1 != ofile1)
|
||||||
free(file1);
|
free(file1);
|
||||||
if (file2 != ofile2)
|
if (file2 != ofile2)
|
||||||
@ -998,19 +993,23 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
|
|||||||
int flags = D_HEADER;
|
int flags = D_HEADER;
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
char *fullpath1 = xasprintf("%s/%s", dir1, path1);
|
char *fullpath1 = concat_path_file(dir1, path1);
|
||||||
char *fullpath2 = xasprintf("%s/%s", dir2, path2);
|
char *fullpath2 = concat_path_file(dir2, path2);
|
||||||
|
|
||||||
if (stat(fullpath1, &stb1) != 0) {
|
if (stat(fullpath1, &stb1) != 0) {
|
||||||
flags |= D_EMPTY1;
|
flags |= D_EMPTY1;
|
||||||
memset(&stb1, 0, sizeof(stb1));
|
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) {
|
if (stat(fullpath2, &stb2) != 0) {
|
||||||
flags |= D_EMPTY2;
|
flags |= D_EMPTY2;
|
||||||
memset(&stb2, 0, sizeof(stb2));
|
memset(&stb2, 0, sizeof(stb2));
|
||||||
stb2.st_mode = stb1.st_mode;
|
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)
|
if (stb1.st_mode == 0)
|
||||||
@ -1173,7 +1172,7 @@ static void diffdir(char *p1, char *p2)
|
|||||||
|
|
||||||
int diff_main(int argc, char **argv)
|
int diff_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int gotstdin = 0;
|
smallint gotstdin = 0;
|
||||||
char *U_opt;
|
char *U_opt;
|
||||||
char *f1, *f2;
|
char *f1, *f2;
|
||||||
llist_t *L_arg = NULL;
|
llist_t *L_arg = NULL;
|
||||||
@ -1234,6 +1233,7 @@ int diff_main(int argc, char **argv)
|
|||||||
f2 = concat_path_file(f2, f1);
|
f2 = concat_path_file(f2, f1);
|
||||||
xstat(f2, &stb2);
|
xstat(f2, &stb2);
|
||||||
}
|
}
|
||||||
|
/* XXX: FIXME: */
|
||||||
/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
|
/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
|
||||||
* This can be fixed (volunteers?) */
|
* This can be fixed (volunteers?) */
|
||||||
if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))
|
if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))
|
||||||
|
Loading…
Reference in New Issue
Block a user