From 43ce7fdf594cd22e59db3ccdf331f0887ce4e35d Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 28 May 2020 22:51:10 -0700 Subject: 6425 --- html/apps/print-file.mu.html | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 html/apps/print-file.mu.html (limited to 'html/apps/print-file.mu.html') diff --git a/html/apps/print-file.mu.html b/html/apps/print-file.mu.html new file mode 100644 index 00000000..7576f833 --- /dev/null +++ b/html/apps/print-file.mu.html @@ -0,0 +1,97 @@ + + + + +Mu - apps/print-file.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/apps/print-file.mu +
+ 1 # accept a filename on the commandline, read it and print it out to screen
+ 2 # only ascii right now, just like the rest of Mu
+ 3 
+ 4 fn main _args: (addr array (addr array byte)) -> exit-status/ebx: int {
+ 5   var args/eax: (addr array (addr array byte)) <- copy _args
+ 6 $main-body: {
+ 7     var n/ecx: int <- length args
+ 8     compare n, 1
+ 9     {
+10       break-if->
+11       print-string "usage: cat <filename>\n"
+12       break $main-body
+13     }
+14     {
+15       break-if-<=
+16       var filename/edx: (addr addr array byte) <- index args 1
+17       var in: (handle buffered-file)
+18       {
+19         var addr-in/eax: (addr handle buffered-file) <- address in
+20         open *filename, 0, addr-in
+21       }
+22       var _in-addr/eax: (addr buffered-file) <- lookup in
+23       var in-addr/ecx: (addr buffered-file) <- copy _in-addr
+24       {
+25         var c/eax: byte <- read-byte-buffered in-addr
+26         compare c, 0xffffffff
+27         break-if-=
+28         print-byte c
+29         loop
+30       }
+31     }
+32   }
+33   flush-stdout
+34   exit-status <- copy 0
+35 }
+
+ + + -- cgit 1.4.1-2-gfad0