diff --git a/check.t b/check.t index 2d2a658..9105d8e 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.355 2010/01/25 14:11:25 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.356 2010/01/25 14:25:13 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -5263,6 +5263,7 @@ stdin: set -A ae 1 2 set -A af 1 2 set -A ag 1 2 + set -A ah 1 2 typeset -Z3 aa ab ac ad ae af ag print 1a ${aa[*]} . print 1b ${ab[*]} . @@ -5271,6 +5272,7 @@ stdin: print 1e ${ae[*]} . print 1f ${af[*]} . print 1g ${ag[*]} . + print 1h ${ah[*]} . fna fnb fnc @@ -5278,6 +5280,7 @@ stdin: fne fnf fng + typeset -Z5 ah[*] print 2a ${aa[*]} . print 2b ${ab[*]} . print 2c ${ac[*]} . @@ -5285,6 +5288,7 @@ stdin: print 2e ${ae[*]} . print 2f ${af[*]} . print 2g ${ag[*]} . + print 2h ${ah[*]} . expected-stdout: 1a 001 002 . 1b 001 002 . @@ -5293,6 +5297,7 @@ expected-stdout: 1e 001 002 . 1f 001 002 . 1g 001 002 . + 1h 1 2 . 2a 9 . 2b 001 002 . 2c 92 . @@ -5300,6 +5305,7 @@ expected-stdout: 2e 9 . 2f 9 002 . 2g 009 . + 2h 00001 00002 . --- name: varexpand-substr-1 description: diff --git a/mksh.1 b/mksh.1 index 799bf8c..5b60cc6 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.207 2010/01/25 14:11:27 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.208 2010/01/25 14:25:15 tg Exp $ .\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 @@ -4360,6 +4360,9 @@ arguments are given, the attributes of the named parameters are set or cleared .Pq Ic + . Values for parameters may optionally be specified. +For +.Ar name Ns [*] , +the change affects the entire array, and no value may be specified. If .Ic typeset is used inside a function, any newly created parameters are local to the diff --git a/var.c b/var.c index e762f7d..8e2280c 100644 --- a/var.c +++ b/var.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.101 2010/01/25 14:11:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.102 2010/01/25 14:25:16 tg Exp $"); /* * Variables @@ -674,14 +674,13 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) struct tbl *vpbase, *t; char *tvar; const char *val; + int len; /* check for valid variable name, search for value */ val = skip_varname(var, false); if (val == var) return (NULL); if (*val == '[') { - int len; - if (set_refflag) errorf("%s: reference variable cannot be an array", var); @@ -710,6 +709,11 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) return (NULL); strdupx(tvar, var, ATEMP); val = NULL; + /* handle foo[*] ⇒ foo (whole array) mapping for R39b */ + len = strlen(tvar); + if (len > 3 && tvar[len-3] == '[' && tvar[len-2] == '*' && + tvar[len-1] == ']') + tvar[len-3] = '\0'; } /* Prevent typeset from creating a local PATH/ENV/SHELL */ @@ -754,12 +758,13 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) /* most calls are with set/clr == 0 */ if (set | clr) { - int ok = 1; + bool ok = true; + /* XXX if x[0] isn't set, there will be problems: need to have * one copy of attributes for arrays... */ for (t = vpbase; t; t = t->u.array) { - int fake_assign; + bool fake_assign; char *s = NULL; char *free_me = NULL; @@ -796,7 +801,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) * zap contents of variable, but keep * the flag settings. */ - ok = 0; + ok = false; if (t->flag & INTEGER) t->flag &= ~ISSET; else {