version 1.1, 1997/05/21 20:40:17
|
version 1.5, 1998/12/08 22:03:13
|
Line 1
|
Line 1
|
\ require.fs |
\ require.fs |
|
|
\ Copyright (C) 1995-1997 Free Software Foundation, Inc. |
\ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. |
|
|
\ This file is part of Gforth. |
\ This file is part of Gforth. |
|
|
Line 20
|
Line 20
|
|
|
\ Now: Kernel Module, Reloadable |
\ Now: Kernel Module, Reloadable |
|
|
\ $Id$ |
|
|
|
create included-files 0 , 0 , ( pointer to and count of included files ) |
create included-files 0 , 0 , ( pointer to and count of included files ) |
here ," the terminal" dup c@ swap 1 + swap , A, here 2 cells - |
here ," ./the terminal" dup c@ swap 1 + swap , A, here 2 cells - |
create image-included-files 1 , A, ( pointer to and count of included files ) |
create image-included-files 1 , A, ( pointer to and count of included files ) |
\ included-files points to ALLOCATEd space, while image-included-files |
\ included-files points to ALLOCATEd space, while image-included-files |
\ points to ALLOTed objects, so it survives a save-system |
\ points to ALLOTed objects, so it survives a save-system |
Line 79 create image-included-files 1 , A, ( po
|
Line 77 create image-included-files 1 , A, ( po
|
throw ; |
throw ; |
|
|
: included ( i*x addr u -- j*x ) \ file |
: included ( i*x addr u -- j*x ) \ file |
open-fpath-file included1 ; |
\G @code{include-file} the file whose name is given by the string |
|
\G @var{addr u}. |
|
open-fpath-file throw included1 ; |
|
|
: required ( i*x addr u -- j*x ) \ gforth |
: required ( i*x addr u -- j*x ) \ gforth |
\G include the file with the name given by addr u, if it is not |
\G include the file with the name given by @var{addr u}, if it is not |
\G included already. Currently this works by comparing the name of |
\G @code{included} (or @code{required}) already. Currently this |
\G the file (with path) against the names of earlier included |
\G works by comparing the name of the file (with path) against the |
\G files; however, it would probably be better to fstat the file, |
\G names of earlier included files. |
\G and compare the device and inode. The advantages would be: no |
\ however, it may be better to fstat the file, |
\G problems with several paths to the same file (e.g., due to |
\ and compare the device and inode. The advantages would be: no |
\G links) and we would catch files included with include-file and |
\ problems with several paths to the same file (e.g., due to |
\G write a require-file. |
\ links) and we would catch files included with include-file and |
open-fpath-file 2dup included? |
\ write a require-file. |
|
open-fpath-file throw 2dup included? |
if |
if |
2drop close-file throw |
2drop close-file throw |
else |
else |
Line 99 create image-included-files 1 , A, ( po
|
Line 100 create image-included-files 1 , A, ( po
|
|
|
\ INCLUDE 9may93jaw |
\ INCLUDE 9may93jaw |
|
|
: include ( "file" -- ) \ gforth |
: include ( ... "file" -- ... ) \ gforth |
|
\G includes @var{file} |
name included ; |
name included ; |
|
|
: require ( "file" -- ) \ gforth |
: require ( ... "file" -- ... ) \ gforth |
|
\G includes @var{file} only if it is not included already |
name required ; |
name required ; |
|
|
0 [IF] |
0 [IF] |