home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
tsearch.seq
< prev
next >
Wrap
Text File
|
1989-11-02
|
2KB
|
73 lines
\ 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 implementation
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;
FORTH DECIMAL TARGET >LIBRARY \ A Library file
CODE SEARCH ( sadr slen dadr dcnt -- offset found? )
[ASSEMBLER]
XCHG SI, SP
MOV CX, BX
pop di
pop bx pop ax
cmp bx, # 0 \ if search length "slen" is 0 then return true
0= if push bx
mov BX, # $FFFF \ TRUE
XCHG SI, SP
RET
then
push di
push es
push si push bp
MOV ES, SSEG
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 BX, # $FFFF \ TRUE
XCHG SI, SP
RET
then
repeat
inc di dec cx mov bx, dx
repeat
pop bp pop si pop es
pop dx sub di, dx push di
SUB BX, BX
XCHG SI, SP
RET END-CODE
FORTH TARGET >TARGET