#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;
int pred;
};
-struct line {
+static struct line {
int serial;
int value;
} *file[2];
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)
{
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;
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;
}
}
}
- return;
}
}
/*
- * 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)
{