Hash :
1a08f436
Author :
Date :
2010-08-25T09:23:17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
id: @(#)fileio.fth 1.3 04/04/15 19:10:04
purpose:
copyright: Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved
copyright: Use is subject to license terms.
\ Copyright 1994 FirmWorks All Rights Reserved
headerless
: (file-read-line) ( adr fd -- actual not-eof? error? )
dup if ( adr source )
/tib swap read-line ( adr len id )
( -37 ) abort" Read error in refill" ( cnt more? )
over /tib = ( -18 ) abort" line too long in input file" ( cnt more? )
else ( adr )
simple-refill-line ( cnt more? )
then ( cnt more? )
; ' (file-read-line) is refill-line
: interpret-lines ( -- ) begin refill while interpret repeat ;
: include-file ( fid -- )
/tib 4 + allocate throw ( fid adr )
save-input 2>r 2>r 2>r ( fid adr )
/tib rot set-input
['] interpret-lines catch ( error# )
source-id close-file drop ( error# )
source-adr free drop ( error# )
2r> 2r> 2r> restore-input throw ( error# )
throw
;
defer $open-error ' noop is $open-error
[ifnexist] include-hook \ Might be defined in xref.fth
headers
defer include-hook ' noop is include-hook
defer include-exit-hook ' noop is include-exit-hook
headerless
[then]
: include-buffer ( adr len -- )
open-buffer ?dup if " <buffer>" $open-error then include-file
;
: $abort-include ( error# filename$ -- ) 2drop throw ;
' $abort-include is $open-error
headers
: included ( adr len -- )
include-hook
r/o open-file ?dup if
opened-filename 2@ $open-error
then ( fid )
include-file
include-exit-hook
;
headerless
' included is cmdline-file
: including ( "name" -- ) safe-parse-word included ;
: fl ( "name" -- ) including ;
0 value error-file
nuser error-line#
nuser error-source-id
nuser error-source-adr
nuser error-#source
chain: init ( -- )
d# 128 alloc-mem is error-file
error-source-id off
0 error-file c!
error-line# off
;
: (eol-mark?) ( c -- flag )
dup 0= >r ( c )
dup control M = r> or ( c cr? )
swap control J = or ( cr? )
;
: (mark-error) ( -- )
\ Suppress message if input is interactive or from "evaluate"
source-id error-source-id !
source-id 0<> if
source-id -1 = if
\ Record the approx error position not the whole buffer!!
true source >r >in @ ( flag adr offset )
begin ( flag adr offset )
rot ( adr offset more? )
over and while ( adr offset )
2dup + c@ ( adr offset )
(eol-mark?) if ( adr offset )
1+ 0 -rot ( 0 adr offset )
else ( adr offset )
true -rot 1- ( -1 adr offset )
then ( flag adr offset )
repeat ( adr offset )
r> swap /string ( adr' len' )
>r 0 over r> ( adr' 0 adr' len )
bounds ?do ( adr' 0 )
i c@ (eol-mark?) if ( adr' len' )
leave ( adr' len' )
else ( adr' len' )
1+ ( adr' len' )
then ( adr' len' )
loop ( adr' len' )
error-#source ! error-source-adr !
else
source-id file-name error-file place
source-id file-line error-line# !
then
then
;
' (mark-error) is mark-error
: (show-error) ( -- )
??cr
error-source-id @ if
error-source-id @ -1 = if
." Evaluating: " error-source-adr @ error-#source @ type cr
else
error-file count ?dup if ( va,len )
type ." :" ( )
error-line# @ (.d) ( $adr,len )
type ." : " ( )
else ( va )
drop ( )
then ( )
then ( )
then ( )
;
' (show-error) is show-error
\ Environment?
headers
defer environment?
: null-environment? ( c-addr u -- false | i*x true ) 2drop false ;
' null-environment? is environment?
: fload fl ;
: $report-name ( name$ -- name$ )
??cr ." Loading " 2dup type cr
;
: fexit ( -- ) source-id close-file drop -1 'source-id ! ;