File:  [gforth] / gforth / kernel / files.fs
Revision 1.15: download - view: text, annotated - select for diffs
Sat Sep 23 15:47:10 2000 UTC (23 years, 7 months ago) by anton
Branches: MAIN
CVS tags: v0-5-0, HEAD
changed FSF address in copyright messages

    1: \ File specifiers                                       11jun93jaw
    2: 
    3: \ Copyright (C) 1995,1996,1997,1998,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
   19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: 
   21: 4 Constant w/o ( -- fam ) \ file	w-o
   22: 2 Constant r/w ( -- fam ) \ file	r-w
   23: 0 Constant r/o ( -- fam ) \ file	r-o
   24: 
   25: : bin ( fam1 -- fam2 ) \ file
   26:     1 or ;
   27: 
   28: \ BIN WRITE-LINE                                        11jun93jaw
   29: 
   30: : write-line ( c-addr u fileid -- ior ) \ file
   31:     dup >r write-file
   32:     ?dup IF
   33: 	r> drop EXIT
   34:     THEN
   35:     newline r> write-file ;
   36: 
   37: \ include-file                                         07apr93py
   38: 
   39: : push-file  ( -- )  r>
   40:     #fill-bytes @ >r
   41:     loadline @    >r
   42:     loadfile @    >r
   43:     blk @         >r
   44:     tibstack @    >r
   45:     >tib @        >r
   46:     #tib @        >r
   47:     >in @         >r  >r
   48:     >tib @ tibstack @ = IF  #tib @ tibstack +!  THEN
   49:     tibstack @ >tib ! ;
   50: 
   51: : pop-file   ( throw-code -- throw-code )
   52:   dup IF
   53:          source >in @ sourceline# sourcefilename
   54: 	 error-stack dup @ dup 1+
   55: 	 max-errors 1- min error-stack !
   56: 	 6 * cells + cell+
   57: 	 5 cells bounds swap DO
   58: 	                    I !
   59: 	 -1 cells +LOOP
   60:   THEN
   61:   r>
   62:   r> >in         !
   63:   r> #tib        !
   64:   r> >tib        !
   65:   r> tibstack    !
   66:   r> blk         !
   67:   r> loadfile    !
   68:   r> loadline    !
   69:   r> #fill-bytes !  >r ;
   70: 
   71: : read-loop ( i*x -- j*x )
   72:   BEGIN  refill  WHILE  interpret  REPEAT ;
   73: 
   74: : include-file1 ( i*x wfileid -- j*x ior1 ior2 )
   75:     \G Interpret (process using the text interpreter) the contents of
   76:     \G the file @var{wfileid}.
   77:     push-file  loadfile !
   78:     0 loadline ! blk off  ['] read-loop catch
   79:     loadfile @ close-file swap 2dup or
   80:     pop-file  drop ;
   81: 
   82: : include-file2 ( i*x wfileid -- j*x )
   83:     \ like include-file, but does not update loadfile#
   84:     include-file1 throw throw ;
   85: 
   86: : include-file ( i*x wfileid -- j*x ) \ file
   87:     loadfilename# @ >r
   88:     3 loadfilename# ! \ "\a file/"
   89:     include-file1
   90:     r> loadfilename# !
   91:     throw throw ;
   92:     
   93: \ additional words only needed if there is file support
   94: 
   95: Warnings off
   96: 
   97: : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ core,file	paren
   98:     loadfile @ 0= IF  postpone (  EXIT  THEN
   99:     BEGIN
  100: 	>in @
  101: 	[char] ) parse nip
  102: 	>in @ rot - = \ is there no delimter?
  103:     WHILE
  104: 	refill 0=
  105: 	IF
  106: 	    warnings @
  107: 	    IF
  108: 		." warning: ')' missing" cr
  109: 	    THEN
  110: 	    EXIT
  111: 	THEN
  112:     REPEAT ; immediate
  113: 
  114: Warnings on

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