-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -861,6 +861,40 @@ only forth also support-functions definitions | |
throw | ||
; | ||
|
||
\ Does the file exist? | ||
: file-exists? ( c-addr/u -- bool ) | ||
O_RDONLY fopen \ open file | ||
dup \ save a copy to not leak | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
-1 <> if | ||
fclose true | ||
else | ||
drop false | ||
then | ||
; | ||
|
||
\ Source file as code if it exists. | ||
: source-if-exists ( c-addr/u -- ) | ||
This comment has been minimized.
Sorry, something went wrong.
devinteske
|
||
|
||
2dup file-exists? if | ||
This comment has been minimized.
Sorry, something went wrong.
devinteske
|
||
\ If file exists then prepend "include" to it | ||
|
||
\ first allocate a string, top of stack is strlen of | ||
\ the filename, so just add a comfortable 15 bytes to it. | ||
dup 15 + | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
splbio
Author
Owner
|
||
allocate if ENOMEM throw then | ||
0 | ||
|
||
s" include " strcat | ||
This comment has been minimized.
Sorry, something went wrong.
devinteske
|
||
\ grab the original string up so we can strcat | ||
3 roll 3 roll | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
strcat | ||
|
||
\ evaluate " include file" | ||
2dup evaluate | ||
drop free | ||
then | ||
; | ||
|
||
: print_line line_buffer strtype cr ; | ||
|
||
: print_syntax_error | ||
|
the dup is not to prevent a leak, but to save a copy of the stack item for later fclose. "to not leak" is incorrect.