~autumnull/treecat-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] update for Hare 0.24.2

Details
Message ID
<20240706213955.997382-1-srht-n2c9ebas@onemoresuza.com>
DKIM signature
pass
Download raw message
Patch: +31 -36
From: Coutinho de Souza <dev@onemoresuza.com>

---
 src/treecat.ha   | 55 +++++++++++++++++++++++-------------------------
 src/untreecat.ha | 12 +++++------
 2 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/src/treecat.ha b/src/treecat.ha
index 71de11c..90a9b56 100644
--- a/src/treecat.ha
+++ b/src/treecat.ha
@@ -58,15 +58,13 @@ fn treecat(
			};

			const lines = strings::tokenize(contents, "\n");
			for (true) match (strings::next_token(&lines)) {
				case void => break;
				case let line: str =>
					fmt::print(prefix)?;
					fmt::print(
						if (final && strings::peek_token(&lines) is void) "└ "
						else "│ "
					)?;
					fmt::println(line)?;
			for (let line => strings::next_token(&lines)) {
				fmt::print(prefix)?;
				fmt::print(
					if (final && strings::peek_token(&lines) is done) "└ "
					else "│ "
				)?;
				fmt::println(line)?;
			};
			return;
		case utf8::invalid => void;
@@ -116,13 +114,16 @@ fn treecat(
		// collect the children we want to scan
		let children: []str = [];
		defer strings::freeall(children);
		for (true) match (fs::next(iter)) {
			case void => break;
		for (let d => fs::next(iter)) match(d) {
			case let d: fs::dirent =>
				if (strings::hasprefix(d.name, '.') && !ctx.dotfiles) continue;
				if (d.name == "." || d.name == "..") continue;
				if (!(fs::isfile(d.ftype) || fs::isdir(d.ftype) || fs::islink(d.ftype))) continue;
				append(children, strings::dup(d.name));
			case let e: fs::error =>
				fmt::errorfln("Couldn't collect dir: {}",
					fs::strerror(e))?;
				os::exit(1);
		};
		sort::sort(children, size(str), &cmp::strs);

@@ -162,24 +163,20 @@ fn escape(filename: str) (str | io::error) = {
	defer io::close(&result)!;

	let iter = strings::iter(filename);
	for (true) match (strings::next(&iter)) {
		case void => break;
		case let r: rune =>
			switch (r) {
			case '\a' => memio::concat(&result, "\\a")?;
			case '\b' => memio::concat(&result, "\\b")?;
			case '\f' => memio::concat(&result, "\\f")?;
			case '\n' => memio::concat(&result, "\\n")?;
			case '\r' => memio::concat(&result, "\\r")?;
			case '\t' => memio::concat(&result, "\\t")?;
			case '\v' => memio::concat(&result, "\\v")?;
			case '\\' => memio::concat(&result, "\\\\")?;
			case '\x1b' => memio::concat(&result, "\\e")?;
			case => if (r: u32 < 0x20 || r == '\x7f') {
					fmt::fprintf(&result, "\\x{:.2x}", r: u32)?;
				} else {
					memio::appendrune(&result, r)?;
				};
	for (let r => strings::next(&iter)) switch (r) {
		case '\a' => memio::concat(&result, "\\a")?;
		case '\b' => memio::concat(&result, "\\b")?;
		case '\f' => memio::concat(&result, "\\f")?;
		case '\n' => memio::concat(&result, "\\n")?;
		case '\r' => memio::concat(&result, "\\r")?;
		case '\t' => memio::concat(&result, "\\t")?;
		case '\v' => memio::concat(&result, "\\v")?;
		case '\\' => memio::concat(&result, "\\\\")?;
		case '\x1b' => memio::concat(&result, "\\e")?;
		case => if (r: u32 < 0x20 || r == '\x7f') {
				fmt::fprintf(&result, "\\x{:.2x}", r: u32)?;
			} else {
				memio::appendrune(&result, r)?;
			};
	};
	return strings::dup(memio::string(&result)!);
diff --git a/src/untreecat.ha b/src/untreecat.ha
index f61c1b2..ee927e2 100644
--- a/src/untreecat.ha
+++ b/src/untreecat.ha
@@ -178,7 +178,7 @@ fn untreecat_r(
					if (i == len(line) - 1) fmt::fatal("Odd length of hexdump line");
					const hex = strings::fromutf8(line[i..i+2])?;
					i += 2;
					const byte = match(strconv::stou8b(hex, 16)) {
					const byte = match(strconv::stou8(hex, 16)) {
						case let b: u8 => yield b;
						case let e: strconv::error =>
							fmt::fatalf("Couldn't parse byte value {}: {}", hex, strconv::strerror(e));
@@ -267,14 +267,12 @@ fn unescape(filename: str) (str | io::error) = {
	defer io::close(&result)!;

	let iter = strings::iter(filename);
	for (true) match (strings::next(&iter)) {
	case void => break;
	case let r: rune =>
	for (let r => strings::next(&iter)) {
		if (r != '\\') {
			memio::appendrune(&result, r)?;
		} else {
			match (strings::next(&iter)) {
			case void => fmt::fatalf("Expected one of \"abefnrtvx\" after \\ in {}", filename);
			case done => fmt::fatalf("Expected one of \"abefnrtvx\" after \\ in {}", filename);
			case let r2: rune =>
				const nextrune = switch (r2) {
				case '\\' => yield '\\';
@@ -289,7 +287,7 @@ fn unescape(filename: str) (str | io::error) = {
				case 'x' =>
					let seq: [2]rune = ['\0', '\0'];
					for (let i = 0z; i < 2; i += 1) match (strings::next(&iter)) {
					case void =>
					case done =>
						fmt::fatalf("Expected 2 hex digits after \\x in {}", filename);
					case let r3: rune =>
						seq[i] = r3;
@@ -298,7 +296,7 @@ fn unescape(filename: str) (str | io::error) = {
					const s = strings::fromrunes(seq);
					defer free(s);

					yield match (strconv::stou8b(s, 16)) {
					yield match (strconv::stou8(s, 16)) {
					case let e: strconv::error =>
						fmt::fatal("Couldn't parse hex escape sequence:", strconv::strerror(e));
					case let b: u8 =>
-- 
2.44.1
Details
Message ID
<D2IS8I2XR1S1.30WQ002CJF2WC@onemoresuza.com>
In-Reply-To
<20240706213955.997382-1-srht-n2c9ebas@onemoresuza.com> (view parent)
DKIM signature
pass
Download raw message
~autumnull, fs::next now may return an error. The error handling I've
applied to such case is to print the human readable string for the
fs::error and exit with the error code 1.

If that's not how it should be handled, let me know and I'll change the
patch accordingly.
Details
Message ID
<3d840a36-dbbf-4598-aeac-fa8704432f6f@posteo.net>
In-Reply-To
<D2IS8I2XR1S1.30WQ002CJF2WC@onemoresuza.com> (view parent)
DKIM signature
pass
Download raw message
On 7/6/24 22:43, Coutinho de Souza wrote:
> ~autumnull, fs::next now may return an error. The error handling I've
> applied to such case is to print the human readable string for the
> fs::error and exit with the error code 1.
> 
> If that's not how it should be handled, let me know and I'll change the
> patch accordingly.

This is great thanks, patch pushed

~Autumn
Reply to thread Export thread (mbox)