about summary refs log tree commit diff
path: root/language
diff options
context:
space:
mode:
Diffstat (limited to 'language')
-rw-r--r--language/dynamic/files.e31
-rw-r--r--language/dynamic/input.e1
2 files changed, 30 insertions, 2 deletions
diff --git a/language/dynamic/files.e b/language/dynamic/files.e
index 4822c2f..e0ef533 100644
--- a/language/dynamic/files.e
+++ b/language/dynamic/files.e
@@ -150,7 +150,7 @@
   ~ (filename, file descriptor)
 
   ~   Notice that we deferred this allocation until after we know that opening
-  ~ the file succeeded. We can't leave it any longer thaan this;
+  ~ the file succeeded. We can't leave it any longer than this;
   ~ push-input-buffer will allocate memory, which will overwrite the scratch
   ~ space.
   swap allocate-string-if-temporary swap
@@ -176,3 +176,32 @@
 : current-input-file-name
   main-input-buffer buffer-filename @ ;
 
+
+: open-file-for-reading
+~ (filename -- metadata pointer or 0)
+  dup 0 0 sys-open
+  dup 0 > {
+    ." Couldn't open " swap emitstring space
+    ." because " space . ." ." newline
+    drop 0 exit
+  } if
+  ~ (filename, file descriptor)
+
+  ~ As with include, we deferred this allocation until after successful open.
+  swap allocate-string-if-temporary swap
+
+  allocate-input-buffer-metadata dup zero-input-buffer-metadata
+  ~ (filename, file descriptor)
+
+  dup 3unroll swap attach-input-buffer-to-file-descriptor ;
+
+
+~ Note that this doesn't clear data that's already in the buffer.
+~
+~ (metadata pointer --)
+: close-file
+  dup buffer-file-descriptor @ sys-close drop
+  ~ Ignore a failed close.
+
+  buffer-file-descriptor -1 swap ! ;
+
diff --git a/language/dynamic/input.e b/language/dynamic/input.e
index ccff6ca..d3d094e 100644
--- a/language/dynamic/input.e
+++ b/language/dynamic/input.e
@@ -267,7 +267,6 @@
       { drop drop drop } if-else ;
 
 
-
 ~   Here we have some imperative code that runs immediately, to initialize
 ~ some runtime data structures.
 ~