rem ScriptFormatter V1.4 rem V1.4 rem Added the following [Edited by Chris Gingerich (LiquidCode)]: rem - Updated script to VDS5 rem - Made to include # and elsif rem - Added multi script support. rem V1.3 rem Fixed the following issues: rem - Command names are now presented in lowercase. rem Known bugs: rem - If it's used as tool, sometimes it's not able to reopen the formatted script, sometimes only the open dialog appears. rem - Function names are not always presented in lowercase. rem V1.2 rem Fixed the following issues: rem - The dialog declaration is formatted as it should considering the VDS syntax. DIALOG ADD commands are no longer indented to the right in the declaration. rem Known bugs: rem - If it's used as tool, sometimes it's not able to reopen the formatted script, sometimes only the open dialog appears. rem V1.1 rem Fixed the following issues: rem - If a DIALOG SHOW command was used in V1.0, that doesn't belong to the dialog declaration, the formatting went wrong. rem - If a LIST LOADTEXT command was used in V1.0, the formatting went wrong, because the lines starting with " were formatted to the right too. rem Known bugs: rem - If a conditional DIALOG SHOW command is used, that belongs to the dialog declaration, or the DIALOG SHOW command that should be at the end of the dialog declaration is ommited, the formatting goes wrong. rem - If it's used as tool, sometimes it's not able to reopen the formatted script, sometimes only the open dialog appears. rem V1.0 rem First version rem This script is Copyright 1999 - 2001 Tommy Sools. With any questions, comments, ideas etc. you can mail me at: tommy@sools.com rem You are free to use, modify, improve and (re)distibute this script, rem in compiled or uncompiled form. rem Visual DialogScript 3 is Copyright 1998 - 2000 S.A.D.E. s.a.r.l. www.sade.net rem This script automatically (re)indents the lines of a script in a correct way. rem This could make it much easier to read someone else's code, in your prefered way. rem Be aware of it that any previous formatting will be LOST!!! rem Usage notes: rem - You can use this program, by just running ScriptFormatter.exe rem - You can use this program as tool, by compiling it and copying it in the Visual DialogScript\Tools directory. rem If you launch it as tool, the script that is open currently, is formatted. rem - It's advised to set the following variables to your prefered settings: #define command,Correct option decimalsep,. title ScriptFormatter # if %1 # goto correct # end DIALOG CREATE,ScriptFormatter,-1,0,410,184 REM *** Modified by Dialog Designer on 6/1/2006 - 13:58 *** DIALOG ADD,TEXT,tFilename,10,14,,,Select File[s]: DIALOG ADD,BUTTON,bBrowse,31,32,30,20,... DIALOG ADD,BUTTON,bFormat,71,7,85,24,Format Script[s],DEFAULT DIALOG ADD,LIST,L1,10,95,299,144 #dialog HIDE,tFormatting DIALOG ADD,STATUS,STAT,Ready... dialog SHOW :evloop wait event goto @event() :bBrowsebutton %a = @filedlg("Script Files (*.DSC)|*.DSC",Select Script File,,multi) if @ok() list assign,l1,%a #dialog set,eFilename,%A end goto evloop :bFormatbutton # if @not(@file(@dlgtext(eFilename))) # warn "The filename you entered doesn't exist,"@cr()"please enter a valid script filename." # goto evloop # end #dialog hide,tFilename #dialog hide,eFilename dialog disable,bBrowse dialog disable,bFormat #dialog show,tFormatting #dialog setpos,,,,,50 %x = 0 repeat dialog set,stat,Formatting... @name(@item(l1,%x)) correct @item(l1,%x) %x = @succ(%x) until @equal(%x,@count(l1)) goto close :correct rem %I is the number of spaces/tabs to indent %i = 2 rem %T is the character to use to indent ( usually " " or @tab() ) %t = " " repeat %f = %F%T until @equal(@len(%F),%I) list create,1 #if %1 list loadfile,1,%1 info @text(1) #else # list loadfile,1,@dlgtext(eFilename) #end %e = %F repeat %a = @trim(@item(1)) dialog set,stat,@item(1) rem Parse the line on a space if @zero(@pos(" ",%A)) %b = %A %c = else %b = @substr(%A,1,@pred(@pos(" ",%A))) %c = @substr(%A,@succ(@pos(" ",%A)),@len(%A)) end rem Now %B contains the command name and %C contains the parameters if @equal(%B,if)@equal(%B,repeat) %e = %E%F else if @equal(%B,end)@equal(%B,until) if @not(@equal(@trim(%C),1)) rem The check for the "1" is just to see if UNTIL 1 is used, rem to force the loop to end. rem It's a trick and in that case the number of REPEAT commands rem usually isn't equal to the number of UNTIL commands. %e = @strdel(%E,@diff(@len(%E),@pred(%I)),@len(%E)) end end end if @equal(%B,if)@equal(%B,else)@equal(%B,repeat)@equal(%b,elsif) list put,1,@strdel(%E,@diff(@len(%E),@pred(%I)),@len(%E))@lower(%B) %C else if @equal(@substr(%A,1,1),":")@equal(@substr(%A,1,1),@chr(34))@equal(@substr(%A,1,1),"#") list put,1,%A else if @not(%A) rem If the line is empty, it won't be indented list put,1 else list put,1,%E@lower(%B) %C end end end rem %D is a dummy variable, to let the list pointer go to the next line %d = @next(1) until @equal(@index(1),@count(1)) #if %1 list savefile,1,%1 #else # list savefile,1,@dlgtext(eFilename) #end list close,1 #if %1 # window send,#TMainWin,@ctrl(O) rem Give the open dialog time to popup # wait 0.5 # window send,@winactive(),@alt(O) #end exit :close exit