home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / search.seq < prev    next >
Encoding:
Text File  |  1989-07-13  |  1.8 KB  |  56 lines

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