diff multi-line whitespace to verify Beautifier output

S

Shug

Hi,

We're reformatting a lot of our project code using the excellent
uncrustify beautifier.

However, to gain confidence that it really is only changing whitespace
(forget { } issues for just now), we were hoping to do a diff - a
textual comparison of the files, ignoring whitespace.

However, most diffs we've tried can't handle multi-line whitespace, so
the following two
prototypes are deemed to be different:

void doStuff( int a, float b);

void doStuff(int a,
float b);

Has anyone found a way to do a diff like this, that handles multi-line
whitespace?

Shug
 
V

Victor Bazarov

Shug said:
We're reformatting a lot of our project code using the excellent
uncrustify beautifier.

However, to gain confidence that it really is only changing whitespace
(forget { } issues for just now), we were hoping to do a diff - a
textual comparison of the files, ignoring whitespace.

However, most diffs we've tried can't handle multi-line whitespace, so
the following two
prototypes are deemed to be different:

void doStuff( int a, float b);

void doStuff(int a,
float b);

Has anyone found a way to do a diff like this, that handles multi-line
whitespace?

I would actually do it differently: tokenize both sources. If the set
of tokens is the same, you have the same source (now, don't ask me where
you can find C++ tokenizers, I don't know, GIYF). The other way is to
convert both of those into the third type of formatting (which should
give you the exactly same output) and compare them. If the formatter
make mistakes, it's likely to make them independently.

V
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

I would actually do it differently: tokenize both sources. If the set
of tokens is the same, you have the same source (now, don't ask me where
you can find C++ tokenizers, I don't know, GIYF). The other way is to
convert both of those into the third type of formatting (which should
give you the exactly same output) and compare them. If the formatter
make mistakes, it's likely to make them independently.

A simple third format would be one where every whitespace is replaced
by a newline, which will give a format that is easy to compare (and I
think it will still be valid C++ :)
 
V

Victor Bazarov

Erik said:
A simple third format would be one where every whitespace is replaced
by a newline, which will give a format that is easy to compare (and I
think it will still be valid C++ :)

It wouldn't be valid C++ without some continuation characters (\) in
macro definitions. And broken up include directives aren't going to
work either. :)

V
 
S

Shug

Hi,

We're reformatting a lot of our project code using the excellent
uncrustifybeautifier.

However, to gain confidence that it really is only changing whitespace
(forget { } issues for just now), we were hoping to do a diff - a
textual comparison of the files, ignoring whitespace.

However, most diffs we've tried can't handle multi-line whitespace, so
the following two
prototypes are deemed to be different:

void doStuff( int a, float b);

void doStuff(int a,
float b);

Has anyone found a way to do a diff like this, that handles multi-line
whitespace?

Shug

Thanks for your contributions guys.

In the end, we've managed to find another satisfactory solution.

After reformatting the source code, we run both the before and after
source files through tr:

tr -d '\r\n' < file1.cpp > temp1.txt
tr -d '\r\n' < file2.cpp > temp2.txt

then do a diff on the tr'd files

C:\cygwin\bin\diff -bBw temp1.txt temp2.txt

This is all using a cygwin installation on Windows XP.

This does exactly what we need.

Thanks again.

Shug
 
Joined
Jun 12, 2008
Messages
1
Reaction score
0
it does strike me that this is a problem (which I also have found) with cygwin on windows.
diff -w or -b should ignore whitespace, but whether this is 0A (nix) or 0D 0A (windows), it doesn't work.

void doStuff( int a, float b);

void doStuff(int a,[HEX 0a]or[HEX 0d 0a]
float b);

Should be the same, but is not recognised as such.
Does this diff work on non-windows machines?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top