diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-09 10:08:53 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-09 10:08:53 +0000 |
commit | 72c2d4f75a01139e0a8c737461751dae2a8d3efe (patch) | |
tree | 3bdb925a44694bcf8c35a3e624ec89cb5ba938b0 | |
parent | 2da750fe83beff631f2f3e97adca6a21dcf9b010 (diff) | |
download | busybox-w32-72c2d4f75a01139e0a8c737461751dae2a8d3efe.tar.gz busybox-w32-72c2d4f75a01139e0a8c737461751dae2a8d3efe.tar.bz2 busybox-w32-72c2d4f75a01139e0a8c737461751dae2a8d3efe.zip |
diff: failed to confirm "static bug" in gcc - reinstating statics.
microscopic code improvements.
git-svn-id: svn://busybox.net/trunk/busybox@18051 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/chgrp.c | 5 | ||||
-rw-r--r-- | coreutils/diff.c | 153 | ||||
-rw-r--r-- | include/libbb.h | 1 |
3 files changed, 81 insertions, 78 deletions
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c index eaa29cbc6..cfb8c15b2 100644 --- a/coreutils/chgrp.c +++ b/coreutils/chgrp.c | |||
@@ -7,15 +7,12 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | /* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */ | 10 | /* BB_AUDIT SUSv3 defects - none? */ |
11 | /* BB_AUDIT GNU defects - unsupported long options. */ | 11 | /* BB_AUDIT GNU defects - unsupported long options. */ |
12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ | 12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ |
13 | 13 | ||
14 | #include "busybox.h" | 14 | #include "busybox.h" |
15 | 15 | ||
16 | /* FIXME - move to .h */ | ||
17 | extern int chown_main(int argc, char **argv); | ||
18 | |||
19 | int chgrp_main(int argc, char **argv); | 16 | int chgrp_main(int argc, char **argv); |
20 | int chgrp_main(int argc, char **argv) | 17 | int chgrp_main(int argc, char **argv) |
21 | { | 18 | { |
diff --git a/coreutils/diff.c b/coreutils/diff.c index 0eaf0b1d1..73b576f31 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -65,18 +65,25 @@ | |||
65 | #define FLAG_U (1<<12) | 65 | #define FLAG_U (1<<12) |
66 | #define FLAG_w (1<<13) | 66 | #define FLAG_w (1<<13) |
67 | 67 | ||
68 | /* XXX: FIXME: the following variables should be static, but gcc currently | 68 | /* The following variables should be static, but gcc currently |
69 | * creates a much bigger object if we do this. [which version of gcc? --vda] */ | 69 | * creates a much bigger object if we do this. [which version of gcc? --vda] */ |
70 | /* 4.x, IIRC also 3.x --bernhard */ | 70 | /* 4.x, IIRC also 3.x --bernhard */ |
71 | /* Works for gcc 3.4.3. Sizes without and with "static": | ||
72 | # size busybox.t[34]/coreutils/diff.o | ||
73 | text data bss dec hex filename | ||
74 | 6969 8 305 7282 1c72 busybox.t3/coreutils/diff.o | ||
75 | 6969 8 305 7282 1c72 busybox.t4/coreutils/diff.o | ||
76 | --vda | ||
77 | */ | ||
71 | /* This is the default number of lines of context. */ | 78 | /* This is the default number of lines of context. */ |
72 | int context = 3; | 79 | static int context = 3; |
73 | int status; | 80 | static int status; |
74 | char *start; | 81 | static char *start; |
75 | const char *label1; | 82 | static const char *label1; |
76 | const char *label2; | 83 | static const char *label2; |
77 | struct stat stb1, stb2; | 84 | static struct stat stb1, stb2; |
78 | char **dl; | 85 | static char **dl; |
79 | USE_FEATURE_DIFF_DIR(int dl_count;) | 86 | USE_FEATURE_DIFF_DIR(static int dl_count;) |
80 | 87 | ||
81 | struct cand { | 88 | struct cand { |
82 | int x; | 89 | int x; |
@@ -84,7 +91,7 @@ struct cand { | |||
84 | int pred; | 91 | int pred; |
85 | }; | 92 | }; |
86 | 93 | ||
87 | struct line { | 94 | static struct line { |
88 | int serial; | 95 | int serial; |
89 | int value; | 96 | int value; |
90 | } *file[2]; | 97 | } *file[2]; |
@@ -188,7 +195,7 @@ static int readhash(FILE * f) | |||
188 | 195 | ||
189 | sum = 1; | 196 | sum = 1; |
190 | space = 0; | 197 | space = 0; |
191 | if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) { | 198 | if (!(option_mask32 & (FLAG_b | FLAG_w))) { |
192 | for (i = 0; (t = getc(f)) != '\n'; i++) { | 199 | for (i = 0; (t = getc(f)) != '\n'; i++) { |
193 | if (t == EOF) { | 200 | if (t == EOF) { |
194 | if (i == 0) | 201 | if (i == 0) |
@@ -241,19 +248,18 @@ static int files_differ(FILE * f1, FILE * f2, int flags) | |||
241 | { | 248 | { |
242 | size_t i, j; | 249 | size_t i, j; |
243 | 250 | ||
244 | if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size || | 251 | if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size |
245 | (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) | 252 | || (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT) |
253 | ) { | ||
246 | return 1; | 254 | return 1; |
255 | } | ||
247 | while (1) { | 256 | while (1) { |
248 | i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1); | 257 | i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1); |
249 | j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2); | 258 | j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2); |
250 | if (i != j) | 259 | if (i != j) |
251 | return 1; | 260 | return 1; |
252 | if (i == 0 && j == 0) { | 261 | if (i == 0) |
253 | if (ferror(f1) || ferror(f2)) | 262 | return (ferror(f1) || ferror(f2)); |
254 | return 1; | ||
255 | return 0; | ||
256 | } | ||
257 | if (memcmp(bb_common_bufsiz1, | 263 | if (memcmp(bb_common_bufsiz1, |
258 | bb_common_bufsiz1 + BUFSIZ/2, i) != 0) | 264 | bb_common_bufsiz1 + BUFSIZ/2, i) != 0) |
259 | return 1; | 265 | return 1; |
@@ -337,11 +343,11 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c) | |||
337 | 343 | ||
338 | static int isqrt(int n) | 344 | static int isqrt(int n) |
339 | { | 345 | { |
340 | int y, x = 1; | 346 | int y, x; |
341 | 347 | ||
342 | if (n == 0) | 348 | if (n == 0) |
343 | return 0; | 349 | return 0; |
344 | 350 | x = 1; | |
345 | do { | 351 | do { |
346 | y = x; | 352 | y = x; |
347 | x = n / x; | 353 | x = n / x; |
@@ -647,7 +653,6 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch) | |||
647 | } | 653 | } |
648 | } | 654 | } |
649 | } | 655 | } |
650 | return; | ||
651 | } | 656 | } |
652 | 657 | ||
653 | 658 | ||
@@ -828,66 +833,66 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2) | |||
828 | } | 833 | } |
829 | 834 | ||
830 | /* | 835 | /* |
831 | * The following code uses an algorithm due to Harold Stone, | 836 | * The following code uses an algorithm due to Harold Stone, |
832 | * which finds a pair of longest identical subsequences in | 837 | * which finds a pair of longest identical subsequences in |
833 | * the two files. | 838 | * the two files. |
834 | * | 839 | * |
835 | * The major goal is to generate the match vector J. | 840 | * The major goal is to generate the match vector J. |
836 | * J[i] is the index of the line in file1 corresponding | 841 | * J[i] is the index of the line in file1 corresponding |
837 | * to line i file0. J[i] = 0 if there is no | 842 | * to line i file0. J[i] = 0 if there is no |
838 | * such line in file1. | 843 | * such line in file1. |
839 | * | 844 | * |
840 | * Lines are hashed so as to work in core. All potential | 845 | * Lines are hashed so as to work in core. All potential |
841 | * matches are located by sorting the lines of each file | 846 | * matches are located by sorting the lines of each file |
842 | * on the hash (called ``value''). In particular, this | 847 | * on the hash (called ``value''). In particular, this |
843 | * collects the equivalence classes in file1 together. | 848 | * collects the equivalence classes in file1 together. |
844 | * Subroutine equiv replaces the value of each line in | 849 | * Subroutine equiv replaces the value of each line in |
845 | * file0 by the index of the first element of its | 850 | * file0 by the index of the first element of its |
846 | * matching equivalence in (the reordered) file1. | 851 | * matching equivalence in (the reordered) file1. |
847 | * To save space equiv squeezes file1 into a single | 852 | * To save space equiv squeezes file1 into a single |
848 | * array member in which the equivalence classes | 853 | * array member in which the equivalence classes |
849 | * are simply concatenated, except that their first | 854 | * are simply concatenated, except that their first |
850 | * members are flagged by changing sign. | 855 | * members are flagged by changing sign. |
851 | * | 856 | * |
852 | * Next the indices that point into member are unsorted into | 857 | * Next the indices that point into member are unsorted into |
853 | * array class according to the original order of file0. | 858 | * array class according to the original order of file0. |
854 | * | 859 | * |
855 | * The cleverness lies in routine stone. This marches | 860 | * The cleverness lies in routine stone. This marches |
856 | * through the lines of file0, developing a vector klist | 861 | * through the lines of file0, developing a vector klist |
857 | * of "k-candidates". At step i a k-candidate is a matched | 862 | * of "k-candidates". At step i a k-candidate is a matched |
858 | * pair of lines x,y (x in file0 y in file1) such that | 863 | * pair of lines x,y (x in file0 y in file1) such that |
859 | * there is a common subsequence of length k | 864 | * there is a common subsequence of length k |
860 | * between the first i lines of file0 and the first y | 865 | * between the first i lines of file0 and the first y |
861 | * lines of file1, but there is no such subsequence for | 866 | * lines of file1, but there is no such subsequence for |
862 | * any smaller y. x is the earliest possible mate to y | 867 | * any smaller y. x is the earliest possible mate to y |
863 | * that occurs in such a subsequence. | 868 | * that occurs in such a subsequence. |
864 | * | 869 | * |
865 | * Whenever any of the members of the equivalence class of | 870 | * Whenever any of the members of the equivalence class of |
866 | * lines in file1 matable to a line in file0 has serial number | 871 | * lines in file1 matable to a line in file0 has serial number |
867 | * less than the y of some k-candidate, that k-candidate | 872 | * less than the y of some k-candidate, that k-candidate |
868 | * with the smallest such y is replaced. The new | 873 | * with the smallest such y is replaced. The new |
869 | * k-candidate is chained (via pred) to the current | 874 | * k-candidate is chained (via pred) to the current |
870 | * k-1 candidate so that the actual subsequence can | 875 | * k-1 candidate so that the actual subsequence can |
871 | * be recovered. When a member has serial number greater | 876 | * be recovered. When a member has serial number greater |
872 | * that the y of all k-candidates, the klist is extended. | 877 | * that the y of all k-candidates, the klist is extended. |
873 | * At the end, the longest subsequence is pulled out | 878 | * At the end, the longest subsequence is pulled out |
874 | * and placed in the array J by unravel | 879 | * and placed in the array J by unravel |
875 | * | 880 | * |
876 | * With J in hand, the matches there recorded are | 881 | * With J in hand, the matches there recorded are |
877 | * checked against reality to assure that no spurious | 882 | * checked against reality to assure that no spurious |
878 | * matches have crept in due to hashing. If they have, | 883 | * matches have crept in due to hashing. If they have, |
879 | * they are broken, and "jackpot" is recorded--a harmless | 884 | * they are broken, and "jackpot" is recorded--a harmless |
880 | * matter except that a true match for a spuriously | 885 | * matter except that a true match for a spuriously |
881 | * mated line may now be unnecessarily reported as a change. | 886 | * mated line may now be unnecessarily reported as a change. |
882 | * | 887 | * |
883 | * Much of the complexity of the program comes simply | 888 | * Much of the complexity of the program comes simply |
884 | * from trying to minimize core utilization and | 889 | * from trying to minimize core utilization and |
885 | * maximize the range of doable problems by dynamically | 890 | * maximize the range of doable problems by dynamically |
886 | * allocating what is needed and reusing what is not. | 891 | * allocating what is needed and reusing what is not. |
887 | * The core requirements for problems larger than somewhat | 892 | * The core requirements for problems larger than somewhat |
888 | * are (in words) 2*length(file0) + length(file1) + | 893 | * are (in words) 2*length(file0) + length(file1) + |
889 | * 3*(number of k-candidates installed), typically about | 894 | * 3*(number of k-candidates installed), typically about |
890 | * 6n words for files of length n. | 895 | * 6n words for files of length n. |
891 | */ | 896 | */ |
892 | static unsigned diffreg(char * ofile1, char * ofile2, int flags) | 897 | static unsigned diffreg(char * ofile1, char * ofile2, int flags) |
893 | { | 898 | { |
diff --git a/include/libbb.h b/include/libbb.h index 9aa060691..93edbdc3f 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -514,6 +514,7 @@ int bb_test(int argc, char** argv); | |||
514 | #if ENABLE_ROUTE | 514 | #if ENABLE_ROUTE |
515 | void bb_displayroutes(int noresolve, int netstatfmt); | 515 | void bb_displayroutes(int noresolve, int netstatfmt); |
516 | #endif | 516 | #endif |
517 | int chown_main(int argc, char **argv); | ||
517 | #if ENABLE_GUNZIP | 518 | #if ENABLE_GUNZIP |
518 | int gunzip_main(int argc, char **argv); | 519 | int gunzip_main(int argc, char **argv); |
519 | #endif | 520 | #endif |