about summary refs log tree commit diff stats
path: root/apps/browse
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-07 23:23:25 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-07 23:23:25 -0700
commit8aa1b8d45e99f16dda6bafc85386d05404bd3aee (patch)
treedb780bb025cb69f005ac3ef5cc1b2b2ba8cc6fc8 /apps/browse
parent485228ed727ae3b743514e89bd5f4ad5f8c69ea0 (diff)
downloadmu-8aa1b8d45e99f16dda6bafc85386d05404bd3aee.tar.gz
6756
Diffstat (limited to 'apps/browse')
-rw-r--r--apps/browse/main.mu30
1 files changed, 29 insertions, 1 deletions
diff --git a/apps/browse/main.mu b/apps/browse/main.mu
index e7fea617..bf61ef5c 100644
--- a/apps/browse/main.mu
+++ b/apps/browse/main.mu
@@ -1,4 +1,32 @@
-fn main args: (addr array addr array byte) -> exit-status/ebx: int {
+fn main args-on-stack: (addr array addr array byte) -> exit-status/ebx: int {
+  var args/eax: (addr array addr array byte) <- copy args-on-stack
+  var tmp/ecx: int <- length args
+  $main-body: {
+    # if (len(args) <= 1) print usage and exit
+    compare tmp, 1
+    {
+      break-if->
+      print-string-to-real-screen "usage: browse [filename]\n"
+      print-string-to-real-screen "    or browse test\n"
+      exit-status <- copy 1
+      break $main-body
+    }
+    # if (args[1] == "test") run-tests()
+    var tmp2/ecx: (addr addr array byte) <- index args, 1
+    var tmp3/eax: boolean <- string-equal? *tmp2, "test"
+    compare tmp3, 0
+    {
+      break-if-=
+      run-tests
+      exit-status <- copy 0  # TODO: get at Num-test-failures somehow
+      break $main-body
+    }
+    # otherwise interactive mode
+    exit-status <- interactive args-on-stack
+  }
+}
+
+fn interactive args: (addr array addr array byte) -> exit-status/ebx: int {
   # initialize fs from args[1]
   var filename/eax: (addr array byte) <- first-arg args
   var file-storage: (handle buffered-file)