Jump to content

New tool - a PreProcessor


kjactive
 Share

Recommended Posts

Au3PreProcessor 1.8 - a totally rewrite of one old application of mine that gave me gray hear of trouble but durring the long and dark month here in the December nights in Copenhagen, Denmark - Well almost a black hole, shi¤%/&(...

The application started years ago when I discovered some trouble with the autoit3 compile concepts - to buildin all includes totally, no selective of only used functions and constants and that is just what this tool do - read in depth what is used and not, no limits how deep it goes 'reused functions from other .udf in these includes' . Another thing is that some peoble has concerns that scripts can be read after the 'wrap into an execute' well this tool makes script almost non readable - check out this script your self...

One has to remember with these third level interpretted languages as 'autoit3' that they has to read in every character one by one, build constant variable lists and function lists before any action take place and Au3PreProcess can speed up the execute process and squize the application weight for some 500 Kb in some conditions as the final script only holds the used constans and functions...

The application is a beta version as only the PreProcess action is written and functional and I would like to get responce or ideers for implimentations but planned is to be able to write a Makefile to easy do a directly recompile, do a testing execute process and to do a directly compile pass to 'CompileIt.exe with or without intuition...

There is no way the application can cobe for directly created function calls with the function 'Call' and I do thing that it could be a problem with plug-ins' but I don't know jet here...

Copy the script below to a directory and use the Process gadget - this will do a PreProcessed Clone from the Process options in the local path with a '_Pre' attached...

Please report trouble but beaware that autoit3 is a 'typeless language' and not every Process options is wice in every conditions as ';' is a parametre for comments but could also be written into a string and then the string would be half and faulty...

CODE
Global Const $LVM_FIRST=0x1000

Global Const $GUI_CHECKED= 1

Global Const $LVS_EX_GRIDLINES= 0x00000001

Global Const $LVS_EX_CHECKBOXES= 0x00000004

Global Const $LV_ERR=-1

Global Const $LVIF_STATE=0x8

Global Const $LVIS_STATEIMAGEMASK=0xF000

Global Const $LVM_SETITEMSTATE=($LVM_FIRST+43)

Global Const $MEM_MAP="uint;uint;ptr"

Global Const $MEM_MAP_HPROC=1

Global Const $MEM_MAP_ISIZE=2

Global Const $MEM_MAP_PMEM=3

Global Const $MEM_COMMIT=0x00001000

Global Const $MEM_RESERVE=0x00002000

Global Const $MEM_SHARED=0x08000000

Global Const $PAGE_READWRITE=0x00000004

Global Const $PROCESS_VM_OPERATION=0x00000008

Global Const $PROCESS_VM_READ=0x00000010

Global Const $PROCESS_VM_WRITE=0x00000020

HotKeySet("^q",'Exits');trap Q to quit

Global Const $Prefs='HKEY_CURRENT_USER\software\Au3PreProcess\Prefs'; preferences entry

Global Const $title='Au3Preprocess',$Rev='1.8'; title

Global $dm1,$Main,$Edit,$ListC,$ConstC,$FuncC,$PreproC,$RemCommBC,$RemCommTC,$RemBlankC,$RemTabsC,$RemLinesC,$RemOpeC,$RemPreC,$DoCompC,$DoCheckC,$LabelC,$WriteC,$ReloadC,$RemoveC,$DoTestC,$CompileC; Global main controls

Global Const $Au3Path=RegRead('HKLM\Software\AutoIt v3\AutoIt','InstallDir'); get AutoIt3 path

Global $RemCommB,$RemCommT,$RemBlank,$RemTabs,$RemLines,$RemOpe,$DoComp,$DoCheck; buttons variables to preferences

Global $ProTM,$RunTM,$ComTM,$TopTM,$AboTM,$ExiTM; Tray menus item variables

Global $includelist,$functionlist,$UsedFunctionslist; internal database variables with a blank character as sepperator

Global $Chars; The main script to check-to speedup process we hold it

Global Const $cc=Chr(0x3B),$ch=$cc&' ======================================================================='&@CRLF

GLobal $filein,$fileout,$inpath

ReadPrefs($Prefs); read in the preferences

MainWin(); open main intuition

While 1

$msg=GUIGetMsg(1)

Select

Case $msg[1]=0x00000000; Non initiated ticks handle

Case $msg[1]=$Main; Main window handle

Select

Case $msg[0]=-3; Quit main window handle

Exits()

Case $msg[0]=$RemCommBC

$RemCommB=GUICtrlRead($RemCommBC)

Case $msg[0]=$RemCommTC

$RemCommT=GUICtrlRead($RemCommTC)

Case $msg[0]=$RemBlankC

$RemBlank=GUICtrlRead($RemBlankC)

Case $msg[0]=$RemTabsC

$RemTabs=GUICtrlRead($RemTabsC)

Case $msg[0]=$RemLinesC

$RemLines=GUICtrlRead($RemLinesC)

Case $msg[0]=$RemOpeC

$RemOpe=GUICtrlRead($RemOpeC)

Case $msg[0]=$DoCompC

$DoComp=GUICtrlRead($DoCompC)

Case $msg[0]=$DoCheckC

$DoCheck=GUICtrlRead($DoCheckC)

Case $msg[0]=$PreproC

ExecutePreProcess()

Case $msg[0]=$DoTestC

GUICtrlSetData($LabelC,'Not inteplementated jet-Use Process...')

Case $msg[0]=$WriteC

GUICtrlSetData($LabelC,'Not inteplementated jet-Use Process...')

EndSelect

EndSelect

Wend

Exits()

Func ExecutePreProcess()

If $Filein='' Or StringRight($Filein,1)='\' Then

$f=FileLoad('Load in a file to PreProcess...',$inPath,'Scripts (*.aut;*.au3)')

If $f='' Then

MsgBox(48,'ERROR...','Okay Project Cancel')

Return

Else

If FileExists($f) Then

$Filein=$f

Else

MsgBox(48,'ERROR...','ERROR-Project file failed')

Return

Endif

EndIf

EndIf

GUICtrlSendMsg($ListC,0x1009,0,0)

GUICtrlSendMsg($FuncC,0x1009,0,0)

GUICtrlSendMsg($ConstC,0x1009,0,0)

$fileout=StringReplace($filein,'.','_Pre.')

GetIncludeList($Filein); Init the variable $includelist containing used #includes

GetSubIncludes(); Check all subincludes for includes and insert these into the listview display

MakeFuncAvailableList()

MakeDeepCheckForNewFunctions()

SampleMainAndSubFunctionsTemporary()

CheckTemporaryScriptForGlobalConstants()

WritePreprocessedScriptAndCleanUp($fileout)

Dim $includelist='',$functionlist='',$UsedFunctionslist='',$inpath=StringMid($filein,1,StringInStr($filein,'\',0,-1)),$filein=''

EndFunc

Func WritePreprocessedScriptAndCleanUp($file)

Dim $in=@ScriptDir&'\Temp\TmpScript.txt',$header=$ch&$cc&' '&$title&' '&$Rev&' Preprocessed-Date '&@MDAY&':'&@MON&':'&@YEAR&' Time '&@HOUR&':'&@MIN&@CRLF&$ch

$IDI=FileOpen($in,2)

$ID=FileOpen(@ScriptDir&'\Temp\TmpConstants.txt',0)

$chars=$header&FileRead($ID)&$chars

FileClose($ID)

FileWrite($IDI,$chars)

FileClose($IDI)

$IDO=FileOpen($file,2)

$IDI=FileOpen($in,0)

While 1

$Line=FileReadLine($IDI)

If @error Then Exitloop

$wd=StringInStr($line,$cc)

if $RemCommB=1 AND $wd=1 Then; remove comment blocks

$line='?'

ElseIf $RemCommT=1 AND $wd>1 Then; remove traling comments

$Line=StringMid($line,1,$wd-1)

EndIf

if StringInStr($line,'#include ')=1 Then; Remove Includes

If StringLeft($line,1)='#' Then

$line='?'

EndIf

Elseif $RemLines=1 AND StringLen(StringStripWS($Line,8))=0 Then; remove empty lines

$line='?'

Elseif $RemBlank=1 Then

$line=StringStripWS($Line,7)

EndIf

if $RemTabs=1 Then; remove tab characters

$line=StringReplace($Line,'','')

EndIf

If $line<>'?' then FileWriteLine($IDO,$Line)

WEnd

FileClose($IDI)

FileClose($IDO)

If $RemOpe=1 Then; remove blank characters around operators

$IDI=FileOpen($file,0)

$chars=FileRead($IDI)

FileClose($IDI)

$chars=StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(Strin

gReplace(StringReplace($chars,'=','='),'+','+'),'-','-'),'>','>'),'<','<'),'*','*'),'<>','<>'),'&','&')

