- just whitespace

This commit is contained in:
Bernhard Reutner-Fischer 2006-05-29 12:12:45 +00:00
parent d2c306e862
commit bbc225e13d

View File

@ -68,6 +68,7 @@
/* Command line options */ /* Command line options */
static unsigned long cmd_flags; static unsigned long cmd_flags;
#define FLAG_a (1<<0) #define FLAG_a (1<<0)
#define FLAG_b (1<<1) #define FLAG_b (1<<1)
#define FLAG_d (1<<2) #define FLAG_d (1<<2)
@ -134,14 +135,15 @@ static void print_only(const char *path, size_t dirlen, const char *entry)
{ {
if (dirlen > 1) if (dirlen > 1)
dirlen--; dirlen--;
printf("Only in %.*s: %s\n", (int)dirlen, path, entry); printf("Only in %.*s: %s\n", (int) dirlen, path, 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 *_path1 = entry ? concat_path_file(path1, _entry) : path1;
char *_path2 = entry ? concat_path_file(path2, _entry) : path2; char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
switch (val) { switch (val) {
case D_ONLY: case D_ONLY:
print_only(path1, strlen(path1), entry); print_only(path1, strlen(path1), entry);
@ -186,7 +188,7 @@ static void print_status(int val, char *path1, char *path2, char *entry)
/* /*
* 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.
*/ */
static int readhash(FILE *f) static int readhash(FILE * f)
{ {
int i, t, space; int i, t, space;
int sum; int sum;
@ -202,8 +204,7 @@ static int readhash(FILE *f)
break; break;
} }
sum = sum * 127 + t; sum = sum * 127 + t;
} } else
else
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)
@ -253,15 +254,15 @@ static int readhash(FILE *f)
* Check to see if the given files differ. * Check to see if the given files differ.
* Returns 0 if they are the same, 1 if different, and -1 on error. * Returns 0 if they are the same, 1 if different, and -1 on error.
*/ */
static int files_differ(FILE *f1, FILE *f2, int flags) static int files_differ(FILE * f1, FILE * f2, int flags)
{ {
char buf1[BUFSIZ], buf2[BUFSIZ]; char buf1[BUFSIZ], buf2[BUFSIZ];
size_t i, j; size_t i, j;
if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size ||
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
return (1); return (1);
while(1) { while (1) {
i = fread(buf1, 1, sizeof(buf1), f1); i = fread(buf1, 1, sizeof(buf1), f1);
j = fread(buf2, 1, sizeof(buf2), f2); j = fread(buf2, 1, sizeof(buf2), f2);
if (i != j) if (i != j)
@ -276,7 +277,7 @@ static int files_differ(FILE *f1, FILE *f2, int flags)
} }
} }
static void prepare(int i, FILE *fd, off_t filesize) static void prepare(int i, FILE * fd, off_t filesize)
{ {
struct line *p; struct line *p;
int h; int h;
@ -305,13 +306,10 @@ 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; file[0][pref + 1].value == file[1][pref + 1].value; pref++);
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;
@ -347,9 +345,12 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
c[j] = -1; c[j] = -1;
} }
static int isqrt(int n) { static int isqrt(int n)
{
int y, x = 1; int y, x = 1;
if (n == 0) return(0);
if (n == 0)
return (0);
do { do {
y = x; y = x;
@ -406,8 +407,10 @@ static int stone(int *a, int n, int *b, int *c)
int i, k, y, j, l; int i, k, y, j, l;
int oldc, tc, oldl; int oldc, tc, oldl;
unsigned int numtries; unsigned int numtries;
#if ENABLE_FEATURE_DIFF_MINIMAL #if ENABLE_FEATURE_DIFF_MINIMAL
const unsigned int bound = (cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n)); const unsigned int bound =
(cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
#else #else
const unsigned int bound = MAX(256, isqrt(n)); const unsigned int bound = MAX(256, isqrt(n));
#endif #endif
@ -451,8 +454,7 @@ static void unravel(int p)
int i; int i;
for (i = 0; i <= len[0]; i++) for (i = 0; i <= len[0]; i++)
J[i] = i <= pref ? i : J[i] = i <= pref ? i : i > len[0] - suff ? i + len[1] - len[0] : 0;
i > len[0] - suff ? i + len[1] - len[0] : 0;
for (q = clist + p; q->y != 0; q = clist + q->pred) for (q = clist + p; q->y != 0; q = clist + q->pred)
J[q->x + pref] = q->y + pref; J[q->x + pref] = q->y + pref;
} }
@ -470,7 +472,7 @@ static void unsort(struct line *f, int l, int *b)
free(a); free(a);
} }
static int skipline(FILE *f) static int skipline(FILE * f)
{ {
int i, c; int i, c;
@ -486,7 +488,7 @@ static int skipline(FILE *f)
* to confounding by hashing (which result in "jackpot") * to confounding by hashing (which result in "jackpot")
* 2. collect random access indexes to the two files * 2. collect random access indexes to the two files
*/ */
static void check(FILE *f1, FILE *f2) static void check(FILE * f1, FILE * f2)
{ {
int i, j, jackpot, c, d; int i, j, jackpot, c, d;
long ctold, ctnew; long ctold, ctnew;
@ -506,7 +508,8 @@ static void check(FILE *f1, FILE *f2)
ixnew[j] = ctnew += skipline(f2); ixnew[j] = ctnew += skipline(f2);
j++; j++;
} }
if ((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w) || (cmd_flags & FLAG_i)) { if ((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)
|| (cmd_flags & FLAG_i)) {
while (1) { while (1) {
c = getc(f1); c = getc(f1);
d = getc(f2); d = getc(f2);
@ -515,8 +518,7 @@ static void check(FILE *f1, FILE *f2)
* in one file if bflag || wflag. * in one file if bflag || wflag.
*/ */
if (((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)) && if (((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)) &&
((c == EOF && d == '\n') || ((c == EOF && d == '\n') || (c == '\n' && d == EOF))) {
(c == '\n' && d == EOF))) {
break; break;
} }
ctold++; ctold++;
@ -596,8 +598,7 @@ static void sort(struct line *a, int n)
if (aim < ai) if (aim < ai)
break; /* wraparound */ break; /* wraparound */
if (aim->value > ai[0].value || if (aim->value > ai[0].value ||
(aim->value == ai[0].value && (aim->value == ai[0].value && aim->serial > ai[0].serial))
aim->serial > ai[0].serial))
break; break;
w.value = ai[0].value; w.value = ai[0].value;
ai[0].value = aim->value; ai[0].value = aim->value;
@ -621,7 +622,7 @@ static void uni_range(int a, int b)
printf("%d,0", b); printf("%d,0", b);
} }
static int fetch(long *f, int a, int b, FILE *lb, int ch) static int 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;
@ -654,7 +655,7 @@ static int fetch(long *f, int a, int b, FILE *lb, int ch)
return (0); return (0);
} }
static int asciifile(FILE *f) static int asciifile(FILE * f)
{ {
#if ENABLE_FEATURE_DIFF_BINARY #if ENABLE_FEATURE_DIFF_BINARY
unsigned char buf[BUFSIZ]; unsigned char buf[BUFSIZ];
@ -677,7 +678,7 @@ static int asciifile(FILE *f)
} }
/* dump accumulated "unified" diff changes */ /* dump accumulated "unified" diff changes */
static void dump_unified_vec(FILE *f1, FILE *f2) static void dump_unified_vec(FILE * f1, FILE * f2)
{ {
struct context_vec *cvp = context_vec_start; struct context_vec *cvp = context_vec_start;
int lowa, upb, lowc, upd; int lowa, upb, lowc, upd;
@ -757,17 +758,13 @@ static void dump_unified_vec(FILE *f1, FILE *f2)
static void print_header(const char *file1, const char *file2) static void print_header(const char *file1, const char *file2)
{ {
if (label[0] != NULL) if (label[0] != NULL)
printf("%s %s\n", "---", printf("%s %s\n", "---", label[0]);
label[0]);
else else
printf("%s %s\t%s", "---", printf("%s %s\t%s", "---", file1, ctime(&stb1.st_mtime));
file1, ctime(&stb1.st_mtime));
if (label[1] != NULL) if (label[1] != NULL)
printf("%s %s\n", "+++", printf("%s %s\n", "+++", label[1]);
label[1]);
else else
printf("%s %s\t%s", "+++", printf("%s %s\t%s", "+++", file2, ctime(&stb2.st_mtime));
file2, ctime(&stb2.st_mtime));
} }
@ -779,21 +776,26 @@ static void print_header(const char *file1, const char *file2)
* lines appended (beginning at b). If c is greater than d then there are * lines appended (beginning at b). If c is greater than d then there are
* lines missing from the to file. * lines missing from the to file.
*/ */
static void change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d) static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
int b, int c, int d)
{ {
static size_t max_context = 64; static size_t max_context = 64;
if (a > b && c > d) return; if (a > b && c > d)
if (cmd_flags & FLAG_q) return; return;
if (cmd_flags & FLAG_q)
return;
/* /*
* Allocate change records as needed. * Allocate change records as needed.
*/ */
if (context_vec_ptr == context_vec_end - 1) { if (context_vec_ptr == context_vec_end - 1) {
ptrdiff_t offset = context_vec_ptr - context_vec_start; ptrdiff_t offset = context_vec_ptr - context_vec_start;
max_context <<= 1; max_context <<= 1;
context_vec_start = xrealloc(context_vec_start, context_vec_start = xrealloc(context_vec_start,
max_context * sizeof(struct context_vec)); max_context *
sizeof(struct context_vec));
context_vec_end = context_vec_start + max_context; context_vec_end = context_vec_start + max_context;
context_vec_ptr = context_vec_start + offset; context_vec_ptr = context_vec_start + offset;
} }
@ -821,7 +823,7 @@ static void change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, i
} }
static void output(char *file1, FILE *f1, char *file2, FILE *f2) static void output(char *file1, FILE * f1, char *file2, FILE * f2)
{ {
/* Note that j0 and j1 can't be used as they are defined in math.h. /* Note that j0 and j1 can't be used as they are defined in math.h.
@ -950,9 +952,9 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
f2 = bb_xfopen(file2, "r"); f2 = bb_xfopen(file2, "r");
} }
if ((i=files_differ(f1, f2, flags)) == 0) if ((i = files_differ(f1, f2, flags)) == 0)
goto closem; goto closem;
else if (i != 1) {/* 1 == ok */ else if (i != 1) { /* 1 == ok */
/* error */ /* error */
status |= 2; status |= 2;
goto closem; goto closem;
@ -970,11 +972,11 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
sort(sfile[0], slen[0]); sort(sfile[0], slen[0]);
sort(sfile[1], slen[1]); sort(sfile[1], slen[1]);
member = (int *)file[1]; member = (int *) file[1];
equiv(sfile[0], slen[0], sfile[1], slen[1], member); equiv(sfile[0], slen[0], sfile[1], slen[1], member);
member = xrealloc(member, (slen[1] + 2) * sizeof(int)); member = xrealloc(member, (slen[1] + 2) * sizeof(int));
class = (int *)file[0]; class = (int *) file[0];
unsort(sfile[0], slen[0], class); unsort(sfile[0], slen[0], class);
class = xrealloc(class, (slen[0] + 2) * sizeof(int)); class = xrealloc(class, (slen[0] + 2) * sizeof(int));
@ -996,7 +998,7 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
check(f1, f2); check(f1, f2);
output(file1, f1, file2, f2); output(file1, f1, file2, f2);
closem: closem:
if (anychange) { if (anychange) {
status |= 1; status |= 1;
if (rval == D_SAME) if (rval == D_SAME)
@ -1014,7 +1016,8 @@ closem:
} }
#if ENABLE_FEATURE_DIFF_DIR #if ENABLE_FEATURE_DIFF_DIR
static void do_diff (char *dir1, char *path1, char *dir2, char *path2) { static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
{
int flags = D_HEADER; int flags = D_HEADER;
int val; int val;
@ -1054,27 +1057,31 @@ static void do_diff (char *dir1, char *path1, char *dir2, char *path2) {
#endif #endif
#if ENABLE_FEATURE_DIFF_DIR #if ENABLE_FEATURE_DIFF_DIR
static int dir_strcmp(const void *p1, const void *p2) { static int dir_strcmp(const void *p1, const void *p2)
return strcmp(*(char * const *)p1, *(char * const *)p2); {
return strcmp(*(char *const *) p1, *(char *const *) p2);
} }
/* This function adds a filename to dl, the directory listing. */ /* This function adds a filename to dl, the directory listing. */
static int add_to_dirlist (const char *filename, static int add_to_dirlist(const char *filename,
struct stat ATTRIBUTE_UNUSED *sb, void *userdata) { struct stat ATTRIBUTE_UNUSED * sb, void *userdata)
{
dl_count++; dl_count++;
dl = xrealloc(dl, dl_count * sizeof(char *)); dl = xrealloc(dl, dl_count * sizeof(char *));
dl[dl_count - 1] = bb_xstrdup(filename); dl[dl_count - 1] = bb_xstrdup(filename);
if (cmd_flags & FLAG_r) { if (cmd_flags & FLAG_r) {
int *pp = (int *) userdata; int *pp = (int *) userdata;
int path_len = *pp + 1; int path_len = *pp + 1;
dl[dl_count - 1] = &(dl[dl_count - 1])[path_len]; dl[dl_count - 1] = &(dl[dl_count - 1])[path_len];
} }
return TRUE; return TRUE;
} }
/* This returns a sorted directory listing. */ /* This returns a sorted directory listing. */
static char **get_dir(char *path) { static char **get_dir(char *path)
{
int i; int i;
char **retval; char **retval;
@ -1094,7 +1101,8 @@ static char **get_dir(char *path) {
/* Now fill dl with a listing. */ /* Now fill dl with a listing. */
if (cmd_flags & FLAG_r) if (cmd_flags & FLAG_r)
recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL, userdata); recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL,
userdata);
else { else {
DIR *dp; DIR *dp;
struct dirent *ep; struct dirent *ep;
@ -1119,7 +1127,8 @@ static char **get_dir(char *path) {
return retval; return retval;
} }
static void diffdir (char *p1, char *p2) { static void diffdir(char *p1, char *p2)
{
char **dirlist1, **dirlist2; char **dirlist1, **dirlist2;
char *dp1, *dp2; char *dp1, *dp2;
@ -1164,15 +1173,13 @@ static void diffdir (char *p1, char *p2) {
do_diff(p1, dp1, p2, dp2); do_diff(p1, dp1, p2, dp2);
dirlist1++; dirlist1++;
dirlist2++; dirlist2++;
} } else if (pos < 0) {
else if (pos < 0) {
if (cmd_flags & FLAG_N) if (cmd_flags & FLAG_N)
do_diff(p1, dp1, p2, NULL); do_diff(p1, dp1, p2, NULL);
else else
print_only(p1, strlen(p1) + 1, dp1); print_only(p1, strlen(p1) + 1, dp1);
dirlist1++; dirlist1++;
} } else {
else {
if (cmd_flags & FLAG_N) if (cmd_flags & FLAG_N)
do_diff(p1, NULL, p2, dp2); do_diff(p1, NULL, p2, dp2);
else else
@ -1185,14 +1192,18 @@ static void diffdir (char *p1, char *p2) {
int diff_main(int argc, char **argv) { int diff_main(int argc, char **argv)
{
char *ep; char *ep;
int gotstdin = 0; int gotstdin = 0;
char *U_opt; char *U_opt;
llist_t *L_arg = NULL; llist_t *L_arg = NULL;
bb_opt_complementally = "L::"; bb_opt_complementally = "L::";
cmd_flags = bb_getopt_ulflags(argc, argv, "abdiL:NqrsS:tTU:wu", &L_arg, &start, &U_opt); cmd_flags =
bb_getopt_ulflags(argc, argv, "abdiL:NqrsS:tTU:wu", &L_arg, &start,
&U_opt);
if (cmd_flags & FLAG_L) { if (cmd_flags & FLAG_L) {
while (L_arg) { while (L_arg) {
@ -1209,6 +1220,7 @@ int diff_main(int argc, char **argv) {
/* If both label[0] and label[1] were set, they need to be swapped. */ /* If both label[0] and label[1] were set, they need to be swapped. */
if (label[0] && label[1]) { if (label[0] && label[1]) {
char *tmp; char *tmp;
tmp = label[1]; tmp = label[1];
label[1] = label[0]; label[1] = label[0];
label[0] = tmp; label[0] = tmp;
@ -1252,8 +1264,7 @@ int diff_main(int argc, char **argv) {
#else #else
bb_error_msg_and_die("Directory comparison not supported"); bb_error_msg_and_die("Directory comparison not supported");
#endif #endif
} } else {
else {
if (S_ISDIR(stb1.st_mode)) { if (S_ISDIR(stb1.st_mode)) {
argv[0] = concat_path_file(argv[0], argv[1]); argv[0] = concat_path_file(argv[0], argv[1]);
xstat(argv[0], &stb1); xstat(argv[0], &stb1);
@ -1266,4 +1277,3 @@ int diff_main(int argc, char **argv) {
} }
exit(status); exit(status);
} }