From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: Zsh Workers <zsh-workers@sunsite.auc.dk>
Subject: Re: BUG: vared in function
Date: Wed, 31 May 2000 23:28:08 +0100 [thread overview]
Message-ID: <E12xGy9-000474-00.2000-05-31-23-28-09@mail1.svr.pol.co.uk> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Wed, 31 May 2000 22:55:21 BST." <E12xGSP-0006NP-00.2000-05-31-22-55-21@mail2.svr.pol.co.uk>
Peter Stephenson wrote:
> Bernd Eggink wrote:
> > Argh...
> >
> > # t
> > vared -cp "Aha: " BLAH
> >
> > % t
> > t:vared:2: ZLE not enabled
> >
> > This breaks lots of my scripts!
> > On the command line, 'vared' works.
>
> (I take it that should be `script' rather than `function' in the subject
> line, functions are OK.)
>
> I don't think there's any good reason why zle shouldn't be enabled
> especially.
In fact, what about this? If it works for read, shouldn't it work for
vared? It certainly seems to.
I removed the references to oshout, because it seems to me that if SHTTY is
-1 shout has no business being anything but NULL --- that was certainly the
intention when I introduced shout, although there's been a lot of water
under the bridge (and everywhere else) since then. Maybe the question even
got asked, in which case I missed it.
I'm in two minds on whether to commit this. On the one hand, there is more
of a potential for problems with read or vared. On the other hand, without
it it introduces a new problem just for one version.
I remembered the mod_export, anyway.
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.20
diff -u -r1.20 builtin.c
--- Src/builtin.c 2000/05/27 08:31:32 1.20
+++ Src/builtin.c 2000/05/31 22:22:51
@@ -3357,6 +3357,39 @@
static char *zbuf;
static int readfd;
+/**/
+mod_export int
+openttyspecially(int kopt)
+{
+ int haso = 0;
+
+ if (SHTTY == -1) {
+ /* need to open /dev/tty specially */
+ if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
+ haso = 1;
+ init_shout();
+ }
+ } else if (!shout) {
+ /* We need an output FILE* on the tty */
+ init_shout();
+ }
+ /* We should have a SHTTY opened by now. */
+ if (SHTTY == -1) {
+ /* Unfortunately, we didn't. */
+ fprintf(stderr, "not interactive and can't open terminal\n");
+ fflush(stderr);
+ return 1;
+ }
+ if (unset(INTERACTIVE))
+ gettyinfo(&shttyinfo);
+ /* attach to the tty */
+ attachtty(mypgrp);
+ if (kopt)
+ setcbreak();
+ readfd = SHTTY;
+ return haso;
+}
+
/* Read a character from readfd, or from the buffer zbuf. Return EOF on end of
file/buffer. */
@@ -3376,7 +3409,6 @@
int isem = !strcmp(term, "emacs"), izle = zleactive && getkeyptr;
char *buf, *bptr, *firstarg, *zbuforig;
LinkList readll = newlinklist();
- FILE *oshout = NULL;
if ((ops['k'] || ops['b']) && *args && idigit(**args)) {
if (!(nchars = atoi(*args)))
@@ -3398,33 +3430,8 @@
return compctlread(name, args, ops, reply);
if ((ops['k'] && !ops['u'] && !ops['p']) || ops['q']) {
- if (!zleactive) {
- if (SHTTY == -1) {
- /* need to open /dev/tty specially */
- if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
- haso = 1;
- oshout = shout;
- init_shout();
- }
- } else if (!shout) {
- /* We need an output FILE* on the tty */
- init_shout();
- }
- /* We should have a SHTTY opened by now. */
- if (SHTTY == -1) {
- /* Unfortunately, we didn't. */
- fprintf(stderr, "not interactive and can't open terminal\n");
- fflush(stderr);
- return 1;
- }
- if (unset(INTERACTIVE))
- gettyinfo(&shttyinfo);
- /* attach to the tty */
- attachtty(mypgrp);
- if (!isem && ops['k'])
- setcbreak();
- readfd = SHTTY;
- }
+ if (!zleactive)
+ haso = openttyspecially(!isem && ops['k']);
keys = 1;
} else if (ops['u'] && !ops['p']) {
/* -u means take input from the specified file descriptor. *
@@ -3485,7 +3492,7 @@
settyinfo(&shttyinfo);
if (haso) {
fclose(shout); /* close(SHTTY) */
- shout = oshout;
+ shout = NULL;
SHTTY = -1;
}
}
@@ -3517,7 +3524,7 @@
/* dispose of result appropriately, etc. */
if (haso) {
fclose(shout); /* close(SHTTY) */
- shout = oshout;
+ shout = NULL;
SHTTY = -1;
}
}
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.5
diff -u -r1.5 zle_main.c
--- Src/Zle/zle_main.c 2000/05/30 03:43:27 1.5
+++ Src/Zle/zle_main.c 2000/05/31 22:22:55
@@ -741,10 +741,11 @@
int create = 0, ifl;
int type = PM_SCALAR, obreaks = breaks, haso = 0;
char *p1 = NULL, *p2 = NULL;
- FILE *oshout = NULL;
- if (unset(USEZLE)) {
- zwarnnam(name, "ZLE not enabled", NULL, 0);
+ if (unset(USEZLE) || SHTTY == -1)
+ haso = openttyspecially(0);
+ if (SHTTY == -1) {
+ zwarnnam(name, "can't open terminal", NULL, 0);
return 1;
}
if (zleactive) {
@@ -830,17 +831,6 @@
return 1;
}
- if (SHTTY == -1) {
- /* need to open /dev/tty specially */
- if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) == -1) {
- zwarnnam(name, "can't access terminal", NULL, 0);
- return 1;
- }
- oshout = shout;
- init_shout();
-
- haso = 1;
- }
/* edit the parameter value */
zpushnode(bufstack, ztrdup(s));
@@ -857,7 +847,7 @@
varedarg = ova;
if (haso) {
fclose(shout); /* close(SHTTY) */
- shout = oshout;
+ shout = NULL;
SHTTY = -1;
}
if (!t || errflag) {
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@CambridgeSiliconRadio.com
Web: http://www.pwstephenson.fsnet.co.uk
next prev parent reply other threads:[~2000-05-31 22:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-31 21:06 Bernd Eggink
2000-05-31 21:55 ` Peter Stephenson
2000-05-31 22:28 ` Peter Stephenson [this message]
2000-06-01 0:00 ` Bart Schaefer
2000-06-01 4:55 ` Bart Schaefer
2000-06-01 7:58 ` BUG: vared in script (was: vared in function) Bernd Eggink
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=E12xGy9-000474-00.2000-05-31-23-28-09@mail1.svr.pol.co.uk \
--to=pws@pwstephenson.fsnet.co.uk \
--cc=zsh-workers@sunsite.auc.dk \
/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).