$IDO=FileOpen($file,2)

FileWrite($IDO,StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($chars,'>=','>='),'<=','<='),',',','),'+=','+='),'-=','-='))

FileClose($IDI)

EndIf

If $DoCheck=1 Then

$IDI=FileOpen($file,0)

$chars=FileRead($IDI)

FileClose($IDI)

If StringInStr($chars,'Case $msg[1]=0x00000000')=0 Or StringInStr($chars,'Case $msg[1]=0')=0 then _say('no ticks catch function')

If StringInStr($chars,' Call(')>0 then _say('ERROR-Posible trouble with user-defined function durring the "CALL" function')

If StringInStr($chars,'PluginOpen(')>0 then _say('ERROR-Posible trouble with plugin as this feature is not preprocessed')

EndIf

CleanUp()

EndFunc

Func CheckTemporaryScriptForGlobalConstants()

Dim $tmp=@ScriptDir&'\Temp\Constants.txt',$in=@ScriptDir&'\Temp\TmpScript.txt',$out=@ScriptDir&'\Temp\TmpConstants.txt',$lines[9999]

$ID=FileOpen($tmp,0)

$IDI=FileOpen($in,0)

$chars=FileRead($IDI)

$IDO=FileOpen($out,10)

dim $a=1,$t=''

While 1

$Line=FileReadLine($ID)

If @error Then Exitloop

$wd=_GetWord($Line,3)

If StringLeft($wd,1)='$' Then

$a+=1

$lines[$a]=$line

If StringInStr($chars,$wd) Then

