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 


Variable analizer

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Wed Jul 31, 2002 7:40 pm    Post subject: Variable analizer Reply with quote

I'm not sure if anyone will find this useful or not but it's helped me alot.
If you have some large apps that use a lot of variables in VDS, you
might find this code useful. It was originally designed by Mac to list vars
used. It will now show how many times and where each var is used as
well as the line number and value assigned to it.

Sorry for the plagiarism Mac Very Happy

Hope someone finds it useful,

moke

Code:

OPTION SCALE, 96
  TITLE By Mac/Moke
  DIALOG CREATE,Variable Analizer,-1,0,575,534
  DIALOG ADD,BUTTON,Load,5,5,120,20,"Load DSC File"
  DIALOG ADD,BUTTON,Copy,5,135,120,20,"Append to Clipboard"
  DIALOG ADD,LIST,L1,60,4,286,152,click
  DIALOG ADD,STATUS,Stat, "Ready..."
  DIALOG ADD,TEXT,TEXT1,44,6,,,Var List
  DIALOG ADD,LIST,L2,252,4,286,200,click
  DIALOG ADD,TEXT,TEXT2,235,9,,,Vars appearance by line number
  DIALOG ADD,LIST,L3,59,318,248,155,click
  DIALOG ADD,TEXT,TEXT3,41,321,,,Number of times var is used
  DIALOG ADD,LIST,L4,254,318,249,198,click
  DIALOG ADD,TEXT,TEXT4,238,320,,,Variable values
  DIALOG ADD,TEXT,TEXT5,462,4,,,
  DIALOG ADD,TEXT,TEXT6,489,4,,,
  DIALOG ADD,BUTTON,L1SAVE,36,64,49,20,SAVE
  DIALOG ADD,BUTTON,L3SAVE,36,465,49,20,SAVE
  DIALOG ADD,BUTTON,L2SAVE,228,174,49,20,SAVE
  DIALOG ADD,BUTTON,L4SAVE,230,403,49,20,SAVE
  DIALOG SHOW
  rem -- Put horizontal SCROLL on list --
  %z = @sendmsg(@winexists(~L1),$0194,2000,0)
  %z = @sendmsg(@winexists(~L2),$0194,2000,0)
  %z = @sendmsg(@winexists(~L3),$0194,2000,0)
  %z = @sendmsg(@winexists(~L4),$0194,2000,0)
REM ---CREATE LISTS
  LIST CREATE, 1
  LIST CREATE, 2, SORTED
REM -- LISTS 3 & 4 NOT SORTED TO ALLOW COUNTING OF VAR OCCURANCE FOR L3 & SEQUENTIAL LINE #'S FOR L4
  LIST CREATE, 3,
  LIST CREATE, 4, SORTED
  %a = "0123456789_abcdefghijklmnopqrstuvwxyz"
  %b = "123456789abcdefghijklmnopqrstuvwxyz"
  %5 = L1
  CLIPBOARD CLEAR
:EVLOOP
  WAIT EVENT
  %%EVENT = @EVENT()
REM --- GET 1ST 2  CHARS OF EVENT FOR LIST SAVE AND COPY TO CLIPBOARD
  IF @EQUAL(@SUBSTR(%%EVENT,1,2),L1)@EQUAL(@SUBSTR(%%EVENT,1,2),L2)@EQUAL(@SUBSTR(%%EVENT,1,2),L3)@EQUAL(@SUBSTR(%%EVENT,1,2),L4)
      %5 = @SUBSTR(%%EVENT,1,2)
  END
  goto %%EVENT
REM --- ALLOW LIST CLICK EVENT TO SET %5
REM --- THIS SECTION COULD ALSO BE USED TO CLEAR OTHER LIST SELECTIONS IF NEEDED
:L1CLICK
:L2CLICK
:L3CLICK
:L4CLICK
 GOTO EVLOOP
REM --- SAVE LIST %5
:L1SAVEBUTTON
:L2SAVEBUTTON
:L3SAVEBUTTON
:L4SAVEBUTTON
  %%SAVE = @FILEDLG("Text file(*.txt)|*.txt",Save list to file,VAR-%5.TXT,SAVE)
  IF @NULL(%%SAVE)
      GOTO EVLOOP
  END
  LIST SAVEFILE,%5,%%SAVE
  GOTO EVLOOP
