home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / asic / ls / ls.doc < prev   
Text File  |  1991-12-20  |  6KB  |  137 lines

  1.                               LINE SEARCH
  2.  
  3. This program demonstrates the use of buffered line input using the ASIC
  4. "BASIC" compiler by David A. Visti.  Using this method, I measured a 20
  5. fold increase in speed over a similiar program using the standard INPUT#
  6. line$ CRLF statement.  As a demonstration, this program will read a file
  7. using buffered input and print any lines which contain a substring
  8. provided on the command line.  This program is not an example of how to
  9. write a text searching program.  It is an example of one method of
  10. retrieving data from disk in a reasonable time frame with ASIC.  The
  11. speed increase is due to a reduction in the number of DOS calls needed
  12. to access a disk sector, with this method only 1 call is used to read a
  13. sector, with the standard ASIC method 512 such calls would be needed.
  14. The overhead from the DOS calls makes the standard method almost
  15. unusable for large files.
  16.  
  17. Subroutines gethandle, getline and readsector constitute a buffered line
  18. input system that can be added to any program.  The source below will
  19. not compile due to added comments.  See file LS.ASI for compiliable
  20. source.  These routines may be added to your source code provided that
  21. you include the 4 REMark lines shown below at the top of your source
  22. file.
  23.  
  24.    SOURCE                              COMMENTS
  25.  
  26. REM BUFFERED LINE INPUT by:
  27. REM EFD Systems
  28. REM 7 Cedar Hollow #D
  29. REM Atlanta, GA 30350
  30.  
  31. dim bfr(256)             Dimension a 512 byte array to use as a buffer
  32. bfrst=varptr(bfr(1))     Set pointer to start of array
  33. bfrpos=bfrst             Position pointer, initialize to start of buffer
  34. bfrend=0                 Buffer end pointer, initialize to 0
  35.  
  36. cmd$=command$            Read and parse the command line
  37. cmd$=ltrim$(cmd$)                        "
  38. cmd$=ucase$(cmd$)                        "
  39. ls=len(cmd$)                             "
  40. i=instr(cmd$," ")                        "
  41. if ls=0 then fileerr:                    "
  42. if i=0 then fileerr:                     "
  43. ls=ls-i                                  "
  44. i=i-1                                    "
  45. fn$=left$(cmd$,i)                        "
  46. srch$=right$(cmd$,ls)                    "
  47. print "Searching for ";                  "
  48. print srch$;                             "
  49. print " in ";                            "
  50. print fn$                                "
  51.  
  52. open "I",1,fn$             Open file
  53. if error>0 then fileerr:   Check for errors
  54.  
  55. fn=1                       FN is the file number needed by SUB's below
  56. gosub gethandle:           Get the DOS file handle for file FN
  57.  
  58. main:                      MAIN program loop
  59. line$=""                   Initialize variable to hold line string
  60. gosub getline:             Get a line of data from buffer to line$
  61. if error>0 then done:      Check for end of file--end program if true
  62. line$=ucase$(line$)        Capitalize line for case insensitive search
  63. i=instr(line$,srch$)       Search for presence of search string
  64. if i>0 then                If found then print line containing string
  65.    print line$
  66. endif
  67. goto main:                  Loop until the cows come home
  68.  
  69. getline:                        GETLINE subroutine start
  70.    if bfrpos>bfrend then        Test for pos. pointer beyond buffer end
  71.       gosub readsector:         Read a new sector if true
  72.       if error>0 then           Check for end of file
  73.          return                 Return to main if true
  74.       endif
  75.    endif
  76.    tst=peek(bfrpos)             Get 1 char. from buffer
  77.    if tst=13 then               Test for carriage return char.
  78.       bfrpos=bfrpos+2           Jump over CR-LF
  79.       return                    Return line string
  80.    else
  81.       tstchr$=chr$(tst)         Convert to character
  82.       line$=line$+tstchr$       Add character to line
  83.       bfrpos=bfrpos+1           Increment position pointer
  84.       goto getline:             Get next character
  85.    endif
  86. return
  87.  
  88. readsector:                     READ SECTOR subroutine start
  89.    AX=&hex3F00                  Use Interrupt 21, subfunction 3F
  90.    CX=512                       Read 512 bytes
  91.    DX=varptr(bfr(1))            Place data into buffer area
  92.    BX=hdl                       Read from file handle, hdl
  93.    int86(&hex21,AX,BX,CX,DX,NA,NA,NA,NA,NA)
  94.    bfrpos=bfrst                 Set pointer to start of buffer
  95.    bfrend=bfrst+AX              Set end of buffer, partial read possible
  96.    bfrend=bfrend-1
  97.    if AX=0 then                 Check for 0 bytes i.e. EOF
  98.       error=99                  Set error condition to indicate EOF
  99.    endif
  100. return
  101.  
  102. gethandle:                      GET HANDLE subroutine start
  103.    if fn>3 then fileerr:        Check for illegal file number
  104.    if fn<1 then fileerr:                    "
  105.    x=fn*3                       Set pointer to correct offset in
  106.    x=350+x                          file control table
  107.    hdl=peek(x)                  Get low byte at pointer location
  108.    x=x+1                        Increment pointer
  109.    y=peek(x)                    Get high byte
  110.    y=y*256                      Adjust high byte
  111.    hdl=hdl+y                    DOS Handle = Low byte + High byte
  112. return
  113.  
  114. fileerr:                        FILE ERROR subroutine
  115. print "Command/File error ! "
  116. print "Syntax: LS filename searchstring"
  117. end
  118.  
  119. done:                           END subroutine
  120. print "Finished!"
  121. end
  122.  
  123.                                ABOUT ASIC
  124.  
  125. ASIC is a shareware "BASIC" compiler available from CompuServe and other
  126. sources.  I prefer to think of ASIC as an assembler with BASIC style
  127. high level constructs added.  With minimal effort, it is possible to
  128. apply ASIC to many "assembler" type applications since the resulting
  129. .COM files are very compact and have assembler speed.  This is not your
  130. father's BASIC.  As the name implies, ( ASIC is almost [B]ASIC, get it!),
  131. this is a minimalist implementation with all the usual hand holding and
  132. some other features removed.  ASIC does not produce .OBJ files, the only
  133. serious drawback that I can see.  Otherwise, it is an excellent product
  134. that should be of interest to anyone who occasionally uses assembly
  135. code, not just BASIC programmers.
  136.  
  137.