File:  [gforth] / gforth / kernel / files.fs
Revision 1.23: download - view: text, annotated - select for diffs
Sun Feb 5 17:54:39 2006 UTC (18 years, 1 month ago) by anton
Branches: MAIN
CVS tags: HEAD
better error reporting with input-parse-start
updated copyright year in bootmessage

    1: \ File specifiers                                       11jun93jaw
    2: 
    3: \ Copyright (C) 1995,1996,1997,1998,2000,2003 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: has? new-input 0= [IF]
   40: : loadfilename>r ( addr1 u1 -- R: addr2 u2 )
   41:     r> loadfilename 2@ 2>r >r
   42:     loadfilename 2! ;
   43: 
   44: : r>loadfilename ( R: addr u -- )
   45:     r> 2r> loadfilename 2! >r ;
   46: 
   47: : push-file  ( -- )  r>
   48:     #fill-bytes @ >r
   49:     loadline @    >r
   50:     loadfile @    >r
   51:     blk @         >r
   52:     tibstack @    >r
   53:     >tib @        >r
   54:     #tib @        >r
   55:     >in @         >r  >r
   56:     >tib @ tibstack @ = IF  #tib @ tibstack +!  THEN
   57:     tibstack @ >tib ! ;
   58: 
   59: : pop-file   ( throw-code -- throw-code )
   60:   dup IF
   61:       input-error-data >error
   62:   THEN
   63:   r>
   64:   r> >in         !
   65:   r> #tib        !
   66:   r> >tib        !
   67:   r> tibstack    !
   68:   r> blk         !
   69:   r> loadfile    !
   70:   r> loadline    !
   71:   r> #fill-bytes !  >r ;
   72: 
   73: : read-loop ( i*x -- j*x )
   74:   BEGIN  refill  WHILE  interpret  REPEAT ;
   75: 
   76: : include-file1 ( i*x wfileid -- j*x ior1 ior2 )
   77:     \G Interpret (process using the text interpreter) the contents of
   78:     \G the file @var{wfileid}.
   79:     push-file  loadfile !
   80:     0 loadline ! blk off  ['] read-loop catch
   81:     loadfile @ close-file swap 2dup or
   82:     pop-file  drop ;
   83: 
   84: : include-file2 ( i*x wfileid -- j*x )
   85:     \ like include-file, but does not update loadfile#
   86:     include-file1 throw throw ;
   87: 
   88: : include-file ( i*x wfileid -- j*x ) \ file
   89:     s" *a file*" loadfilename>r
   90:     include-file1
   91:     r>loadfilename
   92:     throw throw ;
   93: [THEN]
   94:     
   95: \ additional words only needed if there is file support
   96: 
   97: Redefinitions-start
   98: 
   99: : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ core,file	paren
  100:     loadfile @ 0= IF  postpone (  EXIT  THEN
  101:     BEGIN
  102: 	>in @
  103: 	[char] ) parse nip
  104: 	>in @ rot - = \ is there no delimter?
  105:     WHILE
  106: 	refill 0=
  107: 	IF
  108: 	    warnings @
  109: 	    IF
  110: 		." warning: ')' missing" cr
  111: 	    THEN
  112: 	    EXIT
  113: 	THEN
  114:     REPEAT ; immediate
  115: 
  116: Redefinitions-end

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