REM --- APPEND CLIPBOARD WITH CURRENT LIST SELECTION
:CopyBUTTON
  INFO %5
  CLIPBOARD APPEND, @ITEM(%5)
  goto EVLOOP
REM --- LOAD DSC FILE FOR PROCESSING 
:LoadBUTTON
REM --- REMOVE TEXT INDICATING # OF VARS USED  & # ALLOWED
  DIALOG REMOVE, TEXT5
  DIALOG REMOVE, TEXT6
  %f = @FILEDLG("VDS file(*.dsc)|*.dsc",Select VDS file to load,*.dsc,)
  if @file(%f)
    DIALOG SET, Stat, Please Wait...
    LIST CLEAR, 1
    LIST CLEAR, 2
    LIST CLEAR, 3
    LIST CLEAR, 4
    LIST CLEAR, L1
   LIST CLEAR, L2
    LIST CLEAR, L3
    LIST CLEAR, L4
    LIST LOADFILE, 1, %f
   LIST ADD,L4, ""
   LIST SEEK,1,0
    %C = 0
   REPEAT
         REM --- REMOVE REMMED OUT LINES FOR VALUES LIST
         IF @MATCH(1,REM" ")
         LIST DELETE,1
      END
      %C = @SUCC(%C)
   UNTIL @EQUAL(%C,@COUNT(1))
   REM --- %X WILL ALLOW COUNTING OF LINE #'S @ LISTS
    %x = 0
:USER-VARS
    REPEAT
      %i = @item(1, %x)
      REM --- LOOK FOR %% IN CURRENT ITEM
     if @greater(@pos("%%", %i), 0)
        %p = @sum(@pos("%%", %i), 2)
        %v = "%%"
        REM --- IF %% IS FOUND BREAK DOWN TO VAR NAME ONLY AND ADD TO LISTS
      REPEAT
          :Found
          %s = @substr(%i, %p)
          if @greater(@pos(%s, %a), 0)
            %v = %v%s
          else
           LIST ADD, 2, %v
         LIST ADD, 3, %v - "@" LINE @SUCC(%X)
         REM --- SEE IF THE VAR VALUE IS BEING SET AND ADD TO LIST 4
         REM --- SINCE LIST 4 IS NOT SORTED CHECK FOR DUPLICATES BEFORE ADDING
         IF @GREATER(@POS(%V" =",%I),0)
            LIST SEEK,L4,@PRED(@COUNT(L4))
            IF @NOT(@EQUAL(@ITEM(L4),LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(%V" =",%I),@LEN(%I))))
                  LIST ADD,L4,LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(%V" =",%I),@LEN(%I))
            END   
          END
         REM --- SAME AS ABOVE IF BUT LOOKING FOR VALUES SET USING PARSE   
         IF @GREATER(@POS(PARSE,%I),0)
            LIST SEEK,L4,@PRED(@COUNT(L4))
            IF @NOT(@EQUAL(@ITEM(L4), LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(PARSE,%I),@LEN(%I))))
                 LIST ADD,L4,LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(PARSE,%I),@LEN(%I))
            END   
          END 
         %i = @strdel(%i, 1, %p)
            if @greater(@pos("%%", %i), 0)
              %p = @sum(@pos("%%", %i), 2)
              %v = "%%"
              goto Found
            else
              %p = @succ(@len(%i))
            end
          end
          %p = @succ(%p)
        UNTIL @greater(%p, @succ(@len(%i)))
      end
      %x = @succ(%x)
      DIALOG SET, Stat, "Searching for user defined vars "@count(2)
    UNTIL @equal(%x, @count(1))
    %u = @count(2)
