Skip to content

Commit

Permalink
Advanced compare: add (in)sensitive option compare
Browse files Browse the repository at this point in the history
* add functions `LStrcmp` and `LStrncmp` in plugin api

* add option "case sensitive file names" in Advanced compare plugin

Fix #2115

Fix part of #2029
  • Loading branch information
akruphi committed Jul 1, 2024
1 parent 64af534 commit 79fb67e
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 24 deletions.
3 changes: 3 additions & 0 deletions compare/configs/plug/CmpEng.hlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ but it also provides additional compare options:

#Compare:#

#case sensitive# Compare file names with/witout
#file names# case sensitive.

#time# Compare file modification time.
Unlike the internal FAR command, this
option will mark files on both panels,
Expand Down
3 changes: 3 additions & 0 deletions compare/configs/plug/CmpRus.hlf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ $ #Расширенное сравнение#

#Сравнивать:#

#учитывать регистр# Сравнивать имена файлов с/без
#имен файлов# учета регистра.

#время# Сравнивать время изменения файлов.
В отличие от встроенной команды FAR,
будут помечены файлы на обеих панелях,
Expand Down
1 change: 1 addition & 0 deletions compare/configs/plug/CompBel.lng
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"&найбольшы узровень укладзенасці:"
"т&олькі адзначаныя файлы/каталогі"
"параўнаць:"
"&улічваць рэгістр імёны файлаў"
"&час"
"дзвухсекундная &дакладнасць"
"&ігнараваць адрозненні з-за гадзінных паясоў"
Expand Down
1 change: 1 addition & 0 deletions compare/configs/plug/CompEng.lng
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"&maximum folder depth:"
"s&elected items only"
"Compare:"
"c&ase sensitive file names"
"&time"
"two seconds &precision"
"&ignore possible time zone differences"
Expand Down
1 change: 1 addition & 0 deletions compare/configs/plug/CompRus.lng
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"&максимальный уровень вложенности:"
"только п&омеченные файлы/папки"
"Сравнивать:"
"&учитывать регистр имен файлов"
"&время"
"двухсекундная &точность"
"&игнорировать различия из-за часовых поясов"
Expand Down
54 changes: 30 additions & 24 deletions compare/src/Compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum CompareLng
MUseMaxScanDepth,
MProcessSelected,
MCompareBox,
MCompareCaseFileNames,
MCompareTime,
MCompareLowPrecision,
MCompareIgnoreTimeZone,
Expand Down Expand Up @@ -80,7 +81,8 @@ enum CompareLng
****************************************************************************/
struct Options
{
int ProcessSubfolders, UseMaxScanDepth, MaxScanDepth, ProcessSelected, ProcessHidden, CompareTime,
int ProcessSubfolders, UseMaxScanDepth, MaxScanDepth, ProcessSelected, ProcessHidden,
CompareCaseFileNames, CompareTime,
LowPrecisionTime, IgnorePossibleTimeZoneDifferences, CompareSize, CompareContents,
CompareContentsIgnore, IgnoreWhitespace, IgnoreNewLines, MessageWhenNoDiff;
} Opt;
Expand Down Expand Up @@ -227,7 +229,7 @@ static bool ShowDialog(bool bPluginPanels, bool bSelectionPresent)
unsigned int Flags;
int *StoreTo;
} InitItems[] = {
/* 0*/ {DI_DOUBLEBOX, 3, 1, 62, 20, MCmpTitle, 0, NULL, 0, NULL},
/* 0*/ {DI_DOUBLEBOX, 3, 1, 62, 21, MCmpTitle, 0, NULL, 0, NULL},
/* 1*/ {DI_TEXT, 5, 2, 0, 0, MProcessBox, 0, NULL, 0, NULL},
/* 2*/
{DI_CHECKBOX, 5, 3, 0, 0, MProcessSubfolders, 0, ("ProcessSubfolders"), 0,
Expand All @@ -241,32 +243,33 @@ static bool ShowDialog(bool bPluginPanels, bool bSelectionPresent)
{DI_CHECKBOX, 5, 5, 0, 0, MProcessSelected, 0, ("ProcessSelected"), 0, &Opt.ProcessSelected},
/* 6*/ {DI_TEXT, 0, 6, 0, 0, MNoLngStringDefined, 0, NULL, DIF_SEPARATOR, NULL},
/* 7*/ {DI_TEXT, 5, 7, 0, 0, MCompareBox, 0, NULL, 0, NULL},
/* 8*/ {DI_CHECKBOX, 5, 8, 0, 0, MCompareTime, 1, ("CompareTime"), 0, &Opt.CompareTime},
/* 9*/
{DI_CHECKBOX, 9, 9, 0, 0, MCompareLowPrecision, 1, ("LowPrecisionTime"), 0,
&Opt.LowPrecisionTime},
/* 8*/ {DI_CHECKBOX, 5, 8, 0, 0, MCompareCaseFileNames, 1, ("CompareCaseFileNames"), 0, &Opt.CompareCaseFileNames},
/* 9*/ {DI_CHECKBOX, 5, 9, 0, 0, MCompareTime, 1, ("CompareTime"), 0, &Opt.CompareTime},
/*10*/
{DI_CHECKBOX, 9, 10, 0, 0, MCompareIgnoreTimeZone, 1, ("IgnorePossibleTimeZoneDifferences"), 0,
{DI_CHECKBOX, 9, 10, 0, 0, MCompareLowPrecision, 1, ("LowPrecisionTime"), 0,
&Opt.LowPrecisionTime},
/*11*/
{DI_CHECKBOX, 9, 11, 0, 0, MCompareIgnoreTimeZone, 1, ("IgnorePossibleTimeZoneDifferences"), 0,
&Opt.IgnorePossibleTimeZoneDifferences},
/*11*/ {DI_CHECKBOX, 5, 11, 0, 0, MCompareSize, 1, ("CompareSize"), 0, &Opt.CompareSize},
/*12*/
{DI_CHECKBOX, 5, 12, 0, 0, MCompareContents, 0, ("CompareContents"), 0, &Opt.CompareContents},
/*12*/ {DI_CHECKBOX, 5, 12, 0, 0, MCompareSize, 1, ("CompareSize"), 0, &Opt.CompareSize},
/*13*/
{DI_CHECKBOX, 9, 13, 0, 0, MCompareContentsIgnore, 0, ("CompareContentsIgnore"), 0,
&Opt.CompareContentsIgnore},
{DI_CHECKBOX, 5, 13, 0, 0, MCompareContents, 0, ("CompareContents"), 0, &Opt.CompareContents},
/*14*/
{DI_RADIOBUTTON, 13, 14, 0, 0, MCompareIgnoreNewLines, 1, ("IgnoreNewLines"), DIF_GROUP,
&Opt.IgnoreNewLines},
{DI_CHECKBOX, 9, 14, 0, 0, MCompareContentsIgnore, 0, ("CompareContentsIgnore"), 0,
&Opt.CompareContentsIgnore},
/*15*/
{DI_RADIOBUTTON, 13, 15, 0, 0, MCompareIgnoreWhitespace, 0, ("IgnoreWhitespace"), 0,
{DI_RADIOBUTTON, 13, 15, 0, 0, MCompareIgnoreNewLines, 1, ("IgnoreNewLines"), DIF_GROUP,
&Opt.IgnoreNewLines},
/*16*/
{DI_RADIOBUTTON, 13, 16, 0, 0, MCompareIgnoreWhitespace, 0, ("IgnoreWhitespace"), 0,
&Opt.IgnoreWhitespace},
/*16*/ {DI_TEXT, 0, 16, 0, 0, MNoLngStringDefined, 0, NULL, DIF_SEPARATOR, NULL},
/*17*/
{DI_CHECKBOX, 5, 17, 0, 0, MMessageWhenNoDiff, 0, ("MessageWhenNoDiff"), 0,
/*17*/ {DI_TEXT, 0, 17, 0, 0, MNoLngStringDefined, 0, NULL, DIF_SEPARATOR, NULL},
/*18*/
{DI_CHECKBOX, 5, 18, 0, 0, MMessageWhenNoDiff, 0, ("MessageWhenNoDiff"), 0,
&Opt.MessageWhenNoDiff},
/*18*/ {DI_TEXT, 0, 18, 0, 0, MNoLngStringDefined, 0, NULL, DIF_SEPARATOR, NULL},
/*19*/ {DI_BUTTON, 0, 19, 0, 0, MOK, 0, NULL, DIF_CENTERGROUP, NULL},
/*20*/ {DI_BUTTON, 0, 19, 0, 0, MCancel, 0, NULL, DIF_CENTERGROUP, NULL}};
/*19*/ {DI_TEXT, 0, 19, 0, 0, MNoLngStringDefined, 0, NULL, DIF_SEPARATOR, NULL},
/*20*/ {DI_BUTTON, 0, 20, 0, 0, MOK, 0, NULL, DIF_CENTERGROUP, NULL},
/*21*/ {DI_BUTTON, 0, 20, 0, 0, MCancel, 0, NULL, DIF_CENTERGROUP, NULL}};
struct FarDialogItem DialogItems[ARRAYSIZE(InitItems)];
TCHAR Mask[] = _T("99999");
#ifdef UNICODE
Expand Down Expand Up @@ -394,10 +397,10 @@ static bool ShowDialog(bool bPluginPanels, bool bSelectionPresent)
}

#ifndef UNICODE
int ExitCode = Info.DialogEx(Info.ModuleNumber, -1, -1, 66, 22, _T("Contents"), DialogItems,
int ExitCode = Info.DialogEx(Info.ModuleNumber, -1, -1, 66, 23, _T("Contents"), DialogItems,
ARRAYSIZE(DialogItems), 0, 0, ShowDialogProc, DlgData);
#else
HANDLE hDlg = Info.DialogInit(Info.ModuleNumber, -1, -1, 66, 22, _T("Contents"), DialogItems,
HANDLE hDlg = Info.DialogInit(Info.ModuleNumber, -1, -1, 66, 23, _T("Contents"), DialogItems,
ARRAYSIZE(DialogItems), 0, 0, ShowDialogProc, DlgData);
if (hDlg == INVALID_HANDLE_VALUE)
return false;
Expand Down Expand Up @@ -511,7 +514,10 @@ static int __cdecl PICompare(const void *el1, const void *el2)
return 1;
}

return -FSF.LStricmp(ppi1->FindData._cFileName, ppi2->FindData._cFileName);
if (Opt.CompareCaseFileNames)
return -FSF.LStrcmp(ppi1->FindData._cFileName, ppi2->FindData._cFileName);
else
return -FSF.LStricmp(ppi1->FindData._cFileName, ppi2->FindData._cFileName);
}

/****************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions far2l/far2sdk/farplug-mb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,8 @@ namespace oldfar
typedef void (WINAPI *FARSTDLOCALSTRLWR)(char *s1);
typedef int (WINAPI *FARSTDLOCALSTRICMP)(const char *s1,const char *s2);
typedef int (WINAPI *FARSTDLOCALSTRNICMP)(const char *s1,const char *s2,int n);
typedef int (WINAPI *FARSTDLOCALSTRCMP)(const char *s1,const char *s2);
typedef int (WINAPI *FARSTDLOCALSTRNCMP)(const char *s1,const char *s2,int n);

enum PROCESSNAME_FLAGS
{
Expand Down
4 changes: 4 additions & 0 deletions far2l/far2sdk/farplug-wide.h
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,8 @@ typedef void (WINAPI *FARSTDLOCALSTRUPR)(wchar_t *s1);
typedef void (WINAPI *FARSTDLOCALSTRLWR)(wchar_t *s1);
typedef int (WINAPI *FARSTDLOCALSTRICMP)(const wchar_t *s1,const wchar_t *s2);
typedef int (WINAPI *FARSTDLOCALSTRNICMP)(const wchar_t *s1,const wchar_t *s2,int n);
typedef int (WINAPI *FARSTDLOCALSTRCMP)(const wchar_t *s1,const wchar_t *s2);
typedef int (WINAPI *FARSTDLOCALSTRNCMP)(const wchar_t *s1,const wchar_t *s2,int n);

enum PROCESSNAME_FLAGS
{
Expand Down Expand Up @@ -2082,6 +2084,8 @@ typedef struct FarStandardFunctions
FARSTDLOCALSTRLWR LStrlwr;
FARSTDLOCALSTRICMP LStricmp;
FARSTDLOCALSTRNICMP LStrnicmp;
FARSTDLOCALSTRICMP LStrcmp;
FARSTDLOCALSTRNICMP LStrncmp;

FARSTDUNQUOTE Unquote;
FARSTDLTRIM LTrim;
Expand Down
2 changes: 2 additions & 0 deletions far2l/src/plug/PluginW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ void CreatePluginStartupInfo(Plugin *pPlugin, PluginStartupInfo *PSI, FarStandar
StandardFunctions.LStrlwr = farStrLower;
StandardFunctions.LStricmp = farStrCmpI;
StandardFunctions.LStrnicmp = farStrCmpNI;
StandardFunctions.LStrcmp = farStrCmp;
StandardFunctions.LStrncmp = farStrCmpN;
StandardFunctions.Unquote = Unquote;
StandardFunctions.LTrim = RemoveLeadingSpaces;
StandardFunctions.RTrim = RemoveTrailingSpaces;
Expand Down
10 changes: 10 additions & 0 deletions far2l/src/plug/plugapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,16 @@ int WINAPI farStrCmpI(const wchar_t *s1, const wchar_t *s2)
return StrCmpI(s1, s2);
}

int WINAPI farStrCmpN(const wchar_t *s1, const wchar_t *s2, int n)
{
return StrCmpN(s1, s2, n);
}

int WINAPI farStrCmp(const wchar_t *s1, const wchar_t *s2)
{
return StrCmp(s1, s2);
}

int WINAPI farIsLower(wchar_t Ch)
{
return IsLower(Ch);
Expand Down
2 changes: 2 additions & 0 deletions far2l/src/plug/plugapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ wchar_t WINAPI farUpper(wchar_t Ch);
wchar_t WINAPI farLower(wchar_t Ch);
int WINAPI farStrCmpNI(const wchar_t *s1, const wchar_t *s2, int n);
int WINAPI farStrCmpI(const wchar_t *s1, const wchar_t *s2);
int WINAPI farStrCmpN(const wchar_t *s1, const wchar_t *s2, int n);
int WINAPI farStrCmp(const wchar_t *s1, const wchar_t *s2);
int WINAPI farIsLower(wchar_t Ch);
int WINAPI farIsUpper(wchar_t Ch);
int WINAPI farIsAlpha(wchar_t Ch);
Expand Down

0 comments on commit 79fb67e

Please sign in to comment.