home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / ZEN1_10.ZIP / STRINGS2.SRC < prev    next >
Encoding:
Text File  |  1989-12-31  |  3.2 KB  |  126 lines

  1. \*
  2.  *   ZEN 1.10  Supplementary string package
  3.  *     C 1990  by Martin Tracy
  4.  *             Last modified  1.1.90
  5.  *\
  6.  
  7. | 1024 CONSTANT #SB   \ Rotating string buffer size in bytes.
  8.                       \ Also maximum length of string.
  9.  
  10. | VARIABLE SB      \ Rotating string buffer.
  11.   1024 ( #SB) CELL - ALLOT
  12.  
  13. \ Allocate u bytes in rotating buffer and return its address.
  14. | : SBALLOT ( u - a)
  15.    #SB OVER SBCTR @ + U< ( wrap?)
  16.    IF  SBCTR OFF  THEN  SB SBCTR @ +  SWAP SBCTR +! ;
  17.  
  18. \ Copy or renew temporary string.
  19. : STRCPY ( a u - a2 u2)
  20.    DUP SBALLOT  SWAP 2DUP 2>R MOVE  2R> ;
  21.  
  22. \ Copy string and concatenate string2 to copy.
  23. : STRCAT ( a u a2 u2 - a3 u3)
  24.    2>R  DUP R@ +  DUP SBALLOT  2>R  R@ SWAP MOVE  2R> SWAP
  25.    2R>  2OVER  ROT OVER SWAP - /STRING MOVE ;
  26.  
  27.  
  28. \ Return -1 if string a1 n < a2 n , 0 if equal, and 1 if >.
  29. CODE -TEXT ( a1 len a2 - -1|0|1)
  30.         mov   di,bx
  31.         mov   bx,ds
  32.         mov   es,bx
  33.         xchg  ax,si
  34.         pop   cx
  35.         pop   si
  36.         jcxz  MTex1
  37.         repe  cmpsb
  38.         jz    MTex1
  39.         mov   cx,1
  40.         jnc   MTex1
  41.         neg   cx
  42. MTex1:  mov   bx,cx
  43.         xchg  ax,si
  44.         NEXT
  45. END-CODE
  46.  
  47. \ Return -1 if a n < a2 n2 , 0 if equal, and 1 if >.
  48. : COMPARE ( a n a2 n2 - -1|0|1)
  49.    ROT  2DUP ( lengths ) 2>R  MIN SWAP  -TEXT  DUP
  50.    IF    2R> 2DROP
  51.    ELSE  DROP  2R> 2DUP = ( lengths = ?)
  52.      IF  2DROP 0  ELSE  > 2* 1+  THEN
  53.    THEN ;
  54.  
  55.  
  56. \ Return the position of string2 in string1.
  57. \ Offset is zero if string2 is found in first char position.
  58. \ Return -1 if no match.
  59. CODE STRNDX ( a u a2 u2 - offset | -1)
  60.         mov   dx,si
  61.         pop   si
  62.         pop   ax
  63.         xchg  ax,bx
  64.         pop   di      ; si=a2 ax=u2 di=a1 bx=u1
  65.         push  dx
  66.         or    ax,ax
  67.         jnz   Strnd1
  68.         pop   si
  69.         sub   bx,bx
  70.         NEXT
  71. Strnd1: sub   bx,ax
  72.         jns   Strnd2
  73.         pop   si
  74.         mov   bx,TRUTH
  75.         NEXT
  76. Strnd2: push  di
  77.         mov   dx,ds
  78.         mov   es,dx
  79. Strnd3: push  si
  80.         push  di
  81.         mov   cx,ax
  82.         repe  cmpsb
  83.         pop   di
  84.         pop   si
  85.         jnz   Strnd4
  86.         pop   si
  87.         sub   di,si
  88.         pop   si
  89.         mov   bx,di
  90.         NEXT
  91. Strnd4: or    bx,bx
  92.         jz    Strnd5
  93.         inc   di
  94.         dec   bx
  95.         jmp   Strnd3
  96. Strnd5: pop   di
  97.         pop   si
  98.         mov   bx,TRUTH
  99.         NEXT
  100. END-CODE
  101.  
  102.  
  103. \*
  104. \ Return -1 if string a1 n < a2 n , 0 if equal, and 1 if >.
  105. : -TEXT ( a1 n a2 - -1|0|1)
  106.    SWAP 0 ?DO  OVER C@ OVER C@ - ( these chars <> ?)
  107.              IF  UNLOOP  C@ SWAP C@ > 2* 1+  EXIT  THEN  1 1 D+
  108.           LOOP  2DROP 0 ;
  109.  
  110.  
  111. \ Return the position of string2 in string1.
  112. \ Offset is zero if string2 is found in first char position.
  113. \ Return -1 if no match.
  114. : STRNDX ( a u a2 u2 - offset | -1)
  115.    DUP 0= IF       2DROP 2DROP     0 EXIT  THEN
  116.    2SWAP  2 PICK OVER SWAP -   ( a2 u2 a u u-u2)
  117.    DUP 0< IF  DROP 2DROP 2DROP  TRUE EXIT  THEN
  118.    0   ( offset) SWAP 1+ 0
  119.    DO  ( offset) >R            ( a2 u2 a u  r: o)
  120.      2OVER 2OVER DROP  -TEXT 0=  ( equal? )
  121.      IF  2DROP 2DROP  R>  UNLOOP EXIT  THEN
  122.      1 /STRING   R> 1+
  123.    LOOP  DROP 2DROP 2DROP  TRUE ;
  124. *\
  125.  
  126.