hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 88a646de6f269a31ddb0a8427337ce420ec24464
parent 3b4816b04acbf0d92306c410fae9bbc7c6de1241
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Feb 2021 21:51:44 -0500

main.ha: demo use of fmt

Diffstat:
Mmain.ha | 21++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/main.ha b/main.ha @@ -1,30 +1,29 @@ +use fmt; use io; use os; export fn main() void = { - if (len(os::args) == 1z) { - match (io::copy(os::stdout, os::stdin)) { - err: io::error => fatal(io::errstr(err)), - size => void, - }; - return; + if (len(os::args) == 1z) match (io::copy(os::stdout, os::stdin)) { + err: io::error => fatal("Error: {}\n", io::errstr(err)), + size => os::exit(0), }; for (let i = 1z; i < len(os::args); i += 1z) { - let in: *io::stream = match (os::open(os::args[i], io::mode::RDONLY)) { + let in = match (os::open(os::args[i], io::mode::RDONLY)) { stream: *io::stream => stream, - err: io::error => fatal(io::errstr(err)), + err: io::error => fatal("Error: {}: {}\n", + os::args[i], io::errstr(err)), }; defer io::close(in); match (io::copy(os::stdout, in)) { - err: io::error => fatal(io::errstr(err)), + err: io::error => fatal("Error: {}\n", io::errstr(err)), size => void, }; }; }; -@noreturn fn fatal(why: str) void = { - io::errorln(why); +@noreturn fn fatal(fmt: str, args: fmt::formattable...) void = { + fmt::errorf(fmt, args...); os::exit(1); };