FileWriteLine($IDO,$Line)

GUICtrlCreateListViewItem($wd,$ConstC)

$t=$t&$wd

EndIf

EndIf

WEnd

$lines[0]=$a

FileClose($ID)

FileClose($IDI)

FileClose($IDO)

$IDO=FileOpen($out,0)

$tmpconst=FileRead($IDO)

FileClose($IDO)

$a=0

Do

$a+=1

$wd=_GetWord($Lines[$a],3)

If StringInStr($tmpconst,$wd)>0 AND StringInStr($t,$wd)=0 Then

$tmpconst=$lines[$a]&@CRLF&$tmpconst

$t=$t&$wd

$a=0

GUICtrlCreateListViewItem($wd,$ConstC)

EndIf

Until $a=$lines[0]

$IDO=FileOpen($out,2)

FileWrite($IDO,$tmpconst)

FileClose($IDO)

EndFunc

Func SampleMainAndSubFunctionsTemporary()

Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt',$out=@ScriptDir&'\Temp\TmpScript.txt'

$IDI=FileOpen($tmp,0)

$IDO=FileOpen($out,10)

$Funcs=FileRead($IDI)

FileWrite($IDO,$chars)

FileWriteLine($IDO,@CRLF&$ch&'; Preprocessed included functions...'&@CRLF&$ch)

FileWrite($IDO,$Funcs)

FileClose($IDI)

FileClose($IDO)

EndFunc

Func MakeDeepCheckForNewFunctions()

$tmp=@ScriptDir&'\Temp\TmpFunctions.txt'

If Fileexists($tmp) Then FileDelete($tmp)

Do

$tmpfunctionlist=_CountWords($UsedFunctionslist)

GetMainScriptUsedFunctions($Filein)

CheckForFuncInFunctions()

Until _CountWords($UsedFunctionslist)=$tmpfunctionlist

EndFunc

Func CheckForFuncInFunctions()

Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt'

$ID=FileOpen($tmp,0)

While 1

$Line=FileReadLine($ID)

If @error Then Exitloop

$wd=StringInStr($Line,' _'); check for blank character before

If $wd=0 Then

$wd=StringInStr($Line,'_'); check for Tab character before

ElseIf $wd=0 Then

$wd=StringInStr($Line,'=_'); check for non blank character before

EndIf

If $wd>4 then

