Skip to content

Commit

Permalink
Рефакторинг.
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jan 11, 2015
1 parent 47fcd95 commit b6e7c8c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 147 deletions.
6 changes: 5 additions & 1 deletion far/changelog
@@ -1,4 +1,8 @@
drkns 09.01.2015 19:25:37 +0200 - build 4237
shmuel 11.01.2015 20:00:05 +0200 - build 4238

1. Рефакторинг.

drkns 09.01.2015 19:25:37 +0200 - build 4237

1. 0002849: ProcessSynchroEventW вызывается при DMODE_NOPLUGINS.

Expand Down
132 changes: 25 additions & 107 deletions far/macro.cpp
Expand Up @@ -388,18 +388,6 @@ static bool ToDouble(__int64 v, double *d)
return false;
}

struct MacroRecord
{
MACROFLAGS_MFLAGS Flags; // Ôëàãè ìàêðîïîñëåäîâàòåëüíîñòè
int Key; // Íàçíà÷åííàÿ êëàâèøà
};

static void InitMacroRecord(MacroRecord* macro, const MacroPluginReturn& Ret)
{
macro->Flags = (MACROFLAGS_MFLAGS)Ret.Values[0].Double;
macro->Key = (int)Ret.Values[1].Double;
}

inline const wchar_t* GetMacroLanguage(FARKEYMACROFLAGS Flags)
{
switch(Flags & KMFLAGS_LANGMASK)
Expand Down Expand Up @@ -483,63 +471,35 @@ bool KeyMacro::IsHistoryDisable(int TypeHistory)
return MacroPluginOp(6.0,(double)TypeHistory,&Ret) ? !!Ret.ReturnType : false;
}

static bool GetCurMacro(MacroRecord* macro)
{
MacroPluginReturn Ret;
if (MacroPluginOp(7.0,false,&Ret) && Ret.ReturnType==MPRT_NORMALFINISH)
{
InitMacroRecord(macro, Ret);
return true;
}
return false;
}

static bool GetTopMacro(MacroRecord* macro)
static bool IsTopMacroOutputDisabled()
{
MacroPluginReturn Ret;
if (MacroPluginOp(8.0,false,&Ret) && Ret.ReturnType==MPRT_NORMALFINISH)
{
InitMacroRecord(macro, Ret);
return true;
}
return false;
return MacroPluginOp(7.0,false,&Ret) ? !!Ret.ReturnType : false;
}

static inline bool IsMacroQueueEmpty()
{
MacroPluginReturn Ret;
return !MacroPluginOp(9.0,false,&Ret) || Ret.ReturnType==1;
return !MacroPluginOp(8.0,false,&Ret) || Ret.ReturnType==1;
}

static inline size_t GetStateStackSize()
{
MacroPluginReturn Ret;
return MacroPluginOp(10.0,false,&Ret) ? Ret.ReturnType : 0;
}

static inline DWORD GetIntKey()
{
MacroPluginReturn Ret;
return MacroPluginOp(11.0,false,&Ret) ? Ret.ReturnType : 0;
}

static inline DWORD GetTopIntKey()
{
MacroPluginReturn Ret;
return MacroPluginOp(13.0,false,&Ret) ? Ret.ReturnType : 0;
return MacroPluginOp(9.0,false,&Ret) ? Ret.ReturnType : 0;
}

static void SetMacroValue(const FarMacroValue& Value)
{
FarMacroValue values[2]={14.0,Value};
FarMacroValue values[2]={11.0,Value};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};
CallMacroPluginSimple(&info);
}

static bool TryToPostMacro(FARMACROAREA Mode,const string& TextKey,DWORD IntKey)
{
FarMacroValue values[] = {16.0,(double)Mode,TextKey.data(),(double)IntKey};
FarMacroValue values[] = {13.0,(double)Mode,TextKey.data(),(double)IntKey};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};
return CallMacroPluginSimple(&info);
Expand Down Expand Up @@ -609,7 +569,7 @@ int KeyMacro::GetCurRecord() const

