Jump to content
Sign in to follow this  
peethebee

CleanScript

Recommended Posts

What does #Region #Endregion do, it seems like it is not documented ?

#Region, #EndRegion are code folding entries that can be added in some of today's coding editors and IDE's that support it. As for documentation, then that would depend on the developer of that editor to inform it's users of the feature.

#region
; some code
; some more code
#endregion

If the feature is supported by your editor, then the above should be able to fold in a style similar to a treeview can fold it's branches. Regioning your scripts make a lot of code easier to browse.

:)

Edit:

Corrected code example

Edited by MHz

Share this post


Link to post
Share on other sites

@peethebee and @Markus

I'm about to try out your little tool. Have you done anything to scite (or other editor) to include your tool in a work - compile cycle? I'm using Sicte4AutoIt. Say you hit F7. Your tool makes the script passes it on to AU3Wrapper (I'm a big fan of that tool :P ) And I get the finished exe/a3x?

Just curious, thanks for your effort and good work :)

Share this post


Link to post
Share on other sites

Hi!

Thanks for your input guys! I have to say that most of the code ist from Markus - I just gave the idea and we did the first steps together...

@Azu: Thanks - we just want to give back what AutoIt gave us - for free!

@The Kandie Man: Thanks for your appreciation! I think the version in that post is not the most recent one. Markus could provide us with this one soon I think. I will ask him to do so in this thread.

The removement of #Region statements should be not too hard to imlement. We did not yet promote including into AutoIt because we still need some more input like yours - otherwise everybody would complain if it has a bug and is currupting user's scripts. If we get it to work correctly, we will implement easier ways to use it.

Do you have information on the speed of your and our script? Ours *should* be much faster as it is coded in C++ and Markus optimized it quite well, I saw.

@Uten: As I wrote @The Kandie Man above we will do that as soon as it works as good as possible. It will probably work in the wa you suggest.

Thanks again for your input, guys!

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

