Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Dec 8, 2024
1 parent 953766b commit 12e8bf6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion far/src/cfg/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ struct Options

FARString strLeftFolder;
FARString strRightFolder;

FARString strLeftCurFile;
FARString strRightCurFile;
FARString strEditViewArg;

int RightSelectedFirst;
int LeftSelectedFirst;
Expand Down
71 changes: 32 additions & 39 deletions far/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ static void UpdatePathOptions(const FARString &strDestName, bool IsActivePanel)


static int MainProcess(
FARString strEditViewArg,
const FARString &strDestName1,
const FARString &strDestName2,
int StartLine,
Expand All @@ -206,13 +205,13 @@ static int MainProcess(
if (Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR_ON_CMDOUT
|| Opt.OnlyEditorViewerUsed == Options::ONLY_VIEWER_ON_CMDOUT)
{
strEditViewArg = ExecuteCommandAndGrabItsOutput(strEditViewArg);
Opt.strEditViewArg = ExecuteCommandAndGrabItsOutput(Opt.strEditViewArg);
}

if (Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR
|| Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR_ON_CMDOUT)
{
FileEditor *ShellEditor=new FileEditor(strEditViewArg,CP_AUTODETECT,FFILEEDIT_CANNEWFILE|FFILEEDIT_ENABLEF6,StartLine,StartChar);
FileEditor *ShellEditor=new FileEditor(Opt.strEditViewArg,CP_AUTODETECT,FFILEEDIT_CANNEWFILE|FFILEEDIT_ENABLEF6,StartLine,StartChar);
_tran(SysLog(L"make shelleditor %p",ShellEditor));

if (!ShellEditor->GetExitCode()) // ????????????
Expand All @@ -222,7 +221,7 @@ static int MainProcess(
}
else
{
FileViewer *ShellViewer=new FileViewer(strEditViewArg,FALSE);
FileViewer *ShellViewer=new FileViewer(Opt.strEditViewArg,FALSE);

if (!ShellViewer->GetExitCode())
{
Expand All @@ -238,7 +237,7 @@ static int MainProcess(
if (Opt.OnlyEditorViewerUsed == Options::ONLY_VIEWER_ON_CMDOUT
|| Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR_ON_CMDOUT)
{
unlink(strEditViewArg.GetMB().c_str());
unlink(Opt.strEditViewArg.GetMB().c_str());
}

CtrlObj.Cp()->LeftPanel = CtrlObj.Cp()->RightPanel = CtrlObj.Cp()->ActivePanel = nullptr;
Expand Down Expand Up @@ -352,8 +351,6 @@ int FarAppMain(int argc, char **argv)
Opt.IsUserAdmin = (geteuid()==0);

_OT(SysLog(L"[[[[[[[[New Session of FAR]]]]]]]]]"));
Opt.OnlyEditorViewerUsed = Options::NOT_ONLY_EDITOR_VIEWER;
FARString strEditViewArg;
FARString DestNames[2];
int StartLine=-1,StartChar=-1;
int CntDestName=0; // количество параметров-имен каталогов
Expand Down Expand Up @@ -387,15 +384,6 @@ int FarAppMain(int argc, char **argv)
unsetenv("FARADMINMODE");
}

// run by symlink in editor mode
auto name = strrchr(argv[0], GOOD_SLASH);
if (strcmp((name ? name+1 : argv[0]), "far2medit") == 0) {
Opt.OnlyEditorViewerUsed = Options::ONLY_EDITOR;
if (argc > 1) {
strEditViewArg = argv[argc - 1]; // use last argument
}
}

// макросы не дисаблим
Opt.Macro.DisableMacro=0;
bool bCustomPlugins = false;
Expand Down Expand Up @@ -457,19 +445,19 @@ int FarAppMain(int argc, char **argv)
if (strcmp(argv[I+1], "-") == 0)
{
Opt.OnlyEditorViewerUsed = Options::ONLY_EDITOR_ON_CMDOUT;
strEditViewArg = ReconstructCommandLine(argc - I - 2, &argv[I+2]);
Opt.strEditViewArg = ReconstructCommandLine(argc - I - 2, &argv[I+2]);
I = argc;
}
else
{
Opt.OnlyEditorViewerUsed = Options::ONLY_EDITOR;
strEditViewArg = argv[I+1];
Opt.strEditViewArg = argv[I+1];
I++;
}
}
else { // -e without filename => new file to editor
Opt.OnlyEditorViewerUsed = Options::ONLY_EDITOR;
strEditViewArg.Clear();
Opt.strEditViewArg.Clear();
}
break;

Expand All @@ -485,13 +473,13 @@ int FarAppMain(int argc, char **argv)
if (strcmp(argv[I+1], "-") == 0)
{
Opt.OnlyEditorViewerUsed = Options::ONLY_VIEWER_ON_CMDOUT;
strEditViewArg = ReconstructCommandLine(argc - I - 2, &argv[I+2]);
Opt.strEditViewArg = ReconstructCommandLine(argc - I - 2, &argv[I+2]);
I = argc;
}
else
{
Opt.OnlyEditorViewerUsed = Options::ONLY_VIEWER;
strEditViewArg = argv[I+1];
Opt.strEditViewArg = argv[I+1];
I++;
}
}
Expand Down Expand Up @@ -629,10 +617,10 @@ int FarAppMain(int argc, char **argv)

// (!!!) temporary STUB because now Editor can not input filename "", see: fileedit.cpp -> FileEditor::Init()
// default Editor file name for new empty file
if ( Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR && strEditViewArg.IsEmpty() )
strEditViewArg = Msg::NewFileName;
if ( Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR && Opt.strEditViewArg.IsEmpty() )
Opt.strEditViewArg = Msg::NewFileName;

int Result = MainProcess(strEditViewArg,DestNames[0],DestNames[1],StartLine,StartChar);
int Result = MainProcess(DestNames[0],DestNames[1],StartLine,StartChar);

EmptyInternalClipboard();
VTShell_Shutdown();//ensure VTShell deinitialized before statics destructors called
Expand Down Expand Up @@ -719,25 +707,30 @@ static void SetCustomSettings(const char *arg)

int _cdecl main(int argc, char *argv[])
{
char *name = strrchr(argv[0], GOOD_SLASH);
if (name) ++name; else name = argv[0];
Opt.OnlyEditorViewerUsed = Options::NOT_ONLY_EDITOR_VIEWER;
if (argc > 0) {
if (strcmp(name, "far2m_askpass")==0)
const char *name = strrchr(argv[0], GOOD_SLASH);
name = name ? name+1 : argv[0];

if (strcmp(name, "far2medit") == 0) { // run by symlink in editor mode
Opt.OnlyEditorViewerUsed = Options::ONLY_EDITOR;
if (argc > 1)
Opt.strEditViewArg = argv[argc - 1]; // use last argument
}
else if (strcmp(name, "far2m_askpass") == 0)
return sudo_main_askpass();
if (strcmp(name, "far2m_sudoapp")==0)
else if (strcmp(name, "far2m_sudoapp") == 0)
return sudo_main_dispatcher(argc - 1, argv + 1);
if (argc >= 5) {
if (strcmp(argv[1], "--libexec") == 0) {
return libexec(argv[2], argv[3], argv[4], argc - 5, argv + 5);
else if (argc > 1) {
if ((strcasecmp(argv[1], "--help") == 0
|| strcasecmp(argv[1], "-h") == 0
|| strcasecmp(argv[1], "-?") == 0)) {
print_help(name);
return 0;
}
else if (strcmp(argv[1], "--libexec") == 0) {
return (argc >= 5) ? libexec(argv[2], argv[3], argv[4], argc - 5, argv + 5) : 0;
}
}
if (argc > 1 &&
(strcasecmp(argv[1], "--help") == 0
|| strcasecmp(argv[1], "-h") == 0
|| strcmp(argv[1], "-?") == 0)) {

print_help(name);
return 0;
}
}

Expand Down
10 changes: 6 additions & 4 deletions luafar/lua_share/far2/test/macrotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,11 @@ local function test_mf_usermenu()
end

local function test_mf_EnumScripts()
local f = assert_func(mf.EnumScripts("Macro"))
local s,i = f()
--assert_table(s) -- in GitHub test there are no macros loaded
local iter = assert_func(mf.EnumScripts("Macro"))
local Id = assert_udata(far.MacroAdd(nil,nil,"foo","return")) -- assure at least 1 macro loaded
local s,i = iter()
far.MacroDelete(Id)
assert_table(s)
assert_num(i)
end

Expand Down Expand Up @@ -2182,7 +2184,7 @@ local function test_win_Clock()
local temp = win.Clock()
win.Sleep(500)
temp = (win.Clock() - temp)
assert(temp > 0.480 and temp < 1.000, temp)
assert(temp > 0.480 and temp < 2.000, temp)
-- check granularity
local OK = false
temp = math.floor(win.Clock()*1e6) % 10
Expand Down

0 comments on commit 12e8bf6

Please sign in to comment.