use a bunch of if statements since it is a few bytes smaller than a switch; also use bb_xfopen() instead of fopen() so comm doesnt segfault when given non-existant files :(

This commit is contained in:
Mike Frysinger 2005-05-12 22:50:12 +00:00
parent b3a6ec3e62
commit dad4cf7e63

View File

@ -40,25 +40,21 @@ 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) { if (class == 1 && !only_file_1)
case 1:
if (!only_file_1)
return; return;
break; else if (class == 2) {
case 2:
if (!only_file_2) if (!only_file_2)
return; return;
if (only_file_1) if (only_file_1)
putchar('\t'); putchar('\t');
break; }
case 3: else if (class == 3) {
if (!both) if (!both)
return; return;
if (only_file_1) if (only_file_1)
putchar('\t'); putchar('\t');
if (only_file_2) if (only_file_2)
putchar('\t'); putchar('\t');
break;
} }
fputs(line, stdout); fputs(line, stdout);
} }
@ -71,7 +67,7 @@ static int cmp_files(char **infiles)
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 : bb_xfopen(infiles[i], "r"));
fgets(thisline[i], 100, streams[i]); fgets(thisline[i], 100, streams[i]);
} }