#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # analyze.c # This archive created: Thu Jul 18 09:30:39 1991 export PATH; PATH=/bin:$PATH echo shar: extracting "'analyze.c'" '(25488 characters)' if test -f 'analyze.c' then echo shar: will not over-write existing file "'analyze.c'" else sed 's/^ X//' << \SHAR_EOF > 'analyze.c' X/* Analyze file differences for GNU DIFF. X Copyright (C) 1988, 1989 Free Software Foundation, Inc. X XThis file is part of GNU DIFF. X XGNU DIFF is free software; you can redistribute it and/or modify Xit under the terms of the GNU General Public License as published by Xthe Free Software Foundation; either version 1, or (at your option) Xany later version. X XGNU DIFF is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY; without even the implied warranty of XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the XGNU General Public License for more details. X XYou should have received a copy of the GNU General Public License Xalong with GNU DIFF; see the file COPYING. If not, write to Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ X X/* The basic algorithm is described in: X "An O(ND) Difference Algorithm and its Variations", Eugene Myers, X Algorithmica Vol. 1 No. 2, 1986, p 251. */ X X#include "diff.h" X Xstruct change *find_change (); X Xextern int quick_and_dirty; Xextern int extended_tests; Xextern int no_discards; X Xstatic int *xvec, *yvec; /* Vectors being compared. */ Xstatic int *fdiag; /* Vector, indexed by diagonal, containing X the X coordinate of the point furthest X along the given diagonal in the forward X search of the edit matrix. */ Xstatic int *bdiag; /* Vector, indexed by diagonal, containing X the X coordinate of the point furthest X along the given diagonal in the backward X search of the edit matrix. */ X X/* Find the midpoint of the shortest edit script for a specified X portion of the two files. X X We scan from the beginnings of the files, and simultaneously from the ends, X doing a breadth-first search through the space of edit-sequence. X When the two searches meet, we have found the midpoint of the shortest X edit sequence. X X The value returned is the number of the diagonal on which the midpoint lies. X The diagonal number equals the number of inserted lines minus the number X of deleted lines (counting only lines before the midpoint). X The edit cost is stored into *COST; this is the total number of X lines inserted or deleted (counting only lines before the midpoint). X X This function assumes that the first lines of the specified portions X of the two files do not match, and likewise that the last lines do not X match. The caller must trim matching lines from the beginning and end X of the portions it is going to specify. X X Note that if we return the "wrong" diagonal value, or if X the value of bdiag at that diagonal is "wrong", X the worst this can do is cause suboptimal diff output. X It cannot cause incorrect diff output. */ X Xstatic int Xdiag (xoff, xlim, yoff, ylim, cost) X int xoff, xlim, yoff, ylim; X int *cost; X{ X int *const fd = fdiag; /* Give the compiler a chance. */ X int *const bd = bdiag; /* Additional help for the compiler. */ X int *const xv = xvec; /* Still more help for the comiler. */ X int *const yv = yvec; /* And more and more . . . */ X const int dmin = xoff - ylim; /* Minimum valid diagonal. */ X const int dmax = xlim - yoff; /* Maximum valid diagonal. */ X const int fmid = xoff - yoff; /* Center diagonal of top-down search. */ X const int bmid = xlim - ylim; /* Center diagonal of bottom-up search. */ X int fmin = fmid, fmax = fmid; /* Limits of top-down search. */ X int bmin = bmid, bmax = bmid; /* Limits of bottom-up search. */ X int c; /* Cost. */ X int odd = fmid - bmid & 1; /* True if southeast corner is on an odd X diagonal with respect to the northwest. */ X X fd[fmid] = xoff; X bd[bmid] = xlim; X X for (c = 1;; ++c) X { X int d; /* Active diagonal. */ X int big_snake = 0; X X /* Extend the top-down search by an edit step in each diagonal. */ X fmin > dmin ? fd[--fmin - 1] = -1 : ++fmin; X fmax < dmax ? fd[++fmax + 1] = -1 : --fmax; X for (d = fmax; d >= fmin; d -= 2) X { X int x, y, oldx, tlo = fd[d - 1], thi = fd[d + 1]; X X if (tlo >= thi) X x = tlo + 1; X else X x = thi; X oldx = x; X y = x - d; X while (x < xlim && y < ylim && xv[x] == yv[y]) X ++x, ++y; X if (x - oldx > 20) X big_snake = 1; X fd[d] = x; X if (odd && bmin <= d && d <= bmax && bd[d] <= fd[d]) X { X *cost = 2 * c - 1; X return d; X } X } X X /* Similar extend the bottom-up search. */ X bmin > dmin ? bd[--bmin - 1] = INT_MAX : ++bmin; X bmax < dmax ? bd[++bmax + 1] = INT_MAX : --bmax; X for (d = bmax; d >= bmin; d -= 2) X { X int x, y, oldx, tlo = bd[d - 1], thi = bd[d + 1]; X X if (tlo < thi) X x = tlo; X else X x = thi - 1; X oldx = x; X y = x - d; X while (x > xoff && y > yoff && xv[x - 1] == yv[y - 1]) X --x, --y; X if (oldx - x > 20) X big_snake = 1; X bd[d] = x; X if (!odd && fmin <= d && d <= fmax && bd[d] <= fd[d]) X { X *cost = 2 * c; X return d; X } X } X X /* Heuristic: check occasionally for a diagonal that has made X lots of progress compared with the edit distance. X If we have any such, find the one that has made the most X progress and return it as if it had succeeded. X X With this heuristic, for files with a constant small density X of changes, the algorithm is linear in the file size. */ X X if (c > 200 && big_snake && heuristic) X { X int best; X int bestpos; X X best = 0; X for (d = fmax; d >= fmin; d -= 2) X { X int dd = d - fmid; X if ((fd[d] - xoff)*2 - dd > 12 * (c + (dd > 0 ? dd : -dd))) X { X if (fd[d] * 2 - dd > best X && fd[d] - xoff > 20 X && fd[d] - d - yoff > 20) X { X int k; X int x = fd[d]; X X /* We have a good enough best diagonal; X now insist that it end with a significant snake. */ X for (k = 1; k <= 20; k++) X if (xvec[x - k] != yvec[x - d - k]) X break; X X if (k == 21) X { X best = fd[d] * 2 - dd; X bestpos = d; X } X } X } X } X if (best > 0) X { X *cost = 2 * c - 1; X return bestpos; X } X X best = 0; X for (d = bmax; d >= bmin; d -= 2) X { X int dd = d - bmid; X if ((xlim - bd[d])*2 + dd > 12 * (c + (dd > 0 ? dd : -dd))) X { X if ((xlim - bd[d]) * 2 + dd > best X && xlim - bd[d] > 20 X && ylim - (bd[d] - d) > 20) X { X /* We have a good enough best diagonal; X now insist that it end with a significant snake. */ X int k; X int x = bd[d]; X X for (k = 0; k < 20; k++) X if (xvec[x + k] != yvec[x - d + k]) X break; X if (k == 20) X { X best = (xlim - bd[d]) * 2 + dd; X bestpos = d; X } X } X } X } X if (best > 0) X { X *cost = 2 * c - 1; X return bestpos; X } X } X } X} X X/* Compare in detail contiguous subsequences of the two files X which are known, as a whole, to match each other. X X The results are recorded in the vectors files[N].changed_flag, by X storing a 1 in the element for each line that is an insertion or deletion. X X The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1. X X Note that XLIM, YLIM are exclusive bounds. X All line numbers are origin-0 and discarded lines are not counted. */ X Xstatic void Xcompareseq (xoff, xlim, yoff, ylim) X int xoff, xlim, yoff, ylim; X{ X /* Slide down the bottom initial diagonal. */ X while (xoff < xlim && yoff < ylim && xvec[xoff] == yvec[yoff]) X ++xoff, ++yoff; X /* Slide up the top initial diagonal. */ X while (xlim > xoff && ylim > yoff && xvec[xlim - 1] == yvec[ylim - 1]) X --xlim, --ylim; X X /* Handle simple cases. */ X if (xoff == xlim) X while (yoff < ylim) X files[1].changed_flag[files[1].realindexes[yoff++]] = 1; X else if (yoff == ylim) X while (xoff < xlim) X files[0].changed_flag[files[0].realindexes[xoff++]] = 1; X else X { X int c, d, f, b; X X /* Find a point of correspondence in the middle of the files. */ X X d = diag (xoff, xlim, yoff, ylim, &c); X f = fdiag[d]; X b = bdiag[d]; X X if (c == 1) X { X /* This should be impossible, because it implies that X one of the two subsequences is empty, X and that case was handled above without calling `diag'. X Let's verify that this is true. */ X abort (); X#if 0 X /* The two subsequences differ by a single insert or delete; X record it and we are done. */ X if (d < xoff - yoff) X files[1].changed_flag[files[1].realindexes[b - d - 1]] = 1; X else X files[0].changed_flag[files[0].realindexes[b]] = 1; X#endif X } X else X { X /* Use that point to split this problem into two subproblems. */ X compareseq (xoff, b, yoff, b - d); X /* This used to use f instead of b, X but that is incorrect! X It is not necessarily the case that diagonal d X has a snake from b to f. */ X compareseq (b, xlim, b - d, ylim); X } X } X} X X/* Discard lines from one file that have no matches in the other file. X X A line which is discarded will not be considered by the actual X comparison algorithm; it will be as if that line were not in the file. X The file's `realindexes' table maps virtual line numbers X (which don't count the discarded lines) into real line numbers; X this is how the actual comparison algorithm produces results X that are comprehensible when the discarded lines are counted. X X When we discard a line, we also mark it as a deletion or insertion X so that it will be printed in the output. */ X Xvoid Xdiscard_confusing_lines (filevec) X struct file_data filevec[]; X{ X int f, i; X char *discarded[2]; X int *equiv_count[2]; X X /* Allocate our results. */ X for (f = 0; f < 2; f++) X { X filevec[f].undiscarded X = (int *) xmalloc (filevec[f].buffered_lines * sizeof (int)); X filevec[f].realindexes X = (int *) xmalloc (filevec[f].buffered_lines * sizeof (int)); X } X X /* Set up equiv_count[F][I] as the number of lines in file F X that fall in equivalence class I. */ X X equiv_count[0] = (int *) xmalloc (filevec[0].equiv_max * sizeof (int)); X bzero (equiv_count[0], filevec[0].equiv_max * sizeof (int)); X equiv_count[1] = (int *) xmalloc (filevec[1].equiv_max * sizeof (int)); X bzero (equiv_count[1], filevec[1].equiv_max * sizeof (int)); X X for (i = 0; i < filevec[0].buffered_lines; ++i) X ++equiv_count[0][filevec[0].equivs[i]]; X for (i = 0; i < filevec[1].buffered_lines; ++i) X ++equiv_count[1][filevec[1].equivs[i]]; X X /* Set up tables of which lines are going to be discarded. */ X X discarded[0] = (char *) xmalloc (filevec[0].buffered_lines); X discarded[1] = (char *) xmalloc (filevec[1].buffered_lines); X bzero (discarded[0], filevec[0].buffered_lines); X bzero (discarded[1], filevec[1].buffered_lines); X X /* Mark to be discarded each line that matches no line of the other file. X If a line matches many lines, mark it as provisionally discardable. */ X X for (f = 0; f < 2; f++) X { X int end = filevec[f].buffered_lines; X char *discards = discarded[f]; X int *counts = equiv_count[1 - f]; X int *equivs = filevec[f].equivs; X for (i = 0; i < end; i++) X { X int nmatch = counts[equivs[i]]; X if (equivs[i] == 0) X continue; X if (nmatch == 0) X discards[i] = 1; X else if (nmatch > 5) X discards[i] = 2; X } X } X X /* Don't really discard the provisional lines if there are less than ten X discardable lines in a row. */ X X for (f = 0; f < 2; f++) X { X int end = filevec[f].buffered_lines; X char *discards = discarded[f]; X X for (i = 0; i < end; i++) X if (discards[i]) X { X register int j; X int length; X int provisional = 0; X X /* Cancel provisional discards at the beginning. */ X while (i < end && discards[i] == 2) X discards[i] = 0; X X /* Find end of this run of discardable lines. X Count how many are provisionally discardable. */ X for (j = i; j < end; j++) X { X if (discards[j] == 0) X break; X if (discards[j] == 2) X ++provisional; X } X X /* Cancel provisional discards at the end, and shrink the run. */ X while (j > i && discards[j - 1] == 2) X discards[j - 1] = 0, --provisional; X X /* Now we have the length of a run of discardable lines X whose first and last are not provisional. */ X length = j - i; X X /* If half the lines in the run are provisional, X cancel discarding of all provisional lines in the run. */ X if (provisional * 2 > length) X { X while (j > i) X if (discards[--j] == 2) X discards[j] = 0; X } X else X { X /* Cancel provisional discards that are near either end. */ X for (j = 0; j < 5 && j < length; j++) X if (discards[i + j] == 2) X discards[i + j] = 0; X /* Meanwhile, I advances to the last line of the run. */ X i += length - 1; X length -= 5; X for (j = 0; j < 5 && j < length; j++) X if (discards[i - j] == 2) X discards[i - j] = 0; X } X } X } X X /* Discard from file 0. */ X for (f = 0; f < 2; f++) X { X char *discards = discarded[f]; X int end = filevec[f].buffered_lines; X int j = 0; X for (i = 0; i < end; ++i) X if (no_discards || discards[i] == 0) X { X filevec[f].undiscarded[j] = filevec[f].equivs[i]; X filevec[f].realindexes[j++] = i; X } X else X filevec[f].changed_flag[i] = 1; X filevec[f].nondiscarded_lines = j; X } X X free (discarded[1]); X free (discarded[0]); X free (equiv_count[1]); X free (equiv_count[0]); X} X X/* Adjust inserts/deletes of blank lines to join changes X as much as possible. X X We do something when a run of changed lines include a blank X line at one end and have an excluded blank line at the other. X We are free to choose which blank line is included. X `compareseq' always chooses the one at the beginning, X but usually it is cleaner to consider the following blank line X to be the "change". The only exception is if the preceding blank line X would join this change to other changes. */ X Xint inhibit; X Xstatic void Xshift_boundaries (filevec) X struct file_data filevec[]; X{ X int f; X X if (inhibit) X return; X X for (f = 0; f < 2; f++) X { X char *changed = filevec[f].changed_flag; X char *other_changed = filevec[1-f].changed_flag; X int i = 0; X int j = 0; X int i_end = filevec[f].buffered_lines; X int preceding = -1; X int other_preceding = -1; X X while (1) X { X int start, end, other_start; X X /* Scan forwards to find beginning of another run of changes. X Also keep track of the corresponding point in the other file. */ X X while (i < i_end && changed[i] == 0) X { X while (other_changed[j++]) X /* Non-corresponding lines in the other file X will count as the preceding batch of changes. */ X other_preceding = j; X i++; X } X X if (i == i_end) X break; X X start = i; X other_start = j; X X while (1) X { X /* Now find the end of this run of changes. */ X X while (i < i_end && changed[i] != 0) i++; X end = i; X X /* If the first changed line matches the following unchanged one, X and this run does not follow right after a previous run, X and there are no lines deleted from the other file here, X then classify the first changed line as unchanged X and the following line as changed in its place. */ X X /* You might ask, how could this run follow right after another? X Only because the previous run was shifted here. */ X X if (end != i_end X && files[f].equivs[start] == files[f].equivs[end] X && !other_changed[j] X && end != i_end X && !((preceding >= 0 && start == preceding) X || (other_preceding >= 0 X && other_start == other_preceding))) X { X changed[end++] = 1; X changed[start++] = 0; X ++i; X /* Since one line-that-matches is now before this run X instead of after, we must advance in the other file X to keep in synch. */ X ++j; X } X else X break; X } X X preceding = i; X other_preceding = j; X } X } X} X X/* Cons an additional entry onto the front of an edit script OLD. X LINE0 and LINE1 are the first affected lines in the two files (origin 0). X DELETED is the number of lines deleted here from file 0. X INSERTED is the number of lines inserted here in file 1. X X If DELETED is 0 then LINE0 is the number of the line before X which the insertion was done; vice versa for INSERTED and LINE1. */ X Xstatic struct change * Xadd_change (line0, line1, deleted, inserted, old) X int line0, line1, deleted, inserted; X struct change *old; X{ X struct change *new = (struct change *) xmalloc (sizeof (struct change)); X X new->line0 = line0; X new->line1 = line1; X new->inserted = inserted; X new->deleted = deleted; X new->link = old; X return new; X} X X/* Scan the tables of which lines are inserted and deleted, X producing an edit script in reverse order. */ X Xstatic struct change * Xbuild_reverse_script (filevec) X struct file_data filevec[]; X{ X struct change *script = 0; X char *changed0 = filevec[0].changed_flag; X char *changed1 = filevec[1].changed_flag; X int len0 = filevec[0].buffered_lines; X int len1 = filevec[1].buffered_lines; X X /* Note that changedN[len0] does exist, and contains 0. */ X X int i0 = 0, i1 = 0; X X while (i0 < len0 || i1 < len1) X { X if (changed0[i0] || changed1[i1]) X { X int line0 = i0, line1 = i1; X X /* Find # lines changed here in each file. */ X while (changed0[i0]) ++i0; X while (changed1[i1]) ++i1; X X /* Record this change. */ X script = add_change (line0, line1, i0 - line0, i1 - line1, script); X } X X /* We have reached lines in the two files that match each other. */ X i0++, i1++; X } X X return script; X} X X/* Scan the tables of which lines are inserted and deleted, X producing an edit script in forward order. */ X Xstatic struct change * Xbuild_script (filevec) X struct file_data filevec[]; X{ X struct change *script = 0; X char *changed0 = filevec[0].changed_flag; X char *changed1 = filevec[1].changed_flag; X int len0 = filevec[0].buffered_lines; X int len1 = filevec[1].buffered_lines; X int i0 = len0, i1 = len1; X X /* Note that changedN[-1] does exist, and contains 0. */ X X /* In RCS comparisons, making the existence or nonexistence of trailing X newlines really matter. */ X if (output_style == OUTPUT_RCS X && filevec[0].missing_newline != filevec[1].missing_newline) X changed0[len0 - 1] = changed1[len1 - 1] = 1; X X while (i0 >= 0 || i1 >= 0) X { X if (changed0[i0 - 1] || changed1[i1 - 1]) X { X int line0 = i0, line1 = i1; X X /* Find # lines changed here in each file. */ X while (changed0[i0 - 1]) --i0; X while (changed1[i1 - 1]) --i1; X X /* Record this change. */ X script = add_change (i0, i1, line0 - i0, line1 - i1, script); X } X X /* We have reached lines in the two files that match each other. */ X i0--, i1--; X } X X return script; X} X X/* Report the differences of two files. DEPTH is the current directory X depth. */ Xint Xdiff_2_files (filevec, depth) X struct file_data filevec[]; X int depth; X{ X int diags; X int i; X struct change *e, *p; X struct change *script; X int binary; X int changes; X X /* See if the two named files are actually the same physical file. X If so, we know they are identical without actually reading them. */ X X if (filevec[0].stat.st_ino == filevec[1].stat.st_ino X && filevec[0].stat.st_dev == filevec[1].stat.st_dev) X return 0; X X if (quick_and_dirty) { X return(quick_compare(filevec)); X } X X binary = read_files (filevec); X X /* If we have detected that file 0 is a binary file, X compare the two files as binary. This can happen X only when the first chunk is read. X Also, -q means treat all files as binary. */ X X if (binary || no_details_flag) X { X int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars X || bcmp (filevec[0].buffer, filevec[1].buffer, X filevec[1].buffered_chars)); X if (differs) X message (binary ? "Binary files %s and %s differ\n" X : "Files %s and %s differ\n", X filevec[0].name, filevec[1].name); X X for (i = 0; i < 2; ++i) X if (filevec[i].buffer) X free (filevec[i].buffer); X return differs; X } X X if (filevec[0].missing_newline != filevec[1].missing_newline X && output_style != OUTPUT_RCS) X { X if (filevec[0].missing_newline) X message ("No newline at end of file %s\n", filevec[0].name, ""); X if (filevec[1].missing_newline) X message ("No newline at end of file %s\n", filevec[1].name, ""); X } X X /* Allocate vectors for the results of comparison: X a flag for each line of each file, saying whether that line X is an insertion or deletion. X Allocate an extra element, always zero, at each end of each vector. */ X X filevec[0].changed_flag = (char *) xmalloc (filevec[0].buffered_lines + 2); X filevec[1].changed_flag = (char *) xmalloc (filevec[1].buffered_lines + 2); X bzero (filevec[0].changed_flag, filevec[0].buffered_lines + 2); X bzero (filevec[1].changed_flag, filevec[1].buffered_lines + 2); X filevec[0].changed_flag++; X filevec[1].changed_flag++; X X /* Some lines are obviously insertions or deletions X because they don't match anything. Detect them now, X and avoid even thinking about them in the main comparison algorithm. */ X X discard_confusing_lines (filevec); X X /* Now do the main comparison algorithm, considering just the X undiscarded lines. */ X X xvec = filevec[0].undiscarded; X yvec = filevec[1].undiscarded; X diags = filevec[0].nondiscarded_lines + filevec[1].nondiscarded_lines + 3; X fdiag = (int *) xmalloc (diags * sizeof (int)); X fdiag += filevec[1].nondiscarded_lines + 1; X bdiag = (int *) xmalloc (diags * sizeof (int)); X bdiag += filevec[1].nondiscarded_lines + 1; X X files[0] = filevec[0]; X files[1] = filevec[1]; X X compareseq (0, filevec[0].nondiscarded_lines, X 0, filevec[1].nondiscarded_lines); X X bdiag -= filevec[1].nondiscarded_lines + 1; X free (bdiag); X fdiag -= filevec[1].nondiscarded_lines + 1; X free (fdiag); X X /* Modify the results slightly to make them prettier X in cases where that can validly be done. */ X X shift_boundaries (filevec); X X /* Get the results of comparison in the form of a chain X of `struct change's -- an edit script. */ X X if (output_style == OUTPUT_ED) X script = build_reverse_script (filevec); X else X script = build_script (filevec); X X if (script) X { X setup_output (files[0].name, files[1].name, depth); X if (output_style == OUTPUT_CONTEXT) X print_context_header (files); X X switch (output_style) X { X case OUTPUT_CONTEXT: X print_context_script (script); X break; X X case OUTPUT_ED: X print_ed_script (script); X break; X X case OUTPUT_FORWARD_ED: X pr_forward_ed_script (script); X break; X X case OUTPUT_RCS: X print_rcs_script (script); X break; X X case OUTPUT_NORMAL: X print_normal_script (script); X break; X X case OUTPUT_IFDEF: X print_ifdef_script (script); X break; X } X X finish_output (); X } X X /* Set CHANGES if we had any diffs that were printed. X If some changes are being ignored, we must scan the script to decide. */ X if (ignore_blank_lines_flag || ignore_regexp) X { X struct change *next = script; X changes = 0; X X while (next && changes == 0) X { X struct change *this, *end; X int first0, last0, first1, last1, deletes, inserts; X X /* Find a set of changes that belong together. */ X this = next; X end = find_change (next); X X /* Disconnect them from the rest of the changes, X making them a hunk, and remember the rest for next iteration. */ X next = end->link; X end->link = NULL; X X /* Determine whether this hunk was printed. */ X analyze_hunk (this, &first0, &last0, &first1, &last1, X &deletes, &inserts); X X /* Reconnect the script so it will all be freed properly. */ X end->link = next; X X if (deletes || inserts) X changes = 1; X } X } X else X changes = (script != 0); X X for (i = 1; i >= 0; --i) X { X free (filevec[i].realindexes); X free (filevec[i].undiscarded); X } X X for (i = 1; i >= 0; --i) X free (--filevec[i].changed_flag); X X for (i = 1; i >= 0; --i) X free (filevec[i].equivs); X X for (i = 0; i < 2; ++i) X { X if (filevec[i].buffer != 0) X free (filevec[i].buffer); X free (filevec[i].linbuf); X } X X for (e = script; e; e = p) X { X p = e->link; X free (e); X } X X return changes; X} X X X#define BUFSIZE 8192 X Xint quick_compare(filevec) X struct file_data filevec[]; X X{ X char buffer0[BUFSIZE]; X char buffer1[BUFSIZE]; X int cc0, cc1; X X /* If the lengths are different, then the files are different. */ X X if (filevec[0].stat.st_size != filevec[1].stat.st_size) { X message ("Files have different sizes: %s and %s\n", X filevec[0].name, filevec[1].name); X return(1); X } X X /* If we're doing extended tests and the block counts are different, X report it but go on. */ X X if (extended_tests && filevec[0].stat.st_blocks != filevec[1].stat.st_blocks) { X message ("Files have different numbers of blocks: %s and %s\n", X filevec[0].name, filevec[1].name); X } X X while (1) { X cc0 = read(filevec[0].desc, buffer0, BUFSIZE); X X if (cc0 < 0) { X perror("read"); X exit(1); X } X X cc1 = read(filevec[1].desc, buffer1, BUFSIZE); X X if (cc1 < 0) { X perror("read"); X exit(1); X } X X if (cc0 != cc1) { X fprintf(stderr, "huh? cc0 and cc1 aren't equal...!\n"); X exit(1); X } X X if (cc0 == 0) { X break; X } X X if (bcmp(buffer0, buffer1, cc0) != 0) { X message("File contents are different: %s and %s\n", X filevec[0].name, X filevec[1].name); X return(1); X } X } X X return(0); X} SHAR_EOF if test 25488 -ne "`wc -c < 'analyze.c'`" then echo shar: error transmitting "'analyze.c'" '(should have been 25488 characters)' fi fi # end of overwriting check # End of shell archive exit 0