$wd=_Getword(StringReplace(StringMid($line,$wd),'(',' '),1); get first word with change the ( character to blank character-then the function call is first word

If StringInStr($UsedFunctionslist,$wd)=0 Then; check for dubblets in database and if not pressent include into temporary database and file-tmpfunctions.txt

$UsedFunctionslist=$UsedFunctionslist&' '&$wd

GUICtrlCreateListViewItem($wd,$FuncC)

$IDO=FileOpen($tmp,9)

$IDI=FileOpen(@ScriptDir&'\Temp\'&$wd&'.au3',0)

$Funcs=FileRead($IDI)

FileWrite($IDO,$Funcs)

FileClose($IDI)

FileClose($IDO)

Endif

EndIf

WEnd

FileClose($ID)

EndFunc

Func GetMainScriptUsedFunctions($File)

Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt'

$ID=FileOpen($File,0)

IF $ID=-1 THEN Return

$chars=FileRead($ID)

FileClose($ID)

$NumOfFunctions=_CountWords($functionlist)

For $a=1 To $NumOfFunctions

$wd=_GetWord($functionlist,$a)

If StringInStr($chars,$wd)>0 Then

If StringInStr($UsedFunctionslist,$wd)=0 Then

$UsedFunctionslist=$UsedFunctionslist&' '&$wd

GUICtrlCreateListViewItem($wd,$FuncC)

$IDI=FileOpen(@ScriptDir&'\Temp\'&$wd&'.au3',0)

$IDO=FileOpen($tmp,9)

$Funcs=FileRead($IDI)

FileWrite($IDO,$Funcs)

FileClose($IDI)

FileClose($IDO)

EndIf

EndIf

Next

EndFunc

Func MakeFuncAvailableList()

Dim $NumIncludes=_CountWords($includelist),$sw=0

For $a=1 To $NumIncludes

$wd=_GetWord($includelist,$a)

$ID=FileOpen($Au3Path&'\Include\'&$wd,0)

While 1

$Line=FileReadLine($ID)

If @error Then Exitloop

If StringLower(StringLeft($Line,5))='func ' Then

$tmp=_Getword(StringReplace($Line,'(',' '),2)

$IDO=FileOpen(@ScriptDir&'\Temp\'&$tmp&'.au3',10)

FileWriteLine($IDO,$Line)

$functionlist=$functionlist&' '&$tmp

$sw=1

Elseif $sw=1 Then

FileWriteLine($IDO,$Line)

If StringLower(StringLeft($Line,7))='endfunc' Then

$sw=1

FileClose($IDO)

EndIf

EndIf

WEnd

FileClose($ID)

Next

EndFunc

Func GetIncludeList($File)

If StringInStr($File,'.au3')=0 then Return; check for filetype

$ID=FileOpen($File,0)

IF $ID=-1 THEN Return

GUICtrlSetData($LabelC,'Checking for include lines-Please wait...')

For $a=1 To 50

$Line=FileReadLine($ID)

If @error Then Exitloop

$pos=StringInStr($line,'#include')

If $pos>0 then

If StringInStr(StringLeft($Line,$Pos),$cc)=0 AND StringInStr($line,'-once')=0 Then

$tmp=StringReplace(StringReplace(StringReplace(StringReplace($line,"'",' '),'"',' '),'<',' '),'>',' ')

$tmp=_Getword(StringMid($tmp,$Pos+9),1)

If StringInStr($includelist,$tmp)=0 Then

$includelist=$includelist&' '&$tmp

EndIf

EndIf

EndIf

Next

FileClose($ID)

GUICtrlSetData($LabelC,'Done...')

Return

EndFunc

Func GetSubIncludes()

dim $NumIncludes=_CountWords($includelist),$a=0,$wd,$tmp=@ScriptDir&'\Temp\Constants.txt'

If Fileexists($tmp) Then FileDelete($tmp)

Do; Get all used includes also in sub scripts

$a+=1

$wd=_GetWord($includelist,$a)

GetIncludeList($Au3Path&'\Include\'&$wd)

$NumIncludes=_CountWords($includelist)

GUICtrlCreateListViewItem($wd,$listC); display all in the listview

_GUICtrlListViewSetCheckState($listC,$a-1,1); check them all

$ID=FileOpen($Au3Path&'\Include\'&$wd,0)

$IDO=FileOpen($tmp,9)

While 1

$Line=FileReadLine($ID)

If @error OR StringLower(StringLeft($Line,5))='func ' Then Exitloop

If StringInStr($line,'Global ')>0 then

FileWriteLine($IDO,$Line)

EndIf

WEnd

FileClose($ID)

FileClose($IDO)

Until $a=$NumIncludes

EndFunc

Func MainWin()

$Main=GuiCreate($title&' '&$Rev,620,305 ,$dm1[1],$dm1[2])

;GUISetIcon(@ScriptDir&"\Data\Default.ico",'',$Main)

$ListC=GUICtrlCreateListView('Checked Includes',0,0,150,280,-1,BitOr($LVS_EX_CHECKBOXES,$LVS_EX_GRIDLINES))

$FuncC=GUICtrlCreateListView('Builin Functions',150,0,150,280,-1,$LVS_EX_GRIDLINES)

$ConstC=GUICtrlCreateListView('Included Global Constants',300,0,150,280,-1,$LVS_EX_GRIDLINES)

GUICtrlCreateGroup('Special PreProcess Actions',460,5,152,178)

$RemCommBC=GUICtrlCreateCheckbox('Remove comment blocks',467,20,-1,-1)

$RemCommTC=GUICtrlCreateCheckbox('Remove trail comments',467,40,-1,-1)

$RemBlankC=GUICtrlCreateCheckbox('Remove multi blank chars',467,60,-1,-1)

$RemTabsC=GUICtrlCreateCheckbox('Remove Tab chars',467,80,-1,-1)

$RemLinesC=GUICtrlCreateCheckbox('Remove empty Lines',467,100,-1,-1)

$RemOpeC=GUICtrlCreateCheckbox('Remove around operators',467,120,-1,-1)

$DoCompC=GUICtrlCreateCheckbox('Auto Compile',467,160,-1,-1)

$LabelC=GUICtrlCreateInput('',0,284,620,20)

GUICtrlCreateGroup('MakeFile',460,185,72,94)

$WriteC=GUICtrlCreateButton('Write',465,205,60,20)

$ReloadC=GUICtrlCreateButton('ReLoad',465,230,60,20)

$RemoveC=GUICtrlCreateButton('Remove',465,255,60,20)

GUICtrlCreateGroup('Action',540,185,72,94)

$PreproC=GUICtrlCreateButton('Process',545,205,60,20)

$DoTestC=GUICtrlCreateButton('Run test',545,230,60,20)

$CompileC=GUICtrlCreateButton('Compile',545,255,60,20)

GUICtrlSendMsg($listC,0x101E,0,146)

GUICtrlSendMsg($ConstC,0x101E,0,146)

GUICtrlSendMsg($FuncC,0x101E,0,146)

GUICtrlSendMsg($ListC,0x14,0,2)

If $RemCommB=1 Then GuiCtrlSetState($RemCommBC,$GUI_CHECKED)

If $RemCommT=1 Then GuiCtrlSetState($RemCommTC,$GUI_CHECKED)

If $RemBlank=1 Then GuiCtrlSetState($RemBlankC,$GUI_CHECKED)

If $RemTabs=1 Then GuiCtrlSetState($RemTabsC,$GUI_CHECKED)

If $RemLines=1 Then GuiCtrlSetState($RemLinesC,$GUI_CHECKED)

If $RemOpe=1 Then GuiCtrlSetState($RemOpeC,$GUI_CHECKED)

If $DoComp=1 Then GuiCtrlSetState($DoCompC ,$GUI_CHECKED)

If $DoCheck=1 Then GuiCtrlSetState($DoCheckC ,$GUI_CHECKED)

GuiSetState()

TraySetIcon(@ScriptDir&"\Data\Default.ico",0)

TraySetToolTip('Au3PreProcess 1.8-The AutoIt3 script PreProcessor')

EndFunc

Func ReadPrefs($Prefs)

$var=RegRead($Prefs,"1")

If @error Then $var='182 234';Main: x y

$dm1=StringSplit($var," ")

$RemCommB=RegRead($Prefs,'RemCommB')

If @error Then $RemCommB='4'

$RemCommT=RegRead($Prefs,'RemCommT')

If @error Then $RemCommT='4'

$RemBlank=RegRead($Prefs,'RemBlank')

If @error Then $RemBlank='4'

$RemTabs=RegRead($Prefs,'RemTabs')

If @error Then $RemTabs='4'

$RemLines=RegRead($Prefs,'RemLines')

If @error Then $RemLines='4'

$RemOpe=RegRead($Prefs,'RemOperators')

If @error Then $RemOpe='4'

$RemPre=RegRead($Prefs,'RemPreprocess')

If @error Then $RemPre='4'

$DoComp=RegRead($Prefs,'DoCompile')

If @error Then $DoComp='4'

$DoCheck=RegRead($Prefs,'CheckSpecial')

If @error Then $DoCheck='4'

$inpath=RegRead($Prefs,'InFilePath')

If @error then $inpath=$Au3Path

EndFunc

Func WritePrefs($Prefs)

$tmp=WinGetPos($Main)

If $tmp[0]>0 Then

RegWrite($Prefs,'1','REG_SZ',$tmp[0]&' '&$tmp[1])

If @error Then MsgBox(48,"ERROR...","Save preferences failed")

RegWrite($Prefs,'RemCommB','REG_SZ',$RemCommB)

RegWrite($Prefs,'RemCommT','REG_SZ',$RemCommT)

RegWrite($Prefs,'RemBlank','REG_SZ',$RemBlank)

RegWrite($Prefs,'RemTabs','REG_SZ',$RemTabs)

RegWrite($Prefs,'RemLines','REG_SZ',$RemLines)

RegWrite($Prefs,'RemOperators','REG_SZ',$RemOpe)

RegWrite($Prefs,'CheckSpecial','REG_SZ',$DoCheck)

RegWrite($Prefs,'DoCompile','REG_SZ',$DoComp)

RegWrite($Prefs,'InFilePath','REG_SZ',$inpath)

EndIf

EndFunc

Func Exits()

WritePrefs($Prefs)

CleanUp()

Exit

EndFunc

Func CleanUp()

local $d=@ScriptDir&'\Temp'

If FileExists($d) Then

IF DirRemove($d,1) Then

GUICtrlSetData($LabelC,'Temporary files removed and Preprocessed file created...')

Else

GUICtrlSetData($LabelC,'ERROR-Failed to remove temporary files but the preprocessed file created...')

EndIf

EndIf

EndFunc

Func FileLoad($mess,$Path,$suff)

$var=FileOpenDialog($mess,$Path,$Suff,5)

If @error Then Return ''

Return StringReplace($var,"|",@CRLF)

EndFunc

Func _GUICtrlListViewSetCheckState($h_listview,$i_index,$i_check=1)

Local $struct="int;int;int;int;int;ptr;int;int;int;int;int;ptr",$ret

Local $p=DllStructCreate($struct)

If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)

DllStructSetData($p,1,$LVIF_STATE)

DllStructSetData($p,2,$i_index)

If ($i_check) Then

DllStructSetData($p,4,0x2000)

Else

DllStructSetData($p,4,0x1000)

EndIf

DllStructSetData($p,5,$LVIS_STATEIMAGEMASK)

If IsHWnd($h_listview) Then

Local $pIndex=DllStructGetPtr($p)

Local $iSize=DllStructGetSize($p)

Local $rMemMap

Local $pMemory=_MemInit ($h_listview,$iSize+4096,$rMemMap)

If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)

_MemWrite ($rMemMap,$pIndex)

If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)

$ret=_SendMessage ($h_listview,$LVM_SETITEMSTATE,$i_index,$pMemory)

If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)

_MemFree ($rMemMap)

If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)

Else

$ret=GUICtrlSendMsg($h_listview,$LVM_SETITEMSTATE,$i_index,DllStructGetPtr($p))

EndIf

Return $ret

EndFunc;==>_GUICtrlListViewSetCheckState

Func _GetWord($st,$no)

If NOT IsString($st) OR NOT IsInt($no) OR $no<1 Then

SetError(1)

Return ''

EndIf

$st=StringReplace(StringReplace(StringReplace($st,'',' '),' ',' '),' ',' ')

$len=StringLen($st)

FOR $a=1 TO $len

$b=StringMid($st,$a,1)

If $b<>' ' Then Exitloop

Next

$st=StringMid($st,$a)

$st=StringSplit($st,' ')

If $no>$st[0] Then return ''

Return $st[$no]

EndFunc

Func _CountWords($st)

If NOT IsString($st) Then

SetError(1)

Return ''

EndIf

$st=StringReplace(StringReplace(StringReplace($st,'',' '),' ',' '),' ',' ')

$len=StringLen($st)

FOR $a=1 TO $len

$b=StringMid($st,$a,1)

If $b<>' ' Then Exitloop

Next

For $b=$len TO 1 Step -1

$c=StringMid($st,$b,1)

If $c<>' ' Then Exitloop

Next

$st=StringSplit(StringMid($st,$a,$b-$a+1),' ')

Return $st[0]

EndFunc

Func _Say($st)

ConsoleWrite($st&@CR)

EndFunc

Func _MemInit($hWnd,$iSize,ByRef $rMemMap,$pAddress=0)

Local $iAccess,$iAllocation

Local $pMemory,$hProcess

Local $iProcessID

_GetWindowThreadProcessId($hWnd,$iProcessID)

$iAccess=BitOR($PROCESS_VM_OPERATION,$PROCESS_VM_READ,$PROCESS_VM_WRITE)

$hProcess=_OpenProcess($iAccess,False,$iProcessID)

Switch @OSVersion

Case "WIN_ME","WIN_98","WIN_95"

$iAllocation=BitOR($MEM_RESERVE,$MEM_COMMIT,$MEM_SHARED)

$pMemory=_VirtualAlloc($pAddress,$iSize,$iAllocation,$PAGE_READWRITE)

Case Else

$iAllocation=BitOR($MEM_RESERVE,$MEM_COMMIT)

$pMemory=_VirtualAllocEx($hProcess,$pAddress,$iSize,$iAllocation,$PAGE_READWRITE)

EndSwitch

If @error Then Return SetError(-1,-1,0)

$rMemMap=DllStructCreate($MEM_MAP)

DllStructSetData($rMemMap,$MEM_MAP_HPROC,$hProcess)

DllStructSetData($rMemMap,$MEM_MAP_ISIZE,$iSize)

DllStructSetData($rMemMap,$MEM_MAP_PMEM,$pMemory)

Return $pMemory

EndFunc;==>_MemInit

Func _SendMessage($h_hWnd,$i_msg,$wParam=0,$lParam=0,$i_r=0,$s_t1="int",$s_t2="int")

Local $a_ret=DllCall("user32.dll","long","SendMessage","hwnd",$h_hWnd,"int",$i_msg,$s_t1,$wParam,$s_t2,$lParam)

If @error Then Return SetError(@error,@extended,"")

If $i_r>=0 And $i_r<=4 Then Return $a_ret[$i_r]

Return $a_ret

EndFunc;==>_SendMessage

Func _GetWindowThreadProcessId($hWnd,ByRef $iProcessID)

Local $rProcessID,$aResult

$rProcessID=DllStructCreate("int")

$aResult=DllCall("User32.dll","int","GetWindowThreadProcessId","hwnd",$hWnd,"ptr",DllStructGetPtr($rProcessID))

If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)

$iProcessID=DllStructGetData($rProcessID,1)

Return $aResult[0]

EndFunc;==>_GetWindowThreadProcessId

Func _OpenProcess($iAccess,$bInherit,$iProcessID)

Local $aResult=DllCall("Kernel32.Dll","int","OpenProcess","int",$iAccess,"int",$bInherit,"int",$iProcessID)

If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)

