~sircmpwn/rc-devel

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

[PATCH v3] interp: implement ~user

Curtis Arthaud <uku82@gmx.fr>
Details
Message ID
<20231030151259.11118-2-uku82@gmx.fr>
DKIM signature
missing
Download raw message
Patch: +34 -4
Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 interp/value.ha | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/interp/value.ha b/interp/value.ha
index 1ac8653..50e6921 100644
--- a/interp/value.ha
+++ b/interp/value.ha
@@ -9,6 +9,8 @@ use path;
use rt;
use strconv;
use strings;
use unix::passwd;
use unix;

// A value object.
// TODO: s/[]value/[]str/g
@@ -97,11 +99,39 @@ export fn expand(state: *state, val: *ast::value, glob: bool) (value | error) =
};

fn expand_tilde(pattern: str) str = {
	const home = os::getenv("HOME") as str;
	let buf = path::init(pattern)!;
	path::popprefix(&buf, "~")!;
	path::prepend(&buf, home)!;
	return strings::dup(path::string(&buf));

	let iter = path::iter(&buf);
	const prefix = match (path::nextiter(&iter)) {
		case let s: str =>
			yield s;
		case =>
			abort();
	};

	const pw = if (prefix == "~") {
		yield passwd::getuid(unix::getuid());
	} else {
		const user = strings::dup(strings::ltrim(prefix, '~'));
		yield passwd::getuser(user);
	};
	match (pw) {
	case void =>
		void;
	case =>
		const pw = pw as passwd::pwent;
		defer passwd::pwent_finish(&pw);
		const home = strings::dup(pw.homedir);
		path::popprefix(&buf, prefix)!;
		path::prepend(&buf, home)!;
	};

	const s = path::string(&buf);
	if (strings::hassuffix(pattern, '/')) {
		return strings::join("", s, "/");
	} else {
		return strings::dup(s);
	};
};

fn expand_glob(pattern: str) (value | error) = {
--
2.42.0
Details
Message ID
<CWMFQ16O500M.3KRFDWF54W10K@taiga>
In-Reply-To
<20231030151259.11118-2-uku82@gmx.fr> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/rc
   0c6918c..87b794f  master -> master
Reply to thread Export thread (mbox)