static bool GetInputFromMacro(MacroPluginReturn *mpr)
{
FarMacroValue values[]={15.0};
FarMacroValue values[]={12.0};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};

Expand Down Expand Up @@ -938,29 +898,15 @@ int KeyMacro::GetKey()

case MPRT_KEYS:
{
const wchar_t* key = mpr.Values[0].String;

if (!StrCmpI(key, L"AKey"))
switch ((int)mpr.Values[0].Double)
{
DWORD aKey=KEY_NONE;
MacroRecord macro = {};
GetCurMacro(&macro);

if (!(macro.Flags&MFLAGS_POSTFROMPLUGIN))
aKey=GetIntKey();
else
aKey=macro.Key;
return aKey;
case 1:
return KEY_OP_SELWORD;
case 2:
return KEY_OP_XLAT;
default:
return (int)mpr.Values[1].Double;
}

if (!StrCmpI(key, L"SelWord"))
return KEY_OP_SELWORD;

if (!StrCmpI(key, L"XLat"))
return KEY_OP_XLAT;

int iKey = KeyNameToKey(key);
return iKey==-1 ? KEY_NONE:iKey;
}

case MPRT_PRINT:
Expand Down Expand Up @@ -1131,7 +1077,7 @@ bool KeyMacro::PostNewMacro(const wchar_t* Sequence,FARKEYMACROFLAGS InputFlags,
if (InputFlags & KMFLAGS_ENABLEOUTPUT) Flags |= MFLAGS_ENABLEOUTPUT;
if (InputFlags & KMFLAGS_NOSENDKEYSTOPLUGINS) Flags |= MFLAGS_NOSENDKEYSTOPLUGINS;

FarMacroValue values[]={12.0,Lang,Sequence,(double)Flags,(double)AKey};
FarMacroValue values[]={10.0,Lang,Sequence,(double)Flags,(double)AKey};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};
return CallMacroPluginSimple(&info);
Expand Down Expand Up @@ -2328,8 +2274,7 @@ intptr_t KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)
case MCODE_F_EDITOR_INSSTR: return editorinsstrFunc(Data);
case MCODE_F_EDITOR_POS:
{
MacroRecord TopMacro;
LockOutput Lock(GetTopMacro(&TopMacro) && !(TopMacro.Flags&MFLAGS_ENABLEOUTPUT));
LockOutput Lock(IsTopMacroOutputDisabled());
return editorposFunc(Data);
}
case MCODE_F_EDITOR_SEL: return editorselFunc(Data);
Expand Down Expand Up @@ -2382,8 +2327,7 @@ intptr_t KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)
case MCODE_F_UCASE: return ucaseFunc(Data);
case MCODE_F_WAITKEY:
{
MacroRecord TopMacro;
LockOutput Lock(GetTopMacro(&TopMacro) && !(TopMacro.Flags&MFLAGS_ENABLEOUTPUT));
LockOutput Lock(IsTopMacroOutputDisabled());

++m_WaitKey;
bool result=waitkeyFunc(Data);
Expand Down Expand Up @@ -2457,6 +2401,14 @@ intptr_t KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)
case 7: PassBoolean(Clipboard::GetUseInternalClipboardState(), Data); break;
case 8: if (Data->Count > 1) Clipboard::SetUseInternalClipboardState(Data->Values[1].Boolean != 0); break;
case 9: if (Data->Count > 1) PassNumber(KeyNameToKey(Data->Values[1].String), Data); break;
case 10:
if (Data->Count > 1)
{
string text;
KeyToText(Data->Values[1].Double, text);
PassString(text, Data);
}
break;
}
}
break;
Expand Down Expand Up @@ -2631,40 +2583,6 @@ intptr_t KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)
PassValue(&tmpVar,Data);
return success;
}

