home *** CD-ROM | disk | FTP | other *** search
- \ SEARCH.SEQ Some string search and replace routines.
-
- 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.
-
- comment;
-
- VARIABLE FOUND
- HEX
- \ It is 10 times faster to scan twice than not to scan
- \ hee at all! Watch my lips, 10 TIMES FASTER !!!
- : SCAN-1ST ( a n c -- a n )
- CAPS @
- IF DUP 5F AND >R \ Make uppercase
- BL OR >R \ Make lower case
- 2DUP R> SCAN \ Scan lowercase
- 2SWAP R> SCAN \ Scan uppercase
- 2 PICK OVER < \ Use whatever works
- IF 2SWAP
- THEN 2DROP
- ELSE SCAN
- THEN ;
- DECIMAL
-
- : SEARCH ( sadr slen badr blen -- n f )
- FOUND OFF SWAP >R 2DUP U> 0=
- IF OVER - 1+ 2 PICK C@ R@ -ROT >R
- BEGIN R@ SCAN-1ST DUP
- IF >R 3DUP SWAP COMPARE 0=
- IF FOUND ON R> DROP 0 >R THEN R> THEN DUP
- WHILE 1 /STRING REPEAT R> 2DROP -ROT
- THEN 2DROP R> - FOUND @ ;
-
- comment:
-
- : DELETE ( buffer size count -- )
- OVER MIN >R R@ - ( left over ) DUP 0>
- IF 2DUP SWAP DUP R@ + -ROT SWAP CMOVE THEN + R> BLANK ;
-
- : INSERT ( string length buffer size -- )
- ROT OVER MIN >R R@ - ( left over )
- OVER DUP R@ + ROT CMOVE> R> CMOVE ;
-
- : REPLACE ( string length buffer size -- ) ROT MIN CMOVE ;
-
- comment;
-