Skip to content
Permalink
Browse files

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

  • Loading branch information...
shmuz committed Jan 21, 2015
1 parent 042acf1 commit c358404690ea4e115fcbf5a1e8d9c337fd701fad
@@ -1,4 +1,8 @@
zg 20.01.2015 23:11:38 +0200 - build 4250
shmuel 21.01.2015 16:51:57 +0200 - build 4251

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

zg 20.01.2015 23:11:38 +0200 - build 4250

1. уточнение 4248 для нередактируемых контролов.

@@ -161,7 +161,7 @@ void print_opcodes()
fprintf(fp, "MCODE_F_HISTORY_DISABLE=0x%X // N=History.Disable([State])\n", MCODE_F_HISTORY_DISABLE);
fprintf(fp, "MCODE_F_FMATCH=0x%X // N=FMatch(S,Mask)\n", MCODE_F_FMATCH);
fprintf(fp, "MCODE_F_PLUGIN_MENU=0x%X // N=Plugin.Menu(Guid[,MenuGuid])\n", MCODE_F_PLUGIN_MENU);
fprintf(fp, "MCODE_F_PLUGIN_CONFIG=0x%X // N=Plugin.Config(Guid[,MenuGuid])\n", MCODE_F_PLUGIN_CONFIG);
fprintf(fp, "MCODE_F_PLUGIN_CALL=0x%X // N=Plugin.Config(Guid[,MenuGuid])\n", MCODE_F_PLUGIN_CALL);
fprintf(fp, "MCODE_F_PLUGIN_SYNCCALL=0x%X // N=Plugin.Call(Guid[,Item])\n", MCODE_F_PLUGIN_SYNCCALL);
fprintf(fp, "MCODE_F_PLUGIN_LOAD=0x%X // N=Plugin.Load(DllPath[,ForceLoad])\n", MCODE_F_PLUGIN_LOAD);
fprintf(fp, "MCODE_F_PLUGIN_COMMAND=0x%X // N=Plugin.Command(Guid[,Command])\n", MCODE_F_PLUGIN_COMMAND);
@@ -380,7 +380,7 @@ struct DlgParam

