[gforth] / gforth / kernel / files.fs  

gforth: gforth/kernel/files.fs


1 : anton 1.1 \ File specifiers 11jun93jaw
2 :    
3 : anton 1.5 \ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4 : anton 1.1
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 :    
21 : anton 1.9 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 : anton 1.1
25 : anton 1.9 : bin ( fam1 -- fam2 ) \ file
26 : anton 1.1 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 : anton 1.8 newline r> write-file ;
36 : anton 1.1
37 : pazsan 1.11 : read-line ( c_addr u1 wfileid -- u2 flag wior )
38 :     (read-line) drop ;
39 :    
40 : anton 1.1 \ include-file 07apr93py
41 :    
42 :     : push-file ( -- ) r>
43 : pazsan 1.3 loadline @ >r
44 :     loadfile @ >r
45 :     blk @ >r
46 :     tibstack @ >r
47 :     >tib @ >r
48 :     #tib @ >r
49 :     >in @ >r >r
50 :     >tib @ tibstack @ = IF #tib @ tibstack +! THEN
51 :     tibstack @ >tib ! ;
52 : anton 1.1
53 :     : pop-file ( throw-code -- throw-code )
54 :     dup IF
55 :     source >in @ sourceline# sourcefilename
56 :     error-stack dup @ dup 1+
57 :     max-errors 1- min error-stack !
58 :     6 * cells + cell+
59 :     5 cells bounds swap DO
60 :     I !
61 :     -1 cells +LOOP
62 :     THEN
63 :     r>
64 : pazsan 1.3 r> >in !
65 :     r> #tib !
66 :     r> >tib !
67 :     r> tibstack !
68 :     r> blk !
69 :     r> loadfile !
70 :     r> loadline ! >r ;
71 : anton 1.1
72 :     : read-loop ( i*x -- j*x )
73 :     BEGIN refill WHILE interpret REPEAT ;
74 :    
75 : anton 1.10 : include-file1 ( i*x wfileid -- j*x ior1 ior2 )
76 : crook 1.6 \G Interpret (process using the text interpreter) the contents of
77 : crook 1.7 \G the file @var{wfileid}.
78 : anton 1.4 push-file loadfile !
79 :     0 loadline ! blk off ['] read-loop catch
80 :     loadfile @ close-file swap 2dup or
81 : anton 1.10 pop-file drop ;
82 :    
83 :     : include-file2 ( i*x wfileid -- j*x )
84 :     \ like include-file, but does not update loadfile#
85 :     include-file1 throw throw ;
86 : anton 1.1
87 : anton 1.10 : include-file ( i*x wfileid -- j*x ) \ file
88 :     loadfilename# @ >r
89 :     3 loadfilename# ! \ "\a file/"
90 :     include-file1
91 :     r> loadfilename# !
92 :     throw throw ;
93 :    
94 : anton 1.1 \ additional words only needed if there is file support
95 :    
96 : jwilke 1.2 Warnings off
97 :    
98 : anton 1.1 : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ core,file paren
99 :     loadfile @ 0= IF postpone ( EXIT THEN
100 :     BEGIN
101 :     >in @
102 :     [char] ) parse nip
103 :     >in @ rot - = \ is there no delimter?
104 :     WHILE
105 :     refill 0=
106 :     IF
107 :     warnings @
108 :     IF
109 :     ." warning: ')' missing" cr
110 :     THEN
111 :     EXIT
112 :     THEN
113 :     REPEAT ; immediate
114 :    
115 : jwilke 1.2 Warnings on

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help