From 12e8bf689b3b462a81199f384907d638dde64ddd Mon Sep 17 00:00:00 2001 From: Shmuel Zeigerman Date: Sun, 8 Dec 2024 14:49:51 +0200 Subject: [PATCH] Refactoring --- far/src/cfg/config.hpp | 2 +- far/src/main.cpp | 71 +++++++++++------------- luafar/lua_share/far2/test/macrotest.lua | 10 ++-- 3 files changed, 39 insertions(+), 44 deletions(-) diff --git a/far/src/cfg/config.hpp b/far/src/cfg/config.hpp index 4e22e24ec..2b6939c0f 100644 --- a/far/src/cfg/config.hpp +++ b/far/src/cfg/config.hpp @@ -374,9 +374,9 @@ struct Options FARString strLeftFolder; FARString strRightFolder; - FARString strLeftCurFile; FARString strRightCurFile; + FARString strEditViewArg; int RightSelectedFirst; int LeftSelectedFirst; diff --git a/far/src/main.cpp b/far/src/main.cpp index a25e5bd73..aee71cdae 100644 --- a/far/src/main.cpp +++ b/far/src/main.cpp @@ -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, @@ -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()) // ???????????? @@ -222,7 +221,7 @@ static int MainProcess( } else { - FileViewer *ShellViewer=new FileViewer(strEditViewArg,FALSE); + FileViewer *ShellViewer=new FileViewer(Opt.strEditViewArg,FALSE); if (!ShellViewer->GetExitCode()) { @@ -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; @@ -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; // количество параметров-имен каталогов @@ -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; @@ -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; @@ -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++; } } @@ -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 @@ -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; } } diff --git a/luafar/lua_share/far2/test/macrotest.lua b/luafar/lua_share/far2/test/macrotest.lua index aef38fc9c..7bb3085ec 100644 --- a/luafar/lua_share/far2/test/macrotest.lua +++ b/luafar/lua_share/far2/test/macrotest.lua @@ -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 @@ -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