case MCODE_F_AKEY: // V=akey(Mode[,Type])
{
auto Params = parseParams<2>(Data);
int tmpType=(int)Params[1].asInteger();
int tmpMode=(int)Params[0].asInteger();

MacroRecord TopMacro;
if (!GetTopMacro(&TopMacro))
{
PassBoolean(0,Data);
return 1;
}

DWORD aKey=TopMacro.Key;

if (!tmpType)
{
if (!(TopMacro.Flags&MFLAGS_POSTFROMPLUGIN))
aKey=GetTopIntKey();
else if (!aKey)
aKey=KEY_NONE;
}

if (!tmpMode)
return aKey;
else
{
string value;
KeyToText(aKey,value);
PassString(value,Data);
return 1;
}
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4237)m4_dnl
m4_define(BUILD,4238)m4_dnl
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 468 },
Version = { 1, 0, 0, 469 },
MinFarVersion = { 3, 0, 0, 4214 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
4 changes: 2 additions & 2 deletions plugins/luamacro/api.lua
Expand Up @@ -25,7 +25,7 @@ end
-- "mf" ("macrofunctions") namespace
mf = {
abs = function(...) return MacroCallFar(0x80C01, ...) end,
akey = function(...) return MacroCallFar(0x80C02, ...) end,
--akey = function(...) return MacroCallFar(0x80C02, ...) end,
asc = function(...) return MacroCallFar(0x80C03, ...) end,
atoi = function(...) return MacroCallFar(0x80C04, ...) end,
beep = function(...) return MacroCallFar(0x80C48, ...) end,
Expand Down Expand Up @@ -537,7 +537,7 @@ end
_G.band, _G.bnot, _G.bor, _G.bxor, _G.lshift, _G.rshift =
bit64.band, bit64.bnot, bit64.bor, bit64.bxor, bit64.lshift, bit64.rshift

_G.akey, _G.eval, _G.msgbox, _G.prompt = mf.akey, mf.eval, mf.msgbox, mf.prompt
_G.eval, _G.msgbox, _G.prompt = mf.eval, mf.msgbox, mf.prompt

mf.Keys, mf.exit, mf.print, mf.printf = _G.Keys, _G.exit, _G.print, _G.printf
--------------------------------------------------------------------------------
6 changes: 5 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,8 @@
shmuel 07.01.2015 10:26:06 +0200 - build 468
shmuel 11.01.2015 19:58:26 +0200 - build 469

1. Рефакторинг.

shmuel 07.01.2015 10:26:06 +0200 - build 468

1. LuaFAR: добавлена функция win.OutputDebugString.

Expand Down
71 changes: 49 additions & 22 deletions plugins/luamacro/keymacro.lua
Expand Up @@ -20,6 +20,8 @@ local MACROSTATE_NOMACRO, MACROSTATE_EXECUTING, MACROSTATE_EXECUTING_COMMON =
local MFLAGS_ENABLEOUTPUT, MFLAGS_NOSENDKEYSTOPLUGINS, MFLAGS_POSTFROMPLUGIN =
0x1, 0x2, 0x10000000

local KEY_NONE = 0x30001

local type, setmetatable = type, setmetatable
local bit = bit or bit64
local band, bor, bxor, lshift = bit.band, bit.bor, bit.bxor, bit.lshift
Expand All @@ -40,6 +42,7 @@ local Import = {
GetUseInternalClipboard = function() return far_MacroCallFar(MCODE_F_KEYMACRO, 7) end,
SetUseInternalClipboard = function(v) return far_MacroCallFar(MCODE_F_KEYMACRO, 8, v) end,
KeyNameToKey = function(v) return far_MacroCallFar(MCODE_F_KEYMACRO, 9, v) end,
KeyToText = function(v) return far_MacroCallFar(MCODE_F_KEYMACRO, 10, v) end,
}
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -334,22 +337,55 @@ function KeyMacro.DisableHistory (Mask)
return oldHistoryDisable
end

function KeyMacro.akey (Mode, Type)
local TopMacro = GetTopMacro()
if TopMacro then
Mode = tonumber(Mode) or 0
Type = tonumber(Type) or 0

local aKey = TopMacro.m_key
if Type == 0 then
if 0 == band(TopMacro:GetFlags(),MFLAGS_POSTFROMPLUGIN) then
aKey = StateStack:top().IntKey
elseif aKey == 0 then
aKey = KEY_NONE
end
end

return Mode == 0 and aKey or Import.KeyToText(aKey)
end
return false
end

function KeyMacro.TransformKey (key)
local lkey = key:lower()
if lkey == "selword" then
return 1
elseif lkey == "xlat" then
return 2
elseif lkey == "akey" then
local macro = GetCurMacro()
if not macro then return nil end
return 3, (0==band(macro:GetFlags(),MFLAGS_POSTFROMPLUGIN)) and CurState.IntKey or macro.m_key
else
local iKey = Import.KeyNameToKey(key)
return 3, iKey==-1 and KEY_NONE or iKey
end
end

local OP_PUSHSTATE = 1
local OP_POPSTATE = 2
local OP_ISEXECUTING = 3
local OP_ISDISABLEOUTPUT = 4
local OP_HISTORYDISABLEMASK = 5
local OP_ISHISTORYDISABLE = 6
local OP_GETCURMACRO = 7
local OP_GETTOPMACRO = 8
local OP_ISMACROQUEUEEMPTY = 9
local OP_GETSTATESTACKSIZE = 10
local OP_GETINTKEY = 11
local OP_POSTNEWMACRO = 12
local OP_GETTOPINTKEY = 13
local OP_SETMACROVALUE = 14
local OP_GETINPUTFROMMACRO = 15
local OP_TRYTOPOSTMACRO = 16
local OP_ISTOPMACROOUTPUTDISABLED = 7
local OP_ISMACROQUEUEEMPTY = 8
local OP_GETSTATESTACKSIZE = 9
local OP_POSTNEWMACRO = 10
local OP_SETMACROVALUE = 11
local OP_GETINPUTFROMMACRO = 12
local OP_TRYTOPOSTMACRO = 13

function KeyMacro.Dispatch (opcode, ...)
local p1 = (...)
Expand All @@ -369,19 +405,13 @@ function KeyMacro.Dispatch (opcode, ...)
return OldMask
elseif opcode == OP_ISHISTORYDISABLE then
return IsHistoryDisable(p1)
elseif opcode == OP_GETCURMACRO or opcode==OP_GETTOPMACRO then
local mr
if opcode==OP_GETCURMACRO then mr=GetCurMacro() else mr=GetTopMacro() end
if mr then
LastMessage = pack(mr:GetFlags(), mr.m_key)
return MPRT_NORMALFINISH, LastMessage
end
elseif opcode==OP_ISTOPMACROOUTPUTDISABLED then
local mr = GetTopMacro()
return mr and 0==band(mr:GetFlags(),MFLAGS_ENABLEOUTPUT) and 1 or 0
elseif opcode == OP_ISMACROQUEUEEMPTY then
return GetCurMacro() and 0 or 1
elseif opcode == OP_GETSTATESTACKSIZE then
return #StateStack
elseif opcode == OP_GETINTKEY then
return CurState.IntKey
elseif opcode == OP_POSTNEWMACRO then
local Lang,Code,Flags,AKey = ...
local f1,f2 = loadmacro(Lang,Code)
Expand All @@ -391,9 +421,6 @@ function KeyMacro.Dispatch (opcode, ...)
else
ErrMsg(f2, Msg.MMacroParseErrorTitle)
end
elseif opcode == OP_GETTOPINTKEY then
local t=StateStack:top()
return t and t.IntKey or 0
elseif opcode == OP_SETMACROVALUE then
local m = GetCurMacro()
if m then m:SetValue(p1) end
Expand Down

0 comments on commit b6e7c8c

Please sign in to comment.