Click here to Skip to main content
15,897,891 members
Articles / Desktop Programming / MFC

Diff Tool

Rate me:
Please Sign up or sign in to vote.
4.97/5 (64 votes)
17 May 20037 min read 401.7K   10K   153  
A simple diff tool, usable on arbitrary file formats, with a nice HTML rendering
This article provides a simple C++ WIN32 tool to perform diffs on arbitrary files. It also features a nice and workable HTML output.
#pragma once

// DiffEngine ////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////
// S.Rodriguez - Feb 2003
//////////////////////////////////////////////////////////////////////
//
//
class CDiffEngine
{
	// Members
protected:
	CString m_szColorText, m_szColorBackground, m_szColorChanged, m_szColorAdded, m_szColorDeleted; // used by the html renderer
	CString m_szHeader, m_szFooter;

	// Constructor
public:
	CDiffEngine();

	// Accessors
public:

	// Methods

	// compare f1 (old version) with f2 (new version)
	// and build two new copies of those file objects with status on a line by line basis
	//
	BOOL Diff(	/*in*/CFilePartition &f1, /*in*/CFilePartition &f2,
				/*out*/CFilePartition &f1_bis, /*out*/CFilePartition &f2_bis);

	// build html report
	//
	void SetTitles(CString &szHeader, CString &szFooter);
	void SetColorStyles(CString &szText, CString &szBackground, CString &szChanged, CString &szAdded, CString &szDeleted);
	BOOL ExportAsHtml(	/*in*/CString &szFilename,
						/*in*/CFilePartition &f1, 
						/*in*/CFilePartition &f2);

	// Helpers
protected:
	CString Escape(CString &s);
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
France France
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

Comments and Discussions