indexing
	cluster: "demangler"
	namespace: "candidate"
	description: "Facility class for comparing file content"
	original_author: "Justin Finnerty"
	original_date: "Sept 2005"
	current_date: "$Date: 2005/09/28 13:39:55 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.5 $"	
	-- $Log: compare_files.ge,v $
	-- Revision 2.5  2005/09/28 13:39:55  finnerty
	-- Updated to work with ISE (handling strings to/from C)
	--
	-- Revision 2.4  2005/09/27 08:21:31  finnerty
	-- Updated to work with VE, third correction
	--
	-- Revision 2.3  2005/09/27 08:18:17  finnerty
	-- Updated to work with VE 2
	--
	-- Revision 2.2  2005/09/27 08:17:25  finnerty
	-- Updated to work with VE
	--
	-- Revision 2.1  2005/09/27 08:09:33  finerty
	-- Migrated compare features into this new facility class
	--

class COMPARE_FILES
	-- Facility class for comparing file content

feature {ANY}
	-- Constants
   
	Uncompressed, Zip, BZip2: INTEGER is unique

feature {ANY}
	-- Access

	compare_fso (a_fso1, a_fso2: FILE_SYSTEM_OBJECT; a_compress_type: INTEGER; a_display: REPORT_VIEW): BOOLEAN is
 			-- Compare two FSOs, return false if different.
 		local
 			l_result: INTEGER
			l_fso1, l_fso2: FILE_SYSTEM_OBJECT
#ifdef ISE
			l_path1, l_path2: C_STRING
 			l_error: C_STRING
#else
 			l_error: STRING
#endif
 		do
 			if a_fso1.properties.is_file and then
 				a_fso2.properties.is_file and then
 				a_fso1.properties.size /= 0 and then
 				a_fso1.properties.size /= 0 then
#ifdef ISE
				!!l_error.make_empty (256)
#else
				!!l_error.make_filled ('%U', 256)
#endif
				if a_compress_type = Uncompressed then
					-- uncompressed files
					if a_fso1.properties.size = a_fso2.properties.size then
#ifdef ISE
						!!l_path1.make (a_fso1.path)
						!!l_path2.make (a_fso2.path)
						l_result := compare_files (l_path1.item, l_path2.item, a_fso1.properties.size, l_error.item, 255)
#else
						l_result := compare_files (a_fso1.path.to_external, a_fso2.path.to_external, a_fso1.properties.size, l_error.to_external, 255)
#endif
					end
				else
					-- compressed files
					if a_fso1.properties.size > a_fso2.properties.size then
						l_fso1 := a_fso2 -- l_fso1 is compressed
						l_fso2 := a_fso1 -- l_fso2 is uncompressed
					else
						l_fso1 := a_fso1 -- l_fso1 is compressed
						l_fso2 := a_fso2 -- l_fso2 is uncompressed
					end
					if a_compress_type = Zip then
#ifdef ISE
						!!l_path1.make (l_fso1.path)
						!!l_path2.make (l_fso2.path)
						l_result := compare_zfiles (l_path1.item, l_path2.item, l_fso2.properties.size, l_error.item, 255)
#else
						l_result := compare_zfiles (l_fso1.path.to_external, l_fso2.path.to_external, l_fso2.properties.size, l_error.to_external, 255)
#endif
					else
						if a_compress_type = BZip2 then
#ifdef ISE
							!!l_path1.make (l_fso1.path)
							!!l_path2.make (l_fso2.path)
							l_result := compare_bzfiles (l_path1.item, l_path2.item, l_fso2.properties.size, l_error.item, 255)
#else
							l_result := compare_bzfiles (l_fso1.path.to_external, l_fso2.path.to_external, l_fso2.properties.size, l_error.to_external, 255)
#endif
						end
					end
 				end
				-- Report any errors
#ifdef ISE
				if l_result = -1 and then not l_error.string.is_empty then
					a_display.report_warning (l_error.string+" ["+a_fso1.path+"] or ["+a_fso2.path+"]")

#else
#ifdef SE
				if l_result = -1 and then l_error.first /= '%U' then
					l_error.remove_all_occurrences ('%U')
#else
				if l_result = -1 and then l_error.item(1) /= '%U' then
					l_error.prune_all ('%U')
#endif					
					a_display.report_warning (l_error+" ["+a_fso1.path+"] or ["+a_fso2.path+"]")
#endif
				end
				if l_result = 1 then
					Result := True
				end
 			end
 		end

	
feature {NONE}
 	-- Implementation (external)

 	compare_files (a_filename1, a_filename2: POINTER; a_filesize: INTEGER; a_error_string: POINTER; a_error_string_length: INTEGER): INTEGER is
 			-- Compare two files. Return 1 if identical, 0 if
 			-- non-identical, -1 if an error occured or -2 if files have
 			-- different sizes
 		external
 			"C"
 		end

 	compare_zfiles (a_filename1, a_filename2: POINTER; a_filesize: INTEGER; a_error_string: POINTER; a_error_string_length: INTEGER): INTEGER is
 			-- Compare two files. Return 1 if identical, 0 if
 			-- non-identical, -1 if an error occured or -2 if files have
 			-- different sizes
 		external
 			"C"
 		end

 	compare_bzfiles (a_filename1, a_filename2: POINTER; a_filesize: INTEGER; a_error_string: POINTER; a_error_string_length: INTEGER): INTEGER is
 			-- Compare two files. Return 1 if identical, 0 if
 			-- non-identical, -1 if an error occured or -2 if files have
 			-- different sizes
 		external
 			"C"
 		end

end -- class COMPARE_FILES
