hautils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 20f3d97b4135a1a36878eb0ccc9f4fc6de36a377
parent b20cdad1bc7fa4e17fd9d8b54310ad910a6b0243
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed,  8 Dec 2021 17:03:10 +0000

Update for new match binding 'case let' syntax

Update code to compile with:
dd73e7df284e61e2fb1e371210dbe5956db84bcb harec
9df4493ae0107fa49d1d646172f328fb93ad8f46 hare

Diffstat:
Mcat.ha | 4++--
Mhead.ha | 10+++++-----
Mmain/main.ha | 4++--
Mnl.ha | 18+++++++++---------
Msleep.ha | 2+-
Mtee.ha | 4++--
6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/cat.ha b/cat.ha @@ -16,10 +16,10 @@ export fn utilmain() (main::error | void) = { for (let i = 0z; i < len(cmd.args); i += 1z) { const file = match (os::open(cmd.args[i])) { - case err: fs::error => + case let err: fs::error => fmt::fatal("Error opening '{}': {}", cmd.args[i], fs::strerror(err)); - case file: io::file => + case let file: io::file => yield file; }; defer io::close(file); diff --git a/head.ha b/head.ha @@ -20,7 +20,7 @@ export fn utilmain() (void | main::error) = { n = match (strconv::stou(opt.1)) { case (strconv::invalid | strconv::overflow) => fmt::fatal("Invalid number given for -n"); - case n: uint => + case let n: uint => yield n; }; }; @@ -31,10 +31,10 @@ export fn utilmain() (void | main::error) = { for (let i = 0z; i < len(cmd.args); i += 1) { const file = match (os::open(cmd.args[i])) { - case err: fs::error => + case let err: fs::error => fmt::fatal("Error opening '{}': {}", cmd.args[i], fs::strerror(err)); - case file: io::file => + case let file: io::file => yield file; }; defer io::close(file); @@ -48,11 +48,11 @@ export fn utilmain() (void | main::error) = { fn head(in: io::handle, n: uint) (void | main::error) = { for (n > 0; n -= 1) { let line = match (bufio::scanline(in)) { - case err: io::error => + case let err: io::error => return err; case io::EOF => break; - case line: []u8 => + case let line: []u8 => yield line; }; defer free(line); diff --git a/main/main.ha b/main/main.ha @@ -9,9 +9,9 @@ export type error = !(io::error | fs::error); // Shared main function for all utilities, to simplify error handling. export @symbol("main") fn main() void = { match (utilmain()) { - case err: io::error => + case let err: io::error => fmt::fatal("I/O error: {}", io::strerror(err)); - case err: fs::error => + case let err: fs::error => fmt::fatal("Filesystem error: {}", fs::strerror(err)); case void => void; }; diff --git a/nl.ha b/nl.ha @@ -124,14 +124,14 @@ export fn utilmain() (void | main::error) = { ctx.incr = match (strconv::stoi(opt.1)) { case (strconv::invalid | strconv::overflow) => usage(help); - case incr: int => + case let incr: int => yield incr; }; case 'l' => ctx.maxblanks = match (strconv::stou(opt.1)) { case (strconv::invalid | strconv::overflow) => usage(help); - case maxblanks: uint => + case let maxblanks: uint => yield if (maxblanks > 0) maxblanks else usage(help); }; case 'n' => @@ -151,14 +151,14 @@ export fn utilmain() (void | main::error) = { ctx.mod.width = match (strconv::stou(opt.1)) { case (strconv::invalid | strconv::overflow) => usage(help); - case width: uint => + case let width: uint => yield if (width > 0) width else usage(help); }; case 'v' => startnum = match (strconv::stoi(opt.1)) { case (strconv::invalid | strconv::overflow) => usage(help); - case startnum: int => + case let startnum: int => yield startnum; }; }; @@ -171,10 +171,10 @@ export fn utilmain() (void | main::error) = { const use_file = len(cmd.args) == 1 && cmd.args[0] != "-"; const input = if (use_file) match (os::open(cmd.args[0])) { - case err: fs::error => + case let err: fs::error => fmt::fatal("Error opening '{}': {}", cmd.args[0], fs::strerror(err)); - case file: io::file => + case let file: io::file => static const rbuf: [os::BUFSIZ]u8 = [0...]; static const wbuf: [os::BUFSIZ]u8 = [0...]; yield bufio::buffered(file, rbuf, wbuf); @@ -195,11 +195,11 @@ export fn utilmain() (void | main::error) = { for (true) { const rawline = match (bufio::scanline(input)) { - case err: io::error => + case let err: io::error => return err; case io::EOF => break; - case rawline: []u8 => + case let rawline: []u8 => yield rawline; }; defer free(rawline); @@ -266,7 +266,7 @@ fn isblank(line: str) bool = { const iter = strings::iter(line); for (true) { const r = match (strings::next(&iter)) { - case r: rune => + case let r: rune => yield r; case void => break; diff --git a/sleep.ha b/sleep.ha @@ -19,7 +19,7 @@ export fn utilmain() (void | main::error) = { const seconds = match (strconv::stou(cmd.args[0])) { case (strconv::invalid | strconv::overflow) => usage(help); - case s: uint => + case let s: uint => yield s: int; }; diff --git a/tee.ha b/tee.ha @@ -38,10 +38,10 @@ export fn utilmain() (main::error | void) = { for (let i = 0z; i < len(cmd.args); i += 1) { const file = match (os::create(cmd.args[i], 0o666, flags)) { - case err: fs::error => + case let err: fs::error => fmt::fatal("Error opening '{}' for writing: {}", cmd.args[i], fs::strerror(err)); - case file: io::file => + case let file: io::file => yield file; }; source = &io::tee(source, file);