svn commit: trunk/busybox/coreutils

vda at busybox.net vda at busybox.net
Sat Apr 7 00:45:27 UTC 2007


Author: vda
Date: 2007-04-06 17:45:27 -0700 (Fri, 06 Apr 2007)
New Revision: 18355

Log:
comm: eliminate statics


Modified:
   trunk/busybox/coreutils/comm.c


Changeset:
Modified: trunk/busybox/coreutils/comm.c
===================================================================
--- trunk/busybox/coreutils/comm.c	2007-04-07 00:44:31 UTC (rev 18354)
+++ trunk/busybox/coreutils/comm.c	2007-04-07 00:45:27 UTC (rev 18355)
@@ -9,41 +9,34 @@
 
 #include "busybox.h"
 
-#define COMM_OPT_1 0x01
-#define COMM_OPT_2 0x02
-#define COMM_OPT_3 0x04
+#define COMM_OPT_1 (1 << 0)
+#define COMM_OPT_2 (1 << 1)
+#define COMM_OPT_3 (1 << 2)
 
-/* These three variables control behaviour if non-zero */
-
-static int only_file_1;
-static int only_file_2;
-static int both;
-
 /* writeline outputs the input given, appropriately aligned according to class */
-static void writeline(char *line, int class)
+static void writeline(char *line, int class, int flags)
 {
 	if (class == 0) {
-		if (!only_file_1)
+		if (flags & COMM_OPT_1)
 			return;
 	} else if (class == 1) {
-		if (!only_file_2)
+		if (flags & COMM_OPT_2)
 			return;
-		if (only_file_1)
+		if (!(flags & COMM_OPT_1))
 			putchar('\t');
-	}
-	else /*if (class == 2)*/ {
-		if (!both)
+	} else /*if (class == 2)*/ {
+		if (flags & COMM_OPT_3)
 			return;
-		if (only_file_1)
+		if (!(flags & COMM_OPT_1))
 			putchar('\t');
-		if (only_file_2)
+		if (!(flags & COMM_OPT_2))
 			putchar('\t');
 	}
 	fputs(line, stdout);
 }
 
-/* This is the real core of the program - lines are compared here */
-static void cmp_files(char **infiles)
+int comm_main(int argc, char **argv);
+int comm_main(int argc, char **argv)
 {
 #define LINE_LEN 100
 #define BB_EOF_0 0x1
@@ -51,12 +44,19 @@
 	char thisline[2][LINE_LEN];
 	FILE *streams[2];
 	int i;
+	unsigned flags;
 
+	opt_complementary = "=2";
+	flags = getopt32(argc, argv, "123");
+	argv += optind;
+
 	for (i = 0; i < 2; ++i) {
-		streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r"));
+		streams[i] = (argv[i][0] == '-' && !argv[i][1]) ? stdin : xfopen(argv[i], "r");
 		fgets(thisline[i], LINE_LEN, streams[i]);
 	}
 
+	/* This is the real core of the program - lines are compared here */
+
 	while (*thisline[0] || *thisline[1]) {
 		int order = 0;
 
@@ -78,11 +78,11 @@
 		}
 
 		if (order == 0 && !i)
-			writeline(thisline[1], 2);
+			writeline(thisline[1], 2, flags);
 		else if (order > 0 && !(i & BB_EOF_1))
-			writeline(thisline[1], 1);
+			writeline(thisline[1], 1, flags);
 		else if (order < 0 && !(i & BB_EOF_0))
-			writeline(thisline[0], 0);
+			writeline(thisline[0], 0, flags);
 
 		if (i & BB_EOF_0 & BB_EOF_1) {
 			break;
@@ -91,7 +91,7 @@
 			i = (i & BB_EOF_0 ? 1 : 0);
 			while (!feof(streams[i])) {
 				if ((order < 0 && i) || (order > 0 && !i))
-					writeline(thisline[i], i);
+					writeline(thisline[i], i, flags);
 				fgets(thisline[i], LINE_LEN, streams[i]);
 			}
 			break;
@@ -104,24 +104,10 @@
 		}
 	}
 
-	fclose(streams[0]);
-	fclose(streams[1]);
-}
+	if (ENABLE_FEATURE_CLEAN_UP) {
+		fclose(streams[0]);
+		fclose(streams[1]);
+	}
 
-int comm_main(int argc, char **argv);
-int comm_main(int argc, char **argv)
-{
-	unsigned long flags;
-
-	flags = getopt32(argc, argv, "123");
-
-	if (optind + 2 != argc)
-		bb_show_usage();
-
-	only_file_1 = !(flags & COMM_OPT_1);
-	only_file_2 = !(flags & COMM_OPT_2);
-	both = !(flags & COMM_OPT_3);
-
-	cmp_files(argv + optind);
-	exit(EXIT_SUCCESS);
+	return EXIT_SUCCESS;
 }




More information about the busybox-cvs mailing list