views:

165

answers:

3

I want to compare side by side some C files with kdiff3 (the tool is what matters the less), but some parts have been "reformatted" in one of the files, thus giving false positives in the differences.

Kdiff3 allows you to run a preprocessor on the input files, and I thought that using "indent" (or similar tools like astyle or uncrustify) would normalize the code so those merely aesthetic changes would disappear, but they preserve too many of the original formatting (like line breaks in the middle of expressions).

Are there any tool (or configuration options for the already mentioned ones) that transforms C code to a "normal" form (whichever it is, I just want it to make the diffs easier to read)?

A: 

That sounds like a good idea, and I also would have thought that using indent as a pre-processor would be a good strategy.

indent has many options. I've gone through all the options for indent in the past, to find those that would format code to meet our company's coding guidelines. Perhaps careful choice of options could make the results closer to what you want.

I imagine it would not be able to do much with comments that have been reformatted, though.

Craig McQueen
+2  A: 

delta includes topformflat, which can "normalize" your C source code such that newlines are only placed in certain locations regardless of where they were before. (Output's kinda ugly, though; you might still want to run it through indent afterwards.)

ephemient
My final kdiff3 preprocess script was `dos2unix | indent -orig -i0 -nhnl | indent -l1000 -orig -hnl` piping two indents is redundant given the way it "honours new lines" (what I wanted is to have line breaks without considering the initial indentation, so similar blocks that have different nesting levels won't break the lines in different places), but I'm keeping that to remember that I have to fix it or replace it with other indenting tool at some point.
fortran
A: 

Check out the Semantic Designs Smart Differencer.

This compares two files according to programming langauge syntax rather than layout/formatting/comments. It reports differences in terms of langauge constructs (identifiers, expressions, statements, blocks, functions) rather than lines, and abstract editing commands (insert, delete, move, rename-identifier) rather than simple "insert line" or "delete line".

Ira Baxter