#include <Array.au3>
Global $bDebug = False
Global $bLog = False
Global $sExclude_Keywords = 'Opt'
Global $aExclude_Keywords = StringSplit($sExclude_Keywords, '|')
Global $sSciTE_Kwrds_File = @ScriptDir & '\au3.keywords.properties'
Global $sSciTE_API_File = @ScriptDir & '\au3.api'
Global $sGeshi_File = @ScriptDir & '\autoit.php'
Global $sSciTE_Kwrds_Data = FileRead($sSciTE_Kwrds_File)
Global $sSciTE_API_File_Data = FileRead($sSciTE_API_File)
Global $sGeshi_File_Data = FileRead($sGeshi_File)
_Geshi_Sync_Keywords('Keywords', 1, '', False)
_Geshi_Sync_Keywords('Macros', 2, '', False)
_Geshi_Sync_Keywords('Functions', 3, '', False)
_Geshi_Sync_Keywords('UDFs', 4, '_', False)
_Geshi_Sync_Keywords('PreProcessor', 5, '#', False)
_Geshi_Sync_Keywords('Special', 8, '#', False)
Func _Geshi_Sync_Keywords($sKeyword, $iKeyword, $sPrefix = '', $bRemoveUnUsed = True)
Local $aGeshi_Keywords = _Geshi_GetKeywords($iKeyword, $sPrefix)
Local $aSciTE_Keywords = _SciTE_GetKeywords($sKeyword)
Local $iRemoved_Count = 0
Local $iAdded_Count = 0
If $bDebug Then
_ArrayDisplay($aGeshi_Keywords, 'Geshi - Before')
_ArrayDisplay($aSciTE_Keywords, 'SciTE - Before')
EndIf
;Check in SciTE keywords to ensure that we don't have unused keywords in Geshi
If $bRemoveUnUsed Then
_LogOutput('Removing "%s"...', $sKeyword, '')
For $i = $aGeshi_Keywords[0] To 1 Step -1
;Geshi Keyword not found in SciTE keywords - remove it from list
If _ArraySearch($aSciTE_Keywords, $aGeshi_Keywords[$i], 1, 0, 0, 2) = -1 Then
_LogOutput('Geshi Keyword.%s "%s" not found in SciTE Keywords (removed)', $sKeyword, $aGeshi_Keywords[$i], '')
_ArrayDelete($aGeshi_Keywords, $i)
$aGeshi_Keywords[0] -= 1
$iRemoved_Count += 1
EndIf
Next
EndIf
_LogOutput('Adding "%s"...', $sKeyword, '')
;Check in Geshi keywords to ensure that we have all used keywords from SciTE
For $i = 1 To $aSciTE_Keywords[0]
;SciTE Keyword not found in Geshi keywords - add it to the list
If _ArraySearch($aGeshi_Keywords, $aSciTE_Keywords[$i], 1, 0, 0, 2) = -1 Then
;If it's in keywords exclude list, then skip it
If _ArraySearch($aExclude_Keywords, $aSciTE_Keywords[$i], 1, 0, 0, 2) <> -1 Then
ContinueLoop
EndIf
_LogOutput('SciTE Keyword.%s "%s" not found in Geshi Keywords (added)', $sKeyword, $aSciTE_Keywords[$i], '')
_ArrayAdd($aGeshi_Keywords, _Geshi_GetKeywordRealName($aSciTE_Keywords[$i]))
$aGeshi_Keywords[0] += 1
$iAdded_Count += 1
EndIf
Next
If $bDebug Then
_ArrayDisplay($aGeshi_Keywords, 'Geshi - After')
_ArrayDisplay($aSciTE_Keywords, 'SciTE - After')
EndIf
Local $sGeshi_Kwrds_Str = ''
Local $sGeshi_Kwrds_Set = ''
Local $sGeshi_Kwrds = ''
For $i = 1 To $aGeshi_Keywords[0]
If StringLeft($aGeshi_Keywords[$i], 1) == $sPrefix Then
$aGeshi_Keywords[$i] = StringTrimLeft($aGeshi_Keywords[$i], 1)
EndIf
$sGeshi_Kwrds_Set &= "'" & $aGeshi_Keywords[$i] & "',"
If StringLen($sGeshi_Kwrds_Set) >= 75 Or $i = $aGeshi_Keywords[0] Then
$sGeshi_Kwrds_Str &= @TAB & @TAB & @TAB & @TAB & @TAB & @TAB & $sGeshi_Kwrds_Set & @CRLF
$sGeshi_Kwrds_Set = ''
EndIf
Next
$sGeshi_Kwrds_Str = StringStripWS(StringRegExpReplace($sGeshi_Kwrds_Str, ',+$', ''), 2)
$sGeshi_Kwrds = StringRegExpReplace($sGeshi_File_Data, _
"(?si)(.*?'KEYWORDS' => array\(\s+.*?" & $iKeyword & " => array\(\r?\n)\s+(.*?)(\s+\),?.*?)", "\1" & $sGeshi_Kwrds_Str & "\3", 1)
_LogOutput('Total Keywords.%s Added: %i', $sKeyword, $iAdded_Count)
_LogOutput('Total Keywords.%s Removed: %i', $sKeyword, $iRemoved_Count, '')
_LogOutput('')
If $bDebug Then
ConsoleWrite($sGeshi_Kwrds_Str & @LF)
;ConsoleWrite($sGeshi_Kwrds & @LF)
ElseIf $iAdded_Count > 0 Or $iRemoved_Count > 0 Then
FileCopy($sGeshi_File, $sGeshi_File & '.bak')
$hFile = FileOpen($sGeshi_File, 2)
FileWrite($hFile, $sGeshi_Kwrds)
FileClose($hFile)
EndIf
EndFunc
Func _LogOutput($sData, $vParam1 = '', $vParam2 = '', $sPrefix = '----------------')
If $bLog Then
ConsoleWrite($sPrefix & ($sPrefix = '' ? '' : @LF) & StringFormat($sData, $vParam1, $vParam2) & @LF)
EndIf
EndFunc
Func _SciTE_GetKeywords($sKeyword)
Local $aKeywords = StringRegExp($sSciTE_Kwrds_Data, "(?si)au3\.keywords\." & $sKeyword & "=(.*?)(?:au3\.keywords\.|\z)", 1)
$aKeywords = StringSplit(StringStripWS(StringReplace($aKeywords[0], '\', ''), 7), ' ')
Return $aKeywords
EndFunc
Func _Geshi_GetKeywords($iKeyword, $sPrefix = '')
Local $aKeywords = StringRegExp($sGeshi_File_Data, "(?si)'KEYWORDS' => array\(\s+.*?" & $iKeyword & " => array\(\s+(.*?)\),?", 1)
$aKeywords = StringSplit(StringStripWS($aKeywords[0], 8), ',')
For $i = 1 To $aKeywords[0]
$aKeywords[$i] = $sPrefix & StringRegExpReplace($aKeywords[$i], "^'+|'+$", "")
Next
Return $aKeywords
EndFunc
Func _Geshi_GetKeywordRealName($sKeyword)
If StringRegExp($sSciTE_API_File_Data, '(?i)(\r?\n|^)\s*(' & $sKeyword & ')(\?|\s*\()') Then
$sKeyword = StringRegExp($sSciTE_API_File_Data, '(?i)(?:\r?\n|^)\s*(' & $sKeyword & ')(?:\?|\s*\()', 1)[0]
EndIf
Return $sKeyword
EndFunc