#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Region CheckVarNames() ; =================================================================== ; CheckVarNames($sFullPath, $bAu3, ByRef $sOutput) ; ; Check Variable Names in the specified file. ; Parameters: ; $sFullPath - IN - The file to test. ; $bAu3 - IN - Filename type : True for .au3 script file ; $sOutput - OUT - Test output is captured to this variable. ; Returns: ; The return nb of errors ; =================================================================== ; #include Func CheckVarNames($sFullPath, $bAu3, ByRef $sOutput) Local $hIn = FileOpen($sFullPath) Local $sLine, $aVarNames Local $iNbErrors = 0, $sErrors While 1 $sLine = GetVarNamesLine($hIn, $bAu3) If @error Then ExitLoop If GetVarNames($sLine, $aVarNames) Then $iNbErrors += CheckVarNamesErrors($aVarNames, $sErrors) ; If StringInStr($sLine, "$tagSYMBOL_INFO ") Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sLine = ' & $sLine & @CRLF & '>UBound($aVarNames): ' & UBound($aVarNames, 1) & ' $sErrors: ' & $sErrors & ' $g_bConst: ' & $g_bConst & @CRLF) ;### Debug Console If $sErrors Then ;~ _DebugArrayDisplay($aVarNames) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sLine = ' & $sLine & @CRLF & '>UBound($aVarNames): ' & UBound($aVarNames, 1) & ' $sErrors: ' & $sErrors & ' $g_bConst: ' & $g_bConst & @CRLF) ;### Debug Console EndIf $sOutput &= $sErrors EndIf WEnd FileClose($hIn) Return SetError(@error, @extended, $iNbErrors) EndFunc ;==>CheckVarNames #EndRegion CheckVarNames() #Region GetVarNamesLine() ; =================================================================== ; GetVarNamesLine($hIn, $bAu3) ; ; Get Variable Names in the specified line. ; Parameters: ; $hIn - IN - Handle of the file to be search ; $bAu3 - IN - True if a .au3 file is being checked ; Returns: ; String containing variable names ; Set @error if End Of File has been reached ; =================================================================== Func GetVarNamesLine($hIn, $bAu3) Local $sLine, $aMatch, $sTemp While 1 $sLine = FileReadLine($hIn) If @error Then Return SetError(@error, @extended, "") ; skip comments block If StringRegExp($sLine, '(?i)^\h*?#c(s|omment-start)') Then Do $sLine = FileReadLine($hIn) If @error Then Return SetError(@error, @extended, "") Until StringRegExp($sLine, '(?i)^\h*?#c(e|omment-end)') $sLine = FileReadLine($hIn) If @error Then Return SetError(@error, @extended, "") EndIf ; skip comments line or directives If $bAu3 And StringRegExp($sLine, '^\h*?[;#]') Then ContinueLoop $g_bGlobal = False $g_bConst = False $g_bGUICtrlCreate = False If $bAu3 Then $sLine = StringRegExpReplace($sLine, '(\h;[^;]*$)', "") ; suppress trailing comment While StringRight($sLine, 1) = "_" ; merge continuation lines $sLine = StringTrimRight($sLine, 1) $sTemp = FileReadLine($hIn) $sLine &= StringRegExpReplace($sTemp, '(\h;[^;]*$)', "") ; suppress trailing comment WEnd ;~ If StringInStr($sLine, "$tagSYMBOL_INFO ") Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sLine = ' & $sLine & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console $sLine = StringRegExpReplace($sLine, '([''"])\V*?\1', "0") ; Strip string literals. By PhoenixXL & guinness. ;~ If StringInStr($sLine, "$tagSYMBOL_INFO ") Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sLine = ' & $sLine & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console If StringRegExp($sLine, '(?i)\h*=\h*GUICtrlCreate') Then $g_bGUICtrlCreate = True Return "(" & $sLine & " $)" EndIf $aMatch = StringRegExp($sLine, "(?i)^\h*\b(Global|Local|Func)\b", $STR_REGEXPARRAYMATCH) If @error Then ContinueLoop If $aMatch[0] <> "Func" Then ; memorise Global Const type $g_bGlobal = ($aMatch[0] = "Global") $g_bConst = StringRegExp($sLine, '\b(Const|Enum)\b') ; Add parenthesis and delimiter to ease extracting variable names $sLine = StringReplace($sLine, $aMatch[0], $aMatch[0] & " (", 1) Else $sLine = StringTrimRight($sLine, 1) ; strip ) to allow $ i nstertion at the end EndIf $sLine &= " $)" ExitLoop Else If StringInStr($sLine, "###Syntax###") Then ; get Syntax definition $sLine = FileReadLine($hIn) If StringInStr($sLine, "#include") Then $sLine = FileReadLine($hIn) $sLine = StringRegExpReplace($sLine, '(\h*;[^;]*$)', "") ; suppress trailing comment While StringRight($sLine, 1) = "_" ; merge continuation lines $sLine = StringTrimRight($sLine, 1) $sTemp = FileReadLine($hIn) $sLine &= StringRegExpReplace($sTemp, '(\h*;[^;]*$)', "") ; suppress trailing comment WEnd $sLine = StringRegExpReplace($sLine, '([''"])\V*?\1', "0") ; Strip string literals. By PhoenixXL & guinness. $sLine = StringRegExpReplace($sLine, "(\[|\])", "") ; suppress [] Else Return SetError(10, 0, "") ; the file is not OK for checking as for Function or $tag UDF help file EndIf $sLine = "Func " & StringRegExpReplace($sLine, "\)$", " $)") ; add an ending delimiter to ease extracting variable names ExitLoop EndIf EndIf WEnd ; strip attributes $sLine = StringRegExpReplace($sLine, '(\b(Const|Static|ByRef|Enum)\b)|(\bStep\b\h*[\*\+-][1-9])', "") Return $sLine EndFunc ;==>GetVarNamesLine #EndRegion GetVarNamesLine()