static bool ToDouble(__int64 v, double *d)
{
if ((v >= 0 && v <= 0x1FFFFFFFFFFFFFLL) || (v < 0 && -v <= 0x1FFFFFFFFFFFFFLL))
if ((v >= 0 && v <= 0x1FFFFFFFFFFFFFLL) || (v < 0 && v >= -0x1FFFFFFFFFFFFFLL))
{
*d = (double)v;
return true;
@@ -431,75 +431,59 @@ template<class T> bool MacroPluginOp(double OpCode, T Param, MacroPluginReturn*
return false;
}

static inline void PushState(bool withClip)
{
MacroPluginOp(1.0, withClip);
}

static inline void PopState(bool withClip)
{
MacroPluginOp(2.0, withClip);
}

int KeyMacro::IsExecuting()
{
MacroPluginReturn Ret;
return MacroPluginOp(3.0,false,&Ret) ? Ret.ReturnType : MACROSTATE_NOMACRO;
return MacroPluginOp(1.0,false,&Ret) ? Ret.ReturnType : MACROSTATE_NOMACRO;
}

int KeyMacro::IsDisableOutput()
{
MacroPluginReturn Ret;
return MacroPluginOp(4.0,false,&Ret) ? Ret.ReturnType : 0;
return MacroPluginOp(2.0,false,&Ret) ? Ret.ReturnType : 0;
}

static inline DWORD SetHistoryDisableMask(DWORD Mask)
{
MacroPluginReturn Ret;
return MacroPluginOp(5.0,(double)Mask,&Ret) ? Ret.ReturnType : 0;
return MacroPluginOp(3.0,(double)Mask,&Ret) ? Ret.ReturnType : 0;
}

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

bool KeyMacro::IsHistoryDisable(int TypeHistory)
{
MacroPluginReturn Ret;
return MacroPluginOp(6.0,(double)TypeHistory,&Ret) ? !!Ret.ReturnType : false;
return MacroPluginOp(4.0,(double)TypeHistory,&Ret) ? !!Ret.ReturnType : false;
}

static bool IsTopMacroOutputDisabled()
{
MacroPluginReturn Ret;
return MacroPluginOp(7.0,false,&Ret) ? !!Ret.ReturnType : false;
return MacroPluginOp(5.0,false,&Ret) ? !!Ret.ReturnType : false;
}

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

static inline size_t GetStateStackSize()
{
MacroPluginReturn Ret;
return MacroPluginOp(9.0,false,&Ret) ? Ret.ReturnType : 0;
return !MacroPluginOp(6.0,false,&Ret) || Ret.ReturnType==1;
}

static void SetMacroValue(const FarMacroValue& Value)
{
FarMacroValue values[2]={11.0,Value};
FarMacroValue values[2]={8.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[] = {13.0,(double)Mode,TextKey.data(),(double)IntKey};
FarMacroValue values[] = {10.0,(double)Mode,TextKey.data(),(double)IntKey};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};
return CallMacroPluginSimple(&info);
@@ -569,7 +553,7 @@ int KeyMacro::GetCurRecord() const

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

@@ -758,7 +742,6 @@ int KeyMacro::ProcessEvent(const FAR_INPUT_RECORD *Rec)
LM_ProcessRecordedMacro(m_StartMode,strKey,m_RecCode,Flags,m_RecDescription);
}

//{FILE* log=fopen("c:\\plugins.log","at"); if(log) {fprintf(log,"%ls\n",m_RecCode.data()); fclose(log);}}
m_Recording=MACROSTATE_NOMACRO;
m_RecCode.clear();
m_RecDescription.clear();
@@ -772,7 +755,6 @@ int KeyMacro::ProcessEvent(const FAR_INPUT_RECORD *Rec)
}
else
{
//{FILE* log=fopen("c:\\plugins.log","at"); if(log) {fprintf(log,"key: %08x\n",Rec->IntKey); fclose(log);}}
if (!Global->IsProcessAssignMacroKey)
{
if (!m_RecCode.empty()) m_RecCode+=L" ";
@@ -796,61 +778,6 @@ static void ShowUserMenu(size_t Count, const FarMacroValue *Values)
UserMenu uMenu(string(Values[0].String));
}

void KeyMacro::CallPlugin(MacroPluginReturn *Params, FarMacroValue *Result, bool CallPluginRules)
{
*Result = false;
if(Params->Count>0 && Params->Values[0].Type==FMVT_STRING)
{
const wchar_t* SysID = Params->Values[0].String;
GUID guid;

if (StrToGuid(SysID,guid) && Global->CtrlObject->Plugins->FindPlugin(guid))
{
FarMacroValue *Values = Params->Count>1 ? Params->Values+1:nullptr;
OpenMacroInfo info={sizeof(OpenMacroInfo),Params->Count-1,Values};
size_t EntryStackSize = GetStateStackSize();

if (CallPluginRules)
{
*Result = true;
SetMacroValue(true);
PushState(true);
}
else
m_InternalInput++;

int lockCount = Global->ScrBuf->GetLockCount();
Global->ScrBuf->SetLockCount(0);

void* ResultCallPlugin = nullptr;
if (!Global->CtrlObject->Plugins->CallPlugin(guid,OPEN_FROMMACRO,&info,&ResultCallPlugin))
ResultCallPlugin = nullptr;

Global->ScrBuf->SetLockCount(lockCount);

bool isSynchroCall=true;
if (CallPluginRules)
{
if (GetStateStackSize() > EntryStackSize) // ýòà ïðîâåðêà íóæíà, ò.ê. PopState() ìîã óæå áûòü âûçâàí.
PopState(true);
else
isSynchroCall=false;
}
else
m_InternalInput--;

if (isSynchroCall)
{
//â windows ãàðàíòèðóåòñÿ, ÷òî íå áûâàåò óêàçàòåëåé ìåíüøå 0x10000
if (reinterpret_cast<uintptr_t>(ResultCallPlugin) >= 0x10000 && ResultCallPlugin != INVALID_HANDLE_VALUE)
*Result = ResultCallPlugin;
else
*Result = (ResultCallPlugin != nullptr);
}
}
}
}

int KeyMacro::GetKey()
{
if (m_InternalInput || !Global->WindowManager->GetCurrentWindow())
@@ -901,14 +828,6 @@ int KeyMacro::GetKey()
return KEY_OP_PLAINTEXT;
}

case MPRT_PLUGINCALL: // V=Plugin.Call(Guid[,param])
{
FarMacroValue fmvalue;
CallPlugin(&mpr, &fmvalue, true);
SetMacroValue(fmvalue);
break;
}

case MPRT_PLUGINMENU: // N=Plugin.Menu(Guid[,MenuGuid])
case MPRT_PLUGINCONFIG: // N=Plugin.Config(Guid[,MenuGuid])
case MPRT_PLUGINCOMMAND: // N=Plugin.Command(Guid[,Command])
@@ -1063,7 +982,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[]={10.0,Lang,Sequence,(double)Flags,(double)AKey};
FarMacroValue values[]={7.0,Lang,Sequence,(double)Flags,(double)AKey};
FarMacroCall fmc={sizeof(FarMacroCall),ARRAYSIZE(values),values,nullptr,nullptr};
OpenMacroPluginInfo info={MCT_KEYMACRO,&fmc};
return CallMacroPluginSimple(&info);
@@ -2321,18 +2240,41 @@ intptr_t KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)

return result;
}
case MCODE_F_PLUGIN_SYNCCALL:
{
MacroPluginReturn mpr = {0,Data->Count,Data->Values};
FarMacroValue Result;
CallPlugin(&mpr, &Result, false);
if (Result.Type == FMVT_POINTER)
Data->Callback(Data->CallbackData, &Result, 1);
else
PassBoolean(Result.Boolean, Data);
case MCODE_F_PLUGIN_CALL:
if(Data->Count>=2 && Data->Values[0].Type==FMVT_BOOLEAN && Data->Values[1].Type==FMVT_STRING)
{
bool SyncCall = (Data->Values[0].Boolean == 0);
const wchar_t* SysID = Data->Values[1].String;
GUID guid;

if (StrToGuid(SysID,guid) && Global->CtrlObject->Plugins->FindPlugin(guid))
{
FarMacroValue *Values = Data->Count>2 ? Data->Values+2:nullptr;
OpenMacroInfo info={sizeof(OpenMacroInfo),Data->Count-2,Values};
void *ResultCallPlugin = nullptr;

if (SyncCall) m_InternalInput++;

if (!Global->CtrlObject->Plugins->CallPlugin(guid,OPEN_FROMMACRO,&info,&ResultCallPlugin))
ResultCallPlugin = nullptr;

if (SyncCall) m_InternalInput--;

//â windows ãàðàíòèðóåòñÿ, ÷òî íå áûâàåò óêàçàòåëåé ìåíüøå 0x10000
if (reinterpret_cast<uintptr_t>(ResultCallPlugin) >= 0x10000 && ResultCallPlugin != INVALID_HANDLE_VALUE)
{
FarMacroValue Result(ResultCallPlugin);
Data->Callback(Data->CallbackData, &Result, 1);
}
else
PassBoolean(ResultCallPlugin != nullptr, Data);

return 0;
}
}
PassBoolean(false, Data);
return 0;
}

