hautils

[hare] Set of POSIX utilities
Log | Files | Refs | README | LICENSE

commit 51d5cdd34c13550ba2ed4759bbdb58b29773437a
parent 40662698e2946aa34fe779329c8d57a843e98f70
Author: Byron Torres <b@torresjrjr.com>
Date:   Fri,  9 Dec 2022 23:56:01 +0000

Update for strings::fromutf8, os::exec::setenv

Diffstat:
Menv.ha | 7++++++-
Mnl.ha | 2+-
Muniq.ha | 8+++++++-
3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/env.ha b/env.ha @@ -1,3 +1,4 @@ +use errors; use fmt; use getopt; use main; @@ -50,7 +51,11 @@ export fn utilmain() (main::error | void) = { }; for (let i = 0z; i < len(environ); i += 1) { let env = strings::cut(environ[i], "="); - exec::setenv(&cmd, env.0, env.1); + match (exec::setenv(&cmd, env.0, env.1)) { + case errors::invalid => + fmt::fatalf("Error: Invalid key '{}'", env.0); + case void => void; + }; }; exec::exec(&cmd); }; diff --git a/nl.ha b/nl.ha @@ -268,7 +268,7 @@ export fn utilmain() (void | main::error) = { }; defer free(rawline); - const line = match (strings::try_fromutf8(rawline)) { + const line = match (strings::fromutf8(rawline)) { case let line: str => yield line; case encoding::utf8::invalid => diff --git a/uniq.ha b/uniq.ha @@ -1,3 +1,4 @@ +use encoding::utf8; use fmt; use strings; use bufio; @@ -49,7 +50,12 @@ fn readline(input: io::handle) (str | io::error | io::EOF) = { yield rawline; }; defer free(rawline); - return strings::dup(strings::fromutf8(rawline)); + match (strings::fromutf8(rawline)) { + case let s: str => + return strings::dup(s); + case encoding::utf8::invalid => + fmt::fatal("Error: Invalid UTF-8 input"); + }; }; fn uniq(cfg: *config) (main::error | void) = {