about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-29 15:09:04 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-29 15:09:04 -0700
commitdac00bd94379ce5dfd7f839d54a1d3789777ebe1 (patch)
tree04c6bd84cde4326b75ecc57a5258a1065c4c43c7
parent0ae8a9f5ad4f1072f4702024662b55736d9f6b68 (diff)
downloadmu-dac00bd94379ce5dfd7f839d54a1d3789777ebe1.tar.gz
6429
Baby steps. I managed to mess up even this tiny refactoring of print-file.mu.
Wish output registers were already checked in calls.
-rw-r--r--apps/browse.mu35
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/browse.mu b/apps/browse.mu
new file mode 100644
index 00000000..0a5c81bd
--- /dev/null
+++ b/apps/browse.mu
@@ -0,0 +1,35 @@
+# render text with word-wrap
+
+fn main args: (addr array (addr array byte)) -> exit-status/ebx: int {
+  var filename/eax: (addr array byte) <- first-arg args
+  var file-contents/ecx: (addr buffered-file) <- load-file filename
+  dump file-contents
+  flush-stdout
+  exit-status <- copy 0
+}
+
+fn first-arg args-on-stack: (addr array (addr array byte)) -> out/eax: (addr array byte) {
+  var args/eax: (addr array (addr array byte)) <- copy args-on-stack
+  var result/eax: (addr addr array byte) <- index args, 1
+  out <- copy *result
+}
+
+fn load-file filename: (addr array byte) -> out/ecx: (addr buffered-file) {
+  var result: (handle buffered-file)
+  {
+    var tmp1/eax: (addr handle buffered-file) <- address result
+    open filename, 0, tmp1
+  }
+  var tmp2/eax: (addr buffered-file) <- lookup result
+  out <- copy tmp2
+}
+
+fn dump in: (addr buffered-file) {
+  {
+    var c/eax: byte <- read-byte-buffered in
+    compare c, 0xffffffff  # EOF marker
+    break-if-=
+    print-byte c
+    loop
+  }
+}