ReactOS 0.4.15-dev-7906-g1b85a5f
fc.c File Reference
#include "fc.h"
#include <stdio.h>
#include <strsafe.h>
#include <shlwapi.h>
Include dependency graph for fc.c:

Go to the source code of this file.

Macros

#define ConInitStdStreams()   /* empty */
 
#define StdOut   stdout
 
#define StdErr   stderr
 
#define IS_DOTS(pch)    ((*(pch) == L'.') && (((pch)[1] == 0) || (((pch)[1] == L'.') && ((pch)[2] == 0))))
 
#define HasWildcard(filename)    ((wcschr((filename), L'*') != NULL) || (wcschr((filename), L'?') != NULL))
 

Functions

void ConPuts (FILE *fp, LPCWSTR psz)
 
void ConPrintf (FILE *fp, LPCWSTR psz,...)
 
void ConResPuts (FILE *fp, UINT nID)
 
void ConResPrintf (FILE *fp, UINT nID,...)
 
FCRET NoDifference (VOID)
 
FCRET Different (LPCWSTR file0, LPCWSTR file1)
 
FCRET LongerThan (LPCWSTR file0, LPCWSTR file1)
 
FCRET OutOfMemory (VOID)
 
FCRET CannotRead (LPCWSTR file)
 
FCRET InvalidSwitch (VOID)
 
FCRET ResyncFailed (VOID)
 
VOID PrintCaption (LPCWSTR file)
 
VOID PrintEndOfDiff (VOID)
 
VOID PrintDots (VOID)
 
VOID PrintLineW (const FILECOMPARE *pFC, DWORD lineno, LPCWSTR psz)
 
VOID PrintLineA (const FILECOMPARE *pFC, DWORD lineno, LPCSTR psz)
 
HANDLE DoOpenFileForInput (LPCWSTR file)
 
static FCRET BinaryFileCompare (FILECOMPARE *pFC)
 
static FCRET TextFileCompare (FILECOMPARE *pFC)
 
static BOOL IsBinaryExt (LPCWSTR filename)
 
static FCRET FileCompare (FILECOMPARE *pFC)
 
static BOOL IsTitleWild (LPCWSTR filename)
 
static FCRET FileCompareOneSideWild (const FILECOMPARE *pFC, BOOL bWildRight)
 
static FCRET FileCompareWildTitle (const FILECOMPARE *pFC)
 
static FCRET FileCompareBothWild (const FILECOMPARE *pFC)
 
static FCRET WildcardFileCompare (FILECOMPARE *pFC)
 
int wmain (int argc, WCHAR **argv)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ ConInitStdStreams

#define ConInitStdStreams ( )    /* empty */

Definition at line 13 of file fc.c.

◆ HasWildcard

#define HasWildcard (   filename)     ((wcschr((filename), L'*') != NULL) || (wcschr((filename), L'?') != NULL))

Definition at line 362 of file fc.c.

◆ IS_DOTS

#define IS_DOTS (   pch)     ((*(pch) == L'.') && (((pch)[1] == 0) || (((pch)[1] == L'.') && ((pch)[2] == 0))))

Definition at line 360 of file fc.c.

◆ StdErr

#define StdErr   stderr

Definition at line 15 of file fc.c.

◆ StdOut

#define StdOut   stdout

Definition at line 14 of file fc.c.

Function Documentation

◆ BinaryFileCompare()

static FCRET BinaryFileCompare ( FILECOMPARE pFC)
static

Definition at line 128 of file fc.c.

