zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/4] internal: Document and simplify multiquote().
@ 2016-11-01 17:26 Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 2/4] internal: Document bin_compadd() Daniel Shahaf
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-11-01 17:26 UTC (permalink / raw)
  To: zsh-workers

The code simplifications take advantage of the fact that all callers
pass either 0 or 1 for 'ign'.

The tildequote() text is from workers/39271.
---
 Src/Zle/compcore.c | 22 +++++++++++++++++-----
 Src/Zle/complete.c |  2 +-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 5443018..f69f680 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -1043,6 +1043,13 @@ makecomplist(char *s, int incmd, int lst)
     }
 }
 
+/*
+ * Quote 's' according to compqstack, aka $compstate[all_quotes].
+ *
+ * If 'ign' is 1, skip the innermost quoting level.  Otherwise 'ign'
+ * must be 0.
+ */
+
 /**/
 mod_export char *
 multiquote(char *s, int ign)
@@ -1050,12 +1057,11 @@ multiquote(char *s, int ign)
     if (s) {
 	char *os = s, *p = compqstack;
 
-	if (p && *p && (ign < 1 || p[ign])) {
-	    if (ign > 0)
-		p += ign;
+	if (p && *p && (ign == 0 || p[1])) {
+	    if (ign)
+		p++;
 	    while (*p) {
-		if (ign >= 0 || p[1])
-		    s = quotestring(s, *p);
+		s = quotestring(s, *p);
 		p++;
 	    }
 	}
@@ -1065,6 +1071,12 @@ multiquote(char *s, int ign)
     return NULL;
 }
 
+/*
+ * tildequote(s, ign): Equivalent to multiquote(s, ign), except that if
+ * compqstack[0] == QT_BACKSLASH and s[0] == '~', then that tilde is not
+ * quoted.
+ */
+
 /**/
 mod_export char *
 tildequote(char *s, int ign)
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 4bf238f..7361934 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -52,7 +52,7 @@ char **compwords,
      *compqiprefix,
      *compqisuffix,
      *compquote,
-     *compqstack,
+     *compqstack,      /* compstate[all_quotes] */
      *comppatmatch,
      *complastprompt;
 /**/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/4] internal: Document bin_compadd().
  2016-11-01 17:26 [PATCH 1/4] internal: Document and simplify multiquote() Daniel Shahaf
@ 2016-11-01 17:26 ` Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 3/4] internal: Document matchspec flags Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 4/4] internal: Document some compadd internals Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-11-01 17:26 UTC (permalink / raw)
  To: zsh-workers

---
 Src/Zle/complete.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 7361934..484754b 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -555,8 +555,8 @@ static int
 bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 {
     struct cadata dat;
-    char *p, **sp, *e, *m = NULL, *mstr = NULL;
-    int dm;
+    char *mstr = NULL; /* argument of -M options, accumulated */
+    int added; /* return value */
     Cmatcher match = NULL;
 
     if (incompfunc != 1) {
@@ -572,14 +572,16 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
     dat.dummies = -1;
 
     for (; *argv && **argv ==  '-'; argv++) {
+	char *p; /* loop variable, points into argv */
 	if (!(*argv)[1]) {
 	    argv++;
 	    break;
 	}
 	for (p = *argv + 1; *p; p++) {
-	    sp = NULL;
-	    e = NULL;
-	    dm = 0;
+	    char *m = NULL; /* argument of -M option (this one only) */
+	    char **sp = NULL; /* the argument to an option should be copied
+				 to *sp. */
+	    const char *e; /* error message */
 	    switch (*p) {
 	    case 'q':
 		dat.flags |= CMF_REMOVE;
@@ -661,7 +663,6 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 	    case 'M':
 		sp = &m;
 		e = "matching specification expected after -%c";
-		dm = 1;
 		break;
 	    case 'X':
 		sp = &(dat.exp);
@@ -748,14 +749,13 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 		    zsfree(mstr);
 		    return 1;
 		}
-		if (dm) {
+		if (m) {
 		    if (mstr) {
 			char *tmp = tricat(mstr, " ", m);
 			zsfree(mstr);
 			mstr = tmp;
 		    } else
 			mstr = ztrdup(m);
-		    m = NULL;
 		}
 	    }
 	}
@@ -774,10 +774,10 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 	return 1;
 
     dat.match = match = cpcmatcher(match);
-    dm = addmatches(&dat, argv);
+    added = addmatches(&dat, argv);
     freecmatcher(match);
 
-    return dm;
+    return added;
 }
 
 #define CVT_RANGENUM 0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/4] internal: Document matchspec flags.
  2016-11-01 17:26 [PATCH 1/4] internal: Document and simplify multiquote() Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 2/4] internal: Document bin_compadd() Daniel Shahaf
@ 2016-11-01 17:26 ` Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 4/4] internal: Document some compadd internals Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-11-01 17:26 UTC (permalink / raw)
  To: zsh-workers

