From fe2c0221b36bcf7300404f063af59362e195c7e0 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 5 Jul 2011 20:19:18 +0000 Subject: [PATCH] =?UTF-8?q?replace=20typeset=20with=20local,=20as=20style(?= =?UTF-8?q?9)=20now=20mandates=20(keep=20globals=20for=20a=20while,=20unti?= =?UTF-8?q?l=20it=E2=80=99s=20widespread,=20though)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit since we don’t export PS1 any longer, no need to stay AT&T ksh compatible --- dot.mkshrc | 48 ++++++++++++++++++++++++------------------------ mksh.1 | 8 +++++--- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/dot.mkshrc b/dot.mkshrc index bd9b3ea..25eb505 100644 --- a/dot.mkshrc +++ b/dot.mkshrc @@ -1,5 +1,5 @@ # $Id$ -# $MirOS: src/bin/mksh/dot.mkshrc,v 1.61 2011/07/03 23:26:47 tg Exp $ +# $MirOS: src/bin/mksh/dot.mkshrc,v 1.62 2011/07/05 20:19:17 tg Exp $ #- # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 # Thorsten Glaser @@ -25,12 +25,12 @@ [[ $HOSTNAME = @(localhost|*([ ])) ]] && HOSTNAME=$(ulimit -c 0;hostname 2>&-) : ${HOSTNAME:=nil}; if (( USER_ID )); then PS1='$'; else PS1='#'; fi function precmd { - typeset e=$? + local e=$? (( e )) && print -n "$e|" } PS1=' $(precmd)${USER:=$(ulimit -c 0;id -un 2>&-||print \?)}@${HOSTNAME%%.*}:$( - typeset d=${PWD:-?} n p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~} + local d=${PWD:-?} n p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~} (( (${%d}>0 ? ${%d}: ${#d}) > (n = (COLUMNS/3<7 ? 7: COLUMNS/3)) )) && { d=${d:(-n)}; p=...; } || p=; print -nr -- "$p$d") '"$PS1 " : ${MKSH:=$(whence -p mksh)}; export EDITOR HOSTNAME MKSH TERM USER @@ -64,7 +64,7 @@ function cd { chpwd "$@" } function cd_csh { - typeset d t=${1/#~/$DIRSTACKBASE} + local d t=${1/#~/$DIRSTACKBASE} if ! d=$(builtin cd "$t" 2>&1); then print -u2 "${1}: ${d##*$t - }." @@ -73,8 +73,8 @@ function cd_csh { cd "$t" } function dirs { - typeset d dwidth - typeset -i isnoglob=0 fl=0 fv=0 fn=0 cpos=0 + local d dwidth + local -i isnoglob=0 fl=0 fv=0 fn=0 cpos=0 [[ $(set +o) == *@(-o noglob)@(| *) ]] && isnoglob=1 set -o noglob @@ -120,8 +120,8 @@ function dirs { return 0 } function popd { - typeset d fa - typeset -i isnoglob=0 n=1 + local d fa + local -i isnoglob=0 n=1 [[ $(set +o) == *@(-o noglob)@(| *) ]] && isnoglob=1 set -o noglob @@ -159,8 +159,8 @@ function popd { dirs $fa } function pushd { - typeset d fa - typeset -i isnoglob=0 n=1 + local d fa + local -i isnoglob=0 n=1 [[ $(set +o) == *@(-o noglob)@(| *) ]] && isnoglob=1 set -o noglob @@ -206,7 +206,7 @@ function pushd { # pager (not control character safe) function smores { - typeset dummy line llen curlin=0 + local dummy line llen curlin=0 cat "$@" | while IFS= read -r line; do llen=${%line} @@ -224,12 +224,12 @@ function smores { # base64 encoder and decoder, RFC compliant, NUL safe function Lb64decode { - [[ -o utf8-mode ]]; typeset u=$? + [[ -o utf8-mode ]]; local u=$? set +U - typeset c s="$*" t= + local c s="$*" t= [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; } - typeset -i i=0 n=${#s} p=0 v x - typeset -i16 o + local -i i=0 n=${#s} p=0 v x + local -i16 o while (( i < n )); do c=${s:(i++):1} @@ -260,16 +260,16 @@ function Lb64decode { set -A Lb64encode_code -- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \ a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + / function Lb64encode { - [[ -o utf8-mode ]]; typeset u=$? + [[ -o utf8-mode ]]; local u=$? set +U - typeset c s t + local c s t if (( $# )); then read -raN-1 s <<<"$*" unset s[${#s[*]}-1] else read -raN-1 s fi - typeset -i i=0 n=${#s[*]} j v + local -i i=0 n=${#s[*]} j v while (( i < n )); do (( v = s[i++] << 16 )) @@ -297,16 +297,16 @@ function Lb64encode { # DJB cdb hash (not via stdio, for speed) typeset -Z11 -Uui16 Lcdbhash_result function Lcdbhash_add { - [[ -o utf8-mode ]]; typeset u=$? + [[ -o utf8-mode ]]; local u=$? set +U - typeset s + local s if (( $# )); then read -raN-1 s <<<"$*" unset s[${#s[*]}-1] else read -raN-1 s fi - typeset -i i=0 n=${#s[*]} + local -i i=0 n=${#s[*]} while (( i < n )); do ((# Lcdbhash_result = (Lcdbhash_result * 33) ^ s[i++] )) @@ -323,16 +323,16 @@ function Lcdbhash { # Jenkins one-at-a-time hash (not via stdio, for speed) typeset -Z11 -Uui16 Loaathash_result function Loaathash_add { - [[ -o utf8-mode ]]; typeset u=$? + [[ -o utf8-mode ]]; local u=$? set +U - typeset s + local s if (( $# )); then read -raN-1 s <<<"$*" unset s[${#s[*]}-1] else read -raN-1 s fi - typeset -i i=0 n=${#s[*]} + local -i i=0 n=${#s[*]} while (( i < n )); do ((# Loaathash_result = (Loaathash_result + s[i++]) * diff --git a/mksh.1 b/mksh.1 index de4f39f..40580c1 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.266 2011/07/02 17:57:24 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.267 2011/07/05 20:19:18 tg Exp $ .\" $OpenBSD: ksh.1,v 1.140 2011/04/23 10:14:59 sobrado Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -72,7 +72,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: July 2 2011 $ +.Dd $Mdocdate: July 5 2011 $ .\" .\" Check which macro package we use .\" @@ -1352,6 +1352,7 @@ The construct is also recognised; the old and new values are immediately concatenated. The fourth way of setting a parameter is with the .Ic export , +.Ic global , .Ic readonly , and .Ic typeset @@ -2045,6 +2046,7 @@ In parameter assignments in the arguments of .Ic alias , .Ic export , +.Ic global , .Ic readonly , and .Ic typeset ) , @@ -2848,7 +2850,7 @@ Additional .Nm special commands .Pp -.Ic builtin , times , typeset +.Ic builtin , global , times , typeset .Pp Very special commands .Pq non-POSIX