home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / tsearch.seq < prev    next >
Text File  |  1989-11-02  |  2KB  |  73 lines

  1. \ SEARCH.SEQ    String search routine.                  by Roger Bird
  2.  
  3. comment:
  4.  
  5.   This file may be removed, but it is used by WORDS.SEQ, and ENVIRON.SEQ,
  6. which is itself used by EXEC.SEQ.
  7.  
  8.   The String manipulation primitives include string comparison and
  9. searching. The string search implemented is used in the editor
  10. to find the desired string.  The only unusual thing about it is
  11. the presence of a variable called CAPS, which determines
  12. whether or not to ignore the case of the subject and pattern
  13. strings.  If case is ignored then A-Z = a-z.  The default is
  14. ignore case.
  15.  
  16.         Much thanks to Roger Bird for this improved implementation
  17.         of SEARCH, it is about 20 % faster than my previous improved
  18.         version, and is 10 times faster in the case where the string
  19.         being searched for starts with a space. It is also 140 bytes
  20.         smaller than the old implimentation.
  21.  
  22. comment;
  23.  
  24. FORTH DECIMAL TARGET >LIBRARY       \ A Library file
  25.  
  26. CODE SEARCH    ( sadr slen dadr dcnt -- offset found? )
  27.         [ASSEMBLER]
  28.         XCHG SI, SP
  29.         MOV CX, BX
  30.         pop di
  31.         pop bx   pop ax
  32.         cmp bx, # 0     \ if search length "slen" is 0 then return true
  33.         0= if         push bx
  34.                       mov BX, # $FFFF   \ TRUE
  35.                       XCHG SI, SP
  36.                       RET
  37.         then
  38.         push di
  39.         push es
  40.         push si       push bp
  41.         MOV ES, SSEG
  42.         mov si, ax
  43.         dec bx dec cx
  44.         mov dx, bx
  45.         cmp CAPS # 0
  46.      0= if    mov bp, # 0
  47.         else  mov bp, # $2020
  48.         then
  49.         begin
  50.             cmp bx, cx
  51.         <= while
  52.             begin
  53.                 mov al, 0 [si+bx]   mov ah, es: 0 [di+bx]
  54.                 or ax, bp   cmp ah, al
  55.             0= while  dec bx
  56.                    0< if     pop bp   pop si   pop es
  57.                              pop dx   sub di, dx
  58.                              push di  mov BX, # $FFFF   \ TRUE
  59.                              XCHG SI, SP
  60.                              RET
  61.                       then
  62.             repeat
  63.             inc di   dec cx   mov bx, dx
  64.         repeat
  65.         pop bp      pop si       pop es
  66.         pop dx      sub di, dx   push di
  67.         SUB BX, BX
  68.         XCHG SI, SP
  69.         RET             END-CODE
  70.  
  71. FORTH TARGET >TARGET
  72.  
  73.