--- gforth/kernel/require.fs 1997/06/01 20:55:22 1.3 +++ gforth/kernel/require.fs 1999/03/23 20:24:26 1.6 @@ -1,6 +1,6 @@ \ 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. @@ -20,10 +20,8 @@ \ Now: Kernel Module, Reloadable -\ $Id: require.fs,v 1.3 1997/06/01 20:55:22 jwilke 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 @@ -51,7 +49,7 @@ create image-included-files 1 , A, ( po image-included-files 2@ nip included-files 2! ; : included? ( c-addr u -- f ) \ gforth - \G true, iff filename c-addr u is in included-files + \G True, iff filename c-addr u is in included-files included-files 2@ 0 ?do ( c-addr u addr ) dup >r 2@ 2over compare 0= @@ -79,17 +77,20 @@ create image-included-files 1 , A, ( po throw ; : included ( i*x addr u -- j*x ) \ file + \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. + \G @code{include-file} 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 @@ -99,12 +100,12 @@ create image-included-files 1 , A, ( po \ INCLUDE 9may93jaw -: include ( "file" -- ) \ gforth -\G includes a file and keeps in mind that this file is loaded +: include ( ... "file" -- ... ) \ gforth +\G @code{include-file} the file @var{file}. name included ; -: require ( "file" -- ) \ gforth -\G load a file only when it is not included already +: require ( ... "file" -- ... ) \ gforth +\G @code{include-file} @var{file} only if it is not included already. name required ; 0 [IF] @@ -142,5 +143,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.3 1997/06/01 20:55:22 jwilke Exp $ +\ \I $Id: require.fs,v 1.6 1999/03/23 20:24:26 crook Exp $