home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
basic
/
library
/
asic
/
ls
/
ls.doc
< prev
Wrap
Text File
|
1991-12-20
|
6KB
|
137 lines
LINE SEARCH
This program demonstrates the use of buffered line input using the ASIC
"BASIC" compiler by David A. Visti. Using this method, I measured a 20
fold increase in speed over a similiar program using the standard INPUT#
line$ CRLF statement. As a demonstration, this program will read a file
using buffered input and print any lines which contain a substring
provided on the command line. This program is not an example of how to
write a text searching program. It is an example of one method of
retrieving data from disk in a reasonable time frame with ASIC. The
speed increase is due to a reduction in the number of DOS calls needed
to access a disk sector, with this method only 1 call is used to read a
sector, with the standard ASIC method 512 such calls would be needed.
The overhead from the DOS calls makes the standard method almost
unusable for large files.
Subroutines gethandle, getline and readsector constitute a buffered line
input system that can be added to any program. The source below will
not compile due to added comments. See file LS.ASI for compiliable
source. These routines may be added to your source code provided that
you include the 4 REMark lines shown below at the top of your source
file.
SOURCE COMMENTS
REM BUFFERED LINE INPUT by:
REM EFD Systems
REM 7 Cedar Hollow #D
REM Atlanta, GA 30350
dim bfr(256) Dimension a 512 byte array to use as a buffer
bfrst=varptr(bfr(1)) Set pointer to start of array
bfrpos=bfrst Position pointer, initialize to start of buffer
bfrend=0 Buffer end pointer, initialize to 0
cmd$=command$ Read and parse the command line
cmd$=ltrim$(cmd$) "
cmd$=ucase$(cmd$) "
ls=len(cmd$) "
i=instr(cmd$," ") "
if ls=0 then fileerr: "
if i=0 then fileerr: "
ls=ls-i "
i=i-1 "
fn$=left$(cmd$,i) "
srch$=right$(cmd$,ls) "
print "Searching for "; "
print srch$; "
print " in "; "
print fn$ "
open "I",1,fn$ Open file
if error>0 then fileerr: Check for errors
fn=1 FN is the file number needed by SUB's below
gosub gethandle: Get the DOS file handle for file FN
main: MAIN program loop
line$="" Initialize variable to hold line string
gosub getline: Get a line of data from buffer to line$
if error>0 then done: Check for end of file--end program if true
line$=ucase$(line$) Capitalize line for case insensitive search
i=instr(line$,srch$) Search for presence of search string
if i>0 then If found then print line containing string
print line$
endif
goto main: Loop until the cows come home
getline: GETLINE subroutine start
if bfrpos>bfrend then Test for pos. pointer beyond buffer end
gosub readsector: Read a new sector if true
if error>0 then Check for end of file
return Return to main if true
endif
endif
tst=peek(bfrpos) Get 1 char. from buffer
if tst=13 then Test for carriage return char.
bfrpos=bfrpos+2 Jump over CR-LF
return Return line string
else
tstchr$=chr$(tst) Convert to character
line$=line$+tstchr$ Add character to line
bfrpos=bfrpos+1 Increment position pointer
goto getline: Get next character
endif
return
readsector: READ SECTOR subroutine start
AX=&hex3F00 Use Interrupt 21, subfunction 3F
CX=512 Read 512 bytes
DX=varptr(bfr(1)) Place data into buffer area
BX=hdl Read from file handle, hdl
int86(&hex21,AX,BX,CX,DX,NA,NA,NA,NA,NA)
bfrpos=bfrst Set pointer to start of buffer
bfrend=bfrst+AX Set end of buffer, partial read possible
bfrend=bfrend-1
if AX=0 then Check for 0 bytes i.e. EOF
error=99 Set error condition to indicate EOF
endif
return
gethandle: GET HANDLE subroutine start
if fn>3 then fileerr: Check for illegal file number
if fn<1 then fileerr: "
x=fn*3 Set pointer to correct offset in
x=350+x file control table
hdl=peek(x) Get low byte at pointer location
x=x+1 Increment pointer
y=peek(x) Get high byte
y=y*256 Adjust high byte
hdl=hdl+y DOS Handle = Low byte + High byte
return
fileerr: FILE ERROR subroutine
print "Command/File error ! "
print "Syntax: LS filename searchstring"
end
done: END subroutine
print "Finished!"
end
ABOUT ASIC
ASIC is a shareware "BASIC" compiler available from CompuServe and other
sources. I prefer to think of ASIC as an assembler with BASIC style
high level constructs added. With minimal effort, it is possible to
apply ASIC to many "assembler" type applications since the resulting
.COM files are very compact and have assembler speed. This is not your
father's BASIC. As the name implies, ( ASIC is almost [B]ASIC, get it!),
this is a minimalist implementation with all the usual hand holding and
some other features removed. ASIC does not produce .OBJ files, the only
serious drawback that I can see. Otherwise, it is an excellent product
that should be of interest to anyone who occasionally uses assembly
code, not just BASIC programmers.