diff: failed to confirm "static bug" in gcc - reinstating statics.
microscopic code improvements.
This commit is contained in:
@ -7,15 +7,12 @@
|
|||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* 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. */
|
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
|
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
|
||||||
|
|
||||||
#include "busybox.h"
|
#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);
|
||||||
int chgrp_main(int argc, char **argv)
|
int chgrp_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
153
coreutils/diff.c
153
coreutils/diff.c
@ -65,18 +65,25 @@
|
|||||||
#define FLAG_U (1<<12)
|
#define FLAG_U (1<<12)
|
||||||
#define FLAG_w (1<<13)
|
#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] */
|
* creates a much bigger object if we do this. [which version of gcc? --vda] */
|
||||||
/* 4.x, IIRC also 3.x --bernhard */
|
/* 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. */
|
/* This is the default number of lines of context. */
|
||||||
int context = 3;
|
static int context = 3;
|
||||||
int status;
|
static int status;
|
||||||
char *start;
|
static char *start;
|
||||||
const char *label1;
|
static const char *label1;
|
||||||
const char *label2;
|
static const char *label2;
|
||||||
struct stat stb1, stb2;
|
static struct stat stb1, stb2;
|
||||||
char **dl;
|
static char **dl;
|
||||||
USE_FEATURE_DIFF_DIR(int dl_count;)
|
USE_FEATURE_DIFF_DIR(static int dl_count;)
|
||||||
|
|
||||||
struct cand {
|
struct cand {
|
||||||
int x;
|
int x;
|
||||||
@ -84,7 +91,7 @@ struct cand {
|
|||||||
int pred;
|
int pred;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line {
|
static struct line {
|
||||||
int serial;
|
int serial;
|
||||||
int value;
|
int value;
|
||||||
} *file[2];
|
} *file[2];
|
||||||
@ -188,7 +195,7 @@ static int readhash(FILE * f)
|
|||||||
|
|
||||||
sum = 1;
|
sum = 1;
|
||||||
space = 0;
|
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++) {
|
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||||
if (t == EOF) {
|
if (t == EOF) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
@ -241,19 +248,18 @@ static int files_differ(FILE * f1, FILE * f2, int flags)
|
|||||||
{
|
{
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size ||
|
if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size
|
||||||
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
|
|| (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)
|
||||||
|
) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1);
|
i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1);
|
||||||
j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2);
|
j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2);
|
||||||
if (i != j)
|
if (i != j)
|
||||||
return 1;
|
return 1;
|
||||||
if (i == 0 && j == 0) {
|
if (i == 0)
|
||||||
if (ferror(f1) || ferror(f2))
|
return (ferror(f1) || ferror(f2));
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (memcmp(bb_common_bufsiz1,
|
if (memcmp(bb_common_bufsiz1,
|
||||||
bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
|
bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -337,11 +343,11 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
|
|||||||
|
|
||||||
static int isqrt(int n)
|
static int isqrt(int n)
|
||||||
{
|
{
|
||||||
int y, x = 1;
|
int y, x;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
x = 1;
|
||||||
do {
|
do {
|
||||||
y = x;
|
y = x;
|
||||||
x = n / x;
|
x = n / x;
|
||||||
@ -647,7 +653,6 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -828,66 +833,66 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following code uses an algorithm due to Harold Stone,
|
* The following code uses an algorithm due to Harold Stone,
|
||||||
* which finds a pair of longest identical subsequences in
|
* which finds a pair of longest identical subsequences in
|
||||||
* the two files.
|
* the two files.
|
||||||
*
|
*
|
||||||
* The major goal is to generate the match vector J.
|
* The major goal is to generate the match vector J.
|
||||||
* J[i] is the index of the line in file1 corresponding
|
* J[i] is the index of the line in file1 corresponding
|
||||||
* to line i file0. J[i] = 0 if there is no
|
* to line i file0. J[i] = 0 if there is no
|
||||||
* such line in file1.
|
* such line in file1.
|
||||||
*
|
*
|
||||||
* Lines are hashed so as to work in core. All potential
|
* Lines are hashed so as to work in core. All potential
|
||||||
* matches are located by sorting the lines of each file
|
* matches are located by sorting the lines of each file
|
||||||
* on the hash (called ``value''). In particular, this
|
* on the hash (called ``value''). In particular, this
|
||||||
* collects the equivalence classes in file1 together.
|
* collects the equivalence classes in file1 together.
|
||||||
* Subroutine equiv replaces the value of each line in
|
* Subroutine equiv replaces the value of each line in
|
||||||
* file0 by the index of the first element of its
|
* file0 by the index of the first element of its
|
||||||
* matching equivalence in (the reordered) file1.
|
* matching equivalence in (the reordered) file1.
|
||||||
* To save space equiv squeezes file1 into a single
|
* To save space equiv squeezes file1 into a single
|
||||||
* array member in which the equivalence classes
|
* array member in which the equivalence classes
|
||||||
* are simply concatenated, except that their first
|
* are simply concatenated, except that their first
|
||||||
* members are flagged by changing sign.
|
* members are flagged by changing sign.
|
||||||
*
|
*
|
||||||
* Next the indices that point into member are unsorted into
|
* Next the indices that point into member are unsorted into
|
||||||
* array class according to the original order of file0.
|
* array class according to the original order of file0.
|
||||||
*
|
*
|
||||||
* The cleverness lies in routine stone. This marches
|
* The cleverness lies in routine stone. This marches
|
||||||
* through the lines of file0, developing a vector klist
|
* through the lines of file0, developing a vector klist
|
||||||
* of "k-candidates". At step i a k-candidate is a matched
|
* 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
|
* pair of lines x,y (x in file0 y in file1) such that
|
||||||
* there is a common subsequence of length k
|
* there is a common subsequence of length k
|
||||||
* between the first i lines of file0 and the first y
|
* between the first i lines of file0 and the first y
|
||||||
* lines of file1, but there is no such subsequence for
|
* lines of file1, but there is no such subsequence for
|
||||||
* any smaller y. x is the earliest possible mate to y
|
* any smaller y. x is the earliest possible mate to y
|
||||||
* that occurs in such a subsequence.
|
* that occurs in such a subsequence.
|
||||||
*
|
*
|
||||||
* Whenever any of the members of the equivalence class of
|
* Whenever any of the members of the equivalence class of
|
||||||
* lines in file1 matable to a line in file0 has serial number
|
* lines in file1 matable to a line in file0 has serial number
|
||||||
* less than the y of some k-candidate, that k-candidate
|
* less than the y of some k-candidate, that k-candidate
|
||||||
* with the smallest such y is replaced. The new
|
* with the smallest such y is replaced. The new
|
||||||
* k-candidate is chained (via pred) to the current
|
* k-candidate is chained (via pred) to the current
|
||||||
* k-1 candidate so that the actual subsequence can
|
* k-1 candidate so that the actual subsequence can
|
||||||
* be recovered. When a member has serial number greater
|
* be recovered. When a member has serial number greater
|
||||||
* that the y of all k-candidates, the klist is extended.
|
* that the y of all k-candidates, the klist is extended.
|
||||||
* At the end, the longest subsequence is pulled out
|
* At the end, the longest subsequence is pulled out
|
||||||
* and placed in the array J by unravel
|
* and placed in the array J by unravel
|
||||||
*
|
*
|
||||||
* With J in hand, the matches there recorded are
|
* With J in hand, the matches there recorded are
|
||||||
* checked against reality to assure that no spurious
|
* checked against reality to assure that no spurious
|
||||||
* matches have crept in due to hashing. If they have,
|
* matches have crept in due to hashing. If they have,
|
||||||
* they are broken, and "jackpot" is recorded--a harmless
|
* they are broken, and "jackpot" is recorded--a harmless
|
||||||
* matter except that a true match for a spuriously
|
* matter except that a true match for a spuriously
|
||||||
* mated line may now be unnecessarily reported as a change.
|
* mated line may now be unnecessarily reported as a change.
|
||||||
*
|
*
|
||||||
* Much of the complexity of the program comes simply
|
* Much of the complexity of the program comes simply
|
||||||
* from trying to minimize core utilization and
|
* from trying to minimize core utilization and
|
||||||
* maximize the range of doable problems by dynamically
|
* maximize the range of doable problems by dynamically
|
||||||
* allocating what is needed and reusing what is not.
|
* allocating what is needed and reusing what is not.
|
||||||
* The core requirements for problems larger than somewhat
|
* The core requirements for problems larger than somewhat
|
||||||
* are (in words) 2*length(file0) + length(file1) +
|
* are (in words) 2*length(file0) + length(file1) +
|
||||||
* 3*(number of k-candidates installed), typically about
|
* 3*(number of k-candidates installed), typically about
|
||||||
* 6n words for files of length n.
|
* 6n words for files of length n.
|
||||||
*/
|
*/
|
||||||
static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
||||||
{
|
{
|
||||||
|
@ -514,6 +514,7 @@ int bb_test(int argc, char** argv);
|
|||||||
#if ENABLE_ROUTE
|
#if ENABLE_ROUTE
|
||||||
void bb_displayroutes(int noresolve, int netstatfmt);
|
void bb_displayroutes(int noresolve, int netstatfmt);
|
||||||
#endif
|
#endif
|
||||||
|
int chown_main(int argc, char **argv);
|
||||||
#if ENABLE_GUNZIP
|
#if ENABLE_GUNZIP
|
||||||
int gunzip_main(int argc, char **argv);
|
int gunzip_main(int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user