implement “typeset -g”, From: Martijn Dekker <martijn@inlv.org>
also deprecate “global”; thanks!
This commit is contained in:
parent
065f9554fa
commit
5b63e5dcb6
28
check.t
28
check.t
|
@ -1,4 +1,4 @@
|
|||
# $MirOS: src/bin/mksh/check.t,v 1.759 2017/03/12 02:35:32 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.760 2017/03/17 22:45:48 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/11
|
||||
@(#)MIRBSD KSH R54 2017/03/17
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
|
@ -39,7 +39,7 @@ name: KSH_VERSION
|
|||
category: shell:legacy-no
|
||||
---
|
||||
expected-stdout:
|
||||
@(#)LEGACY KSH R54 2017/03/11
|
||||
@(#)LEGACY KSH R54 2017/03/17
|
||||
description:
|
||||
Check version of legacy shell.
|
||||
stdin:
|
||||
|
@ -8004,11 +8004,11 @@ expected-stderr-pattern:
|
|||
---
|
||||
name: typeset-1
|
||||
description:
|
||||
Check that global does what typeset is supposed to do
|
||||
Check that typeset -g works correctly
|
||||
stdin:
|
||||
set -A arrfoo 65
|
||||
foo() {
|
||||
global -Uui16 arrfoo[*]
|
||||
typeset -g -Uui16 arrfoo[*]
|
||||
}
|
||||
echo before ${arrfoo[0]} .
|
||||
foo
|
||||
|
@ -8018,7 +8018,7 @@ stdin:
|
|||
echo inside before ${arrbar[0]} .
|
||||
arrbar[0]=97
|
||||
echo inside changed ${arrbar[0]} .
|
||||
global -Uui16 arrbar[*]
|
||||
typeset -g -Uui16 arrbar[*]
|
||||
echo inside typeset ${arrbar[0]} .
|
||||
arrbar[0]=48
|
||||
echo inside changed ${arrbar[0]} .
|
||||
|
@ -8792,21 +8792,21 @@ expected-stdout:
|
|||
name: arrassign-fnc-global
|
||||
description:
|
||||
Check locality of array access inside a function
|
||||
with the mksh-specific global keyword
|
||||
with the bash4/mksh/yash/zsh typeset -g keyword
|
||||
stdin:
|
||||
function fn {
|
||||
global x
|
||||
typeset -g x
|
||||
x+=(f)
|
||||
echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
|
||||
}
|
||||
function rfn {
|
||||
set -A y
|
||||
global y
|
||||
typeset -g y
|
||||
y+=(f)
|
||||
echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
|
||||
}
|
||||
function fnr {
|
||||
global z
|
||||
typeset -g z
|
||||
set -A z
|
||||
z+=(f)
|
||||
echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
|
||||
|
@ -8944,21 +8944,21 @@ expected-stdout:
|
|||
name: strassign-fnc-global
|
||||
description:
|
||||
Check locality of string access inside a function
|
||||
with the mksh-specific global keyword
|
||||
with the bash4/mksh/yash/zsh typeset -g keyword
|
||||
stdin:
|
||||
function fn {
|
||||
global x
|
||||
typeset -g x
|
||||
x+=f
|
||||
echo ".fn:$x:"
|
||||
}
|
||||
function rfn {
|
||||
y=
|
||||
global y
|
||||
typeset -g y
|
||||
y+=f
|
||||
echo ".rfn:$y:"
|
||||
}
|
||||
function fnr {
|
||||
global z
|
||||
typeset -g z
|
||||
z=
|
||||
z+=f
|
||||
echo ".fnr:$z:"
|
||||
|
|
10
funcs.c
10
funcs.c
|
@ -38,7 +38,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.327 2017/03/12 02:31:01 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.328 2017/03/17 22:45:50 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
|
@ -117,6 +117,7 @@ const struct builtin mkshbuiltins[] = {
|
|||
{Tfalse, c_false},
|
||||
{"fc", c_fc},
|
||||
{Tgetopts, c_getopts},
|
||||
/* deprecated, replaced by typeset -g */
|
||||
{"^=global", c_typeset},
|
||||
{Tjobs, c_jobs},
|
||||
{"kill", c_kill},
|
||||
|
@ -742,7 +743,7 @@ do_whence(const char **wp, int fcflags, bool vflag, bool iscommand)
|
|||
return (rv);
|
||||
}
|
||||
|
||||
/* typeset, global, export, and readonly */
|
||||
/* typeset, global(deprecated), export, and readonly */
|
||||
static void c_typeset_vardump(struct tbl *, uint32_t, int, bool, bool);
|
||||
static void c_typeset_vardump_recursive(struct block *, uint32_t, int, bool,
|
||||
bool);
|
||||
|
@ -784,7 +785,7 @@ c_typeset(const char **wp)
|
|||
}
|
||||
|
||||
/* see comment below regarding possible opions */
|
||||
opts = istset ? "L#R#UZ#afi#lnprtux" : "p";
|
||||
opts = istset ? "L#R#UZ#afgi#lnprtux" : "p";
|
||||
|
||||
builtin_opt.flags |= GF_PLUSOPT;
|
||||
/*
|
||||
|
@ -829,6 +830,9 @@ c_typeset(const char **wp)
|
|||
case 'f':
|
||||
func = true;
|
||||
break;
|
||||
case 'g':
|
||||
localv = (builtin_opt.info & GI_PLUS) ? true : false;
|
||||
break;
|
||||
case 'i':
|
||||
flag = INTEGER;
|
||||
basestr = builtin_opt.optarg;
|
||||
|
|
58
mksh.1
58
mksh.1
|
@ -1,4 +1,4 @@
|
|||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.428 2017/03/14 11:32:56 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.429 2017/03/17 22:45:51 tg Exp $
|
||||
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
|
||||
.\"-
|
||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
|
@ -76,7 +76,7 @@
|
|||
.\" with -mandoc, it might implement .Mx itself, but we want to
|
||||
.\" use our own definition. And .Dd must come *first*, always.
|
||||
.\"
|
||||
.Dd $Mdocdate: March 14 2017 $
|
||||
.Dd $Mdocdate: March 17 2017 $
|
||||
.\"
|
||||
.\" Check which macro package we use, and do other -mdoc setup.
|
||||
.\"
|
||||
|
@ -3649,9 +3649,22 @@ resetting
|
|||
.Ev OPTIND
|
||||
may lead to unexpected results.
|
||||
.Pp
|
||||
.It global Ar ...
|
||||
.It Xo
|
||||
.Ic global
|
||||
.Op Ic +\-aglpnrtUux
|
||||
.Oo Fl L Ns Op Ar n
|
||||
.No \*(Ba Fl R Ns Op Ar n
|
||||
.No \*(Ba Fl Z Ns Op Ar n Oc
|
||||
.Op Fl i Ns Op Ar n
|
||||
.Oo Ar name
|
||||
.Op Ns = Ns Ar value
|
||||
.Ar ... Oc
|
||||
.Xc
|
||||
See
|
||||
.Ic typeset .
|
||||
.Ic typeset Fl g .
|
||||
.No Deprecated , Em will
|
||||
be removed from a future version of
|
||||
.Nm .
|
||||
.Pp
|
||||
.It Xo
|
||||
.Ic hash
|
||||
|
@ -4802,26 +4815,20 @@ traps in functions are not yet implemented.
|
|||
A command that exits with a zero value.
|
||||
.Pp
|
||||
.It Xo
|
||||
.Ic global
|
||||
.Oo Op Ic +\-alpnrtUux
|
||||
.Op Fl L Ns Op Ar n
|
||||
.Op Fl R Ns Op Ar n
|
||||
.Op Fl Z Ns Op Ar n
|
||||
.Ic typeset
|
||||
.Op Ic +\-aglpnrtUux
|
||||
.Oo Fl L Ns Op Ar n
|
||||
.No \*(Ba Fl R Ns Op Ar n
|
||||
.No \*(Ba Fl Z Ns Op Ar n Oc
|
||||
.Op Fl i Ns Op Ar n
|
||||
.No \*(Ba Fl f Op Fl tux Oc
|
||||
.Oo Ar name
|
||||
.Op Ns = Ns Ar value
|
||||
.Ar ... Oc
|
||||
.Xc
|
||||
.It Xo
|
||||
.Ic typeset
|
||||
.Oo Op Ic +\-alpnrtUux
|
||||
.Op Fl LRZ Ns Op Ar n
|
||||
.Op Fl i Ns Op Ar n
|
||||
.No \*(Ba Fl f Op Fl tux Oc
|
||||
.Oo Ar name
|
||||
.Op Ns = Ns Ar value
|
||||
.Ar ... Oc
|
||||
.Fl f Op Fl tux
|
||||
.Op Ar name ...
|
||||
.Xc
|
||||
Display or set parameter attributes.
|
||||
This is a declaration utility.
|
||||
|
@ -4847,20 +4854,9 @@ Values for parameters may optionally be specified.
|
|||
For
|
||||
.Ar name Ns \&[*] ,
|
||||
the change affects the entire array, and no value may be specified.
|
||||
.Pp
|
||||
If
|
||||
Any parameters created by
|
||||
.Ic typeset
|
||||
is used inside a function, any parameters specified are localised.
|
||||
This is not done by the otherwise identical
|
||||
.Ic global .
|
||||
.Em Note :
|
||||
This means that
|
||||
.Nm Ns 's Ic global
|
||||
command is
|
||||
.Em not
|
||||
equivalent to other programming languages' as it does not allow a
|
||||
function called from another function to access a parameter at truly
|
||||
global scope, but only prevents putting an accessed one into local scope.
|
||||
have local scope by default.
|
||||
.Pp
|
||||
When
|
||||
.Fl f
|
||||
|
@ -4880,6 +4876,8 @@ Indexed array attribute.
|
|||
.It Fl f
|
||||
Function mode.
|
||||
Display or set functions and their attributes, instead of parameters.
|
||||
.It Fl g
|
||||
Create parameters in global scope, not in local scope.
|
||||
.It Fl i Ns Op Ar n
|
||||
Integer attribute.
|
||||
.Ar n
|
||||
|
|
4
sh.h
4
sh.h
|
@ -175,9 +175,9 @@
|
|||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.794 2017/03/12 02:04:14 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.795 2017/03/17 22:45:53 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R54 2017/03/11"
|
||||
#define MKSH_VERSION "R54 2017/03/17"
|
||||
|
||||
/* arithmetic types: C implementation */
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
|
|
Loading…
Reference in New Issue