Reactos
at master 97 lines 2.8 kB view raw
1/* 2 * PROJECT: ReactOS FC Command 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Comparing files 5 * COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) 6 */ 7#pragma once 8#include <stdlib.h> 9#include <string.h> 10#include <ctype.h> 11#ifdef __REACTOS__ 12 #include <windef.h> 13 #include <winbase.h> 14 #include <winuser.h> 15 #include <winnls.h> 16#else 17 #include <windows.h> 18#endif 19#include <wine/list.h> 20#include "resource.h" 21 22// See also: https://stackoverflow.com/questions/33125766/compare-files-with-a-cmd 23typedef enum FCRET // return code of FC command 24{ 25 FCRET_INVALID = -1, 26 FCRET_IDENTICAL = 0, 27 FCRET_DIFFERENT = 1, 28 FCRET_CANT_FIND = 2, 29 FCRET_NO_MORE_DATA = 3 // (extension) 30} FCRET; 31 32typedef struct NODE_W 33{ 34 struct list entry; 35 LPWSTR pszLine; 36 LPWSTR pszComp; // compressed 37 DWORD lineno; 38 DWORD hash; 39} NODE_W; 40typedef struct NODE_A 41{ 42 struct list entry; 43 LPSTR pszLine; 44 LPSTR pszComp; // compressed 45 DWORD lineno; 46 DWORD hash; 47} NODE_A; 48 49#define FLAG_A (1 << 0) // abbreviation 50#define FLAG_B (1 << 1) // binary 51#define FLAG_C (1 << 2) // ignore cases 52#define FLAG_L (1 << 3) // ASCII mode 53#define FLAG_LBn (1 << 4) // line buffers 54#define FLAG_N (1 << 5) // show line numbers 55#define FLAG_OFFLINE (1 << 6) // ??? 56#define FLAG_T (1 << 7) // prevent fc from converting tabs to spaces 57#define FLAG_U (1 << 8) // Unicode 58#define FLAG_W (1 << 9) // compress white space 59#define FLAG_nnnn (1 << 10) // ??? 60#define FLAG_HELP (1 << 11) // show usage 61 62typedef struct FILECOMPARE 63{ 64 DWORD dwFlags; // FLAG_... 65 INT n; // # of line buffers 66 INT nnnn; // retry count before resynch 67 LPCWSTR file[2]; 68 struct list list[2]; 69} FILECOMPARE; 70 71// text.h 72FCRET TextCompareW(FILECOMPARE *pFC, 73 HANDLE *phMapping0, const LARGE_INTEGER *pcb0, 74 HANDLE *phMapping1, const LARGE_INTEGER *pcb1); 75FCRET TextCompareA(FILECOMPARE *pFC, 76 HANDLE *phMapping0, const LARGE_INTEGER *pcb0, 77 HANDLE *phMapping1, const LARGE_INTEGER *pcb1); 78// fc.c 79VOID PrintLineW(const FILECOMPARE *pFC, DWORD lineno, LPCWSTR psz); 80VOID PrintLineA(const FILECOMPARE *pFC, DWORD lineno, LPCSTR psz); 81VOID PrintCaption(LPCWSTR file); 82VOID PrintEndOfDiff(VOID); 83VOID PrintDots(VOID); 84FCRET NoDifference(VOID); 85FCRET Different(LPCWSTR file0, LPCWSTR file1); 86FCRET LongerThan(LPCWSTR file0, LPCWSTR file1); 87FCRET OutOfMemory(VOID); 88FCRET CannotRead(LPCWSTR file); 89FCRET InvalidSwitch(VOID); 90FCRET ResyncFailed(VOID); 91HANDLE DoOpenFileForInput(LPCWSTR file); 92 93#ifdef _WIN64 94 #define MAX_VIEW_SIZE (256 * 1024 * 1024) // 256 MB 95#else 96 #define MAX_VIEW_SIZE (64 * 1024 * 1024) // 64 MB 97#endif