From 3350c34a74844e21ea69077e01efff3bae64bdcd Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 23 Mar 2021 17:31:08 -0700 Subject: . --- html/linux/print-file.mu.html | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 html/linux/print-file.mu.html (limited to 'html/linux/print-file.mu.html') diff --git a/html/linux/print-file.mu.html b/html/linux/print-file.mu.html new file mode 100644 index 00000000..6cee81a7 --- /dev/null +++ b/html/linux/print-file.mu.html @@ -0,0 +1,101 @@ + + + + +Mu - linux/print-file.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/main/linux/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 # To run:
+ 5 #   $ ./translate print-file.mu
+ 6 #   $ echo abc > x
+ 7 #   $ ./a.elf x
+ 8 #   abc
+ 9 
+10 fn main _args: (addr array addr array byte) -> _/ebx: int {
+11   var args/eax: (addr array addr array byte) <- copy _args
+12   var n/ecx: int <- length args
+13   compare n, 1
+14   {
+15     break-if->
+16     print-string 0/screen, "usage: cat <filename>\n"
+17     return 0
+18   }
+19   {
+20     break-if-<=
+21     var filename/edx: (addr addr array byte) <- index args 1
+22     var in: (handle buffered-file)
+23     {
+24       var addr-in/eax: (addr handle buffered-file) <- address in
+25       open *filename, 0/read-only, addr-in
+26     }
+27     var _in-addr/eax: (addr buffered-file) <- lookup in
+28     var in-addr/ecx: (addr buffered-file) <- copy _in-addr
+29     {
+30       var c/eax: byte <- read-byte-buffered in-addr
+31       compare c, 0xffffffff/end-of-file
+32       break-if-=
+33       var g/eax: grapheme <- copy c
+34       print-grapheme 0/screen, g
+35       loop
+36     }
+37   }
+38   return 0
+39 }
+
+ + + -- cgit 1.4.1-2-gfad0