129{
130 FCRET ret;
131 HANDLE hFile0, hFile1, hMapping0 = NULL, hMapping1 = NULL;
132 LPBYTE pb0 = NULL, pb1 = NULL;
133 LARGE_INTEGER ib, cb0, cb1, cbCommon;
134 DWORD cbView, ibView;
135 BOOL fDifferent = FALSE;
136
137 hFile0 = DoOpenFileForInput(pFC->file[0]);
138 if (hFile0 == INVALID_HANDLE_VALUE)
139 return FCRET_CANT_FIND;
140 hFile1 = DoOpenFileForInput(pFC->file[1]);
141 if (hFile1 == INVALID_HANDLE_VALUE)
142 {
143 CloseHandle(hFile0);
144 return FCRET_CANT_FIND;
145 }
146
147 do
148 {
149 if (_wcsicmp(pFC->file[0], pFC->file[1]) == 0)
150 {
151 ret = NoDifference();
152 break;
153 }
154 if (!GetFileSizeEx(hFile0, &cb0))
155 {
156 ret = CannotRead(pFC->file[0]);
157 break;
158 }
159 if (!GetFileSizeEx(hFile1, &cb1))
160 {
161 ret = CannotRead(pFC->file[1]);
162 break;
163 }
164 cbCommon.QuadPart = min(cb0.QuadPart, cb1.QuadPart);
165 if (cbCommon.QuadPart > 0)
166 {
167 hMapping0 = CreateFileMappingW(hFile0, NULL, PAGE_READONLY,
168 cb0.HighPart, cb0.LowPart, NULL);
169 if (hMapping0 == NULL)
170 {
171 ret = CannotRead(pFC->file[0]);
172 break;
173 }
174 hMapping1 = CreateFileMappingW(hFile1, NULL, PAGE_READONLY,
175 cb1.HighPart, cb1.LowPart, NULL);
176 if (hMapping1 == NULL)
177 {
178 ret = CannotRead(pFC->file[1]);
179 break;
180 }
181
183 for (ib.QuadPart = 0; ib.QuadPart < cbCommon.QuadPart; )
184 {
185 cbView = (DWORD)min(cbCommon.QuadPart - ib.QuadPart, MAX_VIEW_SIZE);
186 pb0 = MapViewOfFile(hMapping0, FILE_MAP_READ, ib.HighPart, ib.LowPart, cbView);
187 pb1 = MapViewOfFile(hMapping1, FILE_MAP_READ, ib.HighPart, ib.LowPart, cbView);
188 if (!pb0 || !pb1)
189 {
190 ret = OutOfMemory();
191 break;
192 }
193 for (ibView = 0; ibView < cbView; ++ib.QuadPart, ++ibView)
194 {
195 if (pb0[ibView] == pb1[ibView])
196 continue;
197
198 fDifferent = TRUE;
199 if (cbCommon.QuadPart > MAXDWORD)
200 {
201 ConPrintf(StdOut, L"%016I64X: %02X %02X\n", ib.QuadPart,
202 pb0[ibView], pb1[ibView]);
203 }
204 else
205 {
206 ConPrintf(StdOut, L"%08lX: %02X %02X\n", ib.LowPart,
207 pb0[ibView], pb1[ibView]);
208 }
209 }
210 UnmapViewOfFile(pb0);
211 UnmapViewOfFile(pb1);
212 pb0 = pb1 = NULL;
213 }
214 if (ret != FCRET_IDENTICAL)
215 break;
216 }
217
218 if (cb0.QuadPart < cb1.QuadPart)
219 ret = LongerThan(pFC->file[1], pFC->file[0]);
220 else if (cb0.QuadPart > cb1.QuadPart)
221 ret = LongerThan(pFC->file[0], pFC->file[1]);
222 else if (fDifferent)
223 ret = Different(pFC->file[0], pFC->file[1]);
224 else
225 ret = NoDifference();
226 } while (0);
227
228 UnmapViewOfFile(pb0);
229 UnmapViewOfFile(pb1);
230 CloseHandle(hMapping0);
231 CloseHandle(hMapping1);
232 CloseHandle(hFile0);
233 CloseHandle(hFile1);
234 return ret;
235}
FCRET NoDifference(VOID)
Definition: fc.c:46
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
HANDLE DoOpenFileForInput(LPCWSTR file)
Definition: fc.c:118
#define StdOut
Definition: fc.c:14
FCRET Different(LPCWSTR file0, LPCWSTR file1)
Definition: fc.c:52
FCRET CannotRead(LPCWSTR file)
Definition: fc.c:70
FCRET LongerThan(LPCWSTR file0, LPCWSTR file1)
Definition: fc.c:58
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define FILE_MAP_READ
Definition: compat.h:776
#define GetFileSizeEx
Definition: compat.h:757
#define MapViewOfFile
Definition: compat.h:745
FCRET
Definition: fc.h:24
@ FCRET_IDENTICAL
Definition: fc.h:26
@ FCRET_CANT_FIND
Definition: fc.h:28
#define MAX_VIEW_SIZE
Definition: fc.h:96
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ OutOfMemory
Definition: gdiplustypes.h:29
#define min(a, b)
Definition: monoChain.cc:55
#define DWORD
Definition: nt_native.h:44
#define MAXDWORD
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPCWSTR file[2]
Definition: fc.h:67
unsigned char * LPBYTE
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
int ret

Referenced by FileCompare().

◆ CannotRead()

FCRET CannotRead ( LPCWSTR  file)

Definition at line 70 of file fc.c.

71{
73 return FCRET_INVALID;
74}
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
#define IDS_CANNOT_READ
Definition: resource.h:6
@ FCRET_INVALID
Definition: fc.h:25
Definition: fci.c:127

Referenced by BinaryFileCompare(), and TextFileCompare().

◆ ConPrintf()

void ConPrintf ( FILE fp,
LPCWSTR  psz,
  ... 
)

Definition at line 20 of file fc.c.

