Annotation of gforth/kernel/files.fs, revision 1.18

1.1       anton       1: \ File specifiers                                       11jun93jaw
                      2: 
1.18    ! pazsan      3: \ Copyright (C) 1995-2003 Free Software Foundation, Inc.
1.1       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
                      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.15      anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1       anton      20: 
1.9       anton      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
1.1       anton      24: 
1.9       anton      25: : bin ( fam1 -- fam2 ) \ file
1.1       anton      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
1.8       anton      35:     newline r> write-file ;
1.1       anton      36: 
                     37: \ include-file                                         07apr93py
                     38: 
1.16      pazsan     39: has? new-input 0= [IF]
1.1       anton      40: : push-file  ( -- )  r>
1.13      pazsan     41:     #fill-bytes @ >r
                     42:     loadline @    >r
                     43:     loadfile @    >r
                     44:     blk @         >r
                     45:     tibstack @    >r
                     46:     >tib @        >r
                     47:     #tib @        >r
                     48:     >in @         >r  >r
1.3       pazsan     49:     >tib @ tibstack @ = IF  #tib @ tibstack +!  THEN
                     50:     tibstack @ >tib ! ;
1.1       anton      51: 
                     52: : pop-file   ( throw-code -- throw-code )
                     53:   dup IF
1.16      pazsan     54:          source >in @ sourceline# sourcefilename >error
1.1       anton      55:   THEN
                     56:   r>
1.13      pazsan     57:   r> >in         !
                     58:   r> #tib        !
                     59:   r> >tib        !
                     60:   r> tibstack    !
                     61:   r> blk         !
                     62:   r> loadfile    !
                     63:   r> loadline    !
                     64:   r> #fill-bytes !  >r ;
1.1       anton      65: 
                     66: : read-loop ( i*x -- j*x )
                     67:   BEGIN  refill  WHILE  interpret  REPEAT ;
                     68: 
1.10      anton      69: : include-file1 ( i*x wfileid -- j*x ior1 ior2 )
1.6       crook      70:     \G Interpret (process using the text interpreter) the contents of
1.7       crook      71:     \G the file @var{wfileid}.
1.4       anton      72:     push-file  loadfile !
                     73:     0 loadline ! blk off  ['] read-loop catch
                     74:     loadfile @ close-file swap 2dup or
1.10      anton      75:     pop-file  drop ;
                     76: 
                     77: : include-file2 ( i*x wfileid -- j*x )
                     78:     \ like include-file, but does not update loadfile#
                     79:     include-file1 throw throw ;
1.1       anton      80: 
1.10      anton      81: : include-file ( i*x wfileid -- j*x ) \ file
                     82:     loadfilename# @ >r
1.16      pazsan     83:     3 loadfilename# ! \ "*a file*"
1.10      anton      84:     include-file1
                     85:     r> loadfilename# !
                     86:     throw throw ;
1.16      pazsan     87: [THEN]
1.10      anton      88:     
1.1       anton      89: \ additional words only needed if there is file support
                     90: 
1.17      jwilke     91: Redefinitions-start
1.2       jwilke     92: 
1.1       anton      93: : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ core,file    paren
                     94:     loadfile @ 0= IF  postpone (  EXIT  THEN
                     95:     BEGIN
                     96:        >in @
                     97:        [char] ) parse nip
                     98:        >in @ rot - = \ is there no delimter?
                     99:     WHILE
                    100:        refill 0=
                    101:        IF
                    102:            warnings @
                    103:            IF
                    104:                ." warning: ')' missing" cr
                    105:            THEN
                    106:            EXIT
                    107:        THEN
                    108:     REPEAT ; immediate
                    109: 
1.17      jwilke    110: Redefinitions-end

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