* fix 'set -A foo -- [2]=a b c' contingency (tested against GNU bash4,
which, in its latest sid incarnation, even received mksh's ability to produce ${!foo[*]} array keys, wow!) * plug a memory leak while here (ATEMP only, but still)
This commit is contained in:
parent
0f10db42ef
commit
417fd60c76
9
check.t
9
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.346 2009/11/28 15:38:28 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.347 2009/12/01 19:15:31 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 $
|
||||
@ -25,7 +25,7 @@
|
||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R39 2009/11/28
|
||||
@(#)MIRBSD KSH R39 2009/12/01
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -5104,8 +5104,13 @@ stdin:
|
||||
v="c d"
|
||||
foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
|
||||
echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
|
||||
x=([128]=foo bar baz)
|
||||
echo k= ${!x[*]} .
|
||||
echo v= ${x[*]} .
|
||||
expected-stdout:
|
||||
5|a|$v|c d||$v|b|
|
||||
k= 128 129 130 .
|
||||
v= foo bar baz .
|
||||
---
|
||||
name: arrays-6
|
||||
description:
|
||||
|
7
mksh.1
7
mksh.1
@ -1,4 +1,4 @@
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.201 2009/11/23 12:49:55 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.202 2009/12/01 19:15:33 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
|
||||
@ -71,7 +71,7 @@
|
||||
.\" with -mandoc, it might implement .Mx itself, but we want to
|
||||
.\" use our own definition. And .Dd must come *first*, always.
|
||||
.\"
|
||||
.Dd $Mdocdate: November 23 2009 $
|
||||
.Dd $Mdocdate: December 1 2009 $
|
||||
.\"
|
||||
.\" Check which macro package we use
|
||||
.\"
|
||||
@ -3719,6 +3719,9 @@ like this:
|
||||
.Ic set \-A foo \-\- [0]=a [1]=b [2]=c
|
||||
or
|
||||
.Ic foo=([0]=a [1]=b [2]=c)
|
||||
which can also be written
|
||||
.Ic foo=([0]=a b c)
|
||||
because indices are incremented automatically.
|
||||
.It Fl a \*(Ba Ic allexport
|
||||
All new parameters are created with the export attribute.
|
||||
.It Fl b \*(Ba Ic notify
|
||||
|
4
sh.h
4
sh.h
@ -134,9 +134,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.366 2009/11/29 17:37:22 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.367 2009/12/01 19:15:34 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R39 2009/11/28"
|
||||
#define MKSH_VERSION "R39 2009/12/01"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
|
24
var.c
24
var.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.98 2009/11/28 14:28:03 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.99 2009/12/01 19:15:35 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -1350,10 +1350,11 @@ mksh_uari_t
|
||||
set_array(const char *var, bool reset, const char **vals)
|
||||
{
|
||||
struct tbl *vp, *vq;
|
||||
mksh_uari_t i, n;
|
||||
mksh_uari_t i;
|
||||
const char *ccp;
|
||||
#ifndef MKSH_SMALL
|
||||
char *cp;
|
||||
mksh_uari_t j;
|
||||
#endif
|
||||
|
||||
/* to get local array, use "typeset foo; set -A foo" */
|
||||
@ -1370,7 +1371,13 @@ set_array(const char *var, bool reset, const char **vals)
|
||||
* completely fail. Only really effects integer arrays:
|
||||
* evaluation of some of vals[] may fail...
|
||||
*/
|
||||
for (n = i = 0; (ccp = vals[i]); n = ++i) {
|
||||
i = 0;
|
||||
#ifndef MKSH_SMALL
|
||||
j = 0;
|
||||
#else
|
||||
#define j i
|
||||
#endif
|
||||
while ((ccp = vals[i])) {
|
||||
#ifndef MKSH_SMALL
|
||||
if (*ccp == '[') {
|
||||
int level = 0;
|
||||
@ -1385,21 +1392,26 @@ set_array(const char *var, bool reset, const char **vals)
|
||||
if (*ccp == ']' && level == 0 && ccp[1] == '=') {
|
||||
strndupx(cp, vals[i] + 1, ccp - (vals[i] + 1),
|
||||
ATEMP);
|
||||
evaluate(substitute(cp, 0), (mksh_ari_t *)&n,
|
||||
evaluate(substitute(cp, 0), (mksh_ari_t *)&j,
|
||||
KSH_UNWIND_ERROR, true);
|
||||
afree(cp, ATEMP);
|
||||
ccp += 2;
|
||||
} else
|
||||
ccp = vals[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
vq = arraysearch(vp, n);
|
||||
vq = arraysearch(vp, j);
|
||||
/* would be nice to deal with errors here... (see above) */
|
||||
#if 0
|
||||
shprintf("setting '%s'[%lu]='%s' <- '%s'\n",
|
||||
vp->name, (unsigned long)n, ccp, vals[i]);
|
||||
vp->name, (unsigned long)j, ccp, vals[i]);
|
||||
#endif
|
||||
setstr(vq, ccp, KSH_RETURN_ERROR);
|
||||
i++;
|
||||
#ifndef MKSH_SMALL
|
||||
j++;
|
||||
#endif
|
||||
}
|
||||
|
||||
return (i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user