home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / FFA.ZIP / SEARCH.SEQ < prev    next >
Encoding:
Text File  |  1987-12-22  |  2.0 KB  |  58 lines

  1. \ SEARCH.SEQ    Some string search and replace routines.
  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. comment;
  17.  
  18. VARIABLE FOUND
  19. HEX
  20.                 \ It is 10 times faster to scan twice than not to scan
  21.                 \ hee at all! Watch my lips, 10 TIMES FASTER !!!
  22. : SCAN-1ST      ( a n c -- a n )
  23.                 CAPS @
  24.                 IF      DUP 5F AND >R                   \ Make uppercase
  25.                              BL OR >R                   \ Make lower case
  26.                         2DUP  R> SCAN                   \ Scan lowercase
  27.                         2SWAP R> SCAN                   \ Scan uppercase
  28.                         2 PICK OVER <                   \ Use whatever works
  29.                         IF      2SWAP
  30.                         THEN    2DROP
  31.                 ELSE    SCAN
  32.                 THEN    ;
  33. DECIMAL
  34.  
  35. : SEARCH   ( sadr slen badr blen -- n f )
  36.    FOUND OFF  SWAP >R   2DUP U> 0=
  37.    IF  OVER - 1+ 2 PICK C@  R@ -ROT >R
  38.      BEGIN  R@ SCAN-1ST DUP
  39.        IF  >R 3DUP SWAP COMPARE 0=
  40.          IF  FOUND ON  R> DROP 0 >R  THEN  R>  THEN  DUP
  41.      WHILE   1 /STRING  REPEAT  R> 2DROP -ROT
  42.    THEN  2DROP  R> -  FOUND @  ;
  43.  
  44. comment:
  45.  
  46. : DELETE   ( buffer size count -- )
  47.    OVER MIN >R  R@ - ( left over )  DUP 0>
  48.    IF  2DUP SWAP DUP R@ + -ROT SWAP CMOVE  THEN  + R> BLANK ;
  49.  
  50. : INSERT   ( string length buffer size -- )
  51.    ROT OVER MIN >R  R@ - ( left over )
  52.    OVER DUP R@ +  ROT CMOVE>   R> CMOVE  ;
  53.  
  54. : REPLACE   ( string length buffer size -- )  ROT MIN CMOVE ;
  55.  
  56. comment;
  57.  
  58.