hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3ac9c5240b17d094b139c2a79f0ac67f0a965ebb
parent 679d5ac9427f951b708931151068a2ad3c743ba4
Author: Alexey Yerin <yyp@disroot.org>
Date:   Sun,  5 Mar 2023 22:30:21 +0300

cmd/hare: simplify getcmd and getenv

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mcmd/hare/schedule.ha | 31++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -20,22 +20,17 @@ use strio; use unix::tty; fn getenv(var: str) []str = { - let vals: []str = []; - match(os::getenv(var)) { + match (os::getenv(var)) { case let val: str => - if(len(val) > 0) { - match(shlex::split(val)) { - case let val: []str => - for(let i = 0z; i < len(val); i += 1) { - append(vals, val[i]); - }; - case shlex::syntaxerr => void; - }; + match (shlex::split(val)) { + case let fields: []str => + return fields; + case => void; }; - case void => void; + case => void; }; - return vals; + return []; }; // (executable name, executable variable, flags variable) @@ -54,20 +49,14 @@ fn getcmd(tool: *tool, args: str...) []str = { if (len(vals) == 0) { append(execargs, tool.0); } else { - for(let i = 0z; i < len(vals); i += 1) { - append(execargs, vals[i]); - }; + append(execargs, vals...); }; let vals = getenv(tool.2); defer free(vals); - for (let i = 0z; i < len(vals); i += 1) { - append(execargs, vals[i]); - }; + append(execargs, vals...); - for(let i = 0z; i < len(args); i += 1) { - append(execargs, args[i]); - }; + append(execargs, args...); return execargs; };