--- gforth/kernel/require.fs 1997/05/21 20:40:17 1.1 +++ gforth/kernel/require.fs 1998/06/17 16:55:18 1.4 @@ -20,10 +20,10 @@ \ Now: Kernel Module, Reloadable -\ $Id: require.fs,v 1.1 1997/05/21 20:40:17 anton Exp $ +\ $Id: require.fs,v 1.4 1998/06/17 16:55:18 anton Exp $ 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 ) \ included-files points to ALLOCATEd space, while image-included-files \ points to ALLOTed objects, so it survives a save-system @@ -79,18 +79,21 @@ create image-included-files 1 , A, ( po throw ; : 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 - \G include the file with the name given by addr u, if it is not - \G included already. Currently this works by comparing the name of - \G the file (with path) against the names of earlier included - \G files; however, it would probably be better to fstat the file, - \G and compare the device and inode. The advantages would be: no - \G problems with several paths to the same file (e.g., due to - \G links) and we would catch files included with include-file and - \G write a require-file. - open-fpath-file 2dup included? + \G include the file with the name given by @var{addr u}, if it is not + \G @code{included} (or @code{required}) already. Currently this + \G works by comparing the name of the file (with path) against the + \G names of earlier included files. + \ however, it may be better to fstat the file, + \ and compare the device and inode. The advantages would be: no + \ problems with several paths to the same file (e.g., due to + \ links) and we would catch files included with include-file and + \ write a require-file. + open-fpath-file throw 2dup included? if 2drop close-file throw else @@ -99,10 +102,12 @@ create image-included-files 1 , A, ( po \ INCLUDE 9may93jaw -: include ( "file" -- ) \ gforth +: include ( ... "file" -- ... ) \ gforth +\G includes @var{file} name included ; -: require ( "file" -- ) \ gforth +: require ( ... "file" -- ... ) \ gforth +\G includes @var{file} only if it is not included already name required ; 0 [IF] @@ -140,5 +145,5 @@ create image-included-files 1 , A, ( po cr I 2@ type 2 cells +LOOP ; \ contains tools/newrequire.fs -\ \I $Id: require.fs,v 1.1 1997/05/21 20:40:17 anton Exp $ +\ \I $Id: require.fs,v 1.4 1998/06/17 16:55:18 anton Exp $