handle MKSH_SMALL not doing foo+=(…)
This commit is contained in:
parent
40e914e8a5
commit
9fe3ba48d2
25
check.t
25
check.t
@ -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: 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: 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 $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
@ -6267,21 +6267,28 @@ expected-stdout:
|
|||||||
2g 009 .
|
2g 009 .
|
||||||
2h 00001 00002 .
|
2h 00001 00002 .
|
||||||
---
|
---
|
||||||
name: arrays-9
|
name: arrays-9a
|
||||||
description:
|
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:
|
stdin:
|
||||||
unset foo; foo=bar; foo+=baz; echo 1 $foo .
|
unset foo; foo=bar; foo+=baz; echo 1 $foo .
|
||||||
unset foo; typeset -i16 foo=10; foo+=20; echo 2 $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:
|
expected-stdout:
|
||||||
1 barbaz .
|
1 barbaz .
|
||||||
2 16#a20 .
|
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
|
name: varexpand-substr-1
|
||||||
description:
|
description:
|
||||||
|
15
var.c
15
var.c
@ -26,7 +26,7 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#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
|
* Variables
|
||||||
@ -1325,20 +1325,27 @@ set_array(const char *var, bool reset, const char **vals)
|
|||||||
struct tbl *vp, *vq;
|
struct tbl *vp, *vq;
|
||||||
mksh_uari_t i, j = 0;
|
mksh_uari_t i, j = 0;
|
||||||
const char *ccp;
|
const char *ccp;
|
||||||
|
#ifndef MKSH_SMALL
|
||||||
char *cp = NULL;
|
char *cp = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* to get local array, use "typeset foo; set -A foo" */
|
/* to get local array, use "typeset foo; set -A foo" */
|
||||||
|
#ifndef MKSH_SMALL
|
||||||
i = strlen(var);
|
i = strlen(var);
|
||||||
if (i > 0 && var[i - 1] == '+') {
|
if (i > 0 && var[i - 1] == '+') {
|
||||||
/* append mode */
|
/* append mode */
|
||||||
reset = false;
|
reset = false;
|
||||||
strndupx(cp, var, i - 1, ATEMP);
|
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 */
|
/* Note: AT&T ksh allows set -A but not set +A of a read-only var */
|
||||||
if ((vp->flag&RDONLY))
|
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 */
|
/* This code is quite non-optimal */
|
||||||
if (reset)
|
if (reset)
|
||||||
/* trash existing values and attributes */
|
/* 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...
|
* evaluation of some of vals[] may fail...
|
||||||
*/
|
*/
|
||||||
i = 0;
|
i = 0;
|
||||||
|
#ifndef MKSH_SMALL
|
||||||
if (cp != NULL) {
|
if (cp != NULL) {
|
||||||
/* find out where to set when appending */
|
/* find out where to set when appending */
|
||||||
for (vq = vp; vq; vq = vq->u.array) {
|
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);
|
afree(cp, ATEMP);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
while ((ccp = vals[i])) {
|
while ((ccp = vals[i])) {
|
||||||
#ifndef MKSH_SMALL
|
#ifndef MKSH_SMALL
|
||||||
if (*ccp == '[') {
|
if (*ccp == '[') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user