home *** CD-ROM | disk | FTP | other *** search
- \ SEARCH.SEQ String search routine. by Roger Bird
-
- comment:
- This file may be removed, but it is used by WORDS.SEQ, and ENVIRON.SEQ,
- which is itself used by EXEC.SEQ.
-
- The String manipulation primitives include string comparison and
- searching. The string search implemented is used in the editor
- to find the desired string. The only unusual thing about it is
- the presence of a variable called CAPS, which determines
- whether or not to ignore the case of the subject and pattern
- strings. If case is ignored then A-Z = a-z. The default is
- ignore case.
-
- Much thanks to Roger Bird for this improved impilmentation
- of SEARCH, it is about 20 % faster than my previous improved
- version, and is 10 times faster in the case where the string
- being searched for starts with a space. It is also 140 bytes
- smaller than the old implimentation.
- comment;
-
- CODE SEARCH ( sadr slen dadr dcnt -- offset found? )
- pop cx pop di
- pop bx pop ax
- cmp bx, # 0 \ if search length "slen" is 0 then return true
- 0= if push bx
- mov ax, # true
- 1push
- then
- push di
- push es mov es, sseg push si push bp mov si, ax
- dec bx dec cx
- mov dx, bx cmp caps # 0
- 0= if mov bp, # 0
- else mov bp, # $2020
- then
- begin
- cmp bx, cx
- <= while
- begin
- mov al, 0 [si+bx] mov ah, es: 0 [di+bx]
- or ax, bp cmp ah, al
- 0= while dec bx
- 0< if pop bp pop si pop es
- pop dx sub di, dx
- push di mov ax, # $FFFF 1push
- then
- repeat
- inc di dec cx mov bx, dx
- repeat
- pop bp pop si pop es
- pop dx sub di, dx push di
- sub ax, ax 1push
- end-code
-
-