fix whitespace/coding style

This commit is contained in:
Mike Frysinger 2005-05-12 22:25:41 +00:00
parent a84a512700
commit 0d605e98b2

View File

@ -38,17 +38,21 @@ static int only_file_2;
static int both; static int both;
/* writeline outputs the input given, appropriately aligned according to class */ /* writeline outputs the input given, appropriately aligned according to class */
static void writeline (char *line, int class) { static void writeline (char *line, int class)
{
switch (class) { switch (class) {
case 1: if (!only_file_1) case 1:
if (!only_file_1)
return; return;
break; break;
case 2: if (!only_file_2) case 2:
if (!only_file_2)
return; return;
if (only_file_1) if (only_file_1)
putchar('\t'); putchar('\t');
break; break;
case 3: if (!both) case 3:
if (!both)
return; return;
if (only_file_1) if (only_file_1)
putchar('\t'); putchar('\t');
@ -56,50 +60,49 @@ static void writeline (char *line, int class) {
putchar('\t'); putchar('\t');
break; break;
} }
fputs(line, stdout); fputs(line, stdout);
} }
/* This is the real core of the program - lines are compared here */ /* This is the real core of the program - lines are compared here */
static int cmp_files(char **infiles) { static int cmp_files(char **infiles)
{
char thisline[2][100]; char thisline[2][100];
FILE *streams[2]; FILE *streams[2];
int i = 0; int i = 0;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : fopen(infiles[i], "r")); streams[i] = (strcmp(infiles[i], "=") == 0 ? stdin : fopen(infiles[i], "r"));
fgets(thisline[i], 100, streams[i]); fgets(thisline[i], 100, streams[i]);
} }
while (thisline[0] || thisline[1]) { while (thisline[0] || thisline[1]) {
int order = 0; int order = 0;
int tl0_len = strlen(thisline[0]); int tl0_len = strlen(thisline[0]);
int tl1_len = strlen(thisline[1]); int tl1_len = strlen(thisline[1]);
if (!thisline[0]) if (!thisline[0])
order = 1; order = 1;
else if (!thisline[1]) else if (!thisline[1])
order = -1; order = -1;
else { else {
order = memcmp(thisline[0], thisline[1], tl0_len < tl1_len ? tl0_len : tl1_len); order = memcmp(thisline[0], thisline[1], tl0_len < tl1_len ? tl0_len : tl1_len);
if (!order) if (!order)
order = tl0_len < tl1_len ? -1 : tl0_len != tl1_len; order = tl0_len < tl1_len ? -1 : tl0_len != tl1_len;
} }
if ((order == 0) && (!feof(streams[0])) && (!feof(streams[1]))) if ((order == 0) && (!feof(streams[0])) && (!feof(streams[1])))
writeline(thisline[1], 3); writeline(thisline[1], 3);
else if ((order > 0) && (!feof(streams[1]))) else if ((order > 0) && (!feof(streams[1])))
writeline(thisline[1], 2); writeline(thisline[1], 2);
else if ((order < 0) && (!feof(streams[0]))) else if ((order < 0) && (!feof(streams[0])))
writeline(thisline[0], 1); writeline(thisline[0], 1);
if (feof(streams[0]) && feof(streams[1])) { if (feof(streams[0]) && feof(streams[1])) {
fclose(streams[0]); fclose(streams[0]);
fclose(streams[1]); fclose(streams[1]);
break; break;
}
else if (feof(streams[0])) { } else if (feof(streams[0])) {
while (!feof(streams[1])) { while (!feof(streams[1])) {
if (order < 0) if (order < 0)
writeline(thisline[1], 2); writeline(thisline[1], 2);
@ -108,9 +111,8 @@ static int cmp_files(char **infiles) {
fclose(streams[0]); fclose(streams[0]);
fclose(streams[1]); fclose(streams[1]);
break; break;
}
else if (feof(streams[1])) {
} else if (feof(streams[1])) {
while (!feof(streams[0])) { while (!feof(streams[0])) {
if (order > 0) if (order > 0)
writeline(thisline[0], 1); writeline(thisline[0], 1);
@ -119,8 +121,8 @@ static int cmp_files(char **infiles) {
fclose(streams[0]); fclose(streams[0]);
fclose(streams[1]); fclose(streams[1]);
break; break;
}
else { } else {
if (order >= 0) if (order >= 0)
fgets(thisline[1], 100, streams[1]); fgets(thisline[1], 100, streams[1]);
if (order <= 0) if (order <= 0)
@ -131,19 +133,18 @@ static int cmp_files(char **infiles) {
return 0; return 0;
} }
int comm_main (int argc, char **argv) { int comm_main (int argc, char **argv)
{
unsigned long opt; unsigned long opt;
only_file_1 = 1; only_file_1 = 1;
only_file_2 = 1; only_file_2 = 1;
both = 1; both = 1;
opt = bb_getopt_ulflags(argc, argv, "123"); opt = bb_getopt_ulflags(argc, argv, "123");
if ((opt & 0x80000000UL) || (optind == argc)) { if ((opt & 0x80000000UL) || (optind == argc))
bb_show_usage(); bb_show_usage();
}
if (opt & COMM_OPT_1) if (opt & COMM_OPT_1)
only_file_1 = 0; only_file_1 = 0;
if (opt & COMM_OPT_2) if (opt & COMM_OPT_2)