Posted: 25th Nov 2002 8:53
As requested my string library! Part of CS-LIBRARY 2002
CS-LIBRARY 2002 contains all you see here plus many many many more! contains 156 librarys all usefull and alot of original functions that I created out of my own design.
If anyone would like to reserve a copy of the finished CerveSoft-LIBRARY 2002 for absolutely nothing its freeware just e-mail me at ironhoof2@wmconnect.com and when its done I'll e-mail it out

My ADVANCED TIMER LIBRARY
+ Code Snippet
`CS-LIBRARY 2002 Russel "IronHoof" Hamrick
`--------------------------------------------------------------
`TRUE TIMERS
`ActiveTimer and SetActiveTimer are used to run timers without stopping
`the program
`Pause pauses in miliseconds while SyncroPause pauses in seconds
`Sequencer calculates PPQN times and outputs the delay time
`DynamicTrackTime manages UPTO 8 timers at once! in sync!
`timers not used will always have a bit value of 1
`to set a DynamicTimer use the SetActiveTimer function
`--------------------------------------------------------------

function ActiveTimer(timelimit)
act=0:if timelimittimer():sync:endwhile
endfunction

function SyncroPause(seconds)
dly=timer()+(seconds*1000)
while dly>timer():sync:endwhile
endfunction

function Sequencer(ppqn)
till=timer()+(500000/ppqn)
endfunction till

function DynamicTrackTime(trk1,trk2,trk3,trk4,trk5,trk6,trk7,trk8)
snc=timer():if trk1LEN(String$) then TMP=0:FND=1
INC TMP,1:ENDWHILE
endfunction TMP-1

Function Rtrim$(String$)
TMP=1:FND=0:TMP$=""
WHILE FND=0:IF MID$(String$,TMP)=" " then INC TMP,1 else FND=1
ENDWHILE
TMP$=Right$(String$,Len(String$)-(TMP-1))
endfunction TMP$

Function Ltrim$(String$)
TMP=LEN(String$):FND=0:TMP$=""
WHILE FND=0:IF MID$(String$,TMP)=" " then DEC TMP,1 else FND=1
ENDWHILE
TMP$=Left$(String$,TMP)
endfunction TMP$

Function Atrim$(String$)
TMP$="":TMP$=LTrim$(String$):TMP$=RTrim$(TMP$)
endfunction TMP$

Function CutLeft$(String$,Char$)
TMP$=Left$(String$,Instr(String$,Char$)-1)
endfunction TMP$

Function CutRight$(String$,Char$)
TMP$=Right$(String$,Len(String$)-Instr(String$,Char$))
endfunction TMP$

Function CutMiddle$(String$,LChar$,RChar$)
TMP$=CutLeft$(String$,RChar$):TMP$=CutRight$(TMP$,LChar$)
endfunction TMP$

Function FindWord(String$,Word$)
TMP=1:FND=0:Char$=Left$(Word$,1)
SCAN:
WHILE FND=0:IF MID$(String$,TMP)=Char$ THEN FND=1
IF TMP>LEN(String$) then TMP=0:FND=1
INC TMP,1:ENDWHILE
WLG=1:SSEC=TMP
MORE:
if WLG>len(Word$) then exitfunction 0
if SSEC>len(String$)+1 then exitfunction 0
if mid$(word$,WLG)=mid$(String$,SSEC-1) and WLG=Len(Word$) then exitfunction TMP-1
if mid$(word$,WLG)=mid$(String$,SSEC-1) then inc WLG,1:inc SSEC,1:goto more:
inc TMP,1:goto SCAN:
endfunction

Function DeleteWord$(String$,Word$)
TMP=FindWord(String$,Word$):WLG=LEN(Word$):TMP2$="":if TMP=0 then exitfunction String$
TMP2$=Left$(String$,TMP-1)+Right$(String$,Len(String$)-(TMP+(WLG-1)))
endfunction  TMP2$

Function Insert$(String$,Word$,Here)
TMP$=Left$(String$,Here-1)+Word$+Right$(String$,Len(String$)-(Here-1))
endfunction TMP$

Function CountChar(String$,Char$)
COUNT=1:TALLY=0
while count2 then ExitFunction str$(Count)+"|"+str$(scan)
scan=1:inc count,1:if count+1>len(String$) then exitfunction "NONE"
goto more:
endfunction ""

Function Trail$(Char$,Amount)
TMP2$="":if amount=0 then exitfunction ""
for tmp=0 to amount-1
TMP2$=TMP2$+Char$
next tmp
endfunction TMP2$

Function GetStringDex(String$,Char$,Word$)
Count=1:FND=0
more:
TMPL$=CutLeft$(String$,Char$):String$=CutRight$(String$,Char$)
if TMPL$=Word$ then FND=1
if Word$=String$ then FND=1:inc count,1
if TMPL$Word$ and Instr(String$,Char$)>0 then inc count,1:goto more:
if FND=0 then ExitFunction 0 
endfunction Count

Function StringDex$(String$,Char$,Ndex)
Count=1:TMP$=""
more:
if Instr(String$,Char$)=0 then ExitFunction String$
TMP$=CutLeft$(String$,Char$):String$=CutRight$(String$,Char$)
if countNdex then inc count,1:goto more:
endfunction TMP$


My data Type conversion library
+ Code Snippet
`CS-LIB 2002 Russel "IronHoof" Hamrick
`-------------------------------------------------------------------
`Conversion Library
`HexVal Converts Hexadecimal to Decimal
`BLS bitshifts a byte left
`BSR bitshifts a byte right
`WriteVLQ Writes a 32 bit variable-Length quantity to a file
`ReadVLQ Reads a 32 bit variable-Length quantity from a file
`-------------------------------------------------------------------