I'm about to try out your little tool. Have you done anything to scite (or other editor) to include your tool in a work - compile cycle? I'm using Sicte4AutoIt. Say you hit F7. Your tool makes the script passes it on to AU3Wrapper (I'm a big fan of that tool :) ) And I get the finished exe/a3x?

This can be done for example by using Scite compiler directive:

#Compiler_Run_Before = CleanScript "%in%"

It can be as default value - for all script or only for desired scripts in their headers.

Share this post


Link to post
Share on other sites

Hi!

First, thanks for your great feedback.

[iMPORTANT]I just noticed something about your cleanscript.exe. I am well aware that it isn't a virus, however, Norton Antivirus freaks out when your cleanscript.exe is placed in the temporary folder. I am not sure why because it doesn't flip if it is in any other folder, it just freaks when it sees that it is in the temporary folder...

Yeah, that's strange! Can't guess, how Norton detects CleanScript as a virus...

One suggestion.

I use #Region and #EndRegion but would like these to be cleaned also...

Shouldn't be a problem to remove those lines, it will be added in the next version.

The first time I tried it, I named an output file in the "Destination path:" and again it did not produce any output script...

Hm try it again with the new version, please.

I'm about to try out your little tool. Have you done anything to scite (or other editor) to include your tool in a work - compile cycle? I'm using Sicte4AutoIt. Say you hit F7. Your tool makes the script passes it on to AU3Wrapper (I'm a big fan of that tool smile.gif ) And I get the finished exe/a3x?

When it's bugfree, it would be nice, if it would be added to scite^^

Here's also the newest version with some improvements, a larger statistic at the end and a total change of the script structure. So far CleanScript was one long sourcefile and nearly impossible to read, now all the functions are included in the "autoitsourcefile class" in the headerfile. For those, who are interested in the C++ source, it should be easier to understand now. And of course I made the output 100% english.

EDIT: removed file

Edited by Markus

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

I tried your CleanScript today on my nearly 4000 lines of code and it doesnt looks like it was "cleaned". I ran the gui's exe and put in the source script and destination script as cleaned.au3...

Checked remove unused functions with Runs 3 times

Checked remove unused Consts and Vars

and Checked show full output

clicked start button and saw the dos prompt came up and did the cleaning (thats what it looked like, it was quick before prompt window disappeared)

original script bytes: 150KB

cleaned script bytes: 193KB

It didnt strip away comments, or unused functions, consts & vars.

I ran Winmerge to did the comparison and they both looked the same except CleanScript added some vars and functions from #include scripts, thats it.

Is there something wrong here?

Share this post


Link to post
Share on other sites

Ok I found out where CleanScript went wrong. Something had to do with checked removed unused consts and vars option.

I had to edit CleanScript GUI.au3 to get the full commandline info when "cleaning" the script and I ran CMD in prompt and excuted the command manually (so dos prompt wont disappeared to see what was the last known cleaning line was before it puked)

It seems to me it puked on deleting the line where it has "Global Enum _" (with underscore symbol) in it

IE3.au3 has those Global Enum so you might want to check it out and update the Cleanscript.

Edited by Blackstar

Share this post


Link to post
Share on other sites

Good work again!

I was searching on the forum wondering if someone have had the same idea, before implementing it. And was a surprise... Find again peethebee as a coauthor. I'll give it a try, and congratulations for the good work @Markus & @peethebee.

edit:

Please put the download link with the latest version more prominently... thanks

Edited by Qsr Nrwn

Rev 127 Et factum et prælium magnum in cælo: Michaël et angeli ejus præliabantur cum dracone, et draco pugnabat, et angeli ejus: 8 et non valuerant, neque locus inventus est eorum amplius in cælo.9 Et projectus est draco ille magnus, serpens antiquus, qui vocatur diabolus, et Satanas, qui seducit universum orbem: et projectus est in terram, et angeli ejus cum illo missi sunt.

Share this post


Link to post
Share on other sites

Ok I found out where CleanScript went wrong. Something had to do with checked removed unused consts and vars option...

Thank you very much, it would have been hard work to find that.

And you're right, the problem was the Enum. I haven't handled that. In the future "cleanscript" will ignore lines including Enum.

Of course it would be possible to delete vars even in those lines, but as the other vars in that line will get other numbers, when one var is missing, there will be ugly bugs, so i think it's the best to ignore such lines. (Other ideas?)

The underscore symbol is no problem, as the functions use transformated forms of the lines, where the underscore isn't existing and the following line after the underscore is added to the upper line.

Please put the download link with the latest version more prominently... thanks

Right. We'll have the latest version in the latest post from now on.

EDIT: Added latest version.

CleanScript.zip

Edited by Markus

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

I worked a little on the GUI front end.

Most notably, the output is captured and displayed in the gui.

secondly, Disabled the start button for invalid filenames.

#cs ----------------------------------------------------------------------------
    AutoIt Version: 3.1.1.133
    Author: peethebee, eltorro
    Markus
    Script Function:
    Provides a GUI for CleanScriptClass.exe
#ce ----------------------------------------------------------------------------
if not(@Compiled) Then
    MsgBox(266288,"CleanScript","StdOut/StdErr read will crash uncompiled scripts."&@LF& _
                        "Please compile this script before executing it.")
Exit
EndIf
Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
Global Const $GUI_CHECKED = 1
Global Const $GUI_ENABLE = 64
Global Const $GUI_DISABLE = 128
Global Const $WS_HSCROLL = 0x00100000
Global Const $WS_VSCROLL = 0x00200000
Global Const $WS_EX_CLIENTEDGE = 0x00000200
Global Const $ES_MULTILINE = 4
Global Const $ES_AUTOVSCROLL = 64
Global Const $ES_AUTOHSCROLL = 128
Global Const $ES_READONLY = 2048
Global Const $ES_WANTRETURN = 4096
Global Const $STDOUT_CHILD    = 2
Global Const $STDERR_CHILD    = 4

Opt("GUIOnEventMode", 1)
$gui = GUICreate("CleanScript GUI 1.0 - by peethebee & Markus, 2006", 700, 500)
GUISetOnEvent(-3, "quit")
GUICtrlCreateLabel("Source path:", 16, 8, 150, 17)
$input_src = GUICtrlCreateInput("", 16, 25, 577, 21, -1, $WS_EX_CLIENTEDGE)
$button_src = GUICtrlCreateButton("...", 608, 25, 51, 25)
GuiCtrlSetOnEvent(-1, "src")
GUICtrlCreateLabel("Destination path:", 16, 56, 150, 20)
$input_dest = GUICtrlCreateInput("", 16, 72, 577, 21, -1, $WS_EX_CLIENTEDGE)
$button_dest = GUICtrlCreateButton("...", 608, 72, 51, 25)
GuiCtrlSetOnEvent(-1, "dest")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Options", 16, 104, 665, 345)
GUICtrlSetColor(-1, 0x0000FF)
$opt1 = GUICtrlCreateCheckbox("Remove Comments", 32, 128, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetState(-1, $GUI_DISABLE)
$opt2 = GUICtrlCreateCheckbox("Remove unused functions", 32, 152, 153, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$opt3 = GUICtrlCreateCheckbox("Remove unused Const and Vars", 32, 176, 177, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$opt_incl = GUICtrlCreateCheckbox("Use Beta includes", 272, 128, 121, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$opt_cout = GUICtrlCreateCheckbox("Show full output", 272, 152, 97, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Runs", 272, 176, 29, 17)
$input_nr = GUICtrlCreateInput("2", 304, 176, 41, 17, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateUpdown(-1)
GUICtrlSetLimit(-1, 9, 1)
$Output = GUICtrlCreateEdit("", 32, 208, 633, 229, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE), $WS_EX_CLIENTEDGE)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x0000000)
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$button_start = GUICtrlCreateButton("Start", 616, 464, 75, 25)
GuiCtrlSetOnEvent(-1, "start")
GUICtrlSetState(-1, 128)
GUISetState(@SW_SHOW)

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x0300
GUIRegisterMsg ($WM_COMMAND, "WM_COMMAND")

While 1
    Sleep(100)
    if GUICtrlRead($Output)= "" Then
        if BitAND(GUICtrlGetState($Output),$GUI_ENABLE)= $GUI_ENABLE Then
            GuiSetState($Output,$GUI_DISABLE)
        EndIf
    Else
        if BitAND(GUICtrlGetState($Output),$GUI_DISABLE)= $GUI_DISABLE Then
            GuiSetState($Output,$GUI_ENABLE)
        EndIf
    EndIf
WEnd
Func quit()
    Exit
EndFunc   ;==>quit

Func src()
    $path = FileOpenDialog("Select source file", @ScriptDir, "AutoIt v3 scripts (*.au3)", 1 + 2)
    If Not @error Then
        GUICtrlSetData($input_src, $path)
        GuiCtrlSetData($Output,"")
    EndIf
EndFunc   ;==>src

Func dest()
    $path = FileOpenDialog("Select destination file", @ScriptDir, "AutoIt v3 scripts (*.au3)|All files (*.*)")
    If Not @error Then
        GUICtrlSetData($input_dest, $path)
       GuiCtrlSetData($Output,"")
    EndIf
EndFunc   ;==>dest

Func start()
    GUICtrlSetState($button_start, 128)
    ; src
    If GUICtrlRead($input_src) <> "" Then
        $input_src_str = '"' & GUICtrlRead($input_src) & '"'
        ;MsgBox(0,"",$input_src_str)
    Else
        MsgBox(16 + 8192, "Error", "No source file specified...")
        GUICtrlSetState($button_start, 64)
        Return -1
    EndIf
    ; dest
    If GUICtrlRead($input_dest) <> "" Then
        $input_dest_str = '"' & GUICtrlRead($input_dest) & '"'
    Else
        $input_dest_str = '"' & StringTrimRight(GUICtrlRead($input_src), 4) & '_clean.au3"'
        ;MsgBox(0,"",$input_dest_str)
    EndIf
    ; options
    $param_str = ""
    If GUICtrlRead($opt1) = 1 Then
        $param_str &= "C"
    Else
        $param_str &= "-"
    EndIf
    If GUICtrlRead($opt2) = 1 Then
        $param_str &= "F"
    Else
        $param_str &= "-"
    EndIf
    If GUICtrlRead($opt3) = 1 Then
        $param_str &= "G"
    Else
        $param_str &= "-"
    EndIf
    If GUICtrlRead($opt_cout) = 1 Then
        $cout_str = "C"
    Else
        $cout_str = "-"
    EndIf
    ; include path
    If GUICtrlRead($opt_incl) = 1 Then
        $incl_dir_str = '"' & RegRead("HKLM\Software\AutoIt v3\AutoIt", "betaInstallDir") & "\Include" & '"'
    Else
        $incl_dir_str = '"' & RegRead("HKLM\Software\AutoIt v3\AutoIt", "InstallDir") & "\Include" & '"'
    EndIf
    ; path
    $parts = StringSplit($input_src_str, "\")
    $script_path = ""
    For $i = 1 To $parts[0] - 1
        $script_path = $script_path & $parts[$i] & "\"
    Next
    $script_path = StringTrimRight($script_path, 1) & '"'
    ;MsgBox(0,"",'"' & @ScriptDir & '\CleanScriptClass.exe" ' & $input_src_str & " " & $param_str & " " & $input_dest_str & " " & $incl_dir_str & " " & $script_path & " " & GUICtrlRead($input_nr) & " " & $do_cout)
    ; start C++ program
    GuiCtrlSetData($Output,"")
    DetailsOut("Process Command:",1)
    Local $cmd = '"' & @ScriptDir & '\CleanScriptClass.exe" ' & $input_src_str & " " & $input_dest_str & " " & $script_path & " " & $incl_dir_str & " " & $param_str & " " & GUICtrlRead($input_nr) & " " & $cout_str
    DetailsOut($cmd,1)
    Local $pid = Run($cmd, @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
    ProcessClose($pid)
    ClipPut($input_src_str & " " & $input_dest_str & " " & $script_path & " " & $incl_dir_str & " " & $param_str & " " & GUICtrlRead($input_nr) & " " & $cout_str)
    ;RunWait(@ScriptDir & "\CleanScript.exe")
    GUICtrlSetState($button_start, 64)
EndFunc   ;==>start

Func DetailsOut($msg,$crlf =0,$append=1)
    ;MsgBox(266288,"",$msg)
    if $crlf Then $msg = $msg&@CRLF
    GUICtrlSetData($Output, $msg,$append )
EndFunc   ;==>DetailsOut

Func _IsAu3File($sFile)
    Local $bValid = False
    $sFile = StringStripWS($sFile, 3)
    If $sFile <> "" Then
        if (FileExists($sFile)) Then
            If Not (StringInStr(FileGetAttrib($sFile), "D")) Then
                If StringRight($sFile, 3) = "au3" Then $bValid = True
            EndIf
        Else
            If StringRight($sFile, 3) = "au3" Then $bValid = True
        EndIf
    EndIf
    Return $bValid
EndFunc   ;==>_IsAu3File

Func _ValidatePath()
    Local $src = GUICtrlRead($input_src)
    Local $dest = GUICtrlRead($input_dest)
    if (_IsAu3File($src) = True) and ($dest = "" or (_IsAu3File($dest) = True)) Then
        GUICtrlSetState($button_start, $GUI_ENABLE)
    Else
        GUICtrlSetState($button_start, $GUI_DISABLE)
    EndIf
EndFunc   ;==>_ValidatePath

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $input_dest Or $nID = $input_src Then
        If $nNotifyCode = $EN_CHANGE Then _ValidatePath()
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Screenshot:

post-7045-1168170670_thumb.jpg

eltorro

Share this post


Link to post
Share on other sites

I'm using CleanScript - it's great.

But now with new AutoIt release 3.2.2 it's not working.

I have instaled 3.2.2.0 and 3.2.1.14 beta and Scite4Autoit3.

When I check "use beta includes" it generates script without any includes with cleaning only my script (all includes are missing).

When I uncheck "use beta includes" it generates script with all it's includes without cleaning.

Share this post


Link to post
Share on other sites

I'm using CleanScript - it's great.

But now with new AutoIt release 3.2.2 it's not working.

I have instaled 3.2.2.0 and 3.2.1.14 beta and Scite4Autoit3.

When I check "use beta includes" it generates script without any includes with cleaning only my script (all includes are missing).

When I uncheck "use beta includes" it generates script with all it's includes without cleaning.

hmmm, it added 122 lines to my coding :S


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

hmmm, it added 122 lines to my coding :S

It's very old topic.

I used Project manager later.

But now with AutoIt 3.2.10 and New Scite4AutoIt3 I use Obfuscator with /striponly option which does the same job as CleanScript/Project manager.

Just add these directives to top of your script:

#AutoIt3Wrapper_run_obfuscator=y
#Obfuscator_parameters=/so
Edited by Zedna

Share this post


Link to post
Share on other sites

Hallo Zedna

Just for clarification, the Project Manager is basic not a cleanup script application but a scripting preprocessor as globals get written into the spots used, operators tighten up, strings into variabels and #include functions not used removed ec.

kjactive :D

Edited by kjactive

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...