From c07f890cbf3d79dd4d4da5372cfc5f4db34a7c42 Mon Sep 17 00:00:00 2001 From: Shmuel Zeigerman Date: Sat, 11 Jan 2025 18:18:33 +0200 Subject: [PATCH] LuaFAR: refactoring --- .gitignore | 1 + far2m.cppcheck | 34 ++++++++++++++++++++++++++++++++++ luafar/src/exported.c | 16 ++++------------ luafar/src/lregex.c | 2 ++ luafar/src/luamacro.c | 2 +- luafar/src/service.c | 31 +------------------------------ 6 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 far2m.cppcheck diff --git a/.gitignore b/.gitignore index abecd9a84..f84d88524 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _build/ +far2m-cppcheck-build-dir/ .luacheckrc far/libluajit.a diff --git a/far2m.cppcheck b/far2m.cppcheck new file mode 100644 index 000000000..5d27d2009 --- /dev/null +++ b/far2m.cppcheck @@ -0,0 +1,34 @@ + + + far2m-cppcheck-build-dir + false + true + true + 2 + 100 + + + + + + + + + + + + + + + + + + + + + + + + + far2m + diff --git a/luafar/src/exported.c b/luafar/src/exported.c index 84f1f8b92..e02621931 100644 --- a/luafar/src/exported.c +++ b/luafar/src/exported.c @@ -121,14 +121,6 @@ void PushPluginPair(lua_State* L, HANDLE hPlugin) lua_pushlightuserdata(L, hPlugin); } -void DestroyCollector(lua_State* L, HANDLE hPlugin, const char* Collector) -{ - PushPluginTable(L, hPlugin); //+1: Tbl - lua_pushnil(L); //+2 - lua_setfield(L, -2, Collector); //+1 - lua_pop(L,1); //+0 -} - // the value is on stack top (-1) // collector table is under the index 'pos' (this index cannot be a pseudo-index) const wchar_t* _AddStringToCollector(lua_State *L, int pos) @@ -245,7 +237,7 @@ void FillPluginPanelItem (lua_State *L, struct PluginPanelItem *pi, int index) void FillFindData(lua_State* L, struct PluginPanelItem **pPanelItems, int *pItemsNumber) { struct PluginPanelItem *ppi; - int i, num=0; + int num = 0; int numLines = lua_objlen(L,-1); ppi = (struct PluginPanelItem*) malloc(sizeof(struct PluginPanelItem) * numLines); @@ -259,7 +251,7 @@ void FillFindData(lua_State* L, struct PluginPanelItem **pPanelItems, int *pItem lua_pushvalue(L,-2); //+6: Tbl,FindData,UData,Coll,ppi,Coll lua_rawset(L, -6); //+4: Tbl,FindData,UData,Coll - for (i=1; i<=numLines; i++) { + for (int i=1; i<=numLines; i++) { lua_rawgeti(L, -3, i); //+5: Tbl,FindData,UData,Coll,FindData[i] if (lua_istable(L,-1)) { FillPluginPanelItem(L, ppi+num, num+1); @@ -806,7 +798,7 @@ HANDLE LF_Open (lua_State* L, int OpenFrom, INT_PTR Item) case OPEN_FROMMACRO: { int top; - struct OpenMacroInfo* data = (struct OpenMacroInfo*)Item; + const struct OpenMacroInfo* data = (struct OpenMacroInfo*)Item; lua_pushinteger(L, 0); // dummy menuitem Id PackMacroValues(L, data->Count, data->Values); top = lua_gettop(L); @@ -1488,7 +1480,7 @@ int LF_GetLinkTarget( if (lua_type(L,-1) == LUA_TSTRING) { size_t size = 0; - wchar_t* ptr = utf8_to_wcstring(L,-1,&size); //+1 (conversion in place) + const wchar_t* ptr = utf8_to_wcstring(L,-1,&size); //+1 (conversion in place) if (Target && TargetSize) { wcsncpy(Target, ptr, TargetSize); diff --git a/luafar/src/lregex.c b/luafar/src/lregex.c index fbde19ae1..a112bf189 100644 --- a/luafar/src/lregex.c +++ b/luafar/src/lregex.c @@ -596,12 +596,14 @@ const luaL_Reg regex_functions[] = {"gsub", func_gsub}, {"match", func_match}, {"exec", func_exec}, + {"tfind", func_tfind}, {"findW", func_findW}, {"gmatchW", func_gmatchW}, {"gsubW", func_gsubW}, {"matchW", func_matchW}, {"execW", func_execW}, + {"tfindW", func_tfindW}, {NULL, NULL} }; diff --git a/luafar/src/luamacro.c b/luafar/src/luamacro.c index f2ba0c599..50697599b 100644 --- a/luafar/src/luamacro.c +++ b/luafar/src/luamacro.c @@ -227,7 +227,7 @@ int far_MacroCallToLua(lua_State *L) { if (lua_type(L,1) == LUA_TLIGHTUSERDATA) { - struct FarMacroCall* Data = (struct FarMacroCall*)lua_touserdata(L, 1); + const struct FarMacroCall* Data = (struct FarMacroCall*)lua_touserdata(L, 1); lua_settop(L, 0); if (Data && !FL_PushParams(L, Data)) { diff --git a/luafar/src/service.c b/luafar/src/service.c index c41e6b1f8..ea4fbaf47 100644 --- a/luafar/src/service.c +++ b/luafar/src/service.c @@ -2056,21 +2056,6 @@ void LF_Error(lua_State *L, const wchar_t* aMsg) lua_pop(L, 1); } -static int SplitToTable(lua_State *L, const wchar_t *Text, wchar_t Delim, int StartIndex) -{ - int count = StartIndex; - const wchar_t *p = Text; - do { - const wchar_t *q = wcschr(p, Delim); - if (q == NULL) q = wcschr(p, L'\0'); - lua_pushinteger(L, ++count); - lua_pushlstring(L, (const char*)p, (q-p)*sizeof(wchar_t)); - lua_rawset(L, -3); - p = *q ? q+1 : NULL; - } while(p); - return count - StartIndex; -} - // 1-st param: message text (if multiline, then lines must be separated by '\n') // 2-nd param: message title (if absent or nil, then "Message" is used) // 3-rd param: buttons (if multiple, then captions must be separated by ';'; @@ -3025,14 +3010,6 @@ LONG_PTR GetEnableFromLua (lua_State *L, int pos) return ret; } -static void SetColorForeAndBack(lua_State *L, const struct FarTrueColorForeAndBack *fb, const char *name) -{ - lua_createtable(L,0,2); - PutIntToTable(L, "ForegroundColor", FarTrueColorToRGB(&fb->Fore)); - PutIntToTable(L, "BackgroundColor", FarTrueColorToRGB(&fb->Back)); - lua_setfield(L, -2, name); -} - DWORD GetColorFromTable(lua_State *L, const char *field, int index) { DWORD val; @@ -3057,13 +3034,6 @@ static void FillColor(lua_State *L, struct FarTrueColorForeAndBack *fb) } } -static void FillColorForeAndBack(lua_State *L, struct FarTrueColorForeAndBack *fb, const char *Name) -{ - lua_getfield(L, -1, Name); - FillColor(L, fb); - lua_pop(L,1); -} - static void FillDialogColors(lua_State *L, struct ColorDialogData *Data) { uint64_t Fore = GetColorFromTable (L, "ForegroundColor", 1) & 0xFFFFFF; @@ -5895,6 +5865,7 @@ static const luaL_Reg dialog_methods[] = PAIR( dlg, GetConstTextPtr), PAIR( dlg, GetCursorPos), PAIR( dlg, GetCursorSize), + PAIR( dlg, GetDefaultColor), PAIR( dlg, GetDialogInfo), PAIR( dlg, GetDlgData), PAIR( dlg, GetDlgItem),