LB Booster
« Library File with Table of Contents »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:28am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Library File with Table of Contents  (Read 938 times)
Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Library File with Table of Contents
« Thread started on: Feb 22nd, 2015, 2:07pm »

I discovered that I could add a Table of Contents in the front of my Library File. With the LBB right click/Jump To feature you can easily find the function def or sub to copy into your programs. To take a look at the TOC, download the boosted Library File with the following DropBox link .



https://www.dropbox.com/s/n7imv8ocj0d8vde/L%20I%20B%20R%20A%20R%20Y.bas?dl=0
« Last Edit: Mar 14th, 2015, 10:13am by Jack Kelly » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Library File with Table of Contents
« Reply #1 on: Feb 22nd, 2015, 3:38pm »

on Feb 22nd, 2015, 2:07pm, Jack Kelly wrote:
I discovered that I could add a Table of Contents in the front of my Library File.

That's a useful trick. In fact there's no need to fabricate a valid calling syntax, you can simply list the function and sub names in comments; the right-click 'Jump to' feature is none the wiser and will still allow you to go to the destination:

Code:
'      TABLE OF CONTENTS

' FUNCTIONS      | SUBROUTINES
' crypto$()      | ArraySize    
' DayOfWeek$()   | CombSortList
' Erl()          | CombSortTable
' exists()       | delay
' factorial()    | DirectoryInfo
' InputAnswer$() | pause$
' LeapYear()     | PrintRuler
' MonthDays()    | PreSetCenteredWindow
' NormalDate$()  | RandomSeed
' password$()    | ShuffleCardDeck
' pi()           | swap 

Richard.
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: Library File with Table of Contents
« Reply #2 on: Feb 23rd, 2015, 01:54am »


Good invention Kelly,

Thanks to you and Richard.

Sarmed.
User IP Logged

Hans
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx Re: Library File with Table of Contents
« Reply #3 on: Mar 3rd, 2015, 1:36pm »

And now a piece of code to extract functions, subs and labels from your code.