function HexVal(hexnum$)
LENG=LEN(hexnum$):COUNT=1:V2=0
IF LENG=1 THEN GOTO SINGLE:
MORE:
NYBBLE$=mid$(hexnum$,COUNT):V=0
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
EMR=(LENG-COUNT):V2=V2+(V*(16^EMR)):V=0
IF COUNT0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
ENDFUNCTION V2+V

function BSL(Initial,ShiftAmount)
ANW=Initial*(2^ShiftAmount)
endfunction ANW

function BSR(Initial,ShiftAmount)
ANW=Initial/(2^ShiftAmount)
endfunction ANW

Function WriteVLQ(Filenum,Value)
BUFFER=Value & hexval("7F")
while value
value=BSR(value,7)
buffer=BSL(buffer,8)
buffer=buffer | ((Value & 127) | 128)
endwhile
INFINITE:
write byte 1,buffer
if (BUFFER & 128) then buffer=BSR(buffer,8) else exitfunction
goto INFINITE:
endfunction

Function ReadVLQ(Filenum)
Value=0
more:
read byte 1,mybyte
Value=Value*128
Mask=mybyte & 127
Value=Value | Mask
if (mybyte & 128)=128 then goto more:
endfunction Value
Posted: 25th Nov 2002 8:56
OOOPZ! lets try that agian!

TIMER LIBRARY

