svn commit: trunk/busybox: coreutils include

vda at busybox.net vda at busybox.net
Fri Mar 9 10:08:55 UTC 2007


Author: vda
Date: 2007-03-09 02:08:53 -0800 (Fri, 09 Mar 2007)
New Revision: 18051

Log:
diff: failed to confirm "static bug" in gcc - reinstating statics.
microscopic code improvements.


Modified:
   trunk/busybox/coreutils/chgrp.c
   trunk/busybox/coreutils/diff.c
   trunk/busybox/include/libbb.h


Changeset:
Modified: trunk/busybox/coreutils/chgrp.c
===================================================================
--- trunk/busybox/coreutils/chgrp.c	2007-03-09 08:55:23 UTC (rev 18050)
+++ trunk/busybox/coreutils/chgrp.c	2007-03-09 10:08:53 UTC (rev 18051)
@@ -7,15 +7,12 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
+/* BB_AUDIT SUSv3 defects - none? */
 /* BB_AUDIT GNU defects - unsupported long options. */
 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
 
 #include "busybox.h"
 
-/* FIXME - move to .h */
-extern int chown_main(int argc, char **argv);
-
 int chgrp_main(int argc, char **argv);
 int chgrp_main(int argc, char **argv)
 {

Modified: trunk/busybox/coreutils/diff.c
===================================================================
--- trunk/busybox/coreutils/diff.c	2007-03-09 08:55:23 UTC (rev 18050)
+++ trunk/busybox/coreutils/diff.c	2007-03-09 10:08:53 UTC (rev 18051)
@@ -65,18 +65,25 @@
 #define FLAG_U	(1<<12)
 #define	FLAG_w	(1<<13)
 
-/* XXX: FIXME: the following variables should be static, but gcc currently
+/* The following variables should be static, but gcc currently
  * creates a much bigger object if we do this. [which version of gcc? --vda] */
 /* 4.x, IIRC also 3.x --bernhard */
+/* Works for gcc 3.4.3. Sizes without and with "static":
+   # size busybox.t[34]/coreutils/diff.o
+   text    data     bss     dec     hex filename
+   6969       8     305    7282    1c72 busybox.t3/coreutils/diff.o
+   6969       8     305    7282    1c72 busybox.t4/coreutils/diff.o
+   --vda
+ */
 /* This is the default number of lines of context. */
-int context = 3;
-int status;
-char *start;
-const char *label1;
-const char *label2;
-struct stat stb1, stb2;
-char **dl;
-USE_FEATURE_DIFF_DIR(int dl_count;)
+static int context = 3;
+static int status;
+static char *start;
+static const char *label1;
+static const char *label2;
+static struct stat stb1, stb2;
+static char **dl;
+USE_FEATURE_DIFF_DIR(static int dl_count;)
 
 struct cand {
 	int x;
@@ -84,7 +91,7 @@
 	int pred;
 };
 
-struct line {
+static struct line {
 	int serial;
 	int value;
 } *file[2];
@@ -188,7 +195,7 @@
 
 	sum = 1;
 	space = 0;
-	if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
+	if (!(option_mask32 & (FLAG_b | FLAG_w))) {
 		for (i = 0; (t = getc(f)) != '\n'; i++) {
 			if (t == EOF) {
 				if (i == 0)
@@ -241,19 +248,18 @@
 {
 	size_t i, j;
 
-	if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size ||
-		(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
+	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) {
 		i = fread(bb_common_bufsiz1,            1, BUFSIZ/2, f1);
 		j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2);
 		if (i != j)
 			return 1;
-		if (i == 0 && j == 0) {
-			if (ferror(f1) || ferror(f2))
-				return 1;
-			return 0;
-		}
+		if (i == 0)
+			return (ferror(f1) || ferror(f2));
 		if (memcmp(bb_common_bufsiz1,
 		           bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
 			return 1;
@@ -337,11 +343,11 @@
 
 static int isqrt(int n)
 {
-	int y, x = 1;
+	int y, x;
 
 	if (n == 0)
 		return 0;
-
+	x = 1;
 	do {
 		y = x;
 		x = n / x;
@@ -647,7 +653,6 @@
 			}
 		}
 	}
-	return;
 }
 
 
@@ -828,66 +833,66 @@
 }
 
 /*
- *      The following code uses an algorithm due to Harold Stone,
- *      which finds a pair of longest identical subsequences in
- *      the two files.
+ * The following code uses an algorithm due to Harold Stone,
+ * which finds a pair of longest identical subsequences in
+ * the two files.
  *
- *      The major goal is to generate the match vector J.
- *      J[i] is the index of the line in file1 corresponding
- *      to line i file0. J[i] = 0 if there is no
- *      such line in file1.
+ * The major goal is to generate the match vector J.
+ * J[i] is the index of the line in file1 corresponding
+ * to line i file0. J[i] = 0 if there is no
+ * such line in file1.
  *
- *      Lines are hashed so as to work in core. All potential
- *      matches are located by sorting the lines of each file
- *      on the hash (called ``value''). In particular, this
- *      collects the equivalence classes in file1 together.
- *      Subroutine equiv replaces the value of each line in
- *      file0 by the index of the first element of its
- *      matching equivalence in (the reordered) file1.
- *      To save space equiv squeezes file1 into a single
- *      array member in which the equivalence classes
- *      are simply concatenated, except that their first
- *      members are flagged by changing sign.
+ * Lines are hashed so as to work in core. All potential
+ * matches are located by sorting the lines of each file
+ * on the hash (called ``value''). In particular, this
+ * collects the equivalence classes in file1 together.
+ * Subroutine equiv replaces the value of each line in
+ * file0 by the index of the first element of its
+ * matching equivalence in (the reordered) file1.
+ * To save space equiv squeezes file1 into a single
+ * array member in which the equivalence classes
+ * are simply concatenated, except that their first
+ * members are flagged by changing sign.
  *
- *      Next the indices that point into member are unsorted into
- *      array class according to the original order of file0.
+ * Next the indices that point into member are unsorted into
+ * array class according to the original order of file0.
  *
- *      The cleverness lies in routine stone. This marches
- *      through the lines of file0, developing a vector klist
- *      of "k-candidates". At step i a k-candidate is a matched
- *      pair of lines x,y (x in file0 y in file1) such that
- *      there is a common subsequence of length k
- *      between the first i lines of file0 and the first y
- *      lines of file1, but there is no such subsequence for
- *      any smaller y. x is the earliest possible mate to y
- *      that occurs in such a subsequence.
+ * The cleverness lies in routine stone. This marches
+ * through the lines of file0, developing a vector klist
+ * of "k-candidates". At step i a k-candidate is a matched
+ * pair of lines x,y (x in file0 y in file1) such that
+ * there is a common subsequence of length k
+ * between the first i lines of file0 and the first y
+ * lines of file1, but there is no such subsequence for
+ * any smaller y. x is the earliest possible mate to y
+ * that occurs in such a subsequence.
  *
- *      Whenever any of the members of the equivalence class of
- *      lines in file1 matable to a line in file0 has serial number
- *      less than the y of some k-candidate, that k-candidate
- *      with the smallest such y is replaced. The new
- *      k-candidate is chained (via pred) to the current
- *      k-1 candidate so that the actual subsequence can
- *      be recovered. When a member has serial number greater
- *      that the y of all k-candidates, the klist is extended.
- *      At the end, the longest subsequence is pulled out
- *      and placed in the array J by unravel
+ * Whenever any of the members of the equivalence class of
+ * lines in file1 matable to a line in file0 has serial number
+ * less than the y of some k-candidate, that k-candidate
+ * with the smallest such y is replaced. The new
+ * k-candidate is chained (via pred) to the current
+ * k-1 candidate so that the actual subsequence can
+ * be recovered. When a member has serial number greater
+ * that the y of all k-candidates, the klist is extended.
+ * At the end, the longest subsequence is pulled out
+ * and placed in the array J by unravel
  *
- *      With J in hand, the matches there recorded are
- *      checked against reality to assure that no spurious
- *      matches have crept in due to hashing. If they have,
- *      they are broken, and "jackpot" is recorded--a harmless
- *      matter except that a true match for a spuriously
- *      mated line may now be unnecessarily reported as a change.
+ * With J in hand, the matches there recorded are
+ * checked against reality to assure that no spurious
+ * matches have crept in due to hashing. If they have,
+ * they are broken, and "jackpot" is recorded--a harmless
+ * matter except that a true match for a spuriously
+ * mated line may now be unnecessarily reported as a change.
  *
- *      Much of the complexity of the program comes simply
- *      from trying to minimize core utilization and
- *      maximize the range of doable problems by dynamically
- *      allocating what is needed and reusing what is not.
- *      The core requirements for problems larger than somewhat
- *      are (in words) 2*length(file0) + length(file1) +
- *      3*(number of k-candidates installed),  typically about
- *      6n words for files of length n.
+ * Much of the complexity of the program comes simply
+ * from trying to minimize core utilization and
+ * maximize the range of doable problems by dynamically
+ * allocating what is needed and reusing what is not.
+ * The core requirements for problems larger than somewhat
+ * are (in words) 2*length(file0) + length(file1) +
+ * 3*(number of k-candidates installed),  typically about
+ * 6n words for files of length n.
  */
 static unsigned diffreg(char * ofile1, char * ofile2, int flags)
 {

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-03-09 08:55:23 UTC (rev 18050)
+++ trunk/busybox/include/libbb.h	2007-03-09 10:08:53 UTC (rev 18051)
@@ -514,6 +514,7 @@
 #if ENABLE_ROUTE
 void bb_displayroutes(int noresolve, int netstatfmt);
 #endif
+int chown_main(int argc, char **argv);
 #if ENABLE_GUNZIP
 int gunzip_main(int argc, char **argv);
 #endif




More information about the busybox-cvs mailing list