Page 1 of 1

exclude comment lines in comparison

Posted: Thu Oct 09, 2003 1:08 pm
by Guest
Hello,

I am using compare it! to find differences in code generated source code files.
In these files there are many lines of automatically generated comment which always differs between the files. However, I want to exclude these comments from comparsion, because they make the results very complex. The comment lines ALways start in the first column either with a / character (C++) or a c character (FORTRAN).

Any help will be appreciated

Posted: Thu Oct 09, 2003 9:21 pm
by TonHu
I'm with you on this one, would have been a nice 'Suggestions' item I guess :wink:

HTH
TonHu

Posted: Tue Oct 14, 2003 6:30 am
by grigsoft
You can easily ignore comments with regular expressions support. Check Options/Comparison/"Use regular expressions".
For example, to ignore // comment:
Search:^\/\/
Action: Ignore string with match

To ignore fortran comment:
Search: ^c
Action: Ignore string with match

Having difficulty with filtering out comment lines...

Posted: Tue Oct 28, 2003 10:27 pm
by RoAblate
I am using an assembler with either an * or ; as a first non-white character to denote a comment line.

I have been trying various versions of the following RE to avoid inclusion of comment lines:

^(^t+| +)\*+|;.*

The action I picked is to replace, where the replace field in empty.
I'd like any line starting with a combination of tabs and spaces followed by an * or ; to be utterly ignored in the encoding of BOTH panes.

Is this even feasible???

Posted: Wed Oct 29, 2003 6:46 am
by grigsoft
You can do it with this pattern:
^\s*[;|\*].*
Action can be "Replace" or "Ignore string with match"

Clarify:
^ - line beginning
\s* - starting blanks sequence
[;|\*] - your comment character (* is reserved, so \ is required)
.* - any ending

Posted: Wed Oct 29, 2003 5:49 pm
by RoAblate
In:
^\s*[;|\*].*
isn't the | inside of [] unnecessary?

And I'm sorry, I mispoke:
* is a comment delimiter only when it is the first character.
; is a comment delimiter whenever it shows up.

So, I have implemented the following 2 filters:
1) ^s\*+.*
set to "Ignore string with match"
2) ;.*
set to "Replace" with an empty field

But there are still problems...

I am finding that when I set the options to ignore inserted empty lines, and tell the filter to either replace the string with an empty field or to ignore the string (actually, it seems to ignore WHOLE the line?), it still shows up as a difference.

Sometimes it looks like it sort of ignores only the first filtered line in a row of lines unmatched to ignored text in that the comment is not highlighted with colors, but it STILL shows up as hatched in the opposing pane.

If I place a CR/LF or other ignored text (eg - a filtered comment line) in the opposing file, then WinCmp3 truely ignores these lines, but not otherwise.


It is as if the "Ignore Inserted Empty Lines" isn't applied consistently AFTER filtering?

Or is there another setting to get it to fully ignore these filtered lines as if they don't exist? Is a separate one needed?

Posted: Thu Oct 30, 2003 8:27 am
by grigsoft
> isn't the | inside of [] unnecessary
Hmm, probably you are right. I have just used to write it this way.

> 1) ^s\*+.*

I guess you mean ^\s*\*.*
'+' is not necessary - next '.*' will absorb multiple '*', if any

As for problem with "Ignore empty lines", you are right - currently Compare It! does not handle it exactly as it should. The problem is all regexp changes done for comparison are not valid during painting, so commented line is drawn as it is, not as empty.

Posted: Wed Jan 18, 2006 11:40 am
by grigsoft
To ignore rest of line after ; try using this:
Search: ;.*
Replace:
Action:Replace

As for first part, your regexp seems to be correct, however if you could send me some portions of your code that iilustrate the problem, I could help you more.

Posted: Wed Jan 18, 2006 12:15 pm
by Confused
Excellent, your suggestion for the "ignore end of line" comments works very well. Will have to go away and ponder why it is what it is, and why it works, though. Thanks very much for that.


As for the first part ...

File 1

Code: Select all

                     J Label1
\
                   Code Line 1
                   Code Line 2
                   Skip Variable <> 1
                     Code Line 3
\ ____________________________________________________________________________________________
\ Initialise Variables
\ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Label1:            Code Line 4
                   Code Line 5
                   Code Line 6


File 2

Code: Select all

                     J Label1
\
\ This is an added comment line that should be ignored
\
                   Code Line 1
                   Code Line 2
                   Skip Variable <> 1
                     Code Line 3
\ ____________________________________________________________________________________________
\ Initialise Variables
\ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Label1:            Code Line 4
                   Code Line 5
                   Code Line 6


Rule 1

Code: Select all

Search ^\\
Replace ^\\
"Ignore String With Match"
Rule 2

Code: Select all

Search ;.*
Replace ;
"Replace"
In fact the lines that should be ignored are highlighted as changes.

Cheers

Posted: Wed Jan 18, 2006 12:16 pm
by Guest
Mmm ... seems to be a couple of rogue word wrap/extra CR/LF in the code blocks :oops:

Posted: Wed Jan 18, 2006 1:46 pm
by grigsoft
Just a quick thought - you probably don't have "Ignore inserted empty lines" option set in Options>Comparison. The problem is your lines are considered as empty, but even empty line is still inserted line, so it is highlighted.
Also, change rule to
Search: ^\\.*
Replace:
"Ignore string with match"

Posted: Wed Jan 18, 2006 2:03 pm
by Confused
That quick thought worked like a charm !
Have also made your other suggested change, will find time when I can to work out why it is better.
Thanks for all your help :D