hare

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

commit 22b7a5c0bfdfc43faaa93361addd80775f6ca985
parent 44b72181fe9d53091d3d9725b54f322f0669cfe9
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 22 Nov 2021 10:19:24 +0100

os::exec::addfile: swap from and to parameters

By convention, the "destination" of an operation is placed in the first
parameter.

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mcmd/hare/release.ha | 18+++++++++---------
Mcmd/haredoc/main.ha | 2+-
Mos/exec/cmd.ha | 16++++++++--------
3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/cmd/hare/release.ha b/cmd/hare/release.ha @@ -214,7 +214,7 @@ fn checkbehind() (void | release_error) = { fn shortlog(out: io::file, what: str) (void | release_error) = { const cmd = exec::cmd("git", "shortlog", "--no-merges", what)?; - exec::addfile(&cmd, out, os::stdout_file); + exec::addfile(&cmd, os::stdout_file, out); const proc = exec::start(&cmd)?; const status = exec::wait(&proc)?; exec::check(&status)?; @@ -286,14 +286,14 @@ fn signtag(name: str, tag: str, key: str) (void | release_error) = { // TODO: It might be better to capture this and print it to stderr // ourselves if ssh-keygen exits nonzero, so that the error details are // available to the user for diagnosis. - exec::addfile(&ssh, exec::nullfd, os::stderr); + exec::addfile(&ssh, os::stderr, exec::nullfd); const pipe1 = exec::pipe(); const pipe2 = exec::pipe(); - exec::addfile(&archive, pipe1.1, os::stdout_file); - exec::addfile(&ssh, pipe1.0, os::stdin_file); - exec::addfile(&ssh, pipe2.1, os::stdout_file); - exec::addfile(&note, pipe2.0, os::stdin_file); + exec::addfile(&archive, os::stdout_file, pipe1.1); + exec::addfile(&ssh, os::stdin_file, pipe1.0); + exec::addfile(&ssh, os::stdout_file, pipe2.1); + exec::addfile(&note, os::stdin_file, pipe2.0); const archive = exec::start(&archive)?; const ssh = exec::start(&ssh)?; const note = exec::start(&note)?; @@ -308,7 +308,7 @@ fn signtag(name: str, tag: str, key: str) (void | release_error) = { fn git_runcmd(args: str...) (void | release_error) = { const cmd = exec::cmd("git", args...)?; - exec::addfile(&cmd, exec::nullfd, os::stderr); + exec::addfile(&cmd, os::stderr, exec::nullfd); const proc = exec::start(&cmd)?; const status = exec::wait(&proc)?; return exec::check(&status)?; @@ -318,8 +318,8 @@ fn git_readcmd(args: str...) (str | release_error) = { const pipe = exec::pipe(); defer io::close(pipe.0); const cmd = exec::cmd("git", args...)?; - exec::addfile(&cmd, pipe.1, os::stdout_file); - exec::addfile(&cmd, exec::nullfd, os::stderr); + exec::addfile(&cmd, os::stdout_file, pipe.1); + exec::addfile(&cmd, os::stderr, exec::nullfd); const proc = exec::start(&cmd)?; io::close(pipe.1); const result = io::drain(pipe.0)?; diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -224,7 +224,7 @@ fn init_tty(ctx: *context) io::handle = { }; const pipe = exec::pipe(); - exec::addfile(&pager, pipe.0, os::stdin_file); + exec::addfile(&pager, os::stdin_file, pipe.0); exec::setenv(&pager, "LESS", "FRX"); ctx.pager = exec::start(&pager)!; return pipe.1; diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha @@ -123,8 +123,8 @@ export fn setenv(cmd: *command, key: str, value: str) void = { // This operation is performed atomically, such that the following code swaps // stdout and stderr: // -// exec::addfile(&cmd, os::stdout_file, os::stderr); // exec::addfile(&cmd, os::stderr, os::stdout_file); +// exec::addfile(&cmd, os::stdout_file, os::stderr); // // Pass [[os::exec::nullfd]] in the 'from' argument to map the child's file // descriptor to /dev/null or the appropriate platform-specific equivalent. @@ -137,8 +137,8 @@ export fn setenv(cmd: *command, key: str, value: str) void = { // together, see the [[pipe]] function. export fn addfile( cmd: *command, - from: (io::file | nullfd | closefd), to: io::file, + from: (io::file | nullfd | closefd), ) void = { append(cmd.files, (from, to)); }; @@ -147,17 +147,17 @@ export fn addfile( // Many programs do not work well under these conditions; you may want // [[nullstd]] instead. export fn closestd(cmd: *command) void = { - addfile(cmd, closefd, os::stdin_file); - addfile(cmd, closefd, os::stdout_file); - addfile(cmd, closefd, os::stderr); + addfile(cmd, os::stdin_file, closefd); + addfile(cmd, os::stdout_file, closefd); + addfile(cmd, os::stderr, closefd); }; // Redirects all standard files (stdin, stdout, and stderr) to /dev/null or the // platform-specific equivalent. export fn nullstd(cmd: *command) void = { - addfile(cmd, nullfd, os::stdin_file); - addfile(cmd, nullfd, os::stdout_file); - addfile(cmd, nullfd, os::stderr); + addfile(cmd, os::stdin_file, nullfd); + addfile(cmd, os::stdout_file, nullfd); + addfile(cmd, os::stderr, nullfd); }; fn lookup(name: str) (platform_cmd | void) = {