#include <Array.au3>
$sScript_File = @DesktopDir & "\Script.au3"
$sAu3_Keywords_File = @AutoItExe & "\..\SciTE\properties\au3.keywords.properties"
$aScript_Read = StringSplit(StringStripCR(FileRead($sScript_File)), @LF)
$sFuncs = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.functions", "", 0)
$sUDFs = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.udfs", "", 0)
$sKeywords = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.keywords", "", 0)
$sMacros = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.macros", "", 0)
$sPreprocessor = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.preprocessor", "", 0)
$sSpecial = _PropertiesRead($sAu3_Keywords_File, "au3.keywords.special", "", 0)
$sAu3_Keywords = StringRegExpReplace(" " & $sFuncs & " " & $sUDFs & " " & $sKeywords & " " & $sMacros & " " & $sPreprocessor & " " & $sSpecial & " ", "[@#]", "")
For $i = 1 To $aScript_Read[0]
$aWords = StringRegExp($aScript_Read[$i], "([a-zA-Z_]+)", 3)
For $j = 0 To UBound($aWords)-1
If Not StringInStr($sAu3_Keywords, " " & $aWords[$j] & " ", 2) Then
$aScript_Read[$i] = StringRegExpReplace($aScript_Read[$i], "([^<_\$#@\.]\s*|^\s*)\Q" & $aWords[$j] & "\E", "\1\$" & $aWords[$j])
EndIf
Next
Next
;~ _ArrayDisplay($aScript_Read)
Dim $sScript_Read
For $i = 1 To $aScript_Read[0]
$sScript_Read &= $aScript_Read[$i] & @CRLF
Next
FileOpen($sScript_File, 2)
FileWrite($sScript_File, $sScript_Read)
FileClose($sScript_File)
Func _PropertiesRead($sFile, $sProperty, $sDefault = "", $iRetArr = 1)
Local $aFileRead = StringSplit(StringStripCR(FileRead($sFile)), @LF)
Local $sRet, $sPattern = '(?i)^\s*\Q' & $sProperty & '\E\s*=\s*'
For $i = 1 To $aFileRead[0]
If StringRegExp($aFileRead[$i], $sPattern) Then
$aFileRead[$i] = StringRegExpReplace($aFileRead[$i], $sPattern, '')
If StringRight($aFileRead[$i], 1) = "\" Then
$aFileRead[$i] = StringTrimRight($aFileRead[$i], 1)
EndIf
$sRet &= StringStripWS($aFileRead[$i], 3)
For $j = $i+1 To $aFileRead[0]
If StringInStr($aFileRead[$j], "=") Then
ExitLoop 2
Else ;If StringLeft(StringStripWS($aFileRead[$j], 1), 1) <> "#" Then
If StringRight($aFileRead[$j], 1) = "\" Then
$aFileRead[$j] = StringTrimRight($aFileRead[$j], 1)
EndIf
$sRet &= " " & StringStripWS($aFileRead[$j], 3)
EndIf
Next
ExitLoop
EndIf
Next
If $sRet == "" Then
$sRet = $sDefault
Else
$sRet = StringStripWS($sRet, 3)
EndIf
If $iRetArr Then
Return StringSplit($sRet, " ")
EndIf
Return $sRet
EndFunc