home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / fileutil / scan.lha / src / fastsearch.asm < prev    next >
Encoding:
Assembly Source File  |  1992-05-21  |  6.0 KB  |  135 lines

  1. ;
  2. ; Copyright © 1991, 1992 by Walter Rothe. You may freely use and modify this
  3. ; program, but not for commercial profit. A modest fee for distribution is
  4. ; allowed. Derivative works must be released with source along with the
  5. ; executable or provisions made to provide the user source, if requested.
  6. ; Uploading source to a major bulletin board system within 6 months of the
  7. ; time of the request satisfies this requirement. This copyright notice
  8. ; must not be deleted from the source.
  9. ;
  10. ; Returns major term index if keyword match found, 2/3 if article delimiter
  11. ; found, and 4/5 if end of buffer pattern found. With the max number of major
  12. ; terms being 128, you would expect the major term index returned to be less
  13. ; than 256. However, duplicate keyword entries can have a major term index
  14. ; greater than 256.
  15.         FAR     DATA
  16.         XDEF    _FastSearch
  17. _FastSearch:
  18.         LINK    A5,#.2
  19.         MOVEM.L .3,-(SP)
  20.         CLR.W   D3
  21.         CLR.L   D2
  22.         CLR.L   D1
  23.         CLR.L   D0
  24.         MOVEA.L 8(A5),A0       ;Argument #1
  25.         LEA     _SubPat,A1     ;64kb indexed by two chars
  26.         LEA     _LowrCs,A4     ;Table to convert to lower case
  27. JLOOP:  LEA     _DsplTb,A2     ;Displ to 1st char of keyword
  28.         LEA     _FrstBt,A3     ;Table with 1st byte of keywords
  29.         LEA     _ScndBt,A6     ;Table with 2nd byte of keywords
  30. ; Begin checking input stream for specific two char patterns.
  31. ILOOP:  MOVE.W  (A0)+,D1       ; 8 clocks on 68K @ 7MHZ
  32.         MOVE.B  0(A1,D1.L),D2  ; 14 clocks; Get maj term index
  33.         BEQ     ILOOP          ; 10 clocks
  34. ; Since a two char match was found, go check to see if 1st 2 bytes of keyword
  35. ; matches the char at the predicted place in the input steam where it should
  36. ; be if the whole word matched. This is done for speed.
  37.         MOVE.B  0(A2,D2.W),D0  ;Get displacement to 1st byte
  38.         BEQ     DUPLIC         ;Check for duplicate two chars
  39.         MOVE.B  -128(A0,D0.W),D3 ;1st char of keyword to be chkd
  40.         MOVE.B  0(A4,D3.W),D3  ;Convert to lower case
  41.         CMP.B   0(A3,D2.W),D3  ;Compare 1st byte
  42.         BNE     ILOOP          ;Loop if 1st byte did not match
  43.         MOVE.B  -127(A0,D0.W),D3 ;2nd char of keyword to be chkd
  44.         MOVE.B  0(A4,D3.W),D3  ;Convert to lower case
  45.         CMP.B   0(A6,D2.W),D3  ;Compare 2nd byte
  46.         BNE     ILOOP          ;Loop if 2nd byte did not match
  47. ; Go check if the rest of the keyword matches with a less speed efficient code.
  48.         MOVE.L  D2,D4          ;Major term number
  49.         LSL.L   #3,D4          ;Index by long words(2 per)
  50.         LEA     _KWTbl,A2      ;Address of keyword table of pointers
  51.         MOVEA.L 0(A2,D4.L),A6  ;Addr of rest of keyword(may be 2 when null)
  52.         MOVEA.L 4(A2,D4.L),A2  ;Address of "End of keyword"(may be 0 for null)
  53.         LEA     -126(A0,D0.W),A3 ;Address of 3rd byte to test
  54. FCMP:   CMPA.L  A6,A2          ;Finished comparing all of keyword?
  55.         BLT     MATCH          ;Yes, so must have matched.
  56.         MOVE.B  (A3)+,D3       ;Next byte from input stream
  57.         MOVE.B  0(A4,D3.W),D3  ;Convert to lower case
  58.         CMP.B   (A6)+,D3
  59.         BNE     JLOOP          ;Jump on miscompare
  60.         JMP     FCMP
  61. MATCH3: SUBA.L  #_DKWTbl+12,A6 ;Get index into dup kw tbl
  62.         MOVE.L  A6,D0
  63.         LSR.L   #4,D0          ;Get major term #
  64.         MOVE.L  A0,_BufIdx     ;Update index into buffer
  65.         MOVEM.L (SP)+,.3
  66.         UNLK    A5
  67.         RTS
  68. MATCH:  MOVE.L  D2,D0          ;Return major term number
  69.         MOVE.L  A0,_BufIdx     ;Update index into buffer
  70.         MOVEM.L (SP)+,.3
  71.         UNLK    A5
  72.         RTS
  73. ; Comes here when more than one keyword has the same two char sub-pattern(>5),
  74. ; if the two char sub-pattern of the article separator is found(2/3), or if
  75. ; the end of buffer delimiter is found(4)
  76. DUPLIC: CMPI.W  #4,D2          ;Major term number < 4?
  77.         BGE     NOTART         ;Jump if not article separator
  78.         MOVE.L  _ArtSep,A2     ;Addr of rest of article separator
  79.         MOVE.L  _EOASep,D4     ;Addr of last byte of article separator to test
  80.         LEA     _DFASep,A3     ;Displacement to rest of art sep to check in buf
  81.         MOVE.B  -2(A3,D2.W),D0 ;
  82.         LEA     -128(A0,D0.W),A3 ;Address of 1st byte to test
  83. FCMP4:  CMP.L   A2,D4          ;Finished comparing all of keyword?
  84.         BLT     MATCH2         ;Yes, so must have matched.
  85.         CMPM.B  (A2)+,(A3)+
  86.         BEQ     FCMP4          ;Jump if same
  87.         JMP     JLOOP
  88. ;
  89. NOTART: CMPI.W  #6,D2
  90.         BLT     EOB            ;Jump if maj term number is 4 or 5
  91.         LSL.L   #4,D2          ;4 long words per entry
  92.         MOVEA.L D2,A6
  93.         ADDA.L  #_DKWTbl,A6    ;Addr of 1st dupl keyword pointers
  94. FCMP3:  MOVEA.L (A6)+,A2       ;Addr of 1st byte of keyword
  95.         MOVE.L  (A6)+,D4       ;Addr of last byte of keyword
  96.         MOVE.L  (A6)+,D0       ;Displacement to rest of keyword to test
  97.         LEA     -128(A0,D0.W),A3 ;Address of 1st byte to test
  98. FCMP2:  CMP.L   A2,D4          ;Finished comparing all of keyword?
  99.         BLT     MATCH3         ;Yes, so must have matched.
  100.         MOVE.B  (A3)+,D3       ;Next byte from input stream
  101.         MOVE.B  0(A4,D3.W),D3  ;Convert to lower case
  102.         CMP.B   (A2)+,D3
  103.         BEQ     FCMP2          ;Jump if same
  104.         TST.L   (A6)           ;Addr of next dupl keyword data
  105.         BEQ     JLOOP
  106.         MOVEA.L (A6),A6
  107.         JMP     FCMP3
  108. EOB:    MOVEA.L _EOCB,A2       ;Get address of EOB
  109.         CMPA.L  A2,A0          ;Did EOB really occur or is it user data
  110.         BLT     JLOOP          ;Jump if not
  111. MATCH2: MOVE.L  D2,D0          ;D2 is 2/3 for article sep and 4 or 5 for EOB
  112.         MOVE.L  A0,_BufIdx     ;Update index into buffer
  113.         MOVEM.L (SP)+,.3
  114.         UNLK    A5
  115.         RTS
  116. .2      EQU     0
  117. .3      REG     A2/A3/A4/D4
  118. ;
  119.         DSEG
  120.         XREF    _SubPat
  121.         XREF    _LowrCs
  122.         XREF    _DsplTb
  123.         XREF    _FrstBt
  124.         XREF    _ScndBt
  125.         XREF    _KWTbl
  126.         XREF    _DKWTbl
  127.         XREF    _EOCB
  128.         XREF    _ArtSep
  129.         XREF    _EOASep
  130.         XREF    _DFASep
  131.         XREF    _BufIdx
  132.         END
  133.  
  134.  
  135.