Victor_VG:
Вот дифф этих изменений [more=дифф]diff --git a/far/cmdline.cpp b/far/cmdline.cpp
index f2f08cf1f..2b226efe8 100644
--- a/far/cmdline.cpp
+++ b/far/cmdline.cpp
@@ -1114,27 +1114,23 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
if (SetPanel->GetType() != panel_type::FILE_PANEL && Global->CtrlObject->Cp()->PassivePanel()->GetType() == panel_type::FILE_PANEL)
SetPanel=Global->CtrlObject->Cp()->PassivePanel();
- const auto IsCommand = [&CmdLine](const string_view cmd, const bool bslash)
- {
- const auto n = cmd.size();
- return starts_with_icase(CmdLine, cmd)
- && (n == CmdLine.size() || contains(L"/ \t"sv, CmdLine[n]) || (bslash && CmdLine[n] == L'\\'));
- };
+ const auto Trimmed = trim(CmdLine);
- const auto FindKey = [&CmdLine](wchar_t Key)
- {
- const auto FirstSpacePos = CmdLine.find(L' ');
- const auto NotSpacePos = CmdLine.find_first_not_of(L' ', FirstSpacePos);
+ const auto Command = Trimmed.substr(0, Trimmed.find_first_of(L' '));
+ const auto Arguments = trim_left(Trimmed.substr(Command.size()));
- return NotSpacePos != string::npos &&
- CmdLine.size() > NotSpacePos + 1 &&
- CmdLine[NotSpacePos] == L'/' &&
- upper(CmdLine[NotSpacePos + 1]) == upper(Key);
- };
+ // Cursed spaceless DOS legacy syntax like cd\ or cd/d
+ // Technically other commands can use this syntax too, but we limit it to cd/chdir
+ const auto CommandCursed = Trimmed.substr(0, Trimmed.find_first_of(L" \\/"));
+ const auto ArgumentsCursed = trim_left(Trimmed.substr(CommandCursed.size()));
- const auto FindHelpKey = [&FindKey]() { return FindKey(L'?'); };
+ const auto FindKey = [&](string_view const Where, wchar_t const Key)
+ {
+ const wchar_t Param[] = { L'/', Key, {} };
+ return Where.starts_with(Param) && (Where.size() == 2 || Where[2] == L' ');
+ };
- if (CmdLine.size() > 1 && CmdLine[1] == L':' && (CmdLine.size() == 2 || CmdLine.find_first_not_of(L' ', 2) == string::npos))
+ if (Command.size() == 2 && Command[1] == L':' && Arguments.empty())
{
ConsoleActivatior(false);
@@ -1147,18 +1143,17 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}
- if (FindHelpKey())
+ if (FindKey(Arguments, L'?'))
return false;
- const auto CommandSet = L"SET"sv;
// SET [variable=[value]]
- if (IsCommand(CommandSet, false))
+ if (equal_icase(Command, L"SET"sv))
{
- if (FindKey(L'A') || FindKey(L'P'))
+ if (FindKey(Arguments, L'A') || FindKey(Arguments, L'P'))
return false; //todo: /p - dialog, /a - calculation; then set variable ...
size_t pos;
- const auto SetParams = trim_left(CmdLine.substr(CommandSet.size()));
+ const auto SetParams = unquote(trim_right(Arguments));
// "set" (display all) or "set var" (display all that begin with "var")
if (SetParams.empty() || ((pos = SetParams.find(L'=')) == string::npos) || !pos)
@@ -1167,14 +1162,12 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
if (SetParams.find_first_of(L"|>"sv) != SetParams.npos)
return false;
- const auto UnquotedSetParams = unquote(SetParams);
-
ConsoleActivatior(true);
const os::env::provider::strings EnvStrings;
for (const auto& i: enum_substrings(EnvStrings.data()))
{
- if (starts_with_icase(i, UnquotedSetParams))
+ if (starts_with_icase(i, SetParams))
{
std::wcout << i << L'\n';
}
@@ -1186,8 +1179,8 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
ConsoleActivatior(false);
- const auto VariableValue = trim_right(SetParams.substr(pos + 1));
- const auto VariableName = unquote(SetParams.substr(0, pos));
+ const auto VariableValue = SetParams.substr(pos + 1);
+ const auto VariableName = SetParams.substr(0, pos);
if (VariableValue.empty()) //set var=
{
@@ -1201,10 +1194,9 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}
- const auto CommandCls = L"CLS"sv;
- if (IsCommand(CommandCls, false))
+ if (equal_icase(Command, L"CLS"sv))
{
- if (!trim_left(CmdLine.substr(CommandCls.size())).empty())
+ if (!Arguments.empty())
{
// Theoretically, in cmd "cls" and "cls blablabla" are the same things.
// But, if the user passed some parameters to cls it's quite probably
@@ -1219,14 +1211,13 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
}
// PUSHD путь | ..
- const auto CommandPushd = L"PUSHD"sv;
- if (IsCommand(CommandPushd, false))
+ if (equal_icase(Command, L"PUSHD"sv))
{
ConsoleActivatior(false);
const auto PushDir = m_CurDir;
- if (const auto NewDir = trim(CmdLine.substr(CommandPushd.size())); NewDir.empty() || IntChDir(NewDir, true))
+ if (const auto NewDir = trim_right(Arguments); NewDir.empty() || IntChDir(NewDir, true))
{
ppstack.push(PushDir);
os::env::set(L"FARDIRSTACK"sv, PushDir);
@@ -1237,7 +1228,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
// POPD
// TODO: добавить необязательный параметр - число, сколько уровней пропустить, после чего прыгнуть.
- if (IsCommand(L"POPD"sv, false))
+ if (equal_icase(Command, L"POPD"sv))
{
ConsoleActivatior(false);
@@ -1260,7 +1251,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
}
// CLRD
- if (IsCommand(L"CLRD"sv, false))
+ if (equal_icase(Command, L"CLRD"sv))
{
ConsoleActivatior(false);
@@ -1275,10 +1266,9 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
nnn Specifies a code page number (Dec or Hex).
Type CHCP without a parameter to display the active code page number.
*/
- const auto CommandChcp = L"CHCP"sv;
- if (IsCommand(CommandChcp, false))
+ if (equal_icase(Command, L"CHCP"sv))
{
- const auto ChcpParams = trim(CmdLine.substr(CommandChcp.size()));
+ const auto ChcpParams = trim_right(Arguments);
uintptr_t cp;
if (!from_string(ChcpParams, cp))
return false;
@@ -1300,12 +1290,9 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}
- const auto CommandCd = L"CD"sv;
- const auto CommandChdir = L"CHDIR"sv;
- const auto IsCommandCd = IsCommand(CommandCd, true);
- if (IsCommandCd || IsCommand(CommandChdir, true))
+ if (const auto IsCommandCd = equal_icase(CommandCursed, L"CD"sv); IsCommandCd || equal_icase(CommandCursed, L"CHDIR"sv))
{
- auto CdParams = trim(CmdLine.substr(IsCommandCd? CommandCd.size() : CommandChdir.size()));
+ auto CdParams = trim_right(ArgumentsCursed);
//проигнорируем /D
//мы и так всегда меняем диск а некоторые в алайсах или по привычке набирают этот ключ
@@ -1325,14 +1312,11 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}
- const auto CommandTitle = L"TITLE"sv;
- if (IsCommand(CommandTitle, false))
+ if (equal_icase(Command, L"TITLE"))
{
ConsoleActivatior(false);
- const auto Title = CmdLine.substr(CommandTitle.size());
-
- ConsoleTitle::SetUserTitle(Title.empty()? Title : Title.substr(1));
+ ConsoleTitle::SetUserTitle(Arguments);
if (!(Global->CtrlObject->Cp()->LeftPanel()->IsVisible() || Global->CtrlObject->Cp()->RightPanel()->IsVisible()))
{
@@ -1341,7 +1325,7 @@ bool CommandLine::ProcessOSCommands(string_view const CmdLine, function_ref<void
return true;
}
- if (IsCommand(L"EXIT"sv, false))
+ if (equal_icase(Command, L"EXIT"sv))
{
ConsoleActivatior(false);
Global->WindowManager->ExitMainLoop(FALSE);
[/more]