It is currently Fri Mar 24, 2017 3:04 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Orphaned FN.DEF finder
Unread postPosted: Sun Mar 20, 2016 5:35 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
This is a handy program which I just made to locate a bunch of FN.DEF functions in my main source .bas file that I no longer was using.

It is horribly inefficient but seemed to work when I ran it against a GW program I made with 390 functions (it took about 5 minutes to run though :o )

It just requires the two .bas files (or you can substitute your own choosefile$() function if you'd like)

http://laughton.com/basic/programs/tool ... %20Finder/

I double checked it and I did find about 15 functions in one of my apps that I truly no longer needed.

Hopefully it won't generate false positives, but you should double check each one with a word processor before you delete them.


Top
 Profile  
 
 Post subject: Re: Orphaned FN.DEF finder
Unread postPosted: Fri Mar 25, 2016 8:07 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 801
cterp wrote:
It is horribly inefficient but seemed to work when I ran it against a GW program I made with 390 functions (it took about 5 minutes to run though :o )


That sounds really, that there is space for optimization. Maybe you can get some benefit by running through the file(s) via IS_IN() function instead of examining every single line.
As an quick example, see snippet below: on my device it lists all userFuns in GW.BAS in less than 200ms

regards, brochi

Code:
GRABFILE         dat$,"../source/gw.bas"
dat$           = LOWER$(REPLACE$(dat$," ",""))

tic            = CLOCK()

DO

pos           = IS_IN("fn.def",dat$,pos)

IF pos

  pos2         = IS_IN ( "(",  dat$,  pos)
  funName$     = MID$  ( dat$, pos+6, pos2-pos-6)

  !list.add     .....
  ctr++
  PRINT          INT$(ctr), funName$
  pos          = pos2

ENDIF

UNTIL            !pos


PRINT
PRINT            CLOCK()-tic

END


Top
 Profile  
 
 Post subject: Re: Orphaned FN.DEF finder
Unread postPosted: Fri Mar 25, 2016 6:59 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
Thanks brochi!

I keep on forgetting that doing everything in strings is MUCH faster than file ops..

Yes.. stripping out all the spaces and doing a search for the function names that don't have a fn.def preceding them did the trick..

The only problem I think it has though is if one function name is a substring of another... or if the context of the string
accidentally concatenates to form a declared function name. Instead of stripping out all the spaces I could just get rid of all the spaces before ('s and any extras after FN.DEF's and then just work from longest to shortest function names and X them out in dat$ as I find them.

Also it doesn't work if there is a function used inside another and the parent isn't needed.

I will tweak more if I need to but this is handy for me to remove functions that I don't use from my libraries.

It works really fast. Cool!

This is the code I use for searching for the functions:

Code:
tic            = CLOCK()


GRABFILE         dat$,f$
dat$           = LOWER$(REPLACE$(dat$," ",""))
LIST.CREATE S, unused

FOR i=1 TO z
LIST.GET fl,i,n$
pos=IS_IN(n$+"(", dat$)
IF pos>0 & MID$(dat$,pos-6,6)="fn.def"
  pos += 6+LEN(n$)
  pos=IS_IN(n$+"(", dat$, pos)
ENDIF
IF !pos THEN LIST.ADD unused,n$
NEXT i

PRINT    CLOCK()-tic


LIST.SIZE unused,z
IF !z
? "no orphans found"
END
ENDIF

?INT$(z)+" possible orphan fns"

FOR i=1 TO z
LIST.GET unused,i,n$
? n$
NEXT i


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
suspicion-preferred