about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-06-19 12:00:59 +0100
committerPeter Stephenson <pws@zsh.org>2015-06-19 12:00:59 +0100
commite03ead4fff0f048935105bef0533e25d6240ee80 (patch)
tree317ef485cfef33e63f7a238208eb4d9ec15648ca
parenta29746ee48c84b40add764f3cbd62d995179f72a (diff)
downloadzsh-e03ead4fff0f048935105bef0533e25d6240ee80.tar.gz
zsh-e03ead4fff0f048935105bef0533e25d6240ee80.tar.xz
zsh-e03ead4fff0f048935105bef0533e25d6240ee80.zip
Debug so basic typeset cases work.
zshlex() needed after ENVSTRING and ENVARRAY in typeset.

WC_TYPESET needs to come before WC_CURSH as not
handled by execfuncs.

More care needed counting and retrieving arguments
in typeset.

Array assignment for new typeset variable should be more like
scalar assignment.
-rw-r--r--Src/builtin.c35
-rw-r--r--Src/parse.c4
-rw-r--r--Src/zsh.h32
3 files changed, 41 insertions, 30 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index bd5d614ff..fb0d09150 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2378,11 +2378,17 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	pm->level = keeplocal;
     else if (on & PM_LOCAL)
 	pm->level = locallevel;
-    if (ASG_VALUEP(asg) && !(pm->node.flags & (PM_ARRAY|PM_HASHED))) {
+    if (ASG_VALUEP(asg)) {
 	Param ipm = pm;
-	DPUTS(ASG_ARRAYP(asg), "BUG: inconsistent array value for scalar");
-	if (!(pm = setsparam(pname, ztrdup(asg->value.scalar))))
-	    return NULL;
+	if (pm->node.flags & (PM_ARRAY|PM_HASHED)) {
+	    DPUTS(!ASG_ARRAYP(asg), "BUG: inconsistent scalar value for array");
+	    if (!(pm=setaparam(pname, zlinklist2array(asg->value.array))))
+		return NULL;
+	} else {
+	    DPUTS(ASG_ARRAYP(asg), "BUG: inconsistent array value for scalar");
+	    if (!(pm = setsparam(pname, ztrdup(asg->value.scalar))))
+		return NULL;
+	}
 	if (pm != ipm) {
 	    DPUTS(ipm->node.flags != pm->node.flags,
 		  "BUG: parameter recreated with wrong flags");
@@ -2419,11 +2425,6 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	}
     }
     pm->node.flags |= (on & PM_READONLY);
-    if (ASG_VALUEP(asg) && (pm->node.flags & (PM_ARRAY|PM_HASHED))) {
-	DPUTS(!ASG_ARRAYP(asg), "BUG: inconsistent scalar value for array");
-	if (!(pm=setaparam(pname, zlinklist2array(asg->value.array))))
-	    return NULL;
-    }
 
     if (OPT_ISSET(ops,'p'))
 	paramtab->printnode(&pm->node, PRINT_TYPESET);
@@ -2451,6 +2452,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
     int on = 0, off = 0, roff, bit = PM_ARRAY;
     int i;
     int returnval = 0, printflags = 0;
+    int hasargs;
 
     /* hash -f is really the builtin `functions' */
     if (OPT_ISSET(ops,'f'))
@@ -2503,7 +2505,8 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
     /* Given no arguments, list whatever the options specify. */
     if (OPT_ISSET(ops,'p'))
 	printflags |= PRINT_TYPESET;
-    if (!*argv) {
+    hasargs = *argv != NULL || (assigns && firstnode(assigns));
+    if (!hasargs) {
 	if (!OPT_ISSET(ops,'p')) {
 	    if (!(on|roff))
 		printflags |= PRINT_TYPE;
@@ -2524,7 +2527,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	Param apm;
 	struct asgment asg0;
 	char *oldval = NULL, *joinstr;
-	int joinchar;
+	int joinchar, nargs;
 
 	if (OPT_ISSET(ops,'m')) {
 	    zwarnnam(name, "incompatible options for -T");
@@ -2532,11 +2535,17 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    return 1;
 	}
 	on &= ~off;
-	if (!argv[1] || (argv[2] && argv[3])) {
+	nargs = arrlen(argv) + (assigns ? countlinknodes(assigns) : 0);
+	if (nargs < 2) {
 	    zwarnnam(name, "-T requires names of scalar and array");
 	    unqueue_signals();
 	    return 1;
 	}
+	if (nargs > 3) {
+	    zwarnnam(name, "too many arguments for -T");
+	    unqueue_signals();
+	    return 1;
+	}
 
 	if (!(asg = getasg(&argv, assigns))) {
 	    unqueue_signals();
@@ -2698,7 +2707,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    tokenize(asg->name);   /* expand argument */
 	    if (!(pprog = patcompile(asg->name, 0, NULL))) {
 		untokenize(asg->name);
-		zwarnnam(name, "bad pattern : %s", argv[-1]);
+		zwarnnam(name, "bad pattern : %s", asg->name);
 		returnval = 1;
 		continue;
 	    }
diff --git a/Src/parse.c b/Src/parse.c
index b0273e254..a95ec6028 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -1863,8 +1863,8 @@ par_simple(int *cmplx, int nr)
 		} else {
 		    ecstr(tokstr);
 		    argc++;
-		    zshlex();
 		}
+		zshlex();
 	    }
 	} else if (IS_REDIROP(tok)) {
 	    *cmplx = c = 1;
@@ -1890,6 +1890,7 @@ par_simple(int *cmplx, int nr)
 		equalsplit(tokstr, &str);
 	    ecstr(name);
 	    ecstr(str);
+	    zshlex();
 	} else if (tok == ENVARRAY) {
 	    int n, parr;
 
@@ -1905,6 +1906,7 @@ par_simple(int *cmplx, int nr)
 	    cmdpop();
 	    if (tok != OUTPAR)
 		YYERROR(oecused);
+	    zshlex();
 	} else if (tok == INOUTPAR) {
 	    zlong oldlineno = lineno;
 	    int onp, so, oecssub = ecssub;
diff --git a/Src/zsh.h b/Src/zsh.h
index 0d43d37a7..ee0609483 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -782,24 +782,24 @@ struct eccstr {
 #define WC_REDIR    4
 #define WC_ASSIGN   5
 #define WC_SIMPLE   6
-#define WC_SUBSH    7
-#define WC_CURSH    8
-#define WC_TIMED    9
-#define WC_FUNCDEF 10
-#define WC_FOR     11
-#define WC_SELECT  12
-#define WC_WHILE   13
-#define WC_REPEAT  14
-#define WC_CASE    15
-#define WC_IF      16
-#define WC_COND    17
-#define WC_ARITH   18
-#define WC_AUTOFN  19
-#define WC_TRY     20
-#define WC_TYPESET 21
+#define WC_TYPESET  7
+#define WC_SUBSH    8
+#define WC_CURSH    9
+#define WC_TIMED   10
+#define WC_FUNCDEF 11
+#define WC_FOR     12
+#define WC_SELECT  13
+#define WC_WHILE   14
+#define WC_REPEAT  15
+#define WC_CASE    16
+#define WC_IF      17
+#define WC_COND    18
+#define WC_ARITH   19
+#define WC_AUTOFN  20
+#define WC_TRY     21
 
 /* increment as necessary */
-#define WC_COUNT   21
+#define WC_COUNT   22
 
 #define WCB_END()           wc_bld(WC_END, 0)