Author |
Topic: Library File with Table of Contents (Read 939 times) |
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
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 » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline
Posts: 93
|
|
Re: Library File with Table of Contents
« Reply #2 on: Feb 23rd, 2015, 01:54am » |
|
Good invention Kelly,
Thanks to you and Richard.
Sarmed.
|
|
Logged
|
|
|
|
Hans
New Member
member is offline
Gender:
Posts: 31
|
|
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
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
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!
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
Richard.
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
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
|
|
Logged
|
|
|
|
Hans
New Member
member is offline
Gender:
Posts: 31
|
|
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
|
|
Logged
|
|
|
|
|