---
 Src/Zle/comp.h     | 6 ++++++
 Src/Zle/complete.c | 8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h
index dfac35c..14af617 100644
--- a/Src/Zle/comp.h
+++ b/Src/Zle/comp.h
@@ -160,9 +160,15 @@ struct cmatcher {
     int ralen;			/* length of right anchor */
 };
 
+/* Flags for cmatcher::flags */
+/* Upon match, insert the string from the line rather than the string
+ * from the trial completion ("word"). */
 #define CMF_LINE  1
+/* Match with an anchor on the left. */
 #define CMF_LEFT  2
+/* Match with an anchor on the right. */
 #define CMF_RIGHT 4
+/* ... */
 #define CMF_INTER 8
 
 /*
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 484754b..7980518 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -249,14 +249,14 @@ parse_cmatcher(char *name, char *s)
 	if (!*s) break;
 
 	switch (*s) {
-	case 'b': fl2 = CMF_INTER;
+	case 'b': fl2 = CMF_INTER; /* FALLTHROUGH */
 	case 'l': fl = CMF_LEFT; break;
-	case 'e': fl2 = CMF_INTER;
+	case 'e': fl2 = CMF_INTER; /* FALLTHROUGH */
 	case 'r': fl = CMF_RIGHT; break;
 	case 'm': fl = 0; break;
-	case 'B': fl2 = CMF_INTER;
+	case 'B': fl2 = CMF_INTER; /* FALLTHROUGH */
 	case 'L': fl = CMF_LEFT | CMF_LINE; break;
-	case 'E': fl2 = CMF_INTER;
+	case 'E': fl2 = CMF_INTER; /* FALLTHROUGH */
 	case 'R': fl = CMF_RIGHT | CMF_LINE; break;
 	case 'M': fl = CMF_LINE; break;
 	case 'x': break;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 4/4] internal: Document some compadd internals.
  2016-11-01 17:26 [PATCH 1/4] internal: Document and simplify multiquote() Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 2/4] internal: Document bin_compadd() Daniel Shahaf
  2016-11-01 17:26 ` [PATCH 3/4] internal: Document matchspec flags Daniel Shahaf
@ 2016-11-01 17:26 ` Daniel Shahaf
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-11-01 17:26 UTC (permalink / raw)
  To: zsh-workers