Return $aResult[0]

EndFunc;==>_OpenProcess

Func _VirtualAlloc($pAddress,$iSize,$iAllocation,$iProtect)

Local $aResult=DllCall("Kernel32.dll","ptr","VirtualAlloc","ptr",$pAddress,"int",$iSize,"int",$iAllocation,"int",$iProtect)

If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)

Return $aResult[0]

EndFunc;==>_VirtualAlloc

Func _VirtualAllocEx($hProcess,$pAddress,$iSize,$iAllocation,$iProtect)

Local $aResult=DllCall("Kernel32.dll","ptr","VirtualAllocEx","int",$hProcess,"ptr",$pAddress,"int",$iSize,"int",$iAllocation,"int",$iProtect)

If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)

Return $aResult[0]

EndFunc;==>_VirtualAllocEx

Happy new year

kjactive :P

Edited by jpm
Link to comment
Share on other sites

Difficult to read your message with a so long code

Ohh that's why the text did that ord thing - but I couldn't find the edit script gadget that used to be located at the buttom...

_memWrite _memread are missing

What do you mean - in my script or another test script...

About Cleanscript well in my case it didn't do anything than clean a testing script from 22Kb into a masive 205Kb while Au3PreProcess sampled the script, nessesary udf functions and only the Constants needed into an independed script at 19,5Kb - well I program applications because it's fun and

