ReactOS 0.4.16-dev-297-gc569aee
comp.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <windef.h>
#include <winbase.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for comp.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define STRBUF   1024
 

Functions

INT GetBuff (PBYTE buff, FILE *in)
 
INT FileSize (FILE *fd)
 
int wmain (int argc, WCHAR *argv[])
 

Macro Definition Documentation

◆ STRBUF

#define STRBUF   1024

Definition at line 39 of file comp.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 31 of file comp.c.

Function Documentation

◆ FileSize()

INT FileSize ( FILE fd)

Definition at line 47 of file comp.c.

48{
49 INT result = -1;
50 if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1)
51 {
52 /* Restoring file pointer */
53 rewind(fd);
54 }
55 return result;
56}
#define SEEK_END
Definition: cabinet.c:29
GLuint64EXT * result
Definition: glext.h:11304
_CRTIMP void __cdecl rewind(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
static int fd
Definition: io.c:51
int32_t INT
Definition: typedefs.h:58

◆ GetBuff()

INT GetBuff ( PBYTE  buff,
FILE in 
)

Definition at line 42 of file comp.c.

43{
44 return fread(buff, sizeof(BYTE), STRBUF, in);
45}
#define STRBUF
Definition: comp.c:39
static unsigned char buff[32768]
Definition: fatten.c:17
GLuint in
Definition: glext.h:9616
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by wmain().

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 59 of file comp.c.

60{
61 INT i;
62
63 /* File pointers */
64 FILE *fp1 = NULL;
65 FILE *fp2 = NULL;
66
67 INT BufLen1, BufLen2;
68 PBYTE Buff1 = NULL;
69 PBYTE Buff2 = NULL;
70 WCHAR File1[_MAX_PATH + 1], // File paths
71 File2[_MAX_PATH + 1];
72 BOOL bAscii = FALSE, // /A switch
73 bLineNos = FALSE; // /L switch
76 INT FileSizeFile1;
77 INT FileSizeFile2;
78 INT NumberOfOptions = 0;
79 INT FilesOK = 1;
81
82 /* Initialize the Console Standard Streams */
84
85 /* Parse command line for options */
86 for (i = 1; i < argc; i++)
87 {
88 if (argv[i][0] == L'/')
89 {
90 switch (towlower(argv[i][1]))
91 {
92 case L'a':
93 bAscii = TRUE;
94 NumberOfOptions++;
95 break;
96
97 case L'l':
98 bLineNos = TRUE;
99 NumberOfOptions++;
100 break;
101
102 case L'?':
104 return EXIT_SUCCESS;
105
106 default:
109 return EXIT_FAILURE;
110 }
111 }
112 }
113
114 if (argc - NumberOfOptions == 3)
115 {
116 wcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH);
117 wcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH);
118 }
119 else
120 {
122 return EXIT_FAILURE;
123 }
124
125 Buff1 = (PBYTE)malloc(STRBUF);
126 if (Buff1 == NULL)
127 {
128 ConPuts(StdErr, L"Can't get free memory for Buff1\n");
130 goto Cleanup;
131 }
132
133 Buff2 = (PBYTE)malloc(STRBUF);
134 if (Buff2 == NULL)
135 {
136 ConPuts(StdErr, L"Can't get free memory for Buff2\n");
138 goto Cleanup;
139 }
140
141 if ((fp1 = _wfopen(File1, L"rb")) == NULL)
142 {
145 goto Cleanup;
146 }
147 if ((fp2 = _wfopen(File2, L"rb")) == NULL)
148 {
151 goto Cleanup;
152 }
153
154 ConResPrintf(StdOut, IDS_COMPARING, File1, File2);
155
156 FileSizeFile1 = FileSize(fp1);
157 if (FileSizeFile1 == -1)
158 {
161 goto Cleanup;
162 }
163
164 FileSizeFile2 = FileSize(fp2);
165 if (FileSizeFile2 == -1)
166 {
169 goto Cleanup;
170 }
171
172 if (FileSizeFile1 != FileSizeFile2)
173 {
176 goto Cleanup;
177 }
178
179 LineNumber = 1;
180 Offset = 0;
181 while (1)
182 {
183 BufLen1 = GetBuff(Buff1, fp1);
184 BufLen2 = GetBuff(Buff2, fp2);
185
186 if (ferror(fp1) || ferror(fp2))
187 {
190 goto Cleanup;
191 }
192
193 if (!BufLen1 && !BufLen2)
194 break;
195
196 assert(BufLen1 == BufLen2);
197 for (i = 0; i < BufLen1; i++)
198 {
199 if (Buff1[i] != Buff2[i])
200 {
201 FilesOK = 0;
202
203 /* Reporting here a mismatch */
204 if (bLineNos)
206 else
208
209 if (bAscii)
210 {
211 ConResPrintf(StdOut, IDS_ASCIIDIFF, 1, Buff1[i]);
212 ConResPrintf(StdOut, IDS_ASCIIDIFF, 2, Buff2[i]);
213 }
214 else
215 {
218 }
219 }
220
221 Offset++;
222
223 if (Buff1[i] == '\n')
224 LineNumber++;
225 }
226 }
227
228 if (FilesOK)
230
231Cleanup:
232 if (fp2)
233 fclose(fp2);
234 if (fp1)
235 fclose(fp1);
236
237 if (Buff2)
238 free(Buff2);
239 if (Buff1)
240 free(Buff1);
241
242 return Status;
243}
static int argc
Definition: ServiceArgs.c:12
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 LineNumber
Definition: acpixf.h:1220
#define IDS_HELP
Definition: resource.h:3
#define IDS_FILEERROR
Definition: resource.h:6
#define IDS_READERROR
Definition: resource.h:10
#define IDS_SIZEDIFFERS
Definition: resource.h:9
#define IDS_ASCIIDIFF
Definition: resource.h:13
#define IDS_FILESIZEERROR
Definition: resource.h:8
#define IDS_HEXADECIMALDIFF
Definition: resource.h:14
#define IDS_INVALIDSWITCH
Definition: resource.h:4
#define IDS_MISMATCHOFFSET
Definition: resource.h:12
#define IDS_COMPARING
Definition: resource.h:7
#define IDS_MISMATCHLINE
Definition: resource.h:11
#define IDS_BADSYNTAX
Definition: resource.h:5
#define IDS_MATCH
Definition: resource.h:15
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
INT GetBuff(PBYTE buff, FILE *in)
Definition: comp.c:42
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define EXIT_FAILURE
Definition: jerror.c:33
#define _MAX_PATH
Definition: utility.h:77
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define towlower(c)
Definition: wctype.h:97
__wchar_t WCHAR
Definition: xmlstorage.h:180