zsh-workers
 help / color / mirror / code / Atom feed
From: "Anthony Heading" <ajrh@ajrh.net>
To: zsh-workers@zsh.org
Subject: [PATCH] using sysread/syswrite with coprocess
Date: Thu, 09 May 2024 13:09:14 +0000	[thread overview]
Message-ID: <fbda2f2c-ba0c-4d32-ae24-be3b3721091a@app.fastmail.com> (raw)

Does the patch below make sense?  I couldn't see a way to do this otherwise, as it doesn't look like the coprocess fds are exposed by any parameter to enable them to be passed explicitly.  I see that using 'p' as a magic integer is supported by 'print' but undocumented, so maybe this style isn't preferred.


diff --git Src/Modules/system.c Src/Modules/system.c
index 929a8b002..e272ff391 100644
--- Src/Modules/system.c
+++ Src/Modules/system.c
@@ -78,14 +78,24 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
 
     /* -i: input file descriptor if not stdin */
     if (OPT_ISSET(ops, 'i')) {
-	infd = getposint(OPT_ARG(ops, 'i'), nam);
+	char *infdarg = OPT_ARG(ops, 'i');
+	if (!strcmp(infdarg, "p")) {
+	    infd = coprocin;
+	} else {
+	    infd = getposint(infdarg, nam);
+	}
 	if (infd < 0)
 	    return 1;
     }
 
     /* -o: output file descriptor, else store in REPLY */
     if (OPT_ISSET(ops, 'o')) {
-	outfd = getposint(OPT_ARG(ops, 'o'), nam);
+	char *outfdarg = OPT_ARG(ops, 'o');
+	if (!strcmp(outfdarg, "p")) {
+	    outfd = coprocout;
+	} else {
+	    outfd = getposint(outfdarg, nam);
+	}
 	if (outfd < 0)
 	    return 1;
     }
@@ -244,7 +254,12 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
 
     /* -o: output file descriptor if not stdout */
     if (OPT_ISSET(ops, 'o')) {
-	outfd = getposint(OPT_ARG(ops, 'o'), nam);
+	char *outfdarg = OPT_ARG(ops, 'o');
+	if (!strcmp(outfdarg, "p")) {
+	    outfd = coprocout;
+	} else {
+	    outfd = getposint(outfdarg, nam);
+	}
 	if (outfd < 0)
 	    return 1;
     }


             reply	other threads:[~2024-05-09 13:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 13:09 Anthony Heading [this message]
2024-05-09 22:38 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fbda2f2c-ba0c-4d32-ae24-be3b3721091a@app.fastmail.com \
    --to=ajrh@ajrh.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).