zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Re: Another ${(z)param} buglet
Date: Tue, 14 Dec 2010 10:20:16 +0000	[thread overview]
Message-ID: <20101214102016.726d2ae6@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20101213181203.5a5ba7d5@pwslap01u.europe.root.pri>

On Mon, 13 Dec 2010 18:12:03 +0000
Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> lexsave/lexrestore should probably save and restore lexflags: not done
> that yet. Then we don't need to do it in bufferwords() (which does
> it cleanly already, but goodness knows what ZLE does).

This does that, which enables a small amount of tidying up in ZLE, and
also adds a special flag for ZLE mode which removes the chance of side
effects when using bufferwords() from elsewhere.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.108
diff -p -u -r1.108 hist.c
--- Src/hist.c	14 Dec 2010 09:59:04 -0000	1.108
+++ Src/hist.c	14 Dec 2010 10:17:10 -0000
@@ -2897,11 +2897,9 @@ histfileIsLocked(void)
  * If index is non-NULL, and input is from a string in ZLE, *index
  * is set to the position of the end of the current editor word.
  *
- * comments is used if buf is non-NULL (i.e. this is not a string
- * from ZLE).
- * If it is 0, comments are not parsed; they are treated as ordinary words.
- * If it is 1, comments are treated as single strings, one per line.
- * If it is 2, comments are removed.
+ * flags is passed directly to lexflags, see lex.c, except that
+ * we 'or' in the bit LEXFLAGS_ACTIVE to make sure the variable
+ * is set.
  */
 
 /**/
@@ -2909,7 +2907,7 @@ mod_export LinkList
 bufferwords(LinkList list, char *buf, int *index, int flags)
 {
     int num = 0, cur = -1, got = 0, ne = noerrs;
-    int owb = wb, owe = we, oadx = addedx, ozp = lexflags, onc = nocomments;
+    int owb = wb, owe = we, oadx = addedx, onc = nocomments;
     int ona = noaliases, ocs = zlemetacs, oll = zlemetall;
     int forloop = 0, rcquotes = opts[RCQUOTES];
     char *p, *addedspaceptr;
@@ -3120,7 +3118,6 @@ bufferwords(LinkList list, char *buf, in
     strinend();
     inpop();
     errflag = 0;
-    lexflags = ozp;
     nocomments = onc;
     noerrs = ne;
     lexrestore();
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.60
diff -p -u -r1.60 lex.c
--- Src/lex.c	14 Dec 2010 09:59:04 -0000	1.60
+++ Src/lex.c	14 Dec 2010 10:17:10 -0000
@@ -126,7 +126,7 @@ mod_export int noaliases;
  * Note that although it is passed into the lexer as an input, the
  * lexer can set it to zero after finding the word it's searching for.
  * This only happens if the line being parsed actually does come from
- * ZLE.
+ * ZLE, and hence the bit LEXFLAGS_ZLE is set.
  */
 
 /**/
@@ -202,6 +202,7 @@ struct lexstack {
     int isfirstch;
     int histactive;
     int histdone;
+    int lexflags;
     int stophist;
     int hlinesz;
     char *hline;
@@ -258,6 +259,7 @@ lexsave(void)
     ls->isfirstch = isfirstch;
     ls->histactive = histactive;
     ls->histdone = histdone;
+    ls->lexflags = lexflags;
     ls->stophist = stophist;
     stophist = 0;
     if (!lstack) {
@@ -332,6 +334,7 @@ lexrestore(void)
     isfirstch = lstack->isfirstch;
     histactive = lstack->histactive;
     histdone = lstack->histdone;
+    lexflags = lstack->lexflags;
     stophist = lstack->stophist;
     chline = lstack->hline;
     hptr = lstack->hptr;
@@ -1804,7 +1807,7 @@ exalias(void)
 	} else
 	    zshlextext = tokstr;
 
-	if (lexflags && !(inbufflags & INP_ALIAS)) {
+	if ((lexflags & LEXFLAGS_ZLE) && !(inbufflags & INP_ALIAS)) {
 	    int zp = lexflags;
 
 	    gotword();
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.171
diff -p -u -r1.171 zsh.h
--- Src/zsh.h	14 Dec 2010 09:59:04 -0000	1.171
+++ Src/zsh.h	14 Dec 2010 10:17:10 -0000
@@ -1835,13 +1835,19 @@ struct histent {
  */
 #define LEXFLAGS_ACTIVE		0x0001
 /*
+ * Being used from zle.  This is slightly more intrusive
+ * (=> grotesquely non-modular) than use from within
+ * the main shell, so it's a separate flag.
+ */
+#define LEXFLAGS_ZLE		0x0002
+/*
  * Parse comments and treat each comment as a single string
  */
-#define LEXFLAGS_COMMENTS_KEEP	0x0002
+#define LEXFLAGS_COMMENTS_KEEP	0x0004
 /*
  * Parse comments and strip them.
  */
-#define LEXFLAGS_COMMENTS_STRIP	0x0004
+#define LEXFLAGS_COMMENTS_STRIP	0x0008
 /*
  * Either of the above
  */
@@ -1849,7 +1855,7 @@ struct histent {
 /*
  * Treat newlines as whitespace
  */
-#define LEXFLAGS_NEWLINE	0x0008
+#define LEXFLAGS_NEWLINE	0x0010
 
 /******************************************/
 /* Definitions for programable completion */
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.103
diff -p -u -r1.103 compcore.c
--- Src/Zle/compcore.c	14 Dec 2010 09:59:04 -0000	1.103
+++ Src/Zle/compcore.c	14 Dec 2010 10:17:10 -0000
@@ -1481,13 +1481,13 @@ set_comp_sep(void)
 
     /* Put the string in the lexer buffer and call the lexer to *
      * get the words we have to expand.                        */
-    lexflags = LEXFLAGS_ACTIVE;
     ocs = zlemetacs;
     oll = zlemetall;
     ol = zlemetaline;
     addedx = 1;
     noerrs = 1;
     lexsave();
+    lexflags = LEXFLAGS_ZLE;
     /*
      * tl is the length of the temporary string including
      * the space at the start and the x at the cursor position,
@@ -1634,7 +1634,7 @@ set_comp_sep(void)
     noaliases = ona;
     strinend();
     inpop();
-    errflag = lexflags = 0;
+    errflag = 0;
     noerrs = ne;
     lexrestore();
     wb = owb;
Index: Src/Zle/compctl.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compctl.c,v
retrieving revision 1.39
diff -p -u -r1.39 compctl.c
--- Src/Zle/compctl.c	14 Dec 2010 09:59:04 -0000	1.39
+++ Src/Zle/compctl.c	14 Dec 2010 10:17:11 -0000
@@ -2789,10 +2789,10 @@ sep_comp_string(char *ss, char *s, int n
 
     /* Put the string in the lexer buffer and call the lexer to *
      * get the words we have to expand.                        */
-    lexflags = LEXFLAGS_ACTIVE;
     addedx = 1;
     noerrs = 1;
     lexsave();
+    lexflags = LEXFLAGS_ZLE;
     tmp = (char *) zhalloc(tl = sl + 3 + strlen(s));
     strcpy(tmp, ss);
     tmp[sl] = ' ';
@@ -2843,7 +2843,7 @@ sep_comp_string(char *ss, char *s, int n
     noaliases = ona;
     strinend();
     inpop();
-    errflag = lexflags = 0;
+    errflag = 0;
     noerrs = ne;
     lexrestore();
     wb = owb;
@@ -3703,8 +3703,8 @@ makecomplistflags(Compctl cc, char *s, i
 
 	/* Put the string in the lexer buffer and call the lexer to *
 	 * get the words we have to expand.                        */
-	lexflags = LEXFLAGS_ACTIVE;
 	lexsave();
+	lexflags = LEXFLAGS_ZLE;
 	tmpbuf = (char *)zhalloc(strlen(cc->str) + 5);
 	sprintf(tmpbuf, "foo %s", cc->str); /* KLUDGE! */
 	inpush(tmpbuf, 0, NULL);
@@ -3721,7 +3721,7 @@ makecomplistflags(Compctl cc, char *s, i
 	noaliases = ona;
 	strinend();
 	inpop();
-	errflag = lexflags = 0;
+	errflag = 0;
 	lexrestore();
 	/* Fine, now do full expansion. */
 	prefork(foo, 0);
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.103
diff -p -u -r1.103 zle_tricky.c
--- Src/Zle/zle_tricky.c	14 Dec 2010 09:59:04 -0000	1.103
+++ Src/Zle/zle_tricky.c	14 Dec 2010 10:17:11 -0000
@@ -1140,9 +1140,9 @@ get_comp_string(void)
     zsfree(varname);
     varname = NULL;
     insubscr = 0;
-    lexflags = LEXFLAGS_ACTIVE;
     clwpos = -1;
     lexsave();
+    lexflags = LEXFLAGS_ZLE;
     inpush(dupstrspace(linptr), 0, NULL);
     strinbeg(0);
     wordpos = tt0 = cp = rd = ins = oins = linarr = parct = ia = redirpos = 0;
@@ -2707,7 +2707,6 @@ doexpandhist(void)
     noaliases = ona;
     strinend();
     inpop();
-    lexflags = 0;
     lexrestore();
     expanding = 0;
 
@@ -2807,8 +2806,8 @@ getcurcmd(void)
     int curlincmd;
     char *s = NULL;
 
-    lexflags = LEXFLAGS_ACTIVE;
     lexsave();
+    lexflags = LEXFLAGS_ZLE;
     metafy_line();
     inpush(dupstrspace(zlemetaline), 0, NULL);
     strinbeg(1);
@@ -2829,7 +2828,7 @@ getcurcmd(void)
     popheap();
     strinend();
     inpop();
-    errflag = lexflags = 0;
+    errflag = 0;
     unmetafy_line();
     lexrestore();
 
-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  reply	other threads:[~2010-12-14 10:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-08  4:34 Bart Schaefer
2010-12-08 17:51 ` Peter Stephenson
2010-12-09 15:42   ` Bart Schaefer
2010-12-09 18:16     ` Peter Stephenson
2010-12-09 20:19       ` Peter Stephenson
2010-12-12 22:45         ` Peter Stephenson
2010-12-13  1:26           ` Bart Schaefer
2010-12-13  9:47             ` Peter Stephenson
2010-12-13 17:35               ` Bart Schaefer
2010-12-13 18:12                 ` Peter Stephenson
2010-12-14 10:20                   ` Peter Stephenson [this message]
2010-12-14 16:57                   ` Bart Schaefer
2010-12-13  5:16           ` Bart Schaefer
2010-12-13 10:15         ` Peter Stephenson
2010-12-09 20:25       ` 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=20101214102016.726d2ae6@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --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).