fix typeset -p x[2]

This commit is contained in:
tg 2017-04-02 16:25:23 +00:00
parent fd1dda2401
commit 0e2c9e55f8
2 changed files with 33 additions and 15 deletions

28
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.767 2017/04/02 14:14:04 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.768 2017/04/02 16:25:20 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout:
@(#)MIRBSD KSH R54 2017/03/25
@(#)MIRBSD KSH R54 2017/04/02
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: !shell:legacy-yes,!shell:textmode-yes
---
expected-stdout:
@(#)LEGACY KSH R54 2017/03/25
@(#)LEGACY KSH R54 2017/04/02
description:
Check version of legacy shell.
stdin:
@ -48,7 +48,7 @@ name: KSH_VERSION-legacy
category: !shell:legacy-no,!shell:textmode-yes
---
expected-stdout:
@(#)MIRBSD KSH R54 2017/03/25 +TEXTMODE
@(#)MIRBSD KSH R54 2017/04/02 +TEXTMODE
description:
Check version of shell.
stdin:
@ -57,7 +57,7 @@ name: KSH_VERSION-textmode
category: !shell:legacy-yes,!shell:textmode-no
---
expected-stdout:
@(#)LEGACY KSH R54 2017/03/25 +TEXTMODE
@(#)LEGACY KSH R54 2017/04/02 +TEXTMODE
description:
Check version of legacy shell.
stdin:
@ -8099,6 +8099,24 @@ expected-stdout:
inside changed 16#30 .
after 16#30 .
---
name: typeset-2
description:
Check that typeset -p on arrays works correctly
stdin:
set -A x -- a b c
echo =
typeset -p x
echo =
typeset -p x[1]
expected-stdout:
=
set -A x
typeset x[0]=a
typeset x[1]=b
typeset x[2]=c
=
typeset x[1]=b
---
name: typeset-padding-1
description:
Check if left/right justification works as per TFM

20
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.212 2017/04/02 16:07:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.213 2017/04/02 16:25:23 tg Exp $");
/*-
* Variables
@ -45,7 +45,7 @@ static uint32_t lcg_state = 5381, qh_state = 4711;
/* may only be set by typeset() just before call to array_index_calc() */
static enum namerefflag innermost_refflag = SRF_NOP;
static void c_typeset_vardump(struct tbl *, uint32_t, int, bool, bool);
static void c_typeset_vardump(struct tbl *, uint32_t, int, int, bool, bool);
static void c_typeset_vardump_recursive(struct block *, uint32_t, int, bool,
bool);
static char *formatstr(struct tbl *, const char *);
@ -2032,8 +2032,9 @@ c_typeset(const char **wp)
}
} else if (wp[builtin_opt.optind]) {
for (i = builtin_opt.optind; wp[i]; i++) {
varsearch(e->loc, &vp, wp[i], hash(wp[i]));
c_typeset_vardump(vp, flag, thing, pflag, istset);
vp = isglobal(wp[i], false);
c_typeset_vardump(vp, flag, thing,
last_lookup_was_array ? 4 : 0, pflag, istset);
}
} else
c_typeset_vardump_recursive(e->loc, flag, thing, pflag, istset);
@ -2050,16 +2051,15 @@ c_typeset_vardump_recursive(struct block *l, uint32_t flag, int thing,
c_typeset_vardump_recursive(l->next, flag, thing, pflag, istset);
blockvars = ktsort(&l->vars);
while ((vp = *blockvars++))
c_typeset_vardump(vp, flag, thing, pflag, istset);
c_typeset_vardump(vp, flag, thing, 0, pflag, istset);
/*XXX doesnt this leak? */
}
static void
c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
bool istset)
c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, int any_set,
bool pflag, bool istset)
{
struct tbl *tvp;
int any_set = 0;
char *s;
if (!vp)
@ -2071,7 +2071,7 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
*/
for (tvp = vp; tvp; tvp = tvp->u.array)
if (tvp->flag & ISSET) {
any_set = 1;
any_set |= 1;
break;
}
@ -2159,5 +2159,5 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
*/
if (!any_set)
return;
} while ((vp = vp->u.array));
} while (!(any_set & 4) && (vp = vp->u.array));
}