SPIFF 1 "February 2, 1988"
Table of contents
spiff - make controlled approximate comparisons between files
script ] [
sfile ] [
value ] -value file1 file2
compares the contents of
and prints a description of the important differences between
White space is ignored except to separate other objects.
maintains tolerances below which differences between two floating-point
numbers are ignored.
Differences in floating-point notation (such as 3.4 3.40 and 3.4e01)
are treated as unimportant.
User-specified delimited strings (i.e. comments) can also be ignored.
Inside other user-specified delimited strings
(i.e. quoted strings) whitespace can be significant.
operation can be altered via command line options, a command script, and with
commands that are embedded in the input files.
The following options affect
has several flags to aid differencing of various programming languages.
See EXAMPLES for a detailed description of the effects of these flags.
suppresses warning messages.
use a visually oriented display. Works only in MGR windows.
By default, the output looks somewhat similar in appearance
to the output of diff(1). Lines with differences are printed with
the differences highlighted. If stdout is a terminal, as determined
by isatty(), then highlighting uses standout mode as determined by termcap.
If stdout is not a tty, then the underlining (via underscore/backspace/char)
is used to highlight differences.
The following option can control the format of the ouput.
treat the input files as C program source code.
treat the input files as Bourne shell program source code.
treat the input files as Fortran program source code.
treat the input files as Modula-2 program source code.
treat the input files as Lisp program source code.
The following option controls the differencing algorithm.
produce output in terms of individual tokens. This option is
most useful for debugging as the output produced is verbose to
the point of being unreadable.
The following options control the command script. More than one of
each may appear at a time. The commands accumulate.
compare each token
in the files with the object in the same ordinal
position in the other file. If the files have a different number
of objects, a warning message is printed
and the objects at the end of the longer file are ignored.
uses a Miller/Myers algorithm to find a minimal edit sequence
that will convert the contents of the first file into the second.
sets a limit on the total number of insertions and deletions
that will be considered.
If the files differ by more than the stated amount,
the program will give up, print a warning message, and exit.
The following options control how individual objects are compared.
a command script to be taken from file
causes the following argument to be taken as a command script.
The following commands will control how the files are parsed.
treat all objects (including floating-point numbers) as literals.
ignore differences between upper and lower case.
The following three flags are used to set the default tolerances.
The floating-point-numbers may be given in the formats accepted
treat white space as objects. Each white space character will
be treated as a separate object when the program is comparing the
treat leading sign characters ( + and - ) as separate even
if they are followed by floating-point numbers.
treat integer decimal numbers (such as 1987) as real numbers (subject to
tolerances) rather than as literal strings.
If more than one
flag appear on the command line,
the tolerances will be OR'd together (i.e. any difference that is within
any of the tolerances will be ignored).
specifies an absolute value for the tolerance in floating-point numbers.
will cause all differences greater than 0.01 to be reported.
specifies a relative tolerance. The value given is interpreted
as a fraction of the larger (in absolute terms)
of the two floating-point numbers being compared.
Thus, the flag
will cause the two floating-point numbers 1.0 and 0.9 to be deemed within
tolerance. The numbers 1.0 and 0.89 will be outside the tolerance.
causes differences between floating-point numbers to be ignored.
If no default tolerances is set on the command line,
the program will use a default tolerance of
A script consists of commands, one per line.
Each command consists of a keyword possibly followed by arguments.
Arguments are separated by one or more tabs or spaces.
The commands are:
More than one comment specification and more than one literal string specification
may be specified at a time.
literal BEGIN-STRING [END-STRING [ESCAPE-STRING]]
Specifies the delimiters surrounding text that is to be treated as a single
literal object. If only one argument is present, then only that string itself is treated
as a literal. If only two arguments are present, they are taking as the starting
and ending delimiters respectively. If three arguments are present, they are treated
as the start delimiter, end delimiter, and a string that may be used to escape
an instance of the end delimiter.
Set the beginning of line character for BEGIN-STRING's in comments.
The default is `^'.
Set the end of line character for END-STRING's in comments.
The default is `$'.
Add NEW-ALPHA-CHARACTER to the set of characters allowed in literal strings.
parses sequences of characters that begin with a letter and followed by
zero or more letters or numbers as a single literal token. This definition
is overly restrictive when dealing with programming languages.
For example, in the C programming language,
the underscore character is allowed in identifiers.
comment BEGIN-STRING [END-STRING [ESCAPE-STRING]]
Specifies the delimiters surrounding text that is to be ignored entirely
(i.e. viewed as comments).
The operation of the comment command is very similar to the literal command.
In addition, if the END-STRING consists of only
the end of line character, the end of line will delimit the end of the comment.
Also, if the BEGIN-STRING starts with the beginning of line character, only
lines that begin with the BEGIN-STRING will be ignored.
Tolerances specified in the command scripts have precedence over the tolerance
specified on the invocation command line. The tolerance specified in
has precedence over the tolerance specified in
nestcom BEGIN-STRING [END-STRING [ESCAPE-STRING]]
Similar to the comment command, but allows comments to be nested.
Note, due to the design of the parser nested comments can not
have a BEGIN-STRING that starts with the beginning of line character.
Clears the list of comment specifications.
Clears the list of literal specifications.
tol [aVALUE\(brrVALUE\(bri\(brd . . . [ ; aVALUE\(brrVALUE\(bri\(brd . . . ] . . . ]
set the tolerance for floating-point comparisons.
The arguments to the tol command are a set of tolerance specifications
separated by semicolons. If more than one a,r,d, or i appears within
a specification, then the tolerances are OR'd together (i.e. any difference
that is within any tolerance will be ignored).
The semantics of a,r, and i are identical to the
flags. The d means that the default tolerance (as specified by the invocation
options) should be used.
If more than one specification appears on the line, the first
specification is applied to the first floating-point number on each line,
the second specification to the second floating-point number one each line
of the input files, and so on. If there are more floating-point numbers
on a given line of input than tolerance specifications,
the last specification is used repeatedly for all remaining floating-point numbers
on that line.
lines in the input file that start with STRING will be interpreted as
command lines. If no "command" is given as part of a
then it will be impossible to embed commands in the input files.
used to place human readable remarks into a command script. Note that the
use of the `#' character differs from other command languages (for instance
the Bourne shell).
will only recognize the `#' as beginning a comment when it is the first
non-blank character on the command line. A `#' character appearing elsewhere
will be treated as part of the command. Cautious users should use `rem'.
Those hopelessly addicted to `#' as a comment character can have command
scripts with a familiar format.
is invoked with the -v option, it will enter an interactive mode rather
than produce an edit sequence. Three windows will be put on the screen.
Two windows will contain corresponding segments of the input files.
Objects that appear in both segments will be examined for differences and
if any difference is found, the objects will be highlighted in reverse video
on the screen. Objects that appear in only one window will have a line drawn
through them to indicate that they aren't being compared with anything in the other
text window. The third window is a command window. The command window will
accept a single tolerance specification (followed by a newline)
in a form suitable to the
command. The tolerance specified will then be used as the default tolerance
and the display will be updated to highlight only those objects that exceed
the new default tolerance. Typing
(followed by a newline) will display the next screenful of text. Typing
(followed by a newline) will cause the program to exit.
Each input file can be no longer that 10,000 lines long or contain more
than 50,000 tokens. Longer files will be truncated.
No line can be longer than 1024 characters. Newlines
will be inserted every 1024 characters.
spiff -e -d foo bar
this invocation (using exact match algorithm and treating integer numbers
as if they were floats) is very useful for examining large tables of numbers.
spiff -0 foo bar
compare the two files, quitting after the first difference is found.
This makes the program operate roughly like cmp(1).
spiff -0 -q foo bar
same as the above, but no output is produced.
The return code is still useful.
spiff -w -b foo bar
will make the program operate much like diff(1).
spiff -a1e-5 -r0.001 foo bar
compare the contents of the files foo and bar and ignore all differences between
floating-point numbers that are less than or equal to
0.00001 or 0.1% of the number of larger magnitude.
tol a.01 r.01
will cause all differences between floating-point numbers that are less than
or equal to
0.01 or 1% of the number of larger magnitude to be ignored.
tol a.01 r.01 ; i
will cause the tolerance in the previous example to be applied to the first
floating-point number on each line. All differences between the second and
subsequent floating-point numbers on each line will be ignored.
tol a.01 r.01 ; i ; a.0001
like the above except that only differences between the second floating-point
number on each line will be ignored. The differences between
third and subsequent floating-point numbers on each number will be ignored if they
are less than or equal to 0.0001.
A useful script for examing C code is:
literal " " \
comment /* */
A useful script for shell programs is:
literal ' ' \
comment # $
A useful script for Fortran programs is:
literal ' ' '
comment ^C $
A useful script for Modula 2 programs is:
literal ' '
literal " "
nestcom (* *)
A useful script for Lisp programs is:
literal " "
comment ; $
exit status is 0 if no differences are found, 1 if differences are found, and
2 upon error.
In C code, escaped newlines will appear as differences.
Comments are treated as token delimiters.
Comments in Basic don't work right. The line number is not ignored.
Continuation lines in Fortran comments don't work.
There is no way to represent strings specified using a
Hollerith notation in Fortran.
In formatted English text, hyphenated words,
movements in pictures, footnotes, etc.
will be reported as differences.
STRING's in script commands can not include whitespace.
Visual mode does not handle tabs properly. Files containing
tabs should be run through
expand(1) before trying to display them with visual mode.
In visual mode, the text windows appear in a fixed size and font.
Lines longer than the window size will not be handled properly.
Objects (literal strings) that contain newlines cause trouble in several places
in visual mode.
Visual mode should accept more than one tolerance specification.
When using visual mode or the exact match comparison algorithm, the program
should do the parsing on the fly rather than truncating long files.
Copyright (c) 1988 Bellcore
All Rights Reserved
Permission is granted to copy or use this program,
EXCEPT that it may not be sold for profit, the copyright
notice must be reproduced on copies, and credit should
be given to Bellcore where it is due.
BELLCORE MAKES NO WARRANTY AND ACCEPTS
NO LIABILITY FOR THIS PROGRAM.
"Spiff -- A Program for Making Controlled Approximate Comparisons of Files",
by Daniel Nachbar.
"A File Comparison Program" by Webb Miller and Eugene W. Myers in Software -
Practice and Experience, Volume 15(11), pp.1025-1040, (November 1985).