;-- TIME_STAMP 2022-03-10 14:37:30 v 0.1 #cs • "ErrorList.au3" ist eine DEBUG-Hilfe zur Nutzung mit SciTE. • Da die Auswertung von AutoIt-Makros erforderlich ist, müssen auch AutoIt-Funktionen verwendet werden. • Der Funktionsaufruf, dessen Errorwerte gelesen werden, wird auch gespeichert und mit Hilfe des SciTE-Interface aus dem Skript gelesen. • Sollte die UDF eingebunden sein, ohne dass das Skript in SciTE gestartet wird, führt das zu keinem Fehler, da das Interface nur angesprochen wird, wenn die SciTE.exe aktiv ist. Die Errorlist-Funktionen (bis auf _Remove) sind auch weiterhin nutzbar, enthalten aber nicht den Funktionsaufruf. • WICHTIG Die Funktionsaufrufe der ErrorList.au3 MÜSSEN allein in einer Zeile stehen (also NICHT: $a = 123, $err = _ErrorList_LastError() ). Hintergund ist, dass _Remove die gesamte Skriptzeile des Funktionsaufrufs löscht. FUNCTIONS _ErrorList_Add() • Fügt die vorherige Skriptzeile der Error-List hinzu. • Gespeichert werden: @error, @extended, @ScriptLineNumber, Funktionsaufruf • Die Werte von @error, @extended werden beim Verlassen der Funktion wieder gesetzt und können normal ausgewertet werden. _ErrorList_LastError($_iType) • Gibt den gewählten Typ (Standard: @error) des zuletzt erfassten Eintrags von _ErrorList_Add() zurück. • Als $_iType: 0=@error, 1=@extended, 2=Array [@error, @extended, @ScriptLineNumber, Funktionsaufruf], 3=String "@error|@extended|@ScriptLineNumber|Funktionsaufruf" (Trenner ist "Opt('GUIDataSeparatorChar')") _ErrorList_List($_bErrorsOnly) • Gibt eine Auflistung aller durch _ErrorList_Add() erfassten Einträge in Listenform in die Konsole aus. • Standard ($_bErrorsOnly=True): Nur Einträge mit "@error <> 0" werden gelistet. _ErrorList_Remove($_bIncl=False) • Entfernt sämtliche Funktionsaufrufe der ErrorList.au3 aus dem Skript (Standard). • Mit "$_bIncl=True" wird auch die entsprechende Include-Zeile entfernt #ce Global $g_bSciTEexists = (ProcessExists('SciTE.exe') <> 0) Global $g_SciTECmd If $g_bSciTEexists Then GUIRegisterMsg(74, "MY_WM_COPYDATA") ; $WM_COPYDATA = 74 Global $g_aErrList[1][4] = [[0]] ; [n][@error, @extended, @ScriptLineNumber, Func-Call] ;=================================================================================================== ; Function Name....: _ErrorList_Add ; Description......: Fügt den Funktionsaufruf aus der vorigen Skriptzeile dem ErrorList-Array hinzu ; Parameter(s).....: Parameter sind vorbelegt und dürfen NICHT überschrieben werden! ; Return Value(s)..: Leitet die @error- und @extended- Werte des vorigen Funktionsaufrufes weiter ;=================================================================================================== Func _ErrorList_Add($_iError=@error, $_iExtended=@extended, $_iLine=@ScriptLineNumber-1) If $_iLine < 1 Then Return ; Lua-Funktion zum Lesen der vorigen Skriptzeile Local $sLua = "function getline(iLine) " & _ " local posTextEnd = editor.LineEndPosition[iLine] " & _ " local posTextStart = editor:PositionFromLine(iLine) " & _ " local lineText = editor:GetLine(iLine) " & _ " return lineText:sub(1, posTextEnd - posTextStart)" & _ "end" ; Aufruf der Lua-Funktion und Rückgabe des Ergebnisses in Property 'extender.result' If $g_bSciTEexists Then _ScI_DostringGet($sLua, $_iLine -1) $sLua = "function getfunc() " & _ " local f = props['extender.result']:match('([%w_]+%s-%b())') " & _ " return f " & _ "end" Local $sFuncCall If $g_bSciTEexists Then $sFuncCall = _ScI_DostringGet($sLua) $g_aErrList[0][0] += 1 ReDim $g_aErrList[$g_aErrList[0][0]+1][4] $g_aErrList[$g_aErrList[0][0]][0] = $_iError $g_aErrList[$g_aErrList[0][0]][1] = $_iExtended $g_aErrList[$g_aErrList[0][0]][2] = $_iLine $g_aErrList[$g_aErrList[0][0]][3] = $sFuncCall ; "Durchreichen" von @error und @extended Return SetError($_iError,$_iExtended) EndFunc ;=================================================================================================== ; Function Name....: _ErrorList_LastError ; Description......: Gibt die Werte für den zuletzt gespeicherten Eintrag zurück ; Parameter(s).....: $_iType Legt die Rückgabe fest ; .................: 0=@error, 1=@extended, 2=[@error, @extended, @ScriptLineNumber, Funktionsaufruf] ; .................: 3=@error|@extended|@ScriptLineNumber|Funktionsaufruf - Trenner: Opt('GUIDataSeparatorChar') ; Return Value(s)..: Der durch $_iType bestimmte Wert ;=================================================================================================== Func _ErrorList_LastError($_iType=0) Local $idx = $g_aErrList[0][0], $sDelim = Opt('GUIDataSeparatorChar') Local $sLastError = StringFormat('%d%s%d%s%d%s%s',$g_aErrList[$idx][0],$sDelim, _ $g_aErrList[$idx][1],$sDelim,$g_aErrList[$idx][2],$sDelim,$g_aErrList[$idx][3]) Switch $_iType Case 0 Return $g_aErrList[$idx][0] Case 1 Return $g_aErrList[$idx][1] Case 2 Return StringSplit($sLastError, $sDelim, 3) Case 3 Return $sLastError EndSwitch EndFunc ;=================================================================================================== ; Function Name....: _ErrorList_List ; Description......: Tabellenförmige Ausgabe der Errorlist Einträge in die Konsole ; Parameter(s).....: $_bErrorsOnly Standard (True) - NUr Einträge mit Fehler <> 0 werden ausgegeben ; Return Value(s)..: Auflistung, wie in die Konsole ausgegeben ;=================================================================================================== Func _ErrorList_List($_bErrorsOnly=True) Local $nErr = 0 If $g_aErrList[0][0] = 0 Then Return '+> [EMPTY LIST]' If $_bErrorsOnly Then For $i = 1 To $g_aErrList[0][0] If $g_aErrList[$i][0] <> 0 Then $nErr += 1 Next If $_bErrorsOnly And $nErr = 0 Then Return '+> No errors have occurred.' EndIf Local $sList = '-> @error @extended @line Function-Call' & @CRLF, $aSign[] = ['>>', '+>', '!>'], $idx = 0 For $i = 1 To $g_aErrList[0][0] If $_bErrorsOnly And $g_aErrList[$i][0] = 0 Then ContinueLoop $idx = Abs($idx-1) $sList &= StringFormat('%s %6s %9s %5s %s\n', $aSign[($g_aErrList[$i][0] <> 0 ? 2 : $idx)], _ $g_aErrList[$i][0], $g_aErrList[$i][1], $g_aErrList[$i][2], $g_aErrList[$i][3]) Next ConsoleWrite($sList & @CRLF) Return $sList EndFunc ;=================================================================================================== ; Function Name....: _ErrorList_Remove ; Description......: Entfernt alle Zeilen mit Funktionsaufrufen der "ErrorList.au3" aus dem aktuellen Skript. ; Parameter(s).....: $_bIncl Standard (False) entfernt alle Funktionsaufrufe. ; .................: "True" entfernt auch die Zeile mit dem Include der ErrorList.au3 ;=================================================================================================== Func _ErrorList_Remove($_bIncl=False) If Not $g_bSciTEexists Then ConsoleWrite('!> "_ErrorList_Remove()" requires the use of SciTE!' & @CRLF) Return EndIf Local $iIncl = $_bIncl ? 1 : 0 Local $sLua = "extender:dostring do " & _ " local caret = editor.CurrentPos " & _ " local fvl = editor.FirstVisibleLine " & _ " local incl = '" & $iIncl & "' " & _ " local tPatt = {'_ErrorList_Add', '_ErrorList_LastError', '_ErrorList_List', '_ErrorList_Remove'} " & _ " for i=editor.LineCount -1, 0, -1 do " & _ " local sleepdummy = output:GetCurLine() " & _ ; ein Mini-Sleep ist erforderlich " local line = editor:GetLine(i) " & _ " for j=1, #tPatt do " & _ " if line ~= nil and line ~= '' then " & _ " if line:find(tPatt[j]..'%s-%b()') then " & _ " editor.CurrentPos = editor:PositionFromLine(i) " & _ " editor:LineDelete() break " & _ " end " & _ " end " & _ " end " & _ " end " & _ " if incl == '1' then " & _ " for i=0, editor.LineCount -1 do " & _ " local line = editor:GetLine(i) " & _ " if line ~= nil and line ~= '' then " & _ " if line:find('#[iI][nN][cC][lL][uU][dD][eE]%s-.+[Ee][rR][rR][oO][rR][Ll][iI][sS][tT]') then " & _ " editor.CurrentPos = editor:PositionFromLine(i) " & _ " editor:LineDelete() break " & _ " end " & _ " end " & _ " end " & _ " end " & _ " editor.CurrentPos = caret " & _ " editor:SetSelection(caret, caret) " & _ " editor.FirstVisibleLine = fvl " & _ " scite.MenuCommand(IDM_SAVE) " & _ "end" SendSciTE_Command($sLua) EndFunc ;=============================================================================== ; Function Name....: _ScI_DostringGet ; Description......: Eine Luafunktion mit/ohne Parameter aufrufen UND ein Ergebnis erhalten ; : Maximal 10 Parameter können übergeben werden. ; Parameter(s).....: $_sLuaFunc - String mit der Lua-Funktion ; : $p1 - [optional] Parameter1 für die Funktion ; : ... bis ; : $p10 - [optional] Parameter10 für die Funktion ; Return Value(s)..: Rückgabewert der Lua-Funktion ; Author(s)........: BugFix ;------------------------------------------------------------------------------- ; Bsp.: ; ohne Parameter: ; Local $sFunc = "function LineFromCursor() return editor:LineFromPosition(editor.CurrentPos)+1 end" ; ConsoleWrite(_ScI_DostringGet($sFunc) & @CRLF) ; ; mit Parameter: ; Local $sFunc = "function LineEnd(iLine) return editor.LineEndPosition[iLine] end" ; ConsoleWrite(_ScI_DostringGet($sFunc, 130) & @CRLF) ;=============================================================================== Func _ScI_DostringGet($_sLuaFunc, $p1=Null, $p2=Null, $p3=Null, $p4=Null, $p5=Null, $p6=Null, $p7=Null, $p8=Null, $p9=Null, $p10=Null) Local $aParamCall[] = [$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10] ; extract function name Local $sFunc = (StringRegExp($_sLuaFunc, 'function (\w+)\(', 1))[0], $sParam = '()' If $p1 <> Null Then ; extract parameters $sParam = (StringRegExp($_sLuaFunc, 'function \w+\(([^)]+)\)', 1))[0] Local $aParam = StringSplit($sParam, ',') ; rebuild sParam with given values $sParam = '' For $i = 1 To $aParam[0] $sParam &= $aParamCall[$i-1] & ',' Next $sParam = '(' & StringTrimRight($sParam,1) & ')' EndIf SendSciTE_Command("extender:dostring do " & $_sLuaFunc & " props['extender.result']=" & $sFunc & $sParam & " end") SendSciTE_Command("askproperty:extender.result") Return StringTrimLeft($g_SciTECmd,StringInStr($g_SciTECmd, ':', 1, 4)) EndFunc ; by BugFix Func _GetHwndDirectorExtension() Local $hActive = WinGetHandle('[ACTIVE]') Local $PIDActive = WinGetProcess($hActive) Local $aExtension = WinList("DirectorExtension") Local $PIDExt For $i = 1 To $aExtension[0][0] $PIDExt = WinGetProcess($aExtension[$i][1]) If $PIDExt = $PIDActive Then Return $aExtension[$i][1] Next EndFunc ; by Jos Func SendSciTE_Command($_sCmd, $Wait_For_Return_Info=0) Local $WM_COPYDATA = 74 Local $WM_GETTEXT = 0x000D Local $WM_GETTEXTLENGTH = 0x000E224 Local Const $SCI_GETLINE = 2153 Local $Scite_hwnd = _GetHwndDirectorExtension() ; Get SciTE DIrector Handle Local $My_Hwnd = GUICreate("AutoIt3-SciTE interface") ; Create GUI to receive SciTE info Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ; Convert my Gui Handle to decimal $_sCmd = ":" & $My_Dec_Hwnd & ":" & $_sCmd ; Add dec my gui handle to commandline to tell SciTE where to send the return info Local $CmdStruct = DllStructCreate('Char[' & StringLen($_sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $_sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($_sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) $g_SciTECmd = '' DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) GUIDelete($My_Hwnd) If $Wait_For_Return_Info Then Local $n = 0 While $g_SciTECmd = '' Or $n < 10 Sleep(20) $n += 1 WEnd EndIf Return $g_SciTECmd EndFunc ;==>SendSciTE_Command Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam) Local $g_SciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[' & $g_SciTECmdLen+1 & ']',DllStructGetData($COPYDATA, 3)) ;~ Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3)) $g_SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $g_SciTECmdLen) EndFunc ;==>MY_WM_COPYDATA