Annotation of gforth/string.fs, revision 1.8

1.1       pazsan      1: \ dynamic string handling                              10aug99py
                      2: 
1.8     ! anton       3: \ Copyright (C) 2000,2005,2007 Free Software Foundation, Inc.
1.3       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
1.7       anton       9: \ as published by the Free Software Foundation, either version 3
1.3       anton      10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
1.7       anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.3       anton      19: 
1.1       pazsan     20: : delete   ( buffer size count -- )
                     21:   over min >r  r@ - ( left over )  dup 0>
                     22:   IF  2dup swap dup  r@ +  -rot swap move  THEN  + r> bl fill ;
                     23: 
1.5       pazsan     24: [IFUNDEF] insert
1.1       pazsan     25: : insert   ( string length buffer size -- )
                     26:   rot over min >r  r@ - ( left over )
                     27:   over dup r@ +  rot move   r> move  ;
1.5       pazsan     28: [THEN]
1.1       pazsan     29: 
                     30: : $padding ( n -- n' )
                     31:   [ 6 cells ] Literal + [ -4 cells ] Literal and ;
                     32: : $! ( addr1 u addr2 -- )
                     33:   dup @ IF  dup @ free throw  THEN
                     34:   over $padding allocate throw over ! @
                     35:   over >r  rot over cell+  r> move 2dup ! + cell+ bl swap c! ;
                     36: : $@len ( addr -- u )  @ @ ;
                     37: : $@ ( addr1 -- addr2 u )  @ dup cell+ swap @ ;
                     38: : $!len ( u addr -- )
                     39:   over $padding over @ swap resize throw over ! @ ! ;
                     40: : $del ( addr off u -- )   >r >r dup $@ r> /string r@ delete
                     41:   dup $@len r> - swap $!len ;
                     42: : $ins ( addr1 u addr2 off -- ) >r
                     43:   2dup dup $@len rot + swap $!len  $@ 1+ r> /string insert ;
                     44: : $+! ( addr1 u addr2 -- ) dup $@len $ins ;
                     45: : $off ( addr -- )  dup @ free throw off ;
                     46: 
                     47: \ dynamic string handling                              12dec99py
                     48: 
                     49: : $split ( addr u char -- addr1 u1 addr2 u2 )
1.2       pazsan     50:   >r 2dup r> scan dup >r dup IF  1 /string  THEN
                     51:   2swap r> - 2swap ;
1.1       pazsan     52: 
                     53: : $iter ( .. $addr char xt -- .. ) { char xt }
                     54:   $@ BEGIN  dup  WHILE  char $split >r >r xt execute r> r>
                     55:      REPEAT  2drop ;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>