do not care if anything is written before - anyway...

kjactive

Edited by kjactive
Link to comment
Share on other sites

Ohh that's why the text did that ord thing - but I couldn't find the edit script gadget that used to be located at the buttom...

What do you mean - in my script or another test script...

About Cleanscript well in my case it didn't do anything than clean a testing script from 22Kb into a masive 205Kb while Au3PreProcess sampled the script, nessesary udf functions and only the Constants needed into an independed script at 19,5Kb - well I program applications because it's fun and

do not care if anything is written before - anyway...

kjactive

You don't need any script gadget just upload your file with the upload button just below the message writing area.

Yes your posted script is missing the mentioned functions.

Happy new year :P

Link to comment
Share on other sites

About Cleanscript well in my case it didn't do anything than clean a testing script from 22Kb into a masive 205Kb while Au3PreProcess sampled the script, nessesary udf functions and only the Constants needed into an independed script at 19,5Kb - well I program applications because it's fun and

do not care if anything is written before - anyway...

kjactive

kjactive no offense I wan't to help you at least with some ideas. I'm using CleanScript and it works very well for me. My output EXEs are noticable smaller, mostly when using huge standard GUI include files.

Link to comment
Share on other sites

  • Developers

.... My output EXEs are noticable smaller, mostly when using huge standard GUI include files.

