hautils

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

commit 56651ec0ddd7c3465babe33404097da7b88cfa98
parent 91f8b07f71317f8b9982f89243509d3848a491df
Author: Byron Torres <b@torresjrjr.com>
Date:   Sat, 21 Oct 2023 21:13:57 +0100

update per upstream; various fixes

Diffstat:
MMakefile | 1+
Mhead.ha | 2+-
Mls.ha | 24++++++++++++------------
Mnl.ha | 8+++++---
Muname.ha | 2++
Muniq.ha | 2+-
6 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/Makefile b/Makefile @@ -10,6 +10,7 @@ utils=\ env \ false \ head \ + ls \ nl \ pwd \ rm \ diff --git a/head.ha b/head.ha @@ -54,7 +54,7 @@ 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)) { + let line = match (bufio::read_line(in)) { case let err: io::error => return err; case io::EOF => diff --git a/ls.ha b/ls.ha @@ -1,4 +1,3 @@ -use datetime; use fmt; use fs; use getopt; @@ -8,6 +7,7 @@ use sort; use strings; use time; use time::chrono; +use time::date; use unix::passwd; type tstamp = (atime | ctime | mtime); @@ -78,9 +78,7 @@ export fn utilmain() (void | main::error) = { const cmd = getopt::parse(os::args, help...); defer getopt::finish(&cmd); - let flg = flags{...}; - flg.timestamp = mtime; - flg.sortby = name; + let flg = flags{ sortby = name, timestamp = mtime, ... }; for (let i = 0z; i < len(cmd.opts); i += 1) { const opt = cmd.opts[i]; switch (opt.0) { @@ -118,6 +116,8 @@ export fn utilmain() (void | main::error) = { case 'u' => flg.sortby = time; flg.timestamp = atime; + case => + main::usage(help); }; }; @@ -191,8 +191,8 @@ fn mkent(path: str, flg: flags) (entry | main::error) = { yield stat.ctime; case mtime => yield stat.mtime; - }, - ..., + }, + ... }; if (fs::islink(stat.mode)) { let targetstat = os::stat(os::readlink(f.name)?)?; @@ -313,12 +313,12 @@ fn ls_printent(ent: entry, flg: flags) (void | main::error) = { fmt::printf("{:10} ", ent.sz)?; - const date = datetime::from_instant(ent.time, chrono::LOCAL); + const date = date::from_instant(chrono::LOCAL, ent.time); const now = time::now(time::clock::REALTIME); if (now.sec > ent.time.sec + (180 * 24 * 60 * 60)) { - datetime::format(os::stdout, "%b %d %Y", &date)!; + date::format(os::stdout, "%b %d %Y", &date)!; } else { - datetime::format(os::stdout, "%b %d %H:%M", &date)!; + date::format(os::stdout, "%b %d %H:%M", &date)!; }; fmt::printf(" ")?; }; @@ -357,7 +357,7 @@ fn shouldlistdir(e: entry, flg: flags) bool = { (!flg.listdir && !flg.fileindicator && !flg.detailed)); }; -fn timecmp(a: const *void, b: const *void) int = { +fn timecmp(a: const *opaque, b: const *opaque) int = { const a = a: *entry, b = b: *entry; const dist = b.time.sec - a.time.sec; if (dist > 0) { @@ -369,7 +369,7 @@ fn timecmp(a: const *void, b: const *void) int = { }; }; -fn sizecmp(a: const *void, b: const *void) int = { +fn sizecmp(a: const *opaque, b: const *opaque) int = { const a = a: *entry, b = b: *entry; const asize = a.sz: int, bsize = b.sz: int; const dist = bsize - asize; @@ -382,7 +382,7 @@ fn sizecmp(a: const *void, b: const *void) int = { }; }; -fn namecmp(a: const *void, b: const *void) int = { +fn namecmp(a: const *opaque, b: const *opaque) int = { const a = a: *entry, b = b: *entry; return strings::compare(a.name, b.name); }; diff --git a/nl.ha b/nl.ha @@ -36,7 +36,7 @@ type context = struct { sep: str, sepblank: str, incr: int, - mod: *fmt::modifiers, + mod: *fmt::mods, }; export fn utilmain() (void | main::error) = { @@ -79,7 +79,7 @@ export fn utilmain() (void | main::error) = { sep = "\t", sepblank = "\t", incr = 1, - mod = &fmt::modifiers { + mod = &fmt::mods { width = 6, padding = fmt::padding::ALIGN_RIGHT, ... @@ -212,6 +212,8 @@ export fn utilmain() (void | main::error) = { case let startnum: int => yield startnum; }; + case => + main::usage(help); }; }; @@ -258,7 +260,7 @@ export fn utilmain() (void | main::error) = { ctx.linenum = startnum; for (true) { - const rawline = match (bufio::scanline(input)) { + const rawline = match (bufio::read_line(input)) { case let err: io::error => return err; case io::EOF => diff --git a/uname.ha b/uname.ha @@ -45,6 +45,8 @@ export fn utilmain() (void | main::error) = { flags |= flags::IMPLNAME; case 'v' => flags |= flags::VERSION; + case => + main::usage(help); }; }; diff --git a/uniq.ha b/uniq.ha @@ -41,7 +41,7 @@ fn comparisonstring(cfg: *config, line: str) str = { }; fn readline(input: io::handle) (str | io::error | io::EOF) = { - const rawline = match (bufio::scanline(input)) { + const rawline = match (bufio::read_line(input)) { case let err: io::error => return err; case io::EOF =>