diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-07-16 08:09:42 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-07-16 08:28:56 -0700 |
commit | 44d26b77c45668c9b0c99894a4294cec004361fe (patch) | |
tree | 68a5dcd4971873efd4ce184e9bf9a531c2161813 /linux/apps/print-file.mu | |
parent | ac45f097153afd3a89f43886e4124c5b2c26b98a (diff) | |
download | mu-44d26b77c45668c9b0c99894a4294cec004361fe.tar.gz |
.
Diffstat (limited to 'linux/apps/print-file.mu')
-rw-r--r-- | linux/apps/print-file.mu | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/linux/apps/print-file.mu b/linux/apps/print-file.mu new file mode 100644 index 00000000..75ce2e39 --- /dev/null +++ b/linux/apps/print-file.mu @@ -0,0 +1,39 @@ +# accept a filename on the commandline, read it and print it out to screen +# only ascii right now, just like the rest of Mu +# +# To run: +# $ ./translate apps/print-file.mu +# $ echo abc > x +# $ ./a.elf x +# abc + +fn main _args: (addr array addr array byte) -> _/ebx: int { + var args/eax: (addr array addr array byte) <- copy _args + var n/ecx: int <- length args + compare n, 1 + { + break-if-> + print-string 0/screen, "usage: cat <filename>\n" + return 0 + } + { + break-if-<= + var filename/edx: (addr addr array byte) <- index args 1 + var in: (handle buffered-file) + { + var addr-in/eax: (addr handle buffered-file) <- address in + open *filename, 0/read-only, addr-in + } + var _in-addr/eax: (addr buffered-file) <- lookup in + var in-addr/ecx: (addr buffered-file) <- copy _in-addr + { + var c/eax: byte <- read-byte-buffered in-addr + compare c, 0xffffffff/end-of-file + break-if-= + var g/eax: grapheme <- copy c + print-grapheme 0/screen, g + loop + } + } + return 0 +} |