Can you give an example of how much that is ? (just curious ) :P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You are absolute right JPM, _MemRead etc. were missing - actually a lot of functions and constants variables were missing

but no more I hope - thanks for the report...

I would like to get bugs reports as it's a totally rewrite of one of my oldiest, I packed it into a .zip archive with execute and the

PreProcessed script, both now functional without the include directory available - all functions and constants totally buildin...

Regarding CleanScript v/ Au3PreProcessor - I did a testing script, PreProcessed and compiled both scripts, result Cleanscript wrapped

a 242Kb file, Au3PreProcess 201Kb ( 20% diff. ), the testing script without any PreProcess made compiled 243Kb - same PreProcess test

but unwrapped into a execute file, Cleanscript 211Kb, Au3PreProcess 29Kb

Please read the readme file first...

kjactive :">

Edited by kjactive
Link to comment
Share on other sites

Nice tool! I've been putting off writing something like this hoping....

I tried on a couple of scripts and I did find a bug.

Au3Preprocess is failing to get variables out of <Constants.au3>. I put together a little test script to demonstrate.

#include <GUIConstants.au3>
#include <Constants.au3>
Global $pid;
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Au3PreProcess test.", 622, 455, 257, 111)
GUISetOnEvent(-3,"Quit")
GUICtrlCreateLabel("Process to launch.", 10, 8, 92, 17)
$Process = GUICtrlCreateInput("", 8, 32, 545, 21, -1, $WS_EX_CLIENTEDGE)
$Browse = GUICtrlCreateButton("...", 568, 32, 41, 25)
GUICtrlSetOnEvent(-1,"Browse")
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Output = GUICtrlCreateEdit("", 8, 64, 601, 337, $ES_READONLY, $WS_EX_CLIENTEDGE)
GUICtrlSetData($Output, "")
GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
$Launch = GUICtrlCreateButton("Launch", 496, 416, 49, 25)
GUICtrlSetOnEvent(-1,"Launch")
$Kill = GUICtrlCreateButton("Kill", 560, 416, 49, 25)
GUICtrlSetOnEvent(-1,"Kill")
GUISetState(@SW_SHOW)
While 1
    Sleep(1000)
WEnd
Exit
Func Quit()
    Exit
EndFunc
Func Browse()
    Local $temp = FileOpenDialog("Choose Exe or script",@ScriptDir,"Exec(*.exe;*.au3)")
    
    if Not(@error) then GuiCtrlSetData($Process,$temp)
