Merge pull request #36 from ellerh/resize-file-limit
authorPhil Burk <philburk@mobileer.com>
Mon, 16 Jan 2017 04:28:45 +0000 (20:28 -0800)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2017 04:28:45 +0000 (20:28 -0800)
This introduces a RESIZE-FILE-LIMIT

1  2 
fth/file.fth
fth/system.fth

diff --combined fth/file.fth
@@@ -117,6 -117,22 +117,22 @@@ create (LINE-TERMINATOR) \n c
      THEN
  ;
  
+ \ A limit used to perform a sanity check on the size argument for
+ \ RESIZE-FILE.
+ 2variable RESIZE-FILE-LIMIT
+ 10000000 0 resize-file-limit 2!  \ 10MB is somewhat arbitrarily chosen
+ : RESIZE-FILE ( ud fileid -- ior )
+     -rot 2dup resize-file-limit 2@ d>             ( fileid ud big? )
+     IF
+         ." Argument (" 0 d.r ." ) is larger then RESIZE-FILE-LIMIT." cr
+         ." (You can increase RESIZE-FILE-LIMIT with 2!)" cr
+         abort
+     ELSE
+         rot (resize-file)
+     THEN
+ ;
  : (  ( "comment<rparen>"  -- )
      source-id
      CASE
      ENDCASE
  ; immediate
  
 +\ We basically try to open the file in read-only mode.  That seems to
 +\ be the best that we can do with ANSI C.  If we ever want to do
 +\ something more sophisticated, like calling access(2), we must create
 +\ a proper primitive.  (OTOH, portable programs can't assume much
 +\ about FILE-STATUS and non-portable programs could create a custom
 +\ function for access(2).)
 +: FILE-STATUS ( c-addr u -- 0 ior )
 +    r/o bin open-file           ( fileid ior1 )
 +    ?dup
 +    IF   nip 0 swap             ( 0 ior1 )
 +    ELSE close-file 0 swap      ( 0 ior2 )
 +    THEN
 +;
 +
  privatize
diff --combined fth/system.fth
        rot = -rot = and
  ;
  
+ : D< ( d1 d2 -- flag )
+     d- nip 0<
+ ;
+ : D> ( d1 d2 -- flag )
+     2swap d<
+ ;
  \ define some useful constants ------------------------------
  1 0= constant FALSE
  0 0= constant TRUE
@@@ -721,11 -729,9 +729,11 @@@ ustack 0stack
  variable TRACE-INCLUDE
  
  : INCLUDE.MARK.START  ( c-addr u -- , mark start of include for FILE?)
 -    " ::::"  pad $MOVE
 -    pad $APPEND
 -    pad ['] noop (:)
 +    dup 5 + allocate throw >r
 +    " ::::" r@ $move
 +    r@ $append
 +    r@ ['] noop (:)
 +    r> free throw
  ;
  
  : INCLUDE.MARK.END  ( -- , mark end of include )