21 {
22 va_list va;
23 va_start(va, psz);
24 vfwprintf(fp, psz, va);
25 va_end(va);
26 }
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
_Check_return_opt_ _CRTIMP int __cdecl vfwprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList)

Referenced by BinaryFileCompare(), CheckLogOrSourceExistence(), ChkdskCallback(), cmdAccounts(), cmdContinue(), cmdGroup(), cmdHelpMsg(), cmdLocalGroup(), cmdPause(), cmdShare(), cmdStop(), DisplayError(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayServerStatistics(), DisplayShare(), DisplayUser(), DisplayWorkstationConfig(), DisplayWorkstationStatistics(), download_file(), DrawTree(), DumpSubstedDrives(), EnumerateConnections(), EnumerateDevices(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateRunningServices(), EnumerateShares(), EnumerateUsers(), EnumFilesWorker(), EnumSessions(), ErrorMessage(), FindString(), FormatExCallback(), HandleFindCommand(), hash_file(), HelpCommand(), HelpCommandList(), HelpContext(), HelpGroup(), HexDump(), InterpretCommand(), PrintAllJobs(), PrintAttributes(), PrintCaption(), PrintDateTime(), PrintError(), PrintErrorMessage(), PrintFileDacl(), PrintHelpCommand(), PrintHorizontalLine(), PrintLineA(), PrintLineW(), PrintLocalTime(), PrintLogonHours(), PrintMessage(), PrintNum(), PrintParserError(), PrintSpace(), PrintString(), PrintSubContext(), PrintWin32Error(), SetParallelState(), ShowHelperCommand(), ShowParallelStatus(), ShowTcpTable(), ShowUdpTable(), StartOneService(), UniqueIdDisk(), Usage(), WherePrintPath(), wmain(), and write_status().

◆ ConPuts()

void ConPuts ( FILE fp,
LPCWSTR  psz 
)

Definition at line 16 of file fc.c.

17 {
18 fputws(psz, fp);
19 }
_Check_return_opt_ _CRTIMP int __cdecl fputws(_In_z_ const wchar_t *_Str, _Inout_ FILE *_File)

Referenced by automount_main(), break_main(), CBindStatusCallback_OnProgress(), ChkdskCallback(), cmdAccounts(), cmdComputer(), cmdConfig(), cmdContinue(), cmdGroup(), cmdHelp(), cmdHelpMsg(), cmdLocalGroup(), cmdPause(), cmdSession(), cmdShare(), cmdStart(), cmdStatistics(), cmdStop(), cmdSyntax(), cmdUser(), ConClearScreen(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryPartition(), CtrlCIntercept(), DeletePartition(), DetailDisk(), DetailPartition(), DetailVolume(), DisplayDnsRecord(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayTableHeader(), DisplayUser(), DisplayWorkstationConfig(), EnumerateDevices(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateRunningServices(), EnumerateShares(), EnumerateUsers(), EnumProcessAndPrint(), EnumSessions(), FileCompare(), FileCompareBothWild(), FileCompareOneSideWild(), FileCompareWildTitle(), filesystems_main(), GetFileSystemInfo(), HandleInfoCommand(), hash_file(), HelpCommand(), HelpCommandList(), InputWait(), InterpretInteractive(), ListDisk(), ListPartition(), ListVirtualDisk(), ListVolume(), ParseCmdline(), Ping(), print_usage(), PrintDaclsOfFiles(), PrintDots(), PrintEndOfDiff(), PrintError(), PrintFileDacl(), PrintHeader(), PrintLogonHours(), PrintMessageString(), PrintMessageStringV(), PrintNetMessage(), PrintPaddedMessageString(), PrintPadding(), PrintSplitLine(), PrintWin32Error(), PromptYesNo(), ReadPassword(), repair_main(), ShowConsoleCPStatus(), ShowConsoleStatus(), ShowHeader(), ShowParallelStatus(), ShowSerialStatus(), UnderlinedResPrintf(), unimplemented(), UniqueIdDisk(), wmain(), and write_status().

◆ ConResPrintf()

void ConResPrintf ( FILE fp,
UINT  nID,
  ... 
)

Definition at line 33 of file fc.c.

34 {
35 va_list va;
36 WCHAR sz[MAX_PATH];
37 va_start(va, nID);
38 LoadStringW(NULL, nID, sz, _countof(sz));
39 vfwprintf(fp, sz, va);
40 va_end(va);
41 }
#define MAX_PATH
Definition: compat.h:34
#define _countof(array)
Definition: sndvol32.h:68
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AddJob(), AddSubst(), CannotRead(), CBindStatusCallback_OnProgress(), CheckLogOrSourceExistence(), ChkdskCallback(), Confirm(), ConFormatMessage(), ConsoleCtrlHandler(), DeleteJob(), DeleteSubst(), DetailDisk(), DetailPartition(), Different(), DisplayDns(), DisplayDnsRecord(), DoOpenFileForInput(), EnumerateDevices(), ErrorMessage(), FileCompare(), FileCompareBothWild(), FileCompareOneSideWild(), FileCompareWildTitle(), FlushDns(), FormatExCallback(), GetFileSystemInfo(), HandleInfoCommand(), HelpCommand(), HelpGroup(), InputWait(), InterpretCommand(), ListPartition(), LongerThan(), ParseArgument(), ParseCmdLine(), Ping(), print_err(), PrintAdapterTypeAndName(), PrintAllJobs(), PrintDisk(), PrintError(), PrintJobDetails(), PrintNodeType(), PrintStats(), PrintVolume(), Release(), Renew(), ResolveTarget(), RunScript(), SelectDisk(), SelectPartition(), SelectVolume(), SerialPortQuery(), SetConsoleCPState(), SetConsoleState(), SetConsoleStateOld(), SetSerialState(), ShowConsoleCPStatus(), ShowConsoleStatus(), ShowEthernetStatistics(), ShowHeader(), ShowIcmpStatistics(), ShowInfo(), ShowIpStatistics(), ShowParallelStatus(), ShowSerialStatus(), ShowTcpStatistics(), ShowTcpTable(), ShowUdpStatistics(), Usage(), WhereDoOption(), WhereGetVariable(), WhereParseCommandLine(), WherePrintPath(), WlanPrintCurrentStatus(), WlanScan(), and wmain().

◆ ConResPuts()

◆ Different()

FCRET Different ( LPCWSTR  file0,
LPCWSTR  file1 
)

Definition at line 52 of file fc.c.

53{
54 ConResPrintf(StdOut, IDS_DIFFERENT, file0, file1);
55 return FCRET_DIFFERENT;
56}
#define IDS_DIFFERENT
Definition: resource.h:11
@ FCRET_DIFFERENT
Definition: fc.h:27

Referenced by BinaryFileCompare(), and Finalize().

◆ DoOpenFileForInput()

HANDLE DoOpenFileForInput ( LPCWSTR  file)

Definition at line 118 of file fc.c.

119{
122 {
124 }
125 return hFile;
126}
#define IDS_CANNOT_OPEN
Definition: resource.h:8
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
_In_ HANDLE hFile
Definition: mswsock.h:90

Referenced by BinaryFileCompare(), and TextFileCompare().

◆ FileCompare()

static FCRET FileCompare ( FILECOMPARE pFC)
static

Definition at line 340 of file fc.c.

341{
342 FCRET ret;
343 ConResPrintf(StdOut, IDS_COMPARING, pFC->file[0], pFC->file[1]);
344
345 if (!(pFC->dwFlags & FLAG_L) &&
346 ((pFC->dwFlags & FLAG_B) || IsBinaryExt(pFC->file[0]) || IsBinaryExt(pFC->file[1])))
347 {
348 ret = BinaryFileCompare(pFC);
349 }
350 else
351 {
352 ret = TextFileCompare(pFC);
353 }
354
355 ConPuts(StdOut, L"\n");
356 return ret;
357}
#define IDS_COMPARING
Definition: resource.h:7
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
static BOOL IsBinaryExt(LPCWSTR filename)
Definition: fc.c:309
static FCRET TextFileCompare(FILECOMPARE *pFC)
Definition: fc.c:237
static FCRET BinaryFileCompare(FILECOMPARE *pFC)
Definition: fc.c:128
#define FLAG_L
Definition: fc.h:52
#define FLAG_B
Definition: fc.h:50
DWORD dwFlags
Definition: fc.h:64

Referenced by FileCompareBothWild(), FileCompareOneSideWild(), FileCompareWildTitle(), and WildcardFileCompare().

◆ FileCompareBothWild()

static FCRET FileCompareBothWild ( const FILECOMPARE pFC)
static

Definition at line 474 of file fc.c.

475{
477 WIN32_FIND_DATAW find0, find1;
478 HANDLE hFind0, hFind1;
479 WCHAR szPath0[MAX_PATH], szPath1[MAX_PATH];
481
482 hFind0 = FindFirstFileW(pFC->file[0], &find0);
483 if (hFind0 == INVALID_HANDLE_VALUE)
484 {
486 ConPuts(StdOut, L"\n");
487 return FCRET_CANT_FIND;
488 }
489 hFind1 = FindFirstFileW(pFC->file[1], &find1);
490 if (hFind1 == INVALID_HANDLE_VALUE)
491 {
492 CloseHandle(hFind0);
494 ConPuts(StdOut, L"\n");
495 return FCRET_CANT_FIND;
496 }
497 StringCbCopyW(szPath0, sizeof(szPath0), pFC->file[0]);
498 StringCbCopyW(szPath1, sizeof(szPath1), pFC->file[1]);
499
500 fc = *pFC;
501 fc.file[0] = szPath0;
502 fc.file[1] = szPath1;
503 do
504 {
505 while (IS_DOTS(find0.cFileName))
506 {
507 if (!FindNextFileW(hFind0, &find0))
508 goto quit;
509 }
510 while (IS_DOTS(find1.cFileName))
511 {
512 if (!FindNextFileW(hFind1, &find1))
513 goto quit;
514 }
515
516 // replace file title
517 PathRemoveFileSpecW(szPath0);
518 PathRemoveFileSpecW(szPath1);
519 PathAppendW(szPath0, find0.cFileName);
520 PathAppendW(szPath1, find1.cFileName);
521
522 switch (FileCompare(&fc))
523 {
524 case FCRET_IDENTICAL:
525 break;
526 case FCRET_DIFFERENT:
527 if (ret != FCRET_INVALID)
529 break;
530 default:
532 break;
533 }
534 } while (FindNextFileW(hFind0, &find0) && FindNextFileW(hFind1, &find1));
535quit:
536 CloseHandle(hFind0);
537 CloseHandle(hFind1);
538 return ret;
539}
static const struct optioninfo * find1(const char **optp, const struct optioninfo *table, comparer_type *comparer)
Definition: adh-opts.c:306
static FCRET FileCompare(FILECOMPARE *pFC)
Definition: fc.c:340
#define IS_DOTS(pch)
Definition: fc.c:360
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
PFOR_CONTEXT fc
Definition: for.c:57
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
#define PathAppendW
Definition: pathcch.h:309
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
Definition: fc.h:63

Referenced by WildcardFileCompare().

◆ FileCompareOneSideWild()

static FCRET FileCompareOneSideWild ( const FILECOMPARE pFC,
BOOL  bWildRight 
)
static

Definition at line 371 of file fc.c.

372{
375 HANDLE hFind;
378
379 hFind = FindFirstFileW(pFC->file[bWildRight], &find);
380 if (hFind == INVALID_HANDLE_VALUE)
381 {
382 ConResPrintf(StdErr, IDS_CANNOT_OPEN, pFC->file[bWildRight]);
383 ConPuts(StdOut, L"\n");
384 return FCRET_CANT_FIND;
385 }
386 StringCbCopyW(szPath, sizeof(szPath), pFC->file[bWildRight]);
387
388 fc = *pFC;
389 fc.file[!bWildRight] = pFC->file[!bWildRight];
390 fc.file[bWildRight] = szPath;
391 do
392 {
393 if (IS_DOTS(find.cFileName))
394 continue;
395
396 // replace file title
398 PathAppendW(szPath, find.cFileName);
399
400 switch (FileCompare(&fc))
401 {
402 case FCRET_IDENTICAL:
403 break;
404 case FCRET_DIFFERENT:
405 if (ret != FCRET_INVALID)
407 break;
408 default:
410 break;
411 }
412 } while (FindNextFileW(hFind, &find));
413
414 FindClose(hFind);
415 return ret;
416}
static TAGID TAGID find
Definition: db.cpp:155
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
LPCWSTR szPath
Definition: env.c:37

Referenced by WildcardFileCompare().

◆ FileCompareWildTitle()

static FCRET FileCompareWildTitle ( const FILECOMPARE pFC)
static

Definition at line 418 of file fc.c.

419{
422 HANDLE hFind;
423 WCHAR szPath0[MAX_PATH], szPath1[MAX_PATH];
425 LPWSTR pch;
426
427 hFind = FindFirstFileW(pFC->file[0], &find);
428 if (hFind == INVALID_HANDLE_VALUE)
429 {
431 ConPuts(StdOut, L"\n");
432 return FCRET_CANT_FIND;
433 }
434 StringCbCopyW(szPath0, sizeof(szPath0), pFC->file[0]);
435 StringCbCopyW(szPath1, sizeof(szPath1), pFC->file[1]);
436 pch = PathFindExtensionW(pFC->file[1]);
437
438 fc = *pFC;
439 fc.file[0] = szPath0;
440 fc.file[1] = szPath1;
441 do
442 {
443 if (IS_DOTS(find.cFileName))
444 continue;
445
446 // replace file title
447 PathRemoveFileSpecW(szPath0);
448 PathRemoveFileSpecW(szPath1);
449 PathAppendW(szPath0, find.cFileName);
450 PathAppendW(szPath1, find.cFileName);
451
452 // replace dot extension
453 PathRemoveExtensionW(szPath1);
454 PathAddExtensionW(szPath1, pch);
455
456 switch (FileCompare(&fc))
457 {
458 case FCRET_IDENTICAL:
459 break;
460 case FCRET_DIFFERENT:
461 if (ret != FCRET_INVALID)
463 break;
464 default:
466 break;
467 }
468 } while (FindNextFileW(hFind, &find));
469
470 FindClose(hFind);
471 return ret;
472}
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
#define pch(ap)
Definition: match.c:418
#define PathAddExtensionW
Definition: pathcch.h:305
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by WildcardFileCompare().

◆ InvalidSwitch()

FCRET InvalidSwitch ( VOID  )

Definition at line 76 of file fc.c.

77{
79 return FCRET_INVALID;
80}
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define IDS_INVALID_SWITCH
Definition: resource.h:7

Referenced by wmain().

◆ IsBinaryExt()

static BOOL IsBinaryExt ( LPCWSTR  filename)
static

Definition at line 309 of file fc.c.

310{
311 // Don't change this array. This is by design.
312 // See also: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fc
313 static const LPCWSTR s_exts[] = { L"EXE", L"COM", L"SYS", L"OBJ", L"LIB", L"BIN" };
314 size_t iext;
315 LPCWSTR pch, ext, pch0 = wcsrchr(filename, L'\\'), pch1 = wcsrchr(filename, L'/');
316 if (!pch0 && !pch1)
317 pch = filename;
318 else if (!pch0 && pch1)
319 pch = pch1;
320 else if (pch0 && !pch1)
321 pch = pch0;
322 else if (pch0 < pch1)
323 pch = pch1;
324 else
325 pch = pch0;
326
327 ext = wcsrchr(pch, L'.');
328 if (ext)
329 {
330 ++ext;
331 for (iext = 0; iext < _countof(s_exts); ++iext)
332 {
333 if (_wcsicmp(ext, s_exts[iext]) == 0)
334 return TRUE;
335 }
336 }
337 return FALSE;
338}
#define wcsrchr
Definition: compat.h:16
static const WCHAR *const ext[]
Definition: module.c:53
const char * filename
Definition: ioapi.h:137
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by FileCompare().

◆ IsTitleWild()

static BOOL IsTitleWild ( LPCWSTR  filename)
inlinestatic

Definition at line 365 of file fc.c.

366{
368 return (pch && *pch == L'*' && pch[1] == L'.' && !HasWildcard(&pch[2]));
369}
#define HasWildcard(filename)
Definition: fc.c:362
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394

Referenced by WildcardFileCompare().

◆ LongerThan()

FCRET LongerThan ( LPCWSTR  file0,
LPCWSTR  file1 
)

Definition at line 58 of file fc.c.

59{
60 ConResPrintf(StdOut, IDS_LONGER_THAN, file0, file1);
61 return FCRET_DIFFERENT;
62}
#define IDS_LONGER_THAN
Definition: resource.h:3

Referenced by BinaryFileCompare().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 665 of file fc.c.

666{
667 INT my_argc;
668 LPWSTR *my_argv = CommandLineToArgvW(GetCommandLineW(), &my_argc);
669 INT ret = wmain(my_argc, my_argv);
670 LocalFree(my_argv);
671 return ret;
672}
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
int wmain()
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:80
int32_t INT
Definition: typedefs.h:58

◆ NoDifference()

FCRET NoDifference ( VOID  )

Definition at line 46 of file fc.c.

47{
49 return FCRET_IDENTICAL;
50}
#define IDS_NO_DIFFERENCE
Definition: resource.h:2

Referenced by BinaryFileCompare(), Finalize(), and TextFileCompare().

◆ OutOfMemory()

FCRET OutOfMemory ( VOID  )

Definition at line 64 of file fc.c.

65{
67 return FCRET_INVALID;
68}
#define IDS_OUT_OF_MEMORY
Definition: resource.h:5

◆ PrintCaption()

VOID PrintCaption ( LPCWSTR  file)

Definition at line 88 of file fc.c.

89{
90 ConPrintf(StdOut, L"***** %ls\n", file);
91}

Referenced by ShowDiff().

◆ PrintDots()

VOID PrintDots ( VOID  )

Definition at line 98 of file fc.c.

99{
100 ConPuts(StdOut, L"...\n");
101}

Referenced by ShowDiff().

◆ PrintEndOfDiff()

VOID PrintEndOfDiff ( VOID  )

Definition at line 93 of file fc.c.

94{
95 ConPuts(StdOut, L"*****\n\n");
96}

Referenced by Finalize(), and TextCompare().

◆ PrintLineA()

VOID PrintLineA ( const FILECOMPARE pFC,
DWORD  lineno,
LPCSTR  psz 
)

Definition at line 110 of file fc.c.

111{
112 if (pFC->dwFlags & FLAG_N)
113 ConPrintf(StdOut, L"%5d: %hs\n", lineno, psz);
114 else
115 ConPrintf(StdOut, L"%hs\n", psz);
116}
#define FLAG_N
Definition: fc.h:54

◆ PrintLineW()

VOID PrintLineW ( const FILECOMPARE pFC,
DWORD  lineno,
LPCWSTR  psz 
)

Definition at line 103 of file fc.c.

104{
105 if (pFC->dwFlags & FLAG_N)
106 ConPrintf(StdOut, L"%5d: %ls\n", lineno, psz);
107 else
108 ConPrintf(StdOut, L"%ls\n", psz);
109}

◆ ResyncFailed()

FCRET ResyncFailed ( VOID  )

Definition at line 82 of file fc.c.

83{
85 return FCRET_DIFFERENT;
86}
#define IDS_RESYNC_FAILED
Definition: resource.h:13

Referenced by TextCompare().

◆ TextFileCompare()

static FCRET TextFileCompare ( FILECOMPARE pFC)
static

Definition at line 237 of file fc.c.

238{
239 FCRET ret;
240 HANDLE hFile0, hFile1, hMapping0 = NULL, hMapping1 = NULL;
241 LARGE_INTEGER cb0, cb1;
242 BOOL fUnicode = !!(pFC->dwFlags & FLAG_U);
243
244 hFile0 = DoOpenFileForInput(pFC->file[0]);
245 if (hFile0 == INVALID_HANDLE_VALUE)
246 return FCRET_CANT_FIND;
247 hFile1 = DoOpenFileForInput(pFC->file[1]);
248 if (hFile1 == INVALID_HANDLE_VALUE)
249 {
250 CloseHandle(hFile0);
251 return FCRET_CANT_FIND;
252 }
253
254 do
255 {
256 if (_wcsicmp(pFC->file[0], pFC->file[1]) == 0)
257 {
258 ret = NoDifference();
259 break;
260 }
261 if (!GetFileSizeEx(hFile0, &cb0))
262 {
263 ret = CannotRead(pFC->file[0]);
264 break;
265 }
266 if (!GetFileSizeEx(hFile1, &cb1))
267 {
268 ret = CannotRead(pFC->file[1]);
269 break;
270 }
271 if (cb0.QuadPart == 0 && cb1.QuadPart == 0)
272 {
273 ret = NoDifference();
274 break;
275 }
276 if (cb0.QuadPart > 0)
277 {
278 hMapping0 = CreateFileMappingW(hFile0, NULL, PAGE_READONLY,
279 cb0.HighPart, cb0.LowPart, NULL);
280 if (hMapping0 == NULL)
281 {
282 ret = CannotRead(pFC->file[0]);
283 break;
284 }
285 }
286 if (cb1.QuadPart > 0)
287 {
288 hMapping1 = CreateFileMappingW(hFile1, NULL, PAGE_READONLY,
289 cb1.HighPart, cb1.LowPart, NULL);
290 if (hMapping1 == NULL)
291 {
292 ret = CannotRead(pFC->file[1]);
293 break;
294 }
295 }
296 if (fUnicode)
297 ret = TextCompareW(pFC, &hMapping0, &cb0, &hMapping1, &cb1);
298 else
299 ret = TextCompareA(pFC, &hMapping0, &cb0, &hMapping1, &cb1);
300 } while (0);
301
302 CloseHandle(hMapping0);
303 CloseHandle(hMapping1);
304 CloseHandle(hFile0);
305 CloseHandle(hFile1);
306 return ret;
307}
FCRET TextCompareW(FILECOMPARE *pFC, HANDLE *phMapping0, const LARGE_INTEGER *pcb0, HANDLE *phMapping1, const LARGE_INTEGER *pcb1)
#define FLAG_U
Definition: fc.h:57
FCRET TextCompareA(FILECOMPARE *pFC, HANDLE *phMapping0, const LARGE_INTEGER *pcb0, HANDLE *phMapping1, const LARGE_INTEGER *pcb1)

Referenced by FileCompare().

◆ WildcardFileCompare()

static FCRET WildcardFileCompare ( FILECOMPARE pFC)
static

Definition at line 541 of file fc.c.

542{
543 BOOL fWild0, fWild1;
544
545 if (pFC->dwFlags & FLAG_HELP)
546 {
548 return FCRET_INVALID;
549 }
550
551 if (!pFC->file[0] || !pFC->file[1])
552 {
554 return FCRET_INVALID;
555 }
556
557 fWild0 = HasWildcard(pFC->file[0]);
558 fWild1 = HasWildcard(pFC->file[1]);
559 if (fWild0 && fWild1)
560 {
561 if (IsTitleWild(pFC->file[0]) && IsTitleWild(pFC->file[1]))
562 return FileCompareWildTitle(pFC);
563 else
564 return FileCompareBothWild(pFC);
565 }
566 else if (fWild0)
567 {
568 return FileCompareOneSideWild(pFC, FALSE);
569 }
570 else if (fWild1)
571 {
572 return FileCompareOneSideWild(pFC, TRUE);
573 }
574 return FileCompare(pFC);
575}
#define IDS_USAGE
Definition: resource.h:3
static BOOL IsTitleWild(LPCWSTR filename)
Definition: fc.c:365
static FCRET FileCompareBothWild(const FILECOMPARE *pFC)
Definition: fc.c:474
static FCRET FileCompareOneSideWild(const FILECOMPARE *pFC, BOOL bWildRight)
Definition: fc.c:371
static FCRET FileCompareWildTitle(const FILECOMPARE *pFC)
Definition: fc.c:418
#define IDS_NEEDS_FILES
Definition: resource.h:9
#define FLAG_HELP
Definition: fc.h:60

Referenced by wmain().

◆ wmain()

int wmain ( int  argc,
WCHAR **  argv 
)

Definition at line 577 of file fc.c.

578{
579 FILECOMPARE fc = { .dwFlags = 0, .n = 100, .nnnn = 2 };
580 PWCHAR endptr;
581 INT i;
582
583 /* Initialize the Console Standard Streams */
585
586 for (i = 1; i < argc; ++i)
587 {
588 if (argv[i][0] != L'/')
589 {
590 if (!fc.file[0])
591 fc.file[0] = argv[i];
592 else if (!fc.file[1])
593 fc.file[1] = argv[i];
594 else
595 return InvalidSwitch();
596 continue;
597 }
598 switch (towupper(argv[i][1]))
599 {
600 case L'A':
601 fc.dwFlags |= FLAG_A;
602 break;
603 case L'B':
604 fc.dwFlags |= FLAG_B;
605 break;
606 case L'C':
607 fc.dwFlags |= FLAG_C;
608 break;
609 case L'L':
610 if (_wcsicmp(argv[i], L"/L") == 0)
611 {
612 fc.dwFlags |= FLAG_L;
613 }
614 else if (towupper(argv[i][2]) == L'B')
615 {
616 if (iswdigit(argv[i][3]))
617 {
618 fc.dwFlags |= FLAG_LBn;
619 fc.n = wcstoul(&argv[i][3], &endptr, 10);
620 if (endptr == NULL || *endptr != 0)
621 return InvalidSwitch();
622 }
623 else
624 {
625 return InvalidSwitch();
626 }
627 }
628 break;
629 case L'N':
630 fc.dwFlags |= FLAG_N;
631 break;
632 case L'O':
633 if (_wcsicmp(argv[i], L"/OFF") == 0 || _wcsicmp(argv[i], L"/OFFLINE") == 0)
634 {
635 fc.dwFlags |= FLAG_OFFLINE;
636 }
637 break;
638 case L'T':
639 fc.dwFlags |= FLAG_T;
640 break;
641 case L'U':
642 fc.dwFlags |= FLAG_U;
643 break;
644 case L'W':
645 fc.dwFlags |= FLAG_W;
646 break;
647 case L'0': case L'1': case L'2': case L'3': case L'4':
648 case L'5': case L'6': case L'7': case L'8': case L'9':
649 fc.nnnn = wcstoul(&argv[i][1], &endptr, 10);
650 if (endptr == NULL || *endptr != 0)
651 return InvalidSwitch();
652 fc.dwFlags |= FLAG_nnnn;
653 break;
654 case L'?':
655 fc.dwFlags |= FLAG_HELP;
656 break;
657 default:
658 return InvalidSwitch();
659 }
660 }
661 return WildcardFileCompare(&fc);
662}
static int argc
Definition: ServiceArgs.c:12
#define ConInitStdStreams()
Definition: fc.c:13
FCRET InvalidSwitch(VOID)
Definition: fc.c:76
static FCRET WildcardFileCompare(FILECOMPARE *pFC)
Definition: fc.c:541
#define FLAG_T
Definition: fc.h:56
#define FLAG_W
Definition: fc.h:58
#define FLAG_A
Definition: fc.h:49
#define FLAG_nnnn
Definition: fc.h:59
#define FLAG_OFFLINE
Definition: fc.h:55
#define FLAG_LBn
Definition: fc.h:53
#define FLAG_C
Definition: fc.h:51
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
#define iswdigit(_c)
Definition: ctype.h:667
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define argv
Definition: mplay32.c:18
#define towupper(c)
Definition: wctype.h:99
uint16_t * PWCHAR
Definition: typedefs.h:56