`CS-LIBRARY 2002 Russel "IronHoof" Hamrick
+ Code Snippet
`--------------------------------------------------------------
`TRUE TIMERS
`ActiveTimer and SetActiveTimer are used to run timers without stopping
`the program
`Pause pauses in miliseconds while SyncroPause pauses in seconds
`Sequencer calculates PPQN times and outputs the delay time
`DynamicTrackTime manages UPTO 8 timers at once! in sync!
`timers not used will always have a bit value of 1
`to set a DynamicTimer use the SetActiveTimer function
`--------------------------------------------------------------

function ActiveTimer(timelimit)
act=0:if timelimit<timer() then act=1
endfunction act

function SetActiveTimer(waittime)
vipper=timer()+waittime
endfunction vipper

function Pause(times)
dly=timer()+times
while dly>timer():sync:endwhile
endfunction

function SyncroPause(seconds)
dly=timer()+(seconds*1000)
while dly>timer():sync:endwhile
endfunction

function Sequencer(ppqn)
till=timer()+(500000/ppqn)
endfunction till

function DynamicTrackTime(trk1,trk2,trk3,trk4,trk5,trk6,trk7,trk8)
snc=timer():if trk1<snc then Chronosync=Chronosync | 128
if trk2<snc then Chronosync=Chronosync | 64
if trk3<snc then Chronosync=Chronosync | 32
if trk4<snc then Chronosync=Chronosync | 16
if trk5<snc then Chronosync=Chronosync | 8
if trk6<snc then Chronosync=Chronosync | 4
if trk7<snc then Chronosync=Chronosync | 2
if trk8<snc then Chronosync=Chronosync | 1
endfunction ChronoSync



STRING LIBRARY


+ Code Snippet
`CS-LIBRARY 2002 Russel "IronHoof" Hamrick
`-----------------------------------------------------------------
`STRING LIBRARY
`No notes needed
`-----------------------------------------------------------------

Function Instr(String$,Char$)
TMP=1:FND=0
WHILE FND=0:IF MID$(String$,TMP)=Char$ THEN FND=1
IF TMP>LEN(String$) then TMP=0:FND=1
INC TMP,1:ENDWHILE
endfunction TMP-1

Function Rtrim$(String$)
TMP=1:FND=0:TMP$=""
WHILE FND=0:IF MID$(String$,TMP)=" " then INC TMP,1 else FND=1
ENDWHILE
TMP$=Right$(String$,Len(String$)-(TMP-1))
endfunction TMP$

Function Ltrim$(String$)
TMP=LEN(String$):FND=0:TMP$=""
WHILE FND=0:IF MID$(String$,TMP)=" " then DEC TMP,1 else FND=1
ENDWHILE
TMP$=Left$(String$,TMP)
endfunction TMP$

Function Atrim$(String$)
TMP$="":TMP$=LTrim$(String$):TMP$=RTrim$(TMP$)
endfunction TMP$

Function CutLeft$(String$,Char$)
TMP$=Left$(String$,Instr(String$,Char$)-1)
endfunction TMP$

Function CutRight$(String$,Char$)
TMP$=Right$(String$,Len(String$)-Instr(String$,Char$))
endfunction TMP$

Function CutMiddle$(String$,LChar$,RChar$)
TMP$=CutLeft$(String$,RChar$):TMP$=CutRight$(TMP$,LChar$)
endfunction TMP$

Function FindWord(String$,Word$)
TMP=1:FND=0:Char$=Left$(Word$,1)
SCAN:
WHILE FND=0:IF MID$(String$,TMP)=Char$ THEN FND=1
IF TMP>LEN(String$) then TMP=0:FND=1
INC TMP,1:ENDWHILE
WLG=1:SSEC=TMP
MORE:
if WLG>len(Word$) then exitfunction 0
if SSEC>len(String$)+1 then exitfunction 0
if mid$(word$,WLG)=mid$(String$,SSEC-1) and WLG=Len(Word$) then exitfunction TMP-1
if mid$(word$,WLG)=mid$(String$,SSEC-1) then inc WLG,1:inc SSEC,1:goto more:
inc TMP,1:goto SCAN:
endfunction

Function DeleteWord$(String$,Word$)
TMP=FindWord(String$,Word$):WLG=LEN(Word$):TMP2$="":if TMP=0 then exitfunction String$
TMP2$=Left$(String$,TMP-1)+Right$(String$,Len(String$)-(TMP+(WLG-1)))
endfunction  TMP2$

Function Insert$(String$,Word$,Here)
TMP$=Left$(String$,Here-1)+Word$+Right$(String$,Len(String$)-(Here-1))
endfunction TMP$

Function CountChar(String$,Char$)
COUNT=1:TALLY=0
while count<Len(String$)+1
if mid$(String$,Count)=Char$ then inc TALLY,1
inc count,1
endwhile
endfunction tally