EndFunc
Func Launch()
    Local $file =GuiCtrlRead($Process)
    if FileExists($file) Then
        if Not(StringInStr(FileGetAttrib($file),"D")) Then
            DetailsOut($file,1)
            GuiCtrlSetState($Kill,$GUI_ENABLE)
            $pid = Run('"'&$file&'"',@ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            DetailsOut("PID ="&$pid,1)
            Local $line
            GUICtrlSetState($Output,$GUI_ENABLE)
            While 1
                $line = StdoutRead ($pid)
                If @error Then ExitLoop
                DetailsOut($line)
            WEnd
            While 1
                $line = StderrRead ($pid)
                If @error Then ExitLoop
                DetailsOut($line)
            WEnd
            DetailsOut("Done.")
            ProcessClose($pid)
        EndIf
    EndIf
    GuiCtrlSetState($Kill,$GUI_DISABLE)
EndFunc
Func Kill()
    if $pid then ProcessClose($pid)
EndFunc
Func DetailsOut($msg,$crlf =0,$append=1)
    if $crlf Then $msg = $msg&@CRLF
    GUICtrlSetData($Output, $msg,$append )
EndFunc   ;==>DetailsOut

$STDERR_CHILD , $STDOUT_CHILD are not added to the processed script. Also Constants.au3 doesn't show in the Listview either.

One last item; The _CloseHandle() func is missing from script in the download.

Looking forward to an update.

eltorro.

Link to comment
Share on other sites

Well I found the trouble about Au3PreProcess not being able to include the contants.au3 as eltorro reported - simple actually as the scan process exclude dubblet calls and in that process it had already included GuiConstants.au3 and when it made a search for Constants.au3 it was already included well now hopefully fixed...

another thing reported was that special line broken constants in IE.au3 was falty as only the first part was included, fixed as these constants

now get rewired into one line before included...

One thing more that I discovered was that some special constants that had a ';' inside was treated as a trailing comment and failed - fixed...

the report from eltorro showed me that FileOpenDialog("Choose Exe or script",@ScriptDir,"Exec(*.exe;*.au3)") was also falty as treated as a comment in the suffix - fixed...

eltorro - I do not get what you mean about

The _CloseHandle() func is missing from script in the download

is it my script that miss the function or what - could you please explane this a little closer...

Keep up reporting as I would like to finish the 'makefile functions to do a fast PreProcess' and the 'pass PreProcessed script to the compile process' as it's a very complexed script involving a lot of actions and I do want to remove as many bugs as posible to keep things as simple as posible before moving on...

Included in archive is PreProcessed script, Au3PreProcess as execute, a readme text and nessesary graphics...

Download application from site: http://www.sitecenter.dk/latenight/nss-fol...t%20Manager.zip

kjactive :P

Edited by kjactive
Link to comment
Share on other sites

Can you give an example of how much that is ? (just curious ) :P

For example: Size of output UPX'ed EXE of my latest version of Log_View: 271KB --> 226 KB (CleanScript)

EDIT: Uncompressed EXE size: 487 KB --> 442 KB

Note: EXE contains my own 15KB uncompressed icons as resources

Edited by Zedna
Link to comment
Share on other sites

This topics is about my rewired Au3PreProcess application and I think that the Cleanscript stuff is mallplaced in this topics - could be in another topics please as this topics is not ment as a competition and a sepparate would serve both programs just as well...

kjactive :P

Edited by kjactive
Link to comment
Share on other sites

Yes, it *was* missing in the version of the script I download. It is used in _MemFree. It is a non-issue now with your latest release.

eltorro.

Link to comment
Share on other sites

Well the _CloseHandle function in memory.au3 was still missing as Au3PreProcess was only doing a deep scan on Functions that was attached to a variable - no more, the deep scan on related functions is rewired and seems okay now...

Au3PreProcess can now handle the special broken constants in IE.au3...

Please report bugs and make comments...

Download latest revision from site http://www.sitecenter.dk/latenight/nss-fol...t%20Manager.zip

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

Awesome Job!

Would it be possible to add 2 options?

-- remove *all* comments.

-- Preserve formatting (Indentation). Probably shell to tidy.

I don't know if this is a bug or by design, but Au3Preprocess skip files that are not in the "include" dirs but are included in the main script. Also it removes the #include statement making the script not compile.

See below:

Save both files in the same dir then run au3Preprocess.

;testfile.au3
#include <GuiConstants.au3>
#Include "someotherfile.au3" ; contains the variable const $Caption.
$Form1 = GUICreate("MyForm")
$label1 = GUICtrlCreateLabel($Caption,8,8)
GUISetState()
$timer=TimerInit()

Do
If TimerDiff($timer) >10000 Then ExitLoop
Sleep(10)
Until(GuiGetMsg() = $GUI_EVENT_CLOSE)
ExitoÝ÷ Ù«­¢+Øíͽµ½Ñ¡É¥±¹ÔÌ(%¹±Õµ½¹)±½°
½¹ÍÐÀÌØí
ÁÑ¥½¸ôÅÕ½Ðí!±±¼ÔÌAɽɵµÈÅÕ½Ðì(oÝ÷ Ù§)à¶èº@»sëzèqë,¢¶®¶­sc²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ²S5&W&ö6W72ã&W&ö6W76VBÒFFR££#rFÖRC£C£²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФvÆö&Â6öç7Bb33c´uTôUdTåEô4Äõ4RÒÓ0¢b33c´f÷&ÓÒuT7&VFRgV÷C´×f÷&ÒgV÷C²¢b33c¶Æ&VÃÒuT7G&Ä7&VFTÆ&VÂb33c´6FöâÃäuT6WE7FFR¢b33c·FÖW#ÕFÖW$æB¤Fð¤bFÖW$Ffbb33c·FÖW"fwC³FVâWDÆö÷¥6ÆVW¥VçFÂwVvWD×6rÒb33c´uTôUdTåEô4Äõ4R¤W@£²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ²&W&ö6W76VBæ6ÇVFVBgVæ7Föç2ââࣲÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÐ

Hope this helps. :)

Edited by eltorro
Link to comment
Share on other sites

Thanks for suggestens eltorro

-- remove *all* comments.

Au3PreProcess do remove all comments just related to two parametre 'Remove block / trailing comments' and the reason for this is the typeless autoit3 design, It would not come that handy as some buildin functions like fileopenrequest use the comments character as a sepparator, the same does some special structure related globals...

-- Preserve formatting (Indentation). Probably shell to tidy.

Could you explane this idear a little forther please - an example maybe...

skip files that are not in the "include" dirs

Yes that's true - I didn't thought that this was nessesary but the search could easy be included and I'll do that in next update...

Thanks eltorry for your effort and nice examples...

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

Well I changed the directory scan for included includes like eltorro suggested - if the include directory scan fails then search local path and I included a messagebox failure if the scan for included UDF's fail compleatly...

download latest revision from site: http://www.sitecenter.dk/latenight/nss-fol...t%20Manager.zip

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

Yes I can see, but what did the attached functions & variable lists said - was the Global variable attached or not, this is displayed in this window lists BUT I just discovered that I had removed a function that could ruin the scan process, could misstreat on variables and put some special variables into functions 'is this a variable or function' check function - this is reattached, please download and try again...

Download from site: http://www.sitecenter.dk/latenight/nss-fol...t%20Manager.zip

Well it could also be that the contant in the UDF is sampled with BitOr - like

Global Const $GUI_SS_DEFAULT_COMBO = BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL)

I'll check into that one later today

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...