:STANDARD-VARS   
   rem -- Standard vars --
    %x = 0
    REPEAT
      %i = @item(1, %x)
     REM --- LOOK FOR % IN CURRENT ITEM
      if @greater(@pos("%", %i), 0)
        %p = @pos("%", %i)
      REM --- IF % IS FOUND BREAK DOWN TO VAR NAME ONLY AND ADD TO LISTS
        REPEAT
          %r = @substr(%i, @pred(%p))
          %s = @substr(%i, %p)
          %v = @substr(%i, @succ(%p))
          if @equal(%s, "%")
            if @not(@equal(%r, "%"))
              if @not(@equal(%v, "%"))
                if @greater(@pos(%v, %b), 0)
                  LIST ADD, 2, %s%v
              LIST ADD, 3, %s%v - "@" LINE @SUCC(%X)
              REM --- SEE IF THE VAR VALUE IS BEING SET AND ADD TO LIST 4
              REM --- SINCE LIST FOR IS NOT SORTED CHECK FOR DUPLICATES BEFORE ADDING
              IF @GREATER(@POS(%S%V" =",%I),0)
                 LIST SEEK,L4,@PRED(@COUNT(L4))
                 IF @NOT(@EQUAL(@ITEM(L4),LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(%S%V" =",%I),@LEN(%I))))
                   LIST ADD,L4,LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(%S%V" =",%I),@LEN(%I))
               END   
               END
              REM --- SAME AS ABOVE IF BUT LOOKING FOR VALUES SET USING PARSE   
              IF @GREATER(@POS(PARSE,%I),0)
                 LIST SEEK,L4,@PRED(@COUNT(L4))
                 IF @NOT(@EQUAL(@ITEM(L4), LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(PARSE,%I),@LEN(%I))))
                  LIST ADD,L4,LINE @SUCC(%X)  -  @SUBSTR(%I,@POS(PARSE,%I),@LEN(%I))
               END   
               END 
                end
              end
            end
          end       
          %p = @succ(%p)
        UNTIL @greater(%p, @len(%i))
      end
      %x = @succ(%x)
      DIALOG SET, Stat, "Searching for standard vars "@diff(@count(2), %u)
    UNTIL @equal(%x, @count(1))
    %s = @diff(@count(2), %u)
    DIALOG SET, Stat, %f
   LIST ASSIGN, L1, 2
    LIST SEEK, L1, 0
  ELSE
     GOTO EVLOOP
  END   
REM --- JUGGLE LISTS 3,4 & L2 TO SORT & REMOVE DUPS FROM L2
   list assign,4,3
   LIST ASSIGN,L2,4
   list seek, L2,0
REM --- COUNT HOW MANY TIME VAR IS USED FOR L3
REM --- DUE TO ABOVE JUGGLING A VAR IS ONLY COUNTED 1X EVEN THOUGH IT MAY APPEAR 2X ON THE SAME LINE
REM --- LIST ASSIGN ABOVE CAN BE REMOVED IF THIS IS NOT WANTED
:getcount
   %m = 0
   Repeat
       %c = 0
       %M = @SUCC(%M)
        Repeat
          %%l3sub = @substr(@item(l2),1,@pos(" - @",@item(l2)))
            if @match(l2,%%l3sub)
               %c = @succ(%c)
            %%next = @next(l2)
            end
        until @not(@EQUAL(%%L3SUB,@SUBSTR(@ITEM(L2),1,@LEN(%%L3SUB))))
       list add, l3, %%l3sub @tab()"->"@tab() %c x
   UNTIL @NULL(@ITEM(L2))
   LIST SEEK,L4,0
   LIST DELETE,L4
   REM LIST ASSIGN,L4,4
   List clear,1
   List clear,2
   List clear,3
   List clear,4
   INFO DONE
REM --- ADD TEXT TO WINDOW SHOWING USER VAR USAGE   
   DIALOG ADD,TEXT,TEXT5,462,4,,,%u" user defined variables  (128 limit for VDS 3.51)"
   DIALOG ADD,TEXT,TEXT6,489,4,,,%s" standard variables  (35 limit for VDS 3.51)"
   goto EVLOOP
:CLOSE
  EXIT
Back to top
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Wed Jul 31, 2002 10:18 pm    Post subject: Reply with quote

Lol moke, I posted the code to be used. Appreciate the
mention though... Wink

I started code to add IF/END and REPEAT/UNTIL checking
to it a while back, but got off on a tangent (as usual). I
think that'd be pretty handy as well...

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 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