Stilgar Posted January 1, 2014 Share Posted January 1, 2014 AutoIt Version : V3.3.0.0 Two older scripts ... they are not longer supported from me, but if anyone can use it ... _Au3Optim.au3: Optimizes au3-source-code + simple PreProzessor (#define-macros) The steps inside the function: ; merging lines ; merging strings ; caching all strings ; replacing #define directives ; replacing "inline" functions e.G. Func test($a,$b) Return $a*$b EndFunc ; replacing GLOBAL constants ; replace StringFormat ; replace StringLower/Upper/Left/Right/Mid/Len/StripWS/StripCR/TrimLeft|TrimRight|Replace ; replace Math-functions ; replace BitAnd/BitOr ; replace simple calculations ; merging one-line If-block ; removing redunant ElseIf ... Example 1 Input: #define msg(txt) MsgBox(0,"Test",txt) #define msg2(txt,title) MsgBox(0,title,txt) #define $bla "blubber" msg("Hallo") msg('Hallo 2') msg2("Hallo", "Titel") $text = $bla Example 2 Output: MsgBox(0,"Test","Hallo") MsgBox(0,"Test",'Hallo 2') MsgBox(0,"Titel","Hallo") $text = "blubber" Example 2 Input: expandcollapse popup; Test.au3 fuer _Au3Optim #define @InetGetActive InetGetInfo() Global const $test=2 ; Test 1 global Const $test2 =4 global const $test3= 8 Global Const $test4 = "das ist ein Test" ; Test 4 global Const $test5 = 'das ist ein anderer Test' $bla1 = $test+ $test2 + $test3 $bla2 = $test4 $bla3 = $test5 DllStructCreate( _ "dword dwsize;" & _ "dword cntUsage;" & _ "dword th32ProcessID;" & _ "uint th32DefaultHeapID;" & _ "dword th32ModuleID;" & _ "dword cntThreads;" & _ "dword th32ParentProcessID;" & _ "long pcPriClassBase;" & _ "dword dwFlags;" & _ "char szExeFile[260]" _ ) $s = @InetGetActive $a7j = _k_() $ms = $s34 *1000*60*$min $t = (3 + 32) * 45 $ms = "1000*60*34" $ms = '1000*60*34' If _Bla() = 0 And $t = 0 or($t = 0) Then $bla = True If $a[0] = False Then $bla = True If @error = 0 Then If $a = 1 Or $t6575 = True Then $bla = True If $a = True Then $bla = True If @error = 1 Then $variable = $variable + 1 $i = $i *10 $s = StringFormat("%s %.2f %s", "test", 4.56345345 , "test") $s = StringFormat("%s %.2f", "test", 4.56345345 * $test2) $s = StringFormat("%s %.2f %s", "Das ist eine Zahl", 4.56345345 , $test20) Msg("Hallo Welt") $c = _F2C($F, 2) $c = _F2C(128, 2) $b1 = _Test0(1, 2) $b2 = _Test0(3, 4) $b3 = Abs(_Test0(5, 6) + 100) $a = 1 _Test1($a, 2) _Test2("Hallo ", "das ist ein ", "Test") ; Test 2 $b = _Test3("text") $c = _Test4(5) ; EndFunc ; ============================================================================== Func _fg($t = 0, $2 = 1) Local $t Return EndFunc Func _k_() Return(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) EndFunc Func _1_() Return "test" EndFunc Func _F2C($F, $iP) Return Round(($F - 32) * 5 / 9, $iP) EndFunc ;==>_F2C Func _Test0($a, $z) Return $z * 3 * $a + 100 EndFunc ;==>_Test0 Func _Test1(ByRef $a, $b) Return ConsoleWrite($a + $b) EndFunc ;==>_Test1 Func _Test2($a, $b, $c) Return ConsoleWrite($a & $b & $c & @CRLF) EndFunc ;==>_Test2 Func _Test3($u) Return $u EndFunc ;==>_Test3 Func _Test4($s) Local $r = $s * 2 Return $r EndFunc ;==>_Test4 Func Msg($s) Return MsgBox(0, "Message:", $s) EndFunc ;==>Msg Example 2 Output: expandcollapse popup; Test.au3 fuer _Au3Optim $bla1 = 14 $bla2 = "das ist ein Test" $bla3 = 'das ist ein anderer Test' DllStructCreate( "dword dwsize;dword cntUsage;dword th32ProcessID;uint th32DefaultHeapID;dword th32ModuleID;dword cntThreads;dword th32ParentProcessID;long pcPriClassBase;dword dwFlags;char szExeFile[260]" ) $s = InetGetInfo() $a7j = (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) $ms = $s34 *60000*$min $t = (35) * 45 $ms = "2040000" $ms = '2040000' If Not _Bla() And Not $t or($t = 0) Then $bla = True If Not $a[0] Then $bla = True If Not @error Then If $a Or $t6575 Then $bla = True If $a Then $bla = True If @error Then $variable += 1 $i *= 10 $s = "test 4.56 test" $s = "test 18.25" $s = StringFormat("%s %.2f %s", "Das ist eine Zahl", 4.56345345 , $test20) MsgBox(0, "Message:", "Hallo Welt") $c = Round(($F - 32) * 0.555555555555556, 2) $c = 53.33 $b1 = 106 $b2 = 136 $b3 = Abs(290) $a = 1 ConsoleWrite($a + 2) ConsoleWrite("Hallo das ist ein Test" & @CRLF) ; Test 2 $b = "text" $c = _Test4(5) ; EndFunc ; ============================================================================== Func _fg($t = 0, $2 = 1) Local $t Return EndFunc Func _Test4($s) Local $r = $s * 2 Return $r EndFunc ;==>_Test4 Download: _Au3Optim.au3 _Patch.au3 Some compatibily patches for older scripts (3.3.0.0 => 3.3.2.0) (inlcuded from _Au3Optim if it in the same directory) expandcollapse popup#region Patches from 3.3.0.0 => 3.3.2.0 #OnAutoItStartRegister "OnAutoItStart" OnAutoItExitRegister("OnAutoItExit") #define @InetGetBytesRead InetGetInfo(Default, 0) #define @InetGetActive (Not InetGetInfo(Default, 2)) ; InetGet("abort") = InetClose($h) ;=============================================================================== Func _SQLite_SaveMode($fSaveModeState) Local $r = _SQLite_SafeMode($fSaveModeState) Return SetError(@error,@extended,$r) EndFunc ;==> ;=============================================================================== Func URLDownloadToFile($sURL, $sFilename, $iReload, $iBackground) ; ??? Return InetGet($sURL, $sFilename, $iReload, $iBackground) EndFunc ;==>URLDownloadToFile ;=============================================================================== Func AdlibEnable($sFunc, $iTime = 250) Return AdlibRegister($sFunc, $sTime) EndFunc ;==>AdlibEnable ;=============================================================================== Func AdlibDisable() Return AdlibUnRegister() EndFunc ;==>AdlibDisable ;=============================================================================== ; #FUNCTION# =================================================================== ; Name...........: _WinAPI_MakeDWord ; Description ...: Returns a DWord value from two int values ; Syntax.........: _WinAPI_MakeDWord($HiWord, $LoWord) ; Parameters ....: $HiWord - Hi word ; $LoWord - Low word ; Return values .: Success - DWord value ; Author ........: Gary Frost (gafrost) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; ============================================================================== Func _WinAPI_MakeDWord($HiWord, $LoWord) Return BitOR($LoWord * 0x10000, BitAND($HiWord, 0xFFFF)) EndFunc ;==>_WinAPI_MakeDWord ; #FUNCTION# =================================================================== ; Name...........: _StringAddThousandsSep ; Description ...: Returns the original numbered string with the Thousands delimiter inserted. ; Syntax.........: _StringAddThousandsSep($sString[, $sThousands = -1[, $sDecimal = -1]]) ; Parameters ....: $sString - The string to be converted. ; $sThousands - Optional: The Thousands delimiter ; $sDecimal - Optional: The decimal delimiter ; Return values .: Success - The string with Thousands delimiter added. ; Author ........: SmOke_N (orignal _StringAddComma ; Modified.......: Valik (complete re-write, new function name) ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; ============================================================================== Func _StringAddThousandsSep($sString, $sThousands = -1, $sDecimal = -1) Local $sResult = "" ; Force string Local $rKey = "HKCU\Control Panel\International" If $sDecimal = -1 Then $sDecimal = RegRead($rKey, "sDecimal") If $sThousands = -1 Then $sThousands = RegRead($rKey, "sThousand") ;~ Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1) Local $aNumber = StringRegExp($sString, "(\D?\d+)\D?(\d*)", 1) ; This one works for negatives. If UBound($aNumber) = 2 Then Local $sLeft = $aNumber[0] While StringLen($sLeft) $sResult = $sThousands & StringRight($sLeft, 3) & $sResult $sLeft = StringTrimRight($sLeft, 3) WEnd ;~ $sResult = StringTrimLeft($sResult, 1) ; Strip leading thousands separator $sResult = StringTrimLeft($sResult, StringLen($sThousands)) ; Strip leading thousands separator If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1] EndIf Return $sResult EndFunc ;==>_StringAddThousandsSep #endregion Patches from 3.3.0.0 => 3.3.2.0 kalans 1 jEdit4AutoIt PlanMaker_UDF Link to comment Share on other sites More sharing options...
guinness Posted January 1, 2014 Share Posted January 1, 2014 (edited) Thanks. Shame you're not supporting, but I may look at your way of expanding Global Constants and see how that differs in my PreExpand project. Edited January 1, 2014 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
guinness Posted January 1, 2014 Share Posted January 1, 2014 ; You didn't take into consideration when certain elements are in strings. ConsoleWrite("'Example' & 'Example'" & @CRLF) ConsoleWrite("If $a = False" & @CRLF) ; There are more, but I didn't document them here. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now