[comp.unix.questions] looking for C language file differ

jlash@cbnewsd.att.com (john.k.lash) (06/01/90)

Does anyoue have or know of a "syntax tolerant" diff program for C files?
What I have in mind is a diff that works on the level of C expressions, 
functions, and declarations as opposed to text lines.  For instance it 
should not consider the following two code fragments to be different:

                     x=y+z; a=b+c;
-------
                     x = y + z;
                     a = b+c;


Also, it should ignore equivalent functions at different places in the 
source files.  I could add lots of other things like ignoring differences
in the ordering of local variables, #defines, and structure definitions.

When it finds a difference it could print the offending lines and line 
numbers.

How bout it, does such a thing exist?  I haven't thought of any impossible
problems with doing this short of finding the time. 

thanks for any help
--john

john lash	jlash@ihlpa.att.com

brnstnd@stealth.acf.nyu.edu (06/01/90)

In article <1990May31.185500.29790@cbnewsd.att.com> jlash@cbnewsd.att.com (john.k.lash) writes:
> Does anyoue have or know of a "syntax tolerant" diff program for C files?

It sounds like you want to pipe both programs through a reindenter
before diffing them. To keep track of the original line numbers, your
safest bet is to use cpp and then add /* 356 */, /* 357 */, ...

> Also, it should ignore equivalent functions at different places in the 
> source files.  I could add lots of other things like ignoring differences
> in the ordering of local variables, #defines, and structure definitions.

cpp handles any #define trickery. For the reordering: After a reindent,
sort the ``pieces'' of the code into order, where pieces are external
declarations, function definitions, etc. This is really easy if your
indent can manage to separate pieces by spaces. Similarly sort the local
variables within each block.

---Dan

david@eng.sun.com (habafropzipulops) (06/02/90)

In article <1990May31.185500.29790@cbnewsd.att.com> jlash@cbnewsd.att.com
(john.k.lash) writes:
>Does anyoue have or know of a "syntax tolerant" diff program for C files?

Sure -- Dick Grune's "sim".  It's in the comp.sources.unix archives, vol 3
and 4.

-- 
David DiGiacomo, Sun Microsystems, Mt. View, CA  david@eng.sun.com