Annotation of gforth/string.fs, revision 1.5

1.1       pazsan      1: \ dynamic string handling                              10aug99py
                      2: 
1.3       anton       3: \ Copyright (C) 2000 Free Software Foundation, Inc.
                      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
                      9: \ as published by the Free Software Foundation; either version 2
                     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
                     18: \ along with this program; if not, write to the Free Software
1.4       anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.3       anton      20: 
1.1       pazsan     21: : delete   ( buffer size count -- )
                     22:   over min >r  r@ - ( left over )  dup 0>
                     23:   IF  2dup swap dup  r@ +  -rot swap move  THEN  + r> bl fill ;
                     24: 
1.5     ! pazsan     25: [IFUNDEF] insert
1.1       pazsan     26: : insert   ( string length buffer size -- )
                     27:   rot over min >r  r@ - ( left over )
                     28:   over dup r@ +  rot move   r> move  ;
1.5     ! pazsan     29: [THEN]
1.1       pazsan     30: 
                     31: : $padding ( n -- n' )
                     32:   [ 6 cells ] Literal + [ -4 cells ] Literal and ;
                     33: : $! ( addr1 u addr2 -- )
                     34:   dup @ IF  dup @ free throw  THEN
                     35:   over $padding allocate throw over ! @
                     36:   over >r  rot over cell+  r> move 2dup ! + cell+ bl swap c! ;
                     37: : $@len ( addr -- u )  @ @ ;
                     38: : $@ ( addr1 -- addr2 u )  @ dup cell+ swap @ ;
                     39: : $!len ( u addr -- )
                     40:   over $padding over @ swap resize throw over ! @ ! ;
                     41: : $del ( addr off u -- )   >r >r dup $@ r> /string r@ delete
                     42:   dup $@len r> - swap $!len ;
                     43: : $ins ( addr1 u addr2 off -- ) >r
                     44:   2dup dup $@len rot + swap $!len  $@ 1+ r> /string insert ;
                     45: : $+! ( addr1 u addr2 -- ) dup $@len $ins ;
                     46: : $off ( addr -- )  dup @ free throw off ;
                     47: 
                     48: \ dynamic string handling                              12dec99py
                     49: 
                     50: : $split ( addr u char -- addr1 u1 addr2 u2 )
1.2       pazsan     51:   >r 2dup r> scan dup >r dup IF  1 /string  THEN
                     52:   2swap r> - 2swap ;
1.1       pazsan     53: 
                     54: : $iter ( .. $addr char xt -- .. ) { char xt }
                     55:   $@ BEGIN  dup  WHILE  char $split >r >r xt execute r> r>
                     56:      REPEAT  2drop ;

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