Compare text files (or sources)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Compare text files (or sources)

Post by Michael Vogel »

Has anyone made a tool to compare text files? Most of the programs (included the purebasic IDE tool) are not able to do a good job for source codes, see the example below (Screenshot):

Code 1:

Code: Select all


blah

procedure a_simple_one
	one	for i=1 to endless
	two		Str(GetJSONInteger(GetJSONMember(o,"id"))) +": "+ GetJSONString(GetJSONMember(o,"title"))
	three	next i
endprocedure

blah, blah

procedure be_more_complex
	alpha	#InternalFontFile="Huii IBM Plex Mono.ttf";	"Huii Console.ttf"
	bravo	#BirdFilter=Chr(#BirdFilterChar)
	charlie	#CharReturn=Chr($21a9);	$21a9, $21b5, $23ce, $2386
endprocedure

blah, blah, blah

procedure code_or_not_code
	ypsilon	!mov rax,[p.p_m]
	chi	!gifdecoder_GifSkipBlock_loop:
	omega	!lea rax,[rax + rcx + 1]
endprocedure
Code 2:

Code: Select all


blah


blah, blah

procedure code_or_not_code
	ypsilon	!mov rax,[p.p_m]
	chi	!gifdecoder_GifSkipBlock_loop:
	psi	!movzx rcx,byte [rax]
	omega	!lea rax,[rax + rcx + 1]
endprocedure

procedure be_more_complex
	alpha	#InternalFontFile="Huii IBM Plex Mono.ttf";	"Huii Console.ttf"
	charlie	#CharReturn=Chr($21a9);	$21a9, $21b5, $23ce, $2386
endprocedure

blah, blah, blah
another new line

procedure a_simple_one
	one	for i=1 to endless
	two		Str(GetJSONInteger(GetJSONMember(o,"id"))) +": "+ GetJSONString(GetJSONMember

(o,"title"))
	three	next i
endprocedure
Last edited by Michael Vogel on Sun Dec 05, 2021 3:56 pm, edited 3 times in total.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Compare text files (or sources)

Post by BarryG »

Your image is too small to view, so here's my view of your two codes with the PureBasic comparison. What's so bad about it? Looks great to me.

You could try https://winmerge.org (free); and Windows has "fc" built-in to use from the command-line.

Image
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Compare text files (or sources)

Post by #NULL »

git diff has an option to detect code moves. You can diff any two files without having any git repo initialized. It's only coloring though, not giving any patch info. Not sure how useful it is.

Code: Select all

git diff --color-moved=plain a b
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Compare text files (or sources)

Post by Michael Vogel »

Procedure 'a' has moved to the bottom and procedure 'c' to the top, but this hasn't been recognized by tools like winmerge, windiff, etc.

I will check git diff, thank you for the hint. :wink:
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Compare text files (or sources)

Post by dige »

Notepad++ will do the job right
"Daddy, I'll run faster, then it is not so far..."
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Compare text files (or sources)

Post by Marc56us »

Procedure 'a' has moved to the bottom and procedure 'c' to the top, but this hasn't been recognized by tools like winmerge, windiff, etc.
Winmerge can do it. See help
"Moved differences
Moved differences are identical lines in different locations. They are shown only if the Enable moved block detection is checked in the Options dialog Compare page. See Difference highlighting for more details about moved differences in the File pane. The Location pane draws a line connecting moved differences in the left and right location bars.
"

(or right click on map and check "No moved blocks / All moved blocks")
:wink:
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Compare text files (or sources)

Post by Michael Vogel »

Not very happy with the results of WinMerge and the Notepad++ plugin as well (did some tests earlier).
Still investigating git diff - will take a while (first I've reduced the portable installation of git to keep only needed files. Seems that not more than the files git.exe, libiconv-2.dll, libpcre2-8-0.dll, libssl-1_1-x64.dll, libintl-8.dll and libssp-0.dll are needed :x)
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Re: Compare text files (or sources)

Post by ebs »

My favorite tool for comparing files is CompareIt! (https://www.grigsoft.com/wincmp3.htm).
It clearly indicates the moved procedure, but I don't have anywhere to post a screenshot.

The usual price for a license is $29, which I consider a bargain, but if you use the coupon code COVID, it's 50% off.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Compare text files (or sources)

Post by skywalk »

My order of preference for text diff's.
1. WinMerge
2. Notepad++ plugin, x64 preferred, x86 fails on larger files.
3. Fossil, quick and dirty comparisons but most often trigger WinMerge.
4. git is too heavy but similar to Fossil.

There are many other tools, but these suffice.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Compare text files (or sources)

Post by dige »

Is the result of the comparison with Notepadd++ not what you need?

Screenshot Notepad compare result:
https://u.pcloud.link/publink/show?code ... F3YQoQeqS7
"Daddy, I'll run faster, then it is not so far..."
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Compare text files (or sources)

Post by Marc56us »

Michael Vogel wrote: Tue Nov 30, 2021 11:30 am Has anyone made a tool to compare text files? Most of the programs (included the purebasic IDE tool) are not able to do a good job for source codes, ...
Yes, you are right. And moreover, these programs are often difficult to read.
It could be interesting to make a special PB program in several steps
1. List the procedures that exist or not between the two
Then
2. For each procedure, see the differences
:wink:
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Compare text files (or sources)

Post by Tenaja »

Your minimal test might be detected as changes even if the tool is capable of detecting moves. Might make them the test more substantial or useable, so it's more than single character comparisons. With the given files, single character could be considered a change, but real functions might be evaluated as moves.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Compare text files (or sources)

Post by RASHAD »

Any Hex Editor like WinHex has a tool to compare data
It's much faster and accurate
BTW:Winmerge looks fine with me
Egypt my love
IzzyB
New User
New User
Posts: 5
Joined: Sun Oct 21, 2012 5:59 am

Re: Compare text files (or sources)

Post by IzzyB »

There's a rather nice compare (and more) software product out there called 'Beyond Compare'. It's not free, but it's pretty strong.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Compare text files (or sources)

Post by Michael Vogel »

First of all, thanks for all replies here, they all contain valuable hints for me...

Meanwhile I've expanded the text content in the example texts (see initial post) to have a more realistic test scenario. Anyhow the results of my tested programs (including additional programs like UEDiff and HxD64) are still far away from good.

WinMerge seems to do a good job in recognizing some of the moved lines (except the mutiple "endprocedure" lines) but is not able to display the corresponding lines.
Post Reply