forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Script Formatter

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Source Code
View previous topic :: View next topic  
Author Message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1711
Location: Space and Time

PostPosted: Sat May 14, 2011 7:42 pm    Post subject: Script Formatter Reply with quote

I took this out of my box and revised it to work with VDS 6. This will format a VDS script adding spaces to indent lines as needed. Works great! Smile

Enjoy!

Code:


  rem ScriptFormatter V2.0
  # Original code by Tommy Sools updated by Chris Gingerich
  # Added code for ElsIf
 
  rem ScriptFormatter V1.3
  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:

  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 = " "

  option decimalsep,.
  repeat
    %f = %F%T
  until @equal(@len(%F),%I)
  title ScriptFormatter
  if %1
    goto correct
  end
  dialog CREATE,ScriptFormatter,-1,0,400,75
  dialog ADD,TEXT,tFilename,10,10,,,Filename:
  dialog ADD,EDIT,eFilename,8,80,275,19
  dialog ADD,BUTTON,bBrowse,8,360,30,20,...
  dialog ADD,BUTTON,bFormat,40,10,80,24,Format Script,DEFAULT
  dialog ADD,TEXT,tFormatting,10,10,,,The script is being formatted...@cr()Please be patient.
  dialog HIDE,tFormatting
  dialog SHOW
:evloop
  wait event
  goto @event()
:bBrowsebutton
  %a = @filedlg("Script Files (*.DSC)|*.DSC",Select Script File)
  if %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 hide,bBrowse
  dialog hide,bFormat
  dialog show,tFormatting
  dialog setpos,,,,,50
  goto correct
:correct
  list create,1
  if %1
    list loadfile,1,%1
  else
    list loadfile,1,@dlgtext(eFilename)
  end
  %e = %F
  repeat
    %a = @trim(@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)@equal(%B,while)
      %e = %E%F
    else
      if @equal(%B,end)@equal(%B,until)@equal(%B,wend)
        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,elsif)@equal(%B,else)@equal(%B,repeat)
      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))
        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
  goto close
:close
  exit

_________________
Chris
Http://vdsfreak.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 5 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group