handle MKSH_SMALL not doing foo+=(…)

This commit is contained in:
tg 2011-05-07 02:02:47 +00:00
parent 40e914e8a5
commit 9fe3ba48d2
2 changed files with 28 additions and 12 deletions

25
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.453 2011/05/07 00:51:09 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.454 2011/05/07 02:02:45 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 $
@ -6267,21 +6267,28 @@ expected-stdout:
2g 009 .
2h 00001 00002 .
---
name: arrays-9
name: arrays-9a
description:
Check that we can concatenate parameters and arrays
Check that we can concatenate arrays
category: !smksh
stdin:
unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
expected-stdout:
1 0 1 : bar baz .
2 0 1 2 : foo bar baz .
3 0 2 3 5 : bar foo baz quux .
---
name: arrays-9b
description:
Check that we can concatenate parameters too
stdin:
unset foo; foo=bar; foo+=baz; echo 1 $foo .
unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
unset foo; foo=(bar); foo+=(baz); echo 3 ${!foo[*]} : ${foo[*]} .
unset foo; foo=(foo bar); foo+=(baz); echo 4 ${!foo[*]} : ${foo[*]} .
unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 5 ${!foo[*]} : ${foo[*]} .
expected-stdout:
1 barbaz .
2 16#a20 .
3 0 1 : bar baz .
4 0 1 2 : foo bar baz .
5 0 2 3 5 : bar foo baz quux .
---
name: varexpand-substr-1
description:

15
var.c
View File

@ -26,7 +26,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.120 2011/05/04 23:16:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.121 2011/05/07 02:02:47 tg Exp $");
/*
* Variables
@ -1325,20 +1325,27 @@ set_array(const char *var, bool reset, const char **vals)
struct tbl *vp, *vq;
mksh_uari_t i, j = 0;
const char *ccp;
#ifndef MKSH_SMALL
char *cp = NULL;
#endif
/* to get local array, use "typeset foo; set -A foo" */
#ifndef MKSH_SMALL
i = strlen(var);
if (i > 0 && var[i - 1] == '+') {
/* append mode */
reset = false;
strndupx(cp, var, i - 1, ATEMP);
}
vp = global(cp ? cp : var);
#define CPORVAR (cp ? cp : var)
#else
#define CPORVAR var
#endif
vp = global(CPORVAR);
/* Note: AT&T ksh allows set -A but not set +A of a read-only var */
if ((vp->flag&RDONLY))
errorfx(2, "%s: %s", cp ? cp : var, "is read only");
errorfx(2, "%s: %s", CPORVAR, "is read only");
/* This code is quite non-optimal */
if (reset)
/* trash existing values and attributes */
@ -1349,6 +1356,7 @@ set_array(const char *var, bool reset, const char **vals)
* evaluation of some of vals[] may fail...
*/
i = 0;
#ifndef MKSH_SMALL
if (cp != NULL) {
/* find out where to set when appending */
for (vq = vp; vq; vq = vq->u.array) {
@ -1359,6 +1367,7 @@ set_array(const char *var, bool reset, const char **vals)
}
afree(cp, ATEMP);
}
#endif
while ((ccp = vals[i])) {
#ifndef MKSH_SMALL
if (*ccp == '[') {