- patch from Rob Sullivan to add support for -L
This commit is contained in:
parent
5fb0fecc1f
commit
bc14214018
@ -88,15 +88,16 @@ static unsigned long cmd_flags;
|
|||||||
#define FLAG_b (1<<1)
|
#define FLAG_b (1<<1)
|
||||||
#define FLAG_d (1<<2)
|
#define FLAG_d (1<<2)
|
||||||
#define FLAG_i (1<<3)
|
#define FLAG_i (1<<3)
|
||||||
#define FLAG_N (1<<4)
|
#define FLAG_L (1<<4)
|
||||||
#define FLAG_q (1<<5)
|
#define FLAG_N (1<<5)
|
||||||
#define FLAG_r (1<<6)
|
#define FLAG_q (1<<6)
|
||||||
#define FLAG_s (1<<7)
|
#define FLAG_r (1<<7)
|
||||||
#define FLAG_S (1<<8)
|
#define FLAG_s (1<<8)
|
||||||
#define FLAG_t (1<<9)
|
#define FLAG_S (1<<9)
|
||||||
#define FLAG_T (1<<10)
|
#define FLAG_t (1<<10)
|
||||||
#define FLAG_U (1<<11)
|
#define FLAG_T (1<<11)
|
||||||
#define FLAG_w (1<<12)
|
#define FLAG_U (1<<12)
|
||||||
|
#define FLAG_w (1<<13)
|
||||||
|
|
||||||
int context, status;
|
int context, status;
|
||||||
char *start, *label[2];
|
char *start, *label[2];
|
||||||
@ -376,7 +377,6 @@ static int isqrt(int n) {
|
|||||||
return (x);
|
return (x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int newcand(int x, int y, int pred)
|
static int newcand(int x, int y, int pred)
|
||||||
{
|
{
|
||||||
struct cand *q;
|
struct cand *q;
|
||||||
@ -422,7 +422,7 @@ 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;
|
||||||
u_int numtries;
|
u_int numtries;
|
||||||
#ifdef CONFIG_FEATURE_DIFF_MINIMAL
|
#if ENABLE_FEATURE_DIFF_MINIMAL
|
||||||
const u_int bound = (cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
|
const u_int bound = (cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
|
||||||
#else
|
#else
|
||||||
const u_int bound = MAX(256, isqrt(n));
|
const u_int bound = MAX(256, isqrt(n));
|
||||||
@ -672,7 +672,7 @@ static int fetch(long *f, int a, int b, FILE *lb, int ch)
|
|||||||
|
|
||||||
static int asciifile(FILE *f)
|
static int asciifile(FILE *f)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_FEATURE_DIFF_BINARY
|
#if ENABLE_FEATURE_DIFF_BINARY
|
||||||
unsigned char buf[BUFSIZ];
|
unsigned char buf[BUFSIZ];
|
||||||
int i, cnt;
|
int i, cnt;
|
||||||
#endif
|
#endif
|
||||||
@ -680,12 +680,14 @@ static int asciifile(FILE *f)
|
|||||||
if ((cmd_flags & FLAG_a) || f == NULL)
|
if ((cmd_flags & FLAG_a) || f == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_DIFF_BINARY
|
#if ENABLE_FEATURE_DIFF_BINARY
|
||||||
rewind(f);
|
rewind(f);
|
||||||
cnt = fread(buf, 1, sizeof(buf), f);
|
cnt = fread(buf, 1, sizeof(buf), f);
|
||||||
for (i = 0; i < cnt; i++)
|
for (i = 0; i < cnt; i++) {
|
||||||
if (!isprint(buf[i]) && !isspace(buf[i]))
|
if (!isprint(buf[i]) && !isspace(buf[i])) {
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@ -837,7 +839,10 @@ 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)
|
||||||
{
|
{
|
||||||
int m, i0, i1, j0, j1;
|
|
||||||
|
/* Note that j0 and j1 can't be used as they are defined in math.h.
|
||||||
|
* This also allows the rather amusing variable 'j00'... */
|
||||||
|
int m, i0, i1, j00, j01;
|
||||||
|
|
||||||
rewind(f1);
|
rewind(f1);
|
||||||
rewind(f2);
|
rewind(f2);
|
||||||
@ -847,13 +852,13 @@ static void output(char *file1, FILE *f1, char *file2, FILE *f2)
|
|||||||
for (i0 = 1; i0 <= m; i0 = i1 + 1) {
|
for (i0 = 1; i0 <= m; i0 = i1 + 1) {
|
||||||
while (i0 <= m && J[i0] == J[i0 - 1] + 1)
|
while (i0 <= m && J[i0] == J[i0 - 1] + 1)
|
||||||
i0++;
|
i0++;
|
||||||
j0 = J[i0 - 1] + 1;
|
j00 = J[i0 - 1] + 1;
|
||||||
i1 = i0 - 1;
|
i1 = i0 - 1;
|
||||||
while (i1 < m && J[i1 + 1] == 0)
|
while (i1 < m && J[i1 + 1] == 0)
|
||||||
i1++;
|
i1++;
|
||||||
j1 = J[i1 + 1] - 1;
|
j01 = J[i1 + 1] - 1;
|
||||||
J[i1] = j1;
|
J[i1] = j01;
|
||||||
change(file1, f1, file2, f2, i0, i1, j0, j1);
|
change(file1, f1, file2, f2, i0, i1, j00, j01);
|
||||||
}
|
}
|
||||||
if (m == 0) {
|
if (m == 0) {
|
||||||
change(file1, f1, file2, f2, 1, 0, 1, len[1]);
|
change(file1, f1, file2, f2, 1, 0, 1, len[1]);
|
||||||
@ -1064,7 +1069,7 @@ static void do_diff (char *dir1, char *path1, char *dir2, char *path2) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_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);
|
||||||
}
|
}
|
||||||
@ -1196,12 +1201,35 @@ static void diffdir (char *p1, char *p2) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern 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;
|
||||||
cmd_flags = bb_getopt_ulflags(argc, argv, "abdiNqrsS:tTU:wu", &start, &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);
|
||||||
|
|
||||||
|
if (cmd_flags & FLAG_L) {
|
||||||
|
while (L_arg) {
|
||||||
|
if (label[0] == NULL)
|
||||||
|
label[0] = L_arg->data;
|
||||||
|
else if (label[1] == NULL)
|
||||||
|
label[1] = L_arg->data;
|
||||||
|
else
|
||||||
|
bb_show_usage();
|
||||||
|
|
||||||
|
L_arg = L_arg->link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context = 3; /* This is the default number of lines of context. */
|
context = 3; /* This is the default number of lines of context. */
|
||||||
if (cmd_flags & FLAG_U) {
|
if (cmd_flags & FLAG_U) {
|
||||||
@ -1235,7 +1263,7 @@ extern int diff_main(int argc, char **argv) {
|
|||||||
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
|
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
|
||||||
bb_error_msg_and_die("Can't compare - to a directory");
|
bb_error_msg_and_die("Can't compare - to a directory");
|
||||||
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
|
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
|
||||||
#ifdef CONFIG_FEATURE_DIFF_DIR
|
#if ENABLE_FEATURE_DIFF_DIR
|
||||||
diffdir(argv[0], argv[1]);
|
diffdir(argv[0], argv[1]);
|
||||||
#else
|
#else
|
||||||
bb_error_msg_and_die("Directory comparison not supported");
|
bb_error_msg_and_die("Directory comparison not supported");
|
||||||
|
@ -454,7 +454,7 @@
|
|||||||
"/dev/sda3 8690864 8553540 137324 98% /\n"
|
"/dev/sda3 8690864 8553540 137324 98% /\n"
|
||||||
|
|
||||||
#define diff_trivial_usage \
|
#define diff_trivial_usage \
|
||||||
"[-abdiNqrTstw] [-S FILE] [-U LINES] FILE1 FILE2"
|
"[-abdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
|
||||||
#define diff_full_usage \
|
#define diff_full_usage \
|
||||||
"Compare files line by line and output the differences between them.\n" \
|
"Compare files line by line and output the differences between them.\n" \
|
||||||
"This diff implementation only supports unified diffs.\n\n" \
|
"This diff implementation only supports unified diffs.\n\n" \
|
||||||
@ -463,6 +463,7 @@
|
|||||||
"\t-b\tIgnore changes in the amount of whitespace\n" \
|
"\t-b\tIgnore changes in the amount of whitespace\n" \
|
||||||
"\t-d\tTry hard to find a smaller set of changes\n" \
|
"\t-d\tTry hard to find a smaller set of changes\n" \
|
||||||
"\t-i\tIgnore case differences\n" \
|
"\t-i\tIgnore case differences\n" \
|
||||||
|
"\t-L\tUse LABEL instead of the filename in the unified header\n" \
|
||||||
"\t-N\tTreat absent files as empty\n" \
|
"\t-N\tTreat absent files as empty\n" \
|
||||||
"\t-q\tOutput only whether files differ\n" \
|
"\t-q\tOutput only whether files differ\n" \
|
||||||
"\t-r\tRecursively compare any subdirectories\n" \
|
"\t-r\tRecursively compare any subdirectories\n" \
|
||||||
|
Loading…
Reference in New Issue
Block a user