Hans
Code:
    dim funcs$(300)
    dim subs$(300)
    dim labels$(300)
    open "B:\Liberty BASIC v4.5 beta 3\cheetah.bas" for input as #1
    while eof(#1)=0
        numline=numline+1
        'print numline
        line input#1,textline$
        textline$=trim$(textline$)
        select case
        case lower$(FNWORD$(textline$," ",1))="sub"
            numsubs=numsubs+1
            subs$(numsubs)=FNWORD$(textline$," ",2)
        case lower$(FNWORD$(textline$," ",1))="function"
            numfuncs=numfuncs+1
            textline$=REPLACE$(textline$,"("," ")
            funcs$(numfuncs)=FNWORD$(textline$," ",2)
        case left$(textline$,1)="["
            numlabels=numlabels+1
            labels$(numlabels)=FNWORD$(textline$,"]",1)+"]"
        end select
    wend
    close #1
    width=25
    open "B:\Liberty BASIC v4.5 beta 3\contents.txt" for output as #1
    print #1,"'                         TABLE OF CONTENTS"
    print#1,""
    print #1, "'";LADJUST$("FUNCTIONS",width);LADJUST$("SUBROUTINES",width);LADJUST$("LABELS",width)
    count=max(numfuncs,numsubs) : count=max(count,numlabels)
    for i=1 to count
        print#1, "'";LADJUST$(funcs$(i),width);LADJUST$(subs$(i),width);LADJUST$(labels$(i),width)
    next i
    close #1
notice "Finished"
END
FUNCTION FNWORD$(string$,separator$,i)
'=breaks up string$ in parts, separator$
  If separator$=" " then string$=COMPRIMEER$(string$) 'remove extra blancs
  string$=trim$(string$)
  string$=string$+separator$
  a=1
  for j=1 to i
    b=instr(string$,separator$,a)
    aold=a
    'x$=mid$(string$,a,b-a)
    a=b+1
  next j
  x$=mid$(string$,aold,b-aold)
  FNWORD$=trim$(x$)
END FUNCTION
FUNCTION COMPRIMEER$(string$)
'=remove extra blancs from string
  a=len(string$)
   b=0
   for i=1 to a
     b$=mid$(string$,i,1)
     if b$<>" " then
        c$=c$+b$
        b=0
     else
        if b=0 then
           c$=c$+b$
           b=1
        else
           'skip
        end if
     end if
   next i
   c$=trim$(c$)
   COMPRIMEER$=c$
END FUNCTION
FUNCTION LADJUST$(string$,length)
'=Force string$ into a fixed length, left adjusted
   string$=REPLACE$(string$,chr$(0)," ")
   if len(string$)<length then                        'fill with blancs
      string$ = string$+space$(length-len(string$))
   else
     if len(string$)>length then                      'trim
        string$=left$(string$,length)
     end if
   end if
   LADJUST$=string$
END FUNCTION
FUNCTION REPLACE$(string$,tobereplaced$,replacement$)
'=Replace tobereplaced$ with replacement$ in string$ at all locations
    lenstring      =len(string$)
    lentobereplaced=len(tobereplaced$)
    lenreplacement =len(replacement$)
    start=1
[start]
    pos=instr(string$,tobereplaced$,start)
    if pos<>0 then
       string$=left$(string$,pos-1)+replacement$+right$(string$,lenstring-pos-lentobereplaced+1)
       lenstring=len(string$)
       start=pos+lenreplacement
       if start+lentobereplaced-1>lenstring then REPLACE$=string$ : exit function
    else
       REPLACE$=string$
       EXIT function
    end if
    goto [start]
END FUNCTION 
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: Library File with Table of Contents
« Reply #4 on: Mar 5th, 2015, 2:45pm »

Good job on that extract utility, Hans. I'll use it often. If you put the contents at the end of the code it becomes an index instead!
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: Library File with Table of Contents
« Reply #5 on: Mar 20th, 2015, 6:31pm »

Hans,
I enhanced your extract utility a bit. I hope you don't mind. It now opens with a filedialog to select the .bas file; sorts the subs, functions, and labels; then appends the commented results to the end of the selected .bas file as an index.

If the changes offend you, I'll delete this post.
Jack

Code:
NoMainWin
dim funcs$(300)
dim subs$(300)
dim labels$(300)
FILEDIALOG "Select program to append index", "*.bas", SelectedFile$
if right$(lower$(SelectedFile$),3)<>"bas" then end
open SelectedFile$ for input as #1
while eof(#1)=0
    numline=numline+1
    line input#1,textline$
    textline$=trim$(textline$)
    select case
        case lower$(FNWORD$(textline$," ",1))="sub"
            numsubs=numsubs+1
            subs$(numsubs)=FNWORD$(textline$," ",2)
        case lower$(FNWORD$(textline$," ",1))="function"
            numfuncs=numfuncs+1
            textline$=REPLACE$(textline$,"("," ")
            funcs$(numfuncs)=FNWORD$(textline$," ",2)
        case left$(textline$,1)="["
            numlabels=numlabels+1
            labels$(numlabels)=FNWORD$(textline$,"]",1)+"]"
    end select
wend
close #1
sort subs$(), 1, numsubs
sort funcs$(), 1, numfuncs
sort labels$(), 1, numlabels
width=25
open SelectedFile$ for append as #1
print #1, ""
print #1, "'                            INDEX"
print #1, ""
print #1, "'";LADJUST$("FUNCTIONS",width);LADJUST$("SUBROUTINES",width);LADJUST$("LABELS",width)
count=max(numfuncs,numsubs) : count=max(count,numlabels)
for i=1 to count
    print#1, "'";LADJUST$(funcs$(i),width);LADJUST$(subs$(i),width);LADJUST$(labels$(i),width)
next i
close #1
NOTICE "Program Complete."
END

FUNCTION FNWORD$(string$,separator$,i)
'=breaks up string$ in parts, separator$
    If separator$=" " then string$=COMPRIMEER$(string$) 'remove extra blancs
    string$=trim$(string$)
    string$=string$+separator$
    a=1
    for j=1 to i
        b=instr(string$,separator$,a)
        aold=a
        a=b+1
    next j
    x$=mid$(string$,aold,b-aold)
    FNWORD$=trim$(x$)
END FUNCTION

FUNCTION COMPRIMEER$(string$)
'=remove extra spaces from string
    a=len(string$)
    b=0
    for i=1 to a
        b$=mid$(string$,i,1)
        if b$<>" " then
                c$=c$+b$
                b=0
            else
                if b=0 then
                        c$=c$+b$
                        b=1
                    else
                        'skip
                end if
        end if
    next i
    c$=trim$(c$)
    COMPRIMEER$=c$
END FUNCTION

FUNCTION LADJUST$(string$,length)
'=Force string$ into a fixed length, left adjusted
    string$=REPLACE$(string$,chr$(0)," ")
    if len(string$)<length then                      'fill with blanks
            string$ = string$+space$(length-len(string$))
        else
            if len(string$)>length then                      'trim
                string$=left$(string$,length)
            end if
    end if
    LADJUST$=string$
END FUNCTION

FUNCTION REPLACE$(string$,tobereplaced$,replacement$)
'=Replace tobereplaced$ with replacement$ in string$ at all locations
    lenstring      =len(string$)
    lentobereplaced=len(tobereplaced$)
    lenreplacement =len(replacement$)
    start=1
[start]
    pos=instr(string$,tobereplaced$,start)
    if pos<>0 then
            string$=left$(string$,pos-1)+replacement$+right$(string$,lenstring-pos-lentobereplaced+1)
            lenstring=len(string$)
            start=pos+lenreplacement
            if start+lentobereplaced-1>lenstring then REPLACE$=string$ : exit function
        else
            REPLACE$=string$
            EXIT function
    end if
    goto [start]
END FUNCTION
  
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Library File with Table of Contents
« Reply #6 on: Mar 21st, 2015, 2:23pm »

on Mar 20th, 2015, 6:31pm, Jack Kelly wrote:
I enhanced your extract utility a bit. I hope you don't mind. It now opens with a filedialog to select the .bas file; sorts the subs, functions, and labels; then appends the commented results to the end of the selected .bas file as an index.

You need to add parentheses () (or at least an open parenthesis) to each of the listed function names otherwise LBB's right-click Jump to option won't recognise them, which rather defeats the object of an index. Note that both LB4 and LBB allow you to have a sub and a function with the same name, so in the index only the parenthesis distinguishes them. wink

Richard.
« Last Edit: Mar 21st, 2015, 2:26pm by Richard Russell » User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: Library File with Table of Contents
« Reply #7 on: Mar 21st, 2015, 11:01pm »

Since Hans didn't object, I have continued to enhance (read "fiddle with") the extract program. The missing parenthesis on the functions has been corrected. In addition the sort is now non-case sensitive; and when completed the program runs LBB so you can admire your work.

Prior indexes must be deleted manually if you rerun the program.

Download the possibly final "append index.bas" at this Dropbox link.

https://www.dropbox.com/s/w6pbynjxq2rjcj2/Append%20Index.BAS?dl=0

User IP Logged

Hans
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx Re: Library File with Table of Contents
« Reply #8 on: Mar 23rd, 2015, 12:02pm »

My original code was a bit raw, I admit. I am always very glad if someone else makes it better. That's what these forums are for. Otherwise I wouldn't have posted it.

Hans
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls