Diff for /gforth/kernel/require.fs between versions 1.3 and 1.6

version 1.3, 1997/06/01 20:55:22 version 1.6, 1999/03/23 20:24:26
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 51  create image-included-files  1 , A, ( po Line 49  create image-included-files  1 , A, ( po
     image-included-files 2@ nip included-files 2! ;      image-included-files 2@ nip included-files 2! ;
   
 : included? ( c-addr u -- f ) \ gforth  : 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      included-files 2@ 0
     ?do ( c-addr u addr )      ?do ( c-addr u addr )
         dup >r 2@ 2over compare 0=          dup >r 2@ 2over compare 0=
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
       \G @code{include-file} the file whose name is given by the string
       \G @var{addr u}.
     open-fpath-file throw included1 ;      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 @code{include-file} 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
       \ write a require-file.
     open-fpath-file throw 2dup included?      open-fpath-file throw 2dup included?
     if      if
         2drop close-file throw          2drop close-file throw
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 a file and keeps in mind that this file is loaded  \G @code{include-file} the file @var{file}.
   name included ;    name included ;
   
 : require  ( "file" -- ) \ gforth  : require  ( ... "file" -- ... ) \ gforth
 \G load a file only when it is not included already  \G @code{include-file} @var{file} only if it is not included already.
   name required ;    name required ;
   
 0 [IF]  0 [IF]

Removed from v.1.3  
changed lines
  Added in v.1.6


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