case MCODE_F_WINDOW_SCROLL: return windowscrollFunc(Data);
case MCODE_F_XLAT: return xlatFunc(Data);
case MCODE_F_PROMPT: return promptFunc(Data);
@@ -100,7 +100,6 @@ class KeyMacro: noncopyable
private:
intptr_t AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2);
int AssignMacroKey(DWORD& MacroKey,UINT64& Flags);
void CallPlugin(MacroPluginReturn *Params, FarMacroValue *Result, bool CallPluginRules);
int GetMacroSettings(int Key,UINT64 &Flags,const wchar_t *Src=nullptr,const wchar_t *Descr=nullptr);
intptr_t ParamMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2);
void RestoreMacroChar() const;
@@ -125,7 +125,7 @@ enum MACRO_OP_CODE
MCODE_F_HISTORY_DISABLE, // N=History.Disable([State])
MCODE_F_FMATCH, // N=FMatch(S,Mask)
MCODE_F_PLUGIN_MENU, // N=Plugin.Menu(Guid[,MenuGuid])
MCODE_F_PLUGIN_CONFIG, // N=Plugin.Config(Guid[,MenuGuid])
MCODE_F_PLUGIN_CALL, // N=Plugin.Call(Guid[,Item])
MCODE_F_PLUGIN_SYNCCALL, // N=Plugin.SyncCall(Guid[,Item])
MCODE_F_PLUGIN_LOAD, // N=Plugin.Load(DllPath[,ForceLoad])
MCODE_F_PLUGIN_COMMAND, // N=Plugin.Command(Guid[,Command])
@@ -1135,7 +1135,7 @@ string __MCODE_ToName(DWORD OpCode)
DEF_MCODE_(F_HISTORY_DISABLE), // N=History.Disable([State])
DEF_MCODE_(F_FMATCH), // N=FMatch(S,Mask)
DEF_MCODE_(F_PLUGIN_MENU), // N=Plugin.Menu(Guid[,MenuGuid])
DEF_MCODE_(F_PLUGIN_CONFIG), // N=Plugin.Config(Guid[,MenuGuid])
DEF_MCODE_(F_PLUGIN_CALL), // N=Plugin.Call(Guid[,Item])
DEF_MCODE_(F_PLUGIN_SYNCCALL), // N=Plugin.SyncCall(Guid[,Item])
DEF_MCODE_(F_PLUGIN_LOAD), // N=Plugin.Load(DllPath[,ForceLoad])
DEF_MCODE_(F_PLUGIN_COMMAND), // N=Plugin.Command(Guid[,Command])
@@ -1 +1 @@
m4_define(BUILD,4250)m4_dnl
m4_define(BUILD,4251)m4_dnl
@@ -1,7 +1,7 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 475 },
MinFarVersion = { 3, 0, 0, 4244 },
Version = { 1, 0, 0, 476 },
MinFarVersion = { 3, 0, 0, 4251 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Description = "Far macros in Lua",
@@ -347,12 +347,9 @@ Plugin = {
Unload = function(...) return MacroCallFar(0x80C53, ...) end,

SyncCall = function(...)
local v = MacroCallFar(0x80C50, ...)
local v = Shared.keymacro.CallPlugin(Shared.pack(...), false)
if type(v)=="userdata" then return far.FarMacroCallToLua(v) else return v end
end,
--Command = function(...) return MacroCallFar(0x80C52, ...) end,
--Config = function(...) return MacroCallFar(0x80C4F, ...) end,
--Menu = function(...) return MacroCallFar(0x80C4E, ...) end,
end
}
--------------------------------------------------------------------------------

@@ -1,4 +1,8 @@
zg 20.01.2015 03:10:50 +0200 - build 475
shmuel 21.01.2015 16:51:11 +0200 - build 476

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

zg 20.01.2015 03:10:50 +0200 - build 475

1. 0002912: В диалогах DM_SETTEXT, DM_GETTEXT не позволяют работать со строками содержащими '\0'.

Oops, something went wrong.

0 comments on commit c358404

Please sign in to comment.
You can’t perform that action at this time.