- just whitespace
This commit is contained in:
parent
d2c306e862
commit
bbc225e13d
138
coreutils/diff.c
138
coreutils/diff.c
@ -68,6 +68,7 @@
|
||||
|
||||
/* Command line options */
|
||||
static unsigned long cmd_flags;
|
||||
|
||||
#define FLAG_a (1<<0)
|
||||
#define FLAG_b (1<<1)
|
||||
#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)
|
||||
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)
|
||||
{
|
||||
const char * const _entry = entry ? 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;
|
||||
|
||||
switch (val) {
|
||||
case D_ONLY:
|
||||
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.
|
||||
*/
|
||||
static int readhash(FILE *f)
|
||||
static int readhash(FILE * f)
|
||||
{
|
||||
int i, t, space;
|
||||
int sum;
|
||||
@ -202,8 +204,7 @@ static int readhash(FILE *f)
|
||||
break;
|
||||
}
|
||||
sum = sum * 127 + t;
|
||||
}
|
||||
else
|
||||
} else
|
||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||
if (t == EOF) {
|
||||
if (i == 0)
|
||||
@ -253,15 +254,15 @@ static int readhash(FILE *f)
|
||||
* Check to see if the given files differ.
|
||||
* 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];
|
||||
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))
|
||||
return (1);
|
||||
while(1) {
|
||||
while (1) {
|
||||
i = fread(buf1, 1, sizeof(buf1), f1);
|
||||
j = fread(buf2, 1, sizeof(buf2), f2);
|
||||
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;
|
||||
int h;
|
||||
@ -305,13 +306,10 @@ static void prune(void)
|
||||
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;
|
||||
@ -347,9 +345,12 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
|
||||
c[j] = -1;
|
||||
}
|
||||
|
||||
static int isqrt(int n) {
|
||||
static int isqrt(int n)
|
||||
{
|
||||
int y, x = 1;
|
||||
if (n == 0) return(0);
|
||||
|
||||
if (n == 0)
|
||||
return (0);
|
||||
|
||||
do {
|
||||
y = x;
|
||||
@ -406,8 +407,10 @@ static int stone(int *a, int n, int *b, int *c)
|
||||
int i, k, y, j, l;
|
||||
int oldc, tc, oldl;
|
||||
unsigned int numtries;
|
||||
|
||||
#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
|
||||
const unsigned int bound = MAX(256, isqrt(n));
|
||||
#endif
|
||||
@ -451,8 +454,7 @@ static void unravel(int p)
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= len[0]; i++)
|
||||
J[i] = i <= pref ? i :
|
||||
i > len[0] - suff ? i + len[1] - len[0] : 0;
|
||||
J[i] = i <= pref ? i : i > len[0] - suff ? i + len[1] - len[0] : 0;
|
||||
for (q = clist + p; q->y != 0; q = clist + q->pred)
|
||||
J[q->x + pref] = q->y + pref;
|
||||
}
|
||||
@ -470,7 +472,7 @@ static void unsort(struct line *f, int l, int *b)
|
||||
free(a);
|
||||
}
|
||||
|
||||
static int skipline(FILE *f)
|
||||
static int skipline(FILE * f)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
@ -486,7 +488,7 @@ static int skipline(FILE *f)
|
||||
* to confounding by hashing (which result in "jackpot")
|
||||
* 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;
|
||||
long ctold, ctnew;
|
||||
@ -506,7 +508,8 @@ static void check(FILE *f1, FILE *f2)
|
||||
ixnew[j] = ctnew += skipline(f2);
|
||||
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) {
|
||||
c = getc(f1);
|
||||
d = getc(f2);
|
||||
@ -515,8 +518,7 @@ static void check(FILE *f1, FILE *f2)
|
||||
* in one file if bflag || wflag.
|
||||
*/
|
||||
if (((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)) &&
|
||||
((c == EOF && d == '\n') ||
|
||||
(c == '\n' && d == EOF))) {
|
||||
((c == EOF && d == '\n') || (c == '\n' && d == EOF))) {
|
||||
break;
|
||||
}
|
||||
ctold++;
|
||||
@ -596,8 +598,7 @@ static void sort(struct line *a, int n)
|
||||
if (aim < ai)
|
||||
break; /* wraparound */
|
||||
if (aim->value > ai[0].value ||
|
||||
(aim->value == ai[0].value &&
|
||||
aim->serial > ai[0].serial))
|
||||
(aim->value == ai[0].value && aim->serial > ai[0].serial))
|
||||
break;
|
||||
w.value = ai[0].value;
|
||||
ai[0].value = aim->value;
|
||||
@ -621,7 +622,7 @@ static void uni_range(int a, int 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;
|
||||
|
||||
@ -654,7 +655,7 @@ static int fetch(long *f, int a, int b, FILE *lb, int ch)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int asciifile(FILE *f)
|
||||
static int asciifile(FILE * f)
|
||||
{
|
||||
#if ENABLE_FEATURE_DIFF_BINARY
|
||||
unsigned char buf[BUFSIZ];
|
||||
@ -677,7 +678,7 @@ static int asciifile(FILE *f)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
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)
|
||||
{
|
||||
if (label[0] != NULL)
|
||||
printf("%s %s\n", "---",
|
||||
label[0]);
|
||||
printf("%s %s\n", "---", label[0]);
|
||||
else
|
||||
printf("%s %s\t%s", "---",
|
||||
file1, ctime(&stb1.st_mtime));
|
||||
printf("%s %s\t%s", "---", file1, ctime(&stb1.st_mtime));
|
||||
if (label[1] != NULL)
|
||||
printf("%s %s\n", "+++",
|
||||
label[1]);
|
||||
printf("%s %s\n", "+++", label[1]);
|
||||
else
|
||||
printf("%s %s\t%s", "+++",
|
||||
file2, ctime(&stb2.st_mtime));
|
||||
printf("%s %s\t%s", "+++", 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 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;
|
||||
|
||||
if (a > b && c > d) return;
|
||||
if (cmd_flags & FLAG_q) return;
|
||||
if (a > b && c > d)
|
||||
return;
|
||||
if (cmd_flags & FLAG_q)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Allocate change records as needed.
|
||||
*/
|
||||
if (context_vec_ptr == context_vec_end - 1) {
|
||||
ptrdiff_t offset = context_vec_ptr - context_vec_start;
|
||||
|
||||
max_context <<= 1;
|
||||
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_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.
|
||||
@ -950,9 +952,9 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
|
||||
f2 = bb_xfopen(file2, "r");
|
||||
}
|
||||
|
||||
if ((i=files_differ(f1, f2, flags)) == 0)
|
||||
if ((i = files_differ(f1, f2, flags)) == 0)
|
||||
goto closem;
|
||||
else if (i != 1) {/* 1 == ok */
|
||||
else if (i != 1) { /* 1 == ok */
|
||||
/* error */
|
||||
status |= 2;
|
||||
goto closem;
|
||||
@ -970,11 +972,11 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
|
||||
sort(sfile[0], slen[0]);
|
||||
sort(sfile[1], slen[1]);
|
||||
|
||||
member = (int *)file[1];
|
||||
member = (int *) file[1];
|
||||
equiv(sfile[0], slen[0], sfile[1], slen[1], member);
|
||||
member = xrealloc(member, (slen[1] + 2) * sizeof(int));
|
||||
|
||||
class = (int *)file[0];
|
||||
class = (int *) file[0];
|
||||
unsort(sfile[0], slen[0], class);
|
||||
class = xrealloc(class, (slen[0] + 2) * sizeof(int));
|
||||
|
||||
@ -996,7 +998,7 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
|
||||
check(f1, f2);
|
||||
output(file1, f1, file2, f2);
|
||||
|
||||
closem:
|
||||
closem:
|
||||
if (anychange) {
|
||||
status |= 1;
|
||||
if (rval == D_SAME)
|
||||
@ -1014,7 +1016,8 @@ closem:
|
||||
}
|
||||
|
||||
#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 val;
|
||||
@ -1054,27 +1057,31 @@ static void do_diff (char *dir1, char *path1, char *dir2, char *path2) {
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_DIFF_DIR
|
||||
static int dir_strcmp(const void *p1, const void *p2) {
|
||||
return strcmp(*(char * const *)p1, *(char * const *)p2);
|
||||
static int dir_strcmp(const void *p1, const void *p2)
|
||||
{
|
||||
return strcmp(*(char *const *) p1, *(char *const *) p2);
|
||||
}
|
||||
|
||||
/* This function adds a filename to dl, the directory listing. */
|
||||
|
||||
static int add_to_dirlist (const char *filename,
|
||||
struct stat ATTRIBUTE_UNUSED *sb, void *userdata) {
|
||||
static int add_to_dirlist(const char *filename,
|
||||
struct stat ATTRIBUTE_UNUSED * sb, void *userdata)
|
||||
{
|
||||
dl_count++;
|
||||
dl = xrealloc(dl, dl_count * sizeof(char *));
|
||||
dl[dl_count - 1] = bb_xstrdup(filename);
|
||||
if (cmd_flags & FLAG_r) {
|
||||
int *pp = (int *) userdata;
|
||||
int path_len = *pp + 1;
|
||||
|
||||
dl[dl_count - 1] = &(dl[dl_count - 1])[path_len];
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* This returns a sorted directory listing. */
|
||||
static char **get_dir(char *path) {
|
||||
static char **get_dir(char *path)
|
||||
{
|
||||
|
||||
int i;
|
||||
char **retval;
|
||||
@ -1094,7 +1101,8 @@ static char **get_dir(char *path) {
|
||||
|
||||
/* Now fill dl with a listing. */
|
||||
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 {
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
@ -1119,7 +1127,8 @@ static char **get_dir(char *path) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void diffdir (char *p1, char *p2) {
|
||||
static void diffdir(char *p1, char *p2)
|
||||
{
|
||||
|
||||
char **dirlist1, **dirlist2;
|
||||
char *dp1, *dp2;
|
||||
@ -1164,15 +1173,13 @@ static void diffdir (char *p1, char *p2) {
|
||||
do_diff(p1, dp1, p2, dp2);
|
||||
dirlist1++;
|
||||
dirlist2++;
|
||||
}
|
||||
else if (pos < 0) {
|
||||
} else if (pos < 0) {
|
||||
if (cmd_flags & FLAG_N)
|
||||
do_diff(p1, dp1, p2, NULL);
|
||||
else
|
||||
print_only(p1, strlen(p1) + 1, dp1);
|
||||
dirlist1++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (cmd_flags & FLAG_N)
|
||||
do_diff(p1, NULL, p2, dp2);
|
||||
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;
|
||||
int gotstdin = 0;
|
||||
|
||||
char *U_opt;
|
||||
llist_t *L_arg = NULL;
|
||||
|
||||
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) {
|
||||
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 (label[0] && label[1]) {
|
||||
char *tmp;
|
||||
|
||||
tmp = label[1];
|
||||
label[1] = label[0];
|
||||
label[0] = tmp;
|
||||
@ -1252,8 +1264,7 @@ int diff_main(int argc, char **argv) {
|
||||
#else
|
||||
bb_error_msg_and_die("Directory comparison not supported");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (S_ISDIR(stb1.st_mode)) {
|
||||
argv[0] = concat_path_file(argv[0], argv[1]);
|
||||
xstat(argv[0], &stb1);
|
||||
@ -1266,4 +1277,3 @@ int diff_main(int argc, char **argv) {
|
||||
}
|
||||
exit(status);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user