Function FindTrail$(String$)
COUNT=1:SCAN=1:if Len(string$)<3 then exitfunction "NONE"
more:
Strt$=mid$(String$,count):Eye$=mid$(String$,count+scan)
if Strt$=Eye$ then inc scan,1:goto more:
if scan>2 then ExitFunction str$(Count)+"|"+str$(scan)
scan=1:inc count,1:if count+1>len(String$) then exitfunction "NONE"
goto more:
endfunction ""

Function Trail$(Char$,Amount)
TMP2$="":if amount=0 then exitfunction ""
for tmp=0 to amount-1
TMP2$=TMP2$+Char$
next tmp
endfunction TMP2$

Function GetStringDex(String$,Char$,Word$)
Count=1:FND=0
more:
TMPL$=CutLeft$(String$,Char$):String$=CutRight$(String$,Char$)
if TMPL$=Word$ then FND=1
if Word$=String$ then FND=1:inc count,1
if TMPL$<>Word$ and Instr(String$,Char$)>0 then inc count,1:goto more:
if FND=0 then ExitFunction 0 
endfunction Count

Function StringDex$(String$,Char$,Ndex)
Count=1:TMP$=""
more:
if Instr(String$,Char$)=0 then ExitFunction String$
TMP$=CutLeft$(String$,Char$):String$=CutRight$(String$,Char$)
if count<>Ndex then inc count,1:goto more:
endfunction TMP$



CONVERSION LIBRARY

+ Code Snippet
`CS-LIB 2002 Russel "IronHoof" Hamrick
`-------------------------------------------------------------------
`Conversion Library
`HexVal Converts Hexadecimal to Decimal
`BLS bitshifts a byte left
`BSR bitshifts a byte right
`WriteVLQ Writes a 32 bit variable-Length quantity to a file
`ReadVLQ Reads a 32 bit variable-Length quantity from a file
`-------------------------------------------------------------------

function HexVal(hexnum$)
LENG=LEN(hexnum$):COUNT=1:V2=0
IF LENG=1 THEN GOTO SINGLE:
MORE:
NYBBLE$=mid$(hexnum$,COUNT):V=0
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
EMR=(LENG-COUNT):V2=V2+(V*(16^EMR)):V=0
IF COUNT<LENG-1 THEN INC COUNT,1:GOTO MORE:
SINGLE:
NYBBLE$=mid$(hexnum$,LENG)
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
ENDFUNCTION V2+V

function BSL(Initial,ShiftAmount)
ANW=Initial*(2^ShiftAmount)
endfunction ANW

function BSR(Initial,ShiftAmount)
ANW=Initial/(2^ShiftAmount)
endfunction ANW

Function WriteVLQ(Filenum,Value)
BUFFER=Value & hexval("7F")
while value
value=BSR(value,7)
buffer=BSL(buffer,8)
buffer=buffer | ((Value & 127) | 128)
endwhile
INFINITE:
write byte 1,buffer
if (BUFFER & 128) then buffer=BSR(buffer,8) else exitfunction
goto INFINITE:
endfunction

Function ReadVLQ(Filenum)
Value=0
more:
read byte 1,mybyte
Value=Value*128
Mask=mybyte & 127
Value=Value | Mask
if (mybyte & 128)=128 then goto more:
endfunction Value
Posted: 25th Nov 2002 9:25
EXPLANATION OF STRING LIBRARY:

Instr()
This command returns the first accurance of a character in a string

print Instr("Hey there","y")

output
3

--------------------------------------

Rtrim$()
This command remove unwanted spaces from the right of the string

Print RTRIM$("HEY THERE! ")+"<"

output
HEY THERE!<

---------------------------------------------------------
LTRIM$()
same as RTRIM$ but removes unwanted spaces from the left of the string

print ">"+Ltrim$(" HEY THERE!")

output
>HEY THERE!

-------------------------------------------------------
ATRIM$() dose the combined function of RTRIM AN LTRIM
removing all spaces from left and right of the string

pint ">"+Atrim$(" HI ")+"<"

output
>HI<

-------------------------------------------------------

CutLeft$()
This HANDY function is simulare to LEFT$ and RIGHT$ except it litterly CUTS from the specified character you say at its first accurance! instead of using a number

print CutLeft$("OPEN|HERE" , "|")

output
OPEN

--------------------------------------------------------
CutRight$()
This dose the reverse of cutleft itcuts from the right of the first accurance of a character specified

print CutRight$(" THIS|GUY " , "|")

output
GUY

--------------------------------------------------------
CutMiddle$()
dose the combined function of cutleft and right by using TWO
character accurances!

print CutMiddle$( " PRINT(PARAMETER) " , "(" , ")" )

output
PARAMETER
-------------------------------------------------------
FindWord$()
is simulae to Instr only it will only return the place
of the first accurance of a MATCHING word in case in the string

Print FindWord$("HEY HI HOWDY COOLIES","HOWDY")

output
8 -Cause HOWDY begins in character space 8 of the searched string

---------------------------------------------------------
DeleteWord$()
This seeks out a matching word in a string and destroys it!

print DeleteWord$("WHATS UP HERE MY FRIEND?" , "HERE ")

output
WHATS UP MY FRIEND? - We use a space after the word we delete because you will have a double space since it removes whatever matches and the spaces between the world would else wise remain like so

alternate output
WHATS UP MY FRIEND?

--------------------------------------------------------
Insert$()
This will insert a word in a string at the specified location

print Insert$("CAN BELIEVE THIS GUY?","YOU ",5)

output
CAN YOU BELIEVE THIS GUY?
---------------------------------------------------------

CountChar()
this counts the number of the specified char in the string

print CountChar(" HEY MIKE HOW IS IT GOING","E")

output
2
----------------------------------------------------
FindTrail$()
This finds thee FIRST ACCURANCE of TRAILING characters in a string! which is aything over double characters in a row!
IT RETURNS THE LOCATION AND LENGTH of the TRAIL at the same time! "use cutleft and right to seprate the values"

print FindTrail$("HEY THERE AL.....")

output
13|5 -which is at position 3 and is 5 .'s long
--------------------------------------------------------
Trail$()
this will create a trail string

print Trail$("R",6)

output
RRRRRR
----------------------------------------------------
GetStringDex()
this function will retrieve the numberic value of a word in a STRING INDEX "which must be seprated by a single character throughout"

A$="HEY;BOB.BMP;SNIFF;STOP;HOOF;SHINE;SLEEK"

print GetStringDex(A$,";","STOP")

output
4 - Cause stop is the 4th word in the stringdex
---------------------------------------------------------
StringDex$()
this retireves a word from the string index

A$="HEY;BOB.BMP;SNIFF;STOP;HOOF;SHINE;SLEEK"

print StringDex$(A$,";",5)

output
HOOF
----------------------------------------------------------
Posted: 25th Nov 2002 23:31
umm just so people know, some of the functions use the & operator, and if they want it to work in DBP they have to change & to && ... rather annoying how that's changed :
Posted: 26th Nov 2002 14:07
Are you going to stick this into a C DLL for intergration into DBPro ?
Posted: 29th Nov 2002 7:18
Can't, I do not own a c++ compilier for windows that can output windows progras or dynamic linked libraries which really bites.. =( anyone know any TRUELY free compiliers that can?
Posted: 29th Nov 2002 9:47
Here is a link to Borlad's Free C++ Compiler and instructions:
http://www.dc.peachnet.edu/~jbenson/csci1401/freecpp.htm
Posted: 29th Nov 2002 11:16
I've got a 'INSTR' plug-in (although I call it something else), on my web site - it finds the first occurance or a word or letter.
Posted: 29th Nov 2002 13:21
http://www.bloodshed.net/dev/devcpp.html
Free C++ compiler that can make DLLs.
-Timpuktu