File:  [gforth] / gforth / savesys.fs
Revision 1.10: download - view: text, annotated - select for diffs
Mon Dec 31 17:34:58 2007 UTC (11 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
updated copyright years

    1: \ image dump                                           15nov94py
    2: 
    3: \ Copyright (C) 1995,1997,2003,2006,2007 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
   19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: 
   21: : save-mem-dict { addr1 u -- addr2 u }
   22:     here { addr2 }
   23:     u allot
   24:     addr1 addr2 u move
   25:     addr2 u ;
   26: 
   27: : delete-prefix ( c-addr1 u1 c-addr2 u2 -- c-addr3 u3 )
   28:     \ if c-addr2 u2 is a prefix of c-addr1 u1, delete it
   29:     2over 2over string-prefix? if
   30:         nip /string
   31:     else
   32:         2drop
   33:     endif ;
   34: 
   35: : update-image-included-files ( -- )
   36:     included-files 2@ { addr cnt }
   37:     image-included-files 2@ { old-addr old-cnt }
   38:     align here { new-addr }
   39:     cnt 2* cells allot
   40:     new-addr cnt image-included-files 2!
   41:     old-addr new-addr old-cnt 2* cells move
   42:     cnt old-cnt
   43:     U+DO
   44:         addr i 2* cells + 2@
   45:         s" GFORTHDESTDIR" getenv delete-prefix save-mem-dict
   46: 	new-addr i 2* cells + 2!
   47:     LOOP
   48:     maxalign ;
   49: 
   50: : dump-fi ( addr u -- )
   51:     w/o bin create-file throw >r
   52:     update-image-included-files
   53:     update-image-order
   54:     here forthstart - forthstart 2 cells + !
   55:     forthstart
   56:     begin \ search for start of file ("#! " at a multiple of 8)
   57: 	8 -
   58: 	dup 3 s" #! " str=
   59:     until ( imagestart )
   60:     here over - r@ write-file throw
   61:     r> close-file throw ;
   62: 
   63: : savesystem ( "name" -- ) \ gforth
   64:     name dump-fi ;

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