---
 Src/Zle/comp.h     | 19 +++++++++----------
 Src/Zle/compcore.c | 12 ++++++++++--
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h
index 14af617..3711fde 100644
--- a/Src/Zle/comp.h
+++ b/Src/Zle/comp.h
@@ -125,7 +125,7 @@ struct cmatch {
 #define CMF_REMOVE   (1<< 1)	/* remove the suffix */
 #define CMF_ISPAR    (1<< 2)	/* is paramter expansion */
 #define CMF_PARBR    (1<< 3)	/* paramter expansion with a brace */
-#define CMF_PARNEST  (1<< 4)	/* nested paramter expansion */
+#define CMF_PARNEST  (1<< 4)	/* nested parameter expansion */
 #define CMF_NOLIST   (1<< 5)	/* should not be listed */
 #define CMF_DISPLINE (1<< 6)	/* display strings one per line */
 #define CMF_HIDE     (1<< 7)	/* temporarily hide this one */
@@ -235,7 +235,6 @@ struct cpattern {
  * the anchor. */
 
 typedef struct cline *Cline;
-typedef struct clsub Clsub;
 
 struct cline {
     Cline next;
@@ -291,14 +290,14 @@ struct menuinfo {
 
 /* Flags for compadd and addmatches(). */
 
-#define CAF_QUOTE    1
-#define CAF_NOSORT   2
-#define CAF_MATCH    4
-#define CAF_UNIQCON  8
-#define CAF_UNIQALL 16
-#define CAF_ARRAYS  32
-#define CAF_KEYS    64
-#define CAF_ALL    128
+#define CAF_QUOTE    1    /* compadd -Q: positional arguments already quoted */
+#define CAF_NOSORT   2    /* compadd -V: don't sort */
+#define CAF_MATCH    4    /* compadd without -U: do matching */
+#define CAF_UNIQCON  8    /* compadd -2: don't deduplicate */
+#define CAF_UNIQALL 16    /* compadd -1: deduplicate */
+#define CAF_ARRAYS  32    /* compadd -a or -k: array/assoc parameter names */
+#define CAF_KEYS    64    /* compadd -k: assoc parameter names */
+#define CAF_ALL    128    /* compadd -C: _all_matches */
 
 /* Data for compadd and addmatches() */
 
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index f69f680..fe16c13 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -1976,6 +1976,11 @@ get_user_var(char *nam)
     }
 }
 
+/*
+ * If KEYS, then NAME is an associative array; return its keys.
+ * Else, NAME is a plain array; return its elements.
+ */
+
 static char **
 get_data_arr(char *name, int keys)
 {
@@ -2037,16 +2042,17 @@ addmatch(char *str, int flags, char ***dispp, int line)
 int
 addmatches(Cadata dat, char **argv)
 {
+    /* ms: "match string" - string to use as completion.
+     * Overloaded at one place as a temporary. */
     char *s, *ms, *lipre = NULL, *lisuf = NULL, *lpre = NULL, *lsuf = NULL;
     char **aign = NULL, **dparr = NULL, *oaq = autoq, *oppre = dat->ppre;
     char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL, *ibuf = NULL;
     char **arrays = NULL;
-    int lpl, lsl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0;
+    int lpl, lsl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0;
     int ppl = 0, psl = 0, ilen = 0;
     int llpl = 0, llsl = 0, nm = mnum, gflags = 0, ohp = haspattern;
     int isexact, doadd, ois = instring, oib = inbackt;
     Cline lc = NULL, pline = NULL, sline = NULL;
-    Cmatch cm;
     struct cmlist mst;
     Cmlist oms = mstack;
     Patprog cp = NULL, *pign = NULL;
@@ -2424,6 +2430,7 @@ addmatches(Cadata dat, char **argv)
 	if (dat->psuf)
 	    psl = strlen(dat->psuf);
 	for (; (s = *argv); argv++) {
+	    int sl;
 	    bpl = obpl;
 	    bsl = obsl;
 	    if (disp) {
@@ -2484,6 +2491,7 @@ addmatches(Cadata dat, char **argv)
 		goto next_array;
 	    }
 	    if (doadd) {
+		Cmatch cm;
 		Brinfo bp;
 
 		for (bp = obpl; bp; bp = bp->next)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-11-01 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-01 17:26 [PATCH 1/4] internal: Document and simplify multiquote() Daniel Shahaf
2016-11-01 17:26 ` [PATCH 2/4] internal: Document bin_compadd() Daniel Shahaf
2016-11-01 17:26 ` [PATCH 3/4] internal: Document matchspec flags Daniel Shahaf
2016-11-01 17:26 ` [PATCH 4/4] internal: Document some compadd internals Daniel Shahaf

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).