summaryrefslogtreecommitdiff
path: root/tnslc/utils/file.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-07-19 03:21:39 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-07-19 03:21:39 -0400
commit5d688b4da97da2c2f684940147478f12d1f2baba (patch)
treede7f4dff152249587790c2b07149769faaefaa37 /tnslc/utils/file.tnsl
parent34e3d4f52264cf707f7e73a8a4167f37eee812d9 (diff)
switch tokenization scheme
Diffstat (limited to 'tnslc/utils/file.tnsl')
-rw-r--r--tnslc/utils/file.tnsl22
1 files changed, 22 insertions, 0 deletions
diff --git a/tnslc/utils/file.tnsl b/tnslc/utils/file.tnsl
index 978f31b..22b11f1 100644
--- a/tnslc/utils/file.tnsl
+++ b/tnslc/utils/file.tnsl
@@ -1,6 +1,7 @@
struct File {
Artifact path,
~void handle,
+ uint pos,
bool at_end
}
@@ -14,6 +15,7 @@ struct File {
self.path.split_cstr(str, '/')
self.handle = NULL
self.at_end = false
+ self.pos = 0
;/
/; relative (~uint8 path) [File]
@@ -75,15 +77,35 @@ struct File {
;/
/; read [uint8]
+ /; if (self.at_end == true)
+ return 0
+ ;/
+
uint8 out
int bytes = _read_byte(self.handle, ~out)
+ self.pos = self.pos + 1
+
/; if (bytes == 0)
self.at_end = true
return 0
;/
+
return out
;/
+ /; unread
+ /; if (self.pos < 1)
+ return
+ ;/
+
+ _fseek(self.handle, self.pos - 1)
+ self.pos = self.pos - 1
+
+ /; if (self.at_end == true)
+ self.at_end = false
+ ;/
+ ;/
+
/; write (uint8 byte)
int written = _write_byte(self.handle, ~byte)
/; if (written == 0)