introduce “typeset -i foo[*]”, rationale see cid 1004B5DA60A56BFB604
This commit is contained in:
parent
c700693d11
commit
2e9654ffa4
8
check.t
8
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: 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 $
|
||||||
@ -5263,6 +5263,7 @@ stdin:
|
|||||||
set -A ae 1 2
|
set -A ae 1 2
|
||||||
set -A af 1 2
|
set -A af 1 2
|
||||||
set -A ag 1 2
|
set -A ag 1 2
|
||||||
|
set -A ah 1 2
|
||||||
typeset -Z3 aa ab ac ad ae af ag
|
typeset -Z3 aa ab ac ad ae af ag
|
||||||
print 1a ${aa[*]} .
|
print 1a ${aa[*]} .
|
||||||
print 1b ${ab[*]} .
|
print 1b ${ab[*]} .
|
||||||
@ -5271,6 +5272,7 @@ stdin:
|
|||||||
print 1e ${ae[*]} .
|
print 1e ${ae[*]} .
|
||||||
print 1f ${af[*]} .
|
print 1f ${af[*]} .
|
||||||
print 1g ${ag[*]} .
|
print 1g ${ag[*]} .
|
||||||
|
print 1h ${ah[*]} .
|
||||||
fna
|
fna
|
||||||
fnb
|
fnb
|
||||||
fnc
|
fnc
|
||||||
@ -5278,6 +5280,7 @@ stdin:
|
|||||||
fne
|
fne
|
||||||
fnf
|
fnf
|
||||||
fng
|
fng
|
||||||
|
typeset -Z5 ah[*]
|
||||||
print 2a ${aa[*]} .
|
print 2a ${aa[*]} .
|
||||||
print 2b ${ab[*]} .
|
print 2b ${ab[*]} .
|
||||||
print 2c ${ac[*]} .
|
print 2c ${ac[*]} .
|
||||||
@ -5285,6 +5288,7 @@ stdin:
|
|||||||
print 2e ${ae[*]} .
|
print 2e ${ae[*]} .
|
||||||
print 2f ${af[*]} .
|
print 2f ${af[*]} .
|
||||||
print 2g ${ag[*]} .
|
print 2g ${ag[*]} .
|
||||||
|
print 2h ${ah[*]} .
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
1a 001 002 .
|
1a 001 002 .
|
||||||
1b 001 002 .
|
1b 001 002 .
|
||||||
@ -5293,6 +5297,7 @@ expected-stdout:
|
|||||||
1e 001 002 .
|
1e 001 002 .
|
||||||
1f 001 002 .
|
1f 001 002 .
|
||||||
1g 001 002 .
|
1g 001 002 .
|
||||||
|
1h 1 2 .
|
||||||
2a 9 .
|
2a 9 .
|
||||||
2b 001 002 .
|
2b 001 002 .
|
||||||
2c 92 .
|
2c 92 .
|
||||||
@ -5300,6 +5305,7 @@ expected-stdout:
|
|||||||
2e 9 .
|
2e 9 .
|
||||||
2f 9 002 .
|
2f 9 002 .
|
||||||
2g 009 .
|
2g 009 .
|
||||||
|
2h 00001 00002 .
|
||||||
---
|
---
|
||||||
name: varexpand-substr-1
|
name: varexpand-substr-1
|
||||||
description:
|
description:
|
||||||
|
5
mksh.1
5
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 $
|
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
.\" 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
|
or cleared
|
||||||
.Pq Ic + .
|
.Pq Ic + .
|
||||||
Values for parameters may optionally be specified.
|
Values for parameters may optionally be specified.
|
||||||
|
For
|
||||||
|
.Ar name Ns [*] ,
|
||||||
|
the change affects the entire array, and no value may be specified.
|
||||||
If
|
If
|
||||||
.Ic typeset
|
.Ic typeset
|
||||||
is used inside a function, any newly created parameters are local to the
|
is used inside a function, any newly created parameters are local to the
|
||||||
|
17
var.c
17
var.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
* Variables
|
||||||
@ -674,14 +674,13 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
struct tbl *vpbase, *t;
|
struct tbl *vpbase, *t;
|
||||||
char *tvar;
|
char *tvar;
|
||||||
const char *val;
|
const char *val;
|
||||||
|
int len;
|
||||||
|
|
||||||
/* check for valid variable name, search for value */
|
/* check for valid variable name, search for value */
|
||||||
val = skip_varname(var, false);
|
val = skip_varname(var, false);
|
||||||
if (val == var)
|
if (val == var)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (*val == '[') {
|
if (*val == '[') {
|
||||||
int len;
|
|
||||||
|
|
||||||
if (set_refflag)
|
if (set_refflag)
|
||||||
errorf("%s: reference variable cannot be an array",
|
errorf("%s: reference variable cannot be an array",
|
||||||
var);
|
var);
|
||||||
@ -710,6 +709,11 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
strdupx(tvar, var, ATEMP);
|
strdupx(tvar, var, ATEMP);
|
||||||
val = NULL;
|
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 */
|
/* 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 */
|
/* most calls are with set/clr == 0 */
|
||||||
if (set | clr) {
|
if (set | clr) {
|
||||||
int ok = 1;
|
bool ok = true;
|
||||||
|
|
||||||
/* XXX if x[0] isn't set, there will be problems: need to have
|
/* XXX if x[0] isn't set, there will be problems: need to have
|
||||||
* one copy of attributes for arrays...
|
* one copy of attributes for arrays...
|
||||||
*/
|
*/
|
||||||
for (t = vpbase; t; t = t->u.array) {
|
for (t = vpbase; t; t = t->u.array) {
|
||||||
int fake_assign;
|
bool fake_assign;
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
char *free_me = 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
|
* zap contents of variable, but keep
|
||||||
* the flag settings.
|
* the flag settings.
|
||||||
*/
|
*/
|
||||||
ok = 0;
|
ok = false;
|
||||||
if (t->flag & INTEGER)
|
if (t->flag & INTEGER)
|
||||||
t->flag &= ~ISSET;
|
t->flag &= ~ISSET;
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user