use the new “\builtin” builtin for quoting, everywhere
This commit is contained in:
		
							
								
								
									
										81
									
								
								check.t
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								check.t
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| # $MirOS: src/bin/mksh/check.t,v 1.761 2017/03/19 18:05:25 tg Exp $ | # $MirOS: src/bin/mksh/check.t,v 1.762 2017/03/19 20:36:04 tg Exp $ | ||||||
| # -*- mode: sh -*- | # -*- mode: sh -*- | ||||||
| #- | #- | ||||||
| # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, | # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, | ||||||
| @@ -244,14 +244,21 @@ name: alias-11 | |||||||
| description: | description: | ||||||
| 	Check that special argument handling still applies with escaped aliases | 	Check that special argument handling still applies with escaped aliases | ||||||
| stdin: | stdin: | ||||||
| 	alias local='\typeset' | 	alias local1='\typeset' | ||||||
| 	function foo { | 	alias local2='\\builtin typeset' | ||||||
| 		local x=$1 y=z | 	function fooa { | ||||||
|  | 		local1 x=$1 y=z | ||||||
| 		print -r -- "$x,$y" | 		print -r -- "$x,$y" | ||||||
| 	} | 	} | ||||||
| 	foo 'bar - baz' | 	function foob { | ||||||
|  | 		local2 x=$1 y=z | ||||||
|  | 		print -r -- "$x,$y" | ||||||
|  | 	} | ||||||
|  | 	x=1 y=2; fooa 'bar - baz' | ||||||
|  | 	x=1 y=2; foob 'bar - baz' | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	bar - baz,z | 	bar - baz,z | ||||||
|  | 	bar - baz,z | ||||||
| --- | --- | ||||||
| name: arith-compound | name: arith-compound | ||||||
| description: | description: | ||||||
| @@ -8274,17 +8281,17 @@ stdin: | |||||||
| 	alias | 	alias | ||||||
| 	typeset -f | 	typeset -f | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	autoload='\typeset -fu' | 	autoload='\\builtin typeset -fu' | ||||||
| 	functions='\typeset -f' | 	functions='\\builtin typeset -f' | ||||||
| 	hash='\builtin alias -t' | 	hash='\\builtin alias -t' | ||||||
| 	history='\builtin fc -l' | 	history='\\builtin fc -l' | ||||||
| 	integer='\typeset -i' | 	integer='\\builtin typeset -i' | ||||||
| 	local='\typeset' | 	local='\\builtin typeset' | ||||||
| 	login='\exec login' | 	login='\\builtin exec login' | ||||||
| 	nameref='\typeset -n' | 	nameref='\\builtin typeset -n' | ||||||
| 	nohup='nohup ' | 	nohup='nohup ' | ||||||
| 	r='\builtin fc -e -' | 	r='\\builtin fc -e -' | ||||||
| 	type='\builtin whence -v' | 	type='\\builtin whence -v' | ||||||
| --- | --- | ||||||
| name: aliases-2b | name: aliases-2b | ||||||
| description: | description: | ||||||
| @@ -8294,17 +8301,17 @@ stdin: | |||||||
| 	alias | 	alias | ||||||
| 	typeset -f | 	typeset -f | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	autoload='\typeset -fu' | 	autoload='\\builtin typeset -fu' | ||||||
| 	functions='\typeset -f' | 	functions='\\builtin typeset -f' | ||||||
| 	hash='\builtin alias -t' | 	hash='\\builtin alias -t' | ||||||
| 	history='\builtin fc -l' | 	history='\\builtin fc -l' | ||||||
| 	integer='\typeset -i' | 	integer='\\builtin typeset -i' | ||||||
| 	local='\typeset' | 	local='\\builtin typeset' | ||||||
| 	login='\exec login' | 	login='\\builtin exec login' | ||||||
| 	nameref='\typeset -n' | 	nameref='\\builtin typeset -n' | ||||||
| 	nohup='nohup ' | 	nohup='nohup ' | ||||||
| 	r='\builtin fc -e -' | 	r='\\builtin fc -e -' | ||||||
| 	type='\builtin whence -v' | 	type='\\builtin whence -v' | ||||||
| --- | --- | ||||||
| name: aliases-3b | name: aliases-3b | ||||||
| description: | description: | ||||||
| @@ -8314,17 +8321,17 @@ stdin: | |||||||
| 	./sh -c 'alias; typeset -f' | 	./sh -c 'alias; typeset -f' | ||||||
| 	rm -f sh | 	rm -f sh | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	autoload='\typeset -fu' | 	autoload='\\builtin typeset -fu' | ||||||
| 	functions='\typeset -f' | 	functions='\\builtin typeset -f' | ||||||
| 	hash='\builtin alias -t' | 	hash='\\builtin alias -t' | ||||||
| 	history='\builtin fc -l' | 	history='\\builtin fc -l' | ||||||
| 	integer='\typeset -i' | 	integer='\\builtin typeset -i' | ||||||
| 	local='\typeset' | 	local='\\builtin typeset' | ||||||
| 	login='\exec login' | 	login='\\builtin exec login' | ||||||
| 	nameref='\typeset -n' | 	nameref='\\builtin typeset -n' | ||||||
| 	nohup='nohup ' | 	nohup='nohup ' | ||||||
| 	r='\builtin fc -e -' | 	r='\\builtin fc -e -' | ||||||
| 	type='\builtin whence -v' | 	type='\\builtin whence -v' | ||||||
| --- | --- | ||||||
| name: aliases-cmdline | name: aliases-cmdline | ||||||
| description: | description: | ||||||
| @@ -8381,8 +8388,8 @@ stdin: | |||||||
| 	:|| local() { :; } | 	:|| local() { :; } | ||||||
| 	alias local | 	alias local | ||||||
| expected-stdout: | expected-stdout: | ||||||
| 	local='\typeset' | 	local='\\builtin typeset' | ||||||
| 	local='\typeset' | 	local='\\builtin typeset' | ||||||
| --- | --- | ||||||
| name: arrays-1 | name: arrays-1 | ||||||
| description: | description: | ||||||
|   | |||||||
							
								
								
									
										375
									
								
								dot.mkshrc
									
									
									
									
									
								
							
							
						
						
									
										375
									
								
								dot.mkshrc
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| # $Id$ | # $Id$ | ||||||
| # $MirOS: src/bin/mksh/dot.mkshrc,v 1.110 2017/02/18 02:37:57 tg Exp $ | # $MirOS: src/bin/mksh/dot.mkshrc,v 1.111 2017/03/19 20:36:07 tg Exp $ | ||||||
| #- | #- | ||||||
| # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, | # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, | ||||||
| #		2011, 2012, 2013, 2014, 2015, 2016, 2017 | #		2011, 2012, 2013, 2014, 2015, 2016, 2017 | ||||||
| @@ -25,93 +25,97 @@ | |||||||
| # catch non-mksh, non-lksh, trying to run this file | # catch non-mksh, non-lksh, trying to run this file | ||||||
| case ${KSH_VERSION:-} in | case ${KSH_VERSION:-} in | ||||||
| *LEGACY\ KSH*|*MIRBSD\ KSH*) ;; | *LEGACY\ KSH*|*MIRBSD\ KSH*) ;; | ||||||
| *) return 0 ;; | *) \return 0 ;; | ||||||
| esac | esac | ||||||
|  |  | ||||||
| # give MidnightBSD's laffer1 a bit of csh feeling | # give MidnightBSD's laffer1 a bit of csh feeling | ||||||
| function setenv { | function setenv { | ||||||
| 	if (( $# )); then | 	if (( $# )); then | ||||||
| 		\eval '\export "$1"="${2:-}"' | 		\\builtin eval '\\builtin export "$1"="${2:-}"' | ||||||
| 	else | 	else | ||||||
| 		\typeset -x | 		\\builtin typeset -x | ||||||
| 	fi | 	fi | ||||||
| } | } | ||||||
|  |  | ||||||
| # pager (not control character safe) | # pager (not control character safe) | ||||||
| smores() ( | smores() ( | ||||||
| 	\set +m | 	\\builtin set +m | ||||||
| 	\cat "$@" |& | 	\\builtin cat "$@" |& | ||||||
| 	\trap "rv=\$?; 'kill' $! >/dev/null 2>&1; 'exit' \$rv" EXIT | 	\\builtin trap "rv=\$?; \\\\builtin kill $! >/dev/null 2>&1; \\\\builtin exit \$rv" EXIT | ||||||
| 	while IFS= \read -pr line; do | 	while IFS= \\builtin read -pr line; do | ||||||
| 		llen=${%line} | 		llen=${%line} | ||||||
| 		(( llen == -1 )) && llen=${#line} | 		(( llen == -1 )) && llen=${#line} | ||||||
| 		(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 )) | 		(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 )) | ||||||
| 		if (( (curlin += llen) >= LINES )); then | 		if (( (curlin += llen) >= LINES )); then | ||||||
| 			\builtin print -n -- '\e[7m--more--\e[0m' | 			\\builtin print -nr -- $'\e[7m--more--\e[0m' | ||||||
| 			\read -u1 || \exit $? | 			\\builtin read -u1 || \\builtin exit $? | ||||||
| 			[[ $REPLY = [Qq]* ]] && \exit 0 | 			[[ $REPLY = [Qq]* ]] && \\builtin exit 0 | ||||||
| 			curlin=$llen | 			curlin=$llen | ||||||
| 		fi | 		fi | ||||||
| 		\builtin print -r -- "$line" | 		\\builtin print -r -- "$line" | ||||||
| 	done | 	done | ||||||
| ) | ) | ||||||
|  |  | ||||||
| \: "${EDITOR:=/bin/ed}${TERM:=vt100}${HOSTNAME:=$(\ulimit -c 0; \echo \ | \\builtin alias ls=ls l='ls -F' la='l -a' ll='l -l' lo='l -alo' | ||||||
|     $(hostname 2>/dev/null))}${USER:=$(\ulimit -c 0; id -un 2>/dev/null)}" | \: "${HOSTNAME:=$(\\builtin ulimit -c 0; \\builtin print -r -- $(hostname \ | ||||||
| [[ $HOSTNAME = ?(?(ip6-)localhost?(6)) ]] && HOSTNAME=nil; \: "${USER:=?}" |     2>/dev/null))}${EDITOR:=/bin/ed}${TERM:=vt100}${USER:=$(\\builtin ulimit \ | ||||||
| \alias ls=ls l='ls -F' la='l -a' ll='l -l' lo='l -alo'; \unalias ls |     -c 0; id -un 2>/dev/null)}${USER:=?}" | ||||||
| \export EDITOR HOSTNAME TERM USER | [[ $HOSTNAME = ?(?(ip6-)localhost?(6)) ]] && HOSTNAME=nil; \\builtin unalias ls | ||||||
|  | \\builtin export EDITOR HOSTNAME TERM USER | ||||||
|  |  | ||||||
| # minimal support for lksh users | # minimal support for lksh users | ||||||
| if [[ $KSH_VERSION = *LEGACY\ KSH* ]]; then | if [[ $KSH_VERSION = *LEGACY\ KSH* ]]; then | ||||||
| 	PS1='$USER@${HOSTNAME%%.*}:$PWD>' | 	PS1='$USER@${HOSTNAME%%.*}:$PWD>' | ||||||
| 	return 0 | 	\\builtin return 0 | ||||||
| fi | fi | ||||||
|  |  | ||||||
| # mksh-specific from here | # mksh-specific from here | ||||||
| \: "${MKSH:=$(\builtin whence -p mksh)}"; \: "${MKSH:=/bin/mksh}"; \export MKSH | \: "${MKSH:=$(\\builtin whence -p mksh)}${MKSH:=/bin/mksh}" | ||||||
|  | \\builtin export MKSH | ||||||
|  |  | ||||||
| PS4='[$EPOCHREALTIME] '; PS1='#'; (( USER_ID )) && PS1='$'; PS1=$'\001\r''${| | PS4='[$EPOCHREALTIME] '; PS1='#'; (( USER_ID )) && PS1='$'; PS1=$'\001\r''${| | ||||||
| 	\typeset e=$? | 	\\builtin typeset e=$? | ||||||
|  |  | ||||||
| 	(( e )) && REPLY+="$e|" | 	(( e )) && REPLY+="$e|" | ||||||
| 	REPLY+=${USER}@${HOSTNAME%%.*}: | 	REPLY+=${USER}@${HOSTNAME%%.*}: | ||||||
|  |  | ||||||
| 	\typeset d=${PWD:-?}/ p=~; [[ $p = ?(*/) ]] || d=${d/#$p\//\~/} | 	\\builtin typeset d=${PWD:-?}/ p=~; [[ $p = ?(*/) ]] || d=${d/#$p\//\~/} | ||||||
| 	d=${d%/}; \typeset m=${%d} n p=...; (( m > 0 )) || m=${#d} | 	d=${d%/}; \\builtin typeset m=${%d} n p=...; (( m > 0 )) || m=${#d} | ||||||
| 	(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p= | 	(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p= | ||||||
| 	REPLY+=$p$d | 	REPLY+=$p$d | ||||||
|  |  | ||||||
| 	\return $e | 	\\builtin return $e | ||||||
| } '"$PS1 " | } '"$PS1 " | ||||||
| \alias doch='sudo mksh -c "$(\builtin fc -ln -1)"' | \\builtin alias doch='sudo mksh -c "$(\\builtin fc -ln -1)"' | ||||||
| \command -v rot13 >/dev/null || \alias rot13='tr \ | \\builtin command -v rot13 >/dev/null || \\builtin alias rot13='tr \ | ||||||
|     abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \ |     abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \ | ||||||
|     nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' |     nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | ||||||
| if \command -v hd >/dev/null; then \:; elif \command -v hexdump >/dev/null; then | if \\builtin command -v hd >/dev/null; then | ||||||
|  | 	\: | ||||||
|  | elif \\builtin command -v hexdump >/dev/null; then | ||||||
| 	function hd { | 	function hd { | ||||||
| 		hexdump -e '"%08.8_ax  " 8/1 "%02X " " - " 8/1 "%02X "' \ | 		hexdump -e '"%08.8_ax  " 8/1 "%02X " " - " 8/1 "%02X "' \ | ||||||
| 		    -e '"  |" "%_p"' -e '"|\n"' "$@" | 		    -e '"  |" "%_p"' -e '"|\n"' "$@" | ||||||
| 	} | 	} | ||||||
| else | else | ||||||
| 	function hd { | 	function hd { | ||||||
| 		\typeset -Uui16 -Z11 pos=0 | 		\\builtin typeset -Uui16 -Z11 pos=0 | ||||||
| 		\typeset -Uui16 -Z5 hv=2147483647 | 		\\builtin typeset -Uui16 -Z5 hv=2147483647 | ||||||
| 		\typeset dasc line i | 		\\builtin typeset dasc line i | ||||||
| 		\set +U | 		\\builtin set +U | ||||||
|  |  | ||||||
| 		\cat "$@" | if \read -arN -1 line; then | 		\\builtin cat "$@" | if \\builtin read -arN -1 line; then | ||||||
| 			\typeset -i1 'line[*]' | 			\\builtin typeset -i1 'line[*]' | ||||||
| 			i=0 | 			i=0 | ||||||
| 			while (( i < ${#line[*]} )); do | 			while (( i < ${#line[*]} )); do | ||||||
| 				hv=${line[i++]} | 				hv=${line[i++]} | ||||||
| 				if (( (pos & 15) == 0 )); then | 				if (( (pos & 15) == 0 )); then | ||||||
| 					(( pos )) && \ | 					(( pos )) && \ | ||||||
| 					    \builtin print -r -- "$dasc|" | 					    \\builtin print -r -- "$dasc|" | ||||||
| 					\builtin print -n "${pos#16#}  " | 					\\builtin print -nr "${pos#16#}  " | ||||||
| 					dasc=' |' | 					dasc=' |' | ||||||
| 				fi | 				fi | ||||||
| 				\builtin print -n "${hv#16#} " | 				\\builtin print -nr "${hv#16#} " | ||||||
| 				#XXX EBCDIC, but we need [[:print:]] to fix this | 				#XXX EBCDIC, but we need [[:print:]] to fix this | ||||||
| 				if (( (hv < 32) || (hv > 126) )); then | 				if (( (hv < 32) || (hv > 126) )); then | ||||||
| 					dasc+=. | 					dasc+=. | ||||||
| @@ -119,69 +123,69 @@ else | |||||||
| 					dasc+=${line[i-1]#1#} | 					dasc+=${line[i-1]#1#} | ||||||
| 				fi | 				fi | ||||||
| 				(( (pos++ & 15) == 7 )) && \ | 				(( (pos++ & 15) == 7 )) && \ | ||||||
| 				    \builtin print -n -- '- ' | 				    \\builtin print -nr -- '- ' | ||||||
| 			done | 			done | ||||||
| 			while (( pos & 15 )); do | 			while (( pos & 15 )); do | ||||||
| 				\builtin print -n '   ' | 				\\builtin print -nr '   ' | ||||||
| 				(( (pos++ & 15) == 7 )) && \ | 				(( (pos++ & 15) == 7 )) && \ | ||||||
| 				    \builtin print -n -- '- ' | 				    \\builtin print -nr -- '- ' | ||||||
| 			done | 			done | ||||||
| 			(( hv == 2147483647 )) || \builtin print -r -- "$dasc|" | 			(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|" | ||||||
| 		fi | 		fi | ||||||
| 	} | 	} | ||||||
| fi | fi | ||||||
|  |  | ||||||
| # Berkeley C shell compatible dirs, popd, and pushd functions | # Berkeley C shell compatible dirs, popd, and pushd functions | ||||||
| # Z shell compatible chpwd() hook, used to update DIRSTACK[0] | # Z shell compatible chpwd() hook, used to update DIRSTACK[0] | ||||||
| DIRSTACKBASE=$(\builtin realpath ~/. 2>/dev/null || \ | DIRSTACKBASE=$(\\builtin realpath ~/. 2>/dev/null || \ | ||||||
|     \builtin print -nr -- "${HOME:-/}") |     \\builtin print -nr -- "${HOME:-/}") | ||||||
| set -A DIRSTACK | set -A DIRSTACK | ||||||
| function chpwd { | function chpwd { | ||||||
| 	DIRSTACK[0]=$(\builtin realpath . 2>/dev/null || \ | 	DIRSTACK[0]=$(\\builtin realpath . 2>/dev/null || \ | ||||||
| 	    \builtin print -r -- "$PWD") | 	    \\builtin print -nr -- "$PWD") | ||||||
| 	[[ $DIRSTACKBASE = ?(*/) ]] || \ | 	[[ $DIRSTACKBASE = ?(*/) ]] || \ | ||||||
| 	    DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/\~} | 	    DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/\~} | ||||||
| 	\: | 	\: | ||||||
| } | } | ||||||
| \chpwd . | \chpwd . | ||||||
| cd() { | cd() { | ||||||
| 	\builtin cd "$@" || \return $? | 	\\builtin cd "$@" || \\builtin return $? | ||||||
| 	\chpwd "$@" | 	\chpwd "$@" | ||||||
| } | } | ||||||
| function cd_csh { | function cd_csh { | ||||||
| 	\typeset d t=${1/#\~/$DIRSTACKBASE} | 	\\builtin typeset d t=${1/#\~/$DIRSTACKBASE} | ||||||
|  |  | ||||||
| 	if ! d=$(\builtin cd "$t" 2>&1); then | 	if ! d=$(\\builtin cd "$t" 2>&1); then | ||||||
| 		\builtin print -u2 "${1}: ${d##*cd: $t: }." | 		\\builtin print -ru2 "${1}: ${d##*cd: $t: }." | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	fi | 	fi | ||||||
| 	\cd "$t" | 	\cd "$t" | ||||||
| } | } | ||||||
| function dirs { | function dirs { | ||||||
| 	\typeset d dwidth | 	\\builtin typeset d dwidth | ||||||
| 	\typeset -i fl=0 fv=0 fn=0 cpos=0 | 	\\builtin typeset -i fl=0 fv=0 fn=0 cpos=0 | ||||||
|  |  | ||||||
| 	while \getopts ":lvn" d; do | 	while \\builtin getopts ":lvn" d; do | ||||||
| 		case $d { | 		case $d { | ||||||
| 		(l)	fl=1 ;; | 		(l)	fl=1 ;; | ||||||
| 		(v)	fv=1 ;; | 		(v)	fv=1 ;; | ||||||
| 		(n)	fn=1 ;; | 		(n)	fn=1 ;; | ||||||
| 		(*)	\builtin print -u2 'Usage: dirs [-lvn].' | 		(*)	\\builtin print -ru2 'Usage: dirs [-lvn].' | ||||||
| 			\return 1 ;; | 			\\builtin return 1 ;; | ||||||
| 		} | 		} | ||||||
| 	done | 	done | ||||||
| 	\shift $((OPTIND - 1)) | 	\\builtin shift $((OPTIND - 1)) | ||||||
| 	if (( $# > 0 )); then | 	if (( $# > 0 )); then | ||||||
| 		\builtin print -u2 'Usage: dirs [-lvn].' | 		\\builtin print -ru2 'Usage: dirs [-lvn].' | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	fi | 	fi | ||||||
| 	if (( fv )); then | 	if (( fv )); then | ||||||
| 		fv=0 | 		fv=0 | ||||||
| 		while (( fv < ${#DIRSTACK[*]} )); do | 		while (( fv < ${#DIRSTACK[*]} )); do | ||||||
| 			d=${DIRSTACK[fv]} | 			d=${DIRSTACK[fv]} | ||||||
| 			(( fl )) && d=${d/#\~/$DIRSTACKBASE} | 			(( fl )) && d=${d/#\~/$DIRSTACKBASE} | ||||||
| 			\builtin print -r -- "$fv	$d" | 			\\builtin print -r -- "$fv	$d" | ||||||
| 			\builtin let fv++ | 			(( ++fv )) | ||||||
| 		done | 		done | ||||||
| 	else | 	else | ||||||
| 		fv=0 | 		fv=0 | ||||||
| @@ -191,117 +195,117 @@ function dirs { | |||||||
| 			(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) )) | 			(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) )) | ||||||
| 			if (( fn && (cpos += dwidth + 1) >= 79 && \ | 			if (( fn && (cpos += dwidth + 1) >= 79 && \ | ||||||
| 			    dwidth < 80 )); then | 			    dwidth < 80 )); then | ||||||
| 				\builtin print | 				\\builtin print | ||||||
| 				(( cpos = dwidth + 1 )) | 				(( cpos = dwidth + 1 )) | ||||||
| 			fi | 			fi | ||||||
| 			\builtin print -nr -- "$d " | 			\\builtin print -nr -- "$d " | ||||||
| 			\builtin let fv++ | 			(( ++fv )) | ||||||
| 		done | 		done | ||||||
| 		\builtin print | 		\\builtin print | ||||||
| 	fi | 	fi | ||||||
| 	\return 0 | 	\\builtin return 0 | ||||||
| } | } | ||||||
| function popd { | function popd { | ||||||
| 	\typeset d fa | 	\\builtin typeset d fa | ||||||
| 	\typeset -i n=1 | 	\\builtin typeset -i n=1 | ||||||
|  |  | ||||||
| 	while \getopts ":0123456789lvn" d; do | 	while \\builtin getopts ":0123456789lvn" d; do | ||||||
| 		case $d { | 		case $d { | ||||||
| 		(l|v|n)	fa+=" -$d" ;; | 		(l|v|n)	fa+=" -$d" ;; | ||||||
| 		(+*)	n=2 | 		(+*)	n=2 | ||||||
| 			\break ;; | 			\\builtin break ;; | ||||||
| 		(*)	\builtin print -u2 'Usage: popd [-lvn] [+<n>].' | 		(*)	\\builtin print -ru2 'Usage: popd [-lvn] [+<n>].' | ||||||
| 			\return 1 ;; | 			\\builtin return 1 ;; | ||||||
| 		} | 		} | ||||||
| 	done | 	done | ||||||
| 	\shift $((OPTIND - n)) | 	\\builtin shift $((OPTIND - n)) | ||||||
| 	n=0 | 	n=0 | ||||||
| 	if (( $# > 1 )); then | 	if (( $# > 1 )); then | ||||||
| 		\builtin print -u2 popd: Too many arguments. | 		\\builtin print -ru2 popd: Too many arguments. | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then | 	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then | ||||||
| 		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then | 		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then | ||||||
| 			\builtin print -u2 popd: Directory stack not that deep. | 			\\builtin print -ru2 popd: Directory stack not that deep. | ||||||
| 			\return 1 | 			\\builtin return 1 | ||||||
| 		fi | 		fi | ||||||
| 	elif [[ -n $1 ]]; then | 	elif [[ -n $1 ]]; then | ||||||
| 		\builtin print -u2 popd: Bad directory. | 		\\builtin print -ru2 popd: Bad directory. | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	fi | 	fi | ||||||
| 	if (( ${#DIRSTACK[*]} < 2 )); then | 	if (( ${#DIRSTACK[*]} < 2 )); then | ||||||
| 		\builtin print -u2 popd: Directory stack empty. | 		\\builtin print -ru2 popd: Directory stack empty. | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	fi | 	fi | ||||||
| 	\unset DIRSTACK[n] | 	\\builtin unset DIRSTACK[n] | ||||||
| 	\set -A DIRSTACK -- "${DIRSTACK[@]}" | 	\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}" | ||||||
| 	\cd_csh "${DIRSTACK[0]}" || \return 1 | 	\cd_csh "${DIRSTACK[0]}" || \\builtin return 1 | ||||||
| 	\dirs $fa | 	\dirs $fa | ||||||
| } | } | ||||||
| function pushd { | function pushd { | ||||||
| 	\typeset d fa | 	\\builtin typeset d fa | ||||||
| 	\typeset -i n=1 | 	\\builtin typeset -i n=1 | ||||||
|  |  | ||||||
| 	while \getopts ":0123456789lvn" d; do | 	while \\builtin getopts ":0123456789lvn" d; do | ||||||
| 		case $d { | 		case $d { | ||||||
| 		(l|v|n)	fa+=" -$d" ;; | 		(l|v|n)	fa+=" -$d" ;; | ||||||
| 		(+*)	n=2 | 		(+*)	n=2 | ||||||
| 			\break ;; | 			\\builtin break ;; | ||||||
| 		(*)	\builtin print -u2 'Usage: pushd [-lvn] [<dir>|+<n>].' | 		(*)	\\builtin print -ru2 'Usage: pushd [-lvn] [<dir>|+<n>].' | ||||||
| 			\return 1 ;; | 			\\builtin return 1 ;; | ||||||
| 		} | 		} | ||||||
| 	done | 	done | ||||||
| 	\shift $((OPTIND - n)) | 	\\builtin shift $((OPTIND - n)) | ||||||
| 	if (( $# == 0 )); then | 	if (( $# == 0 )); then | ||||||
| 		if (( ${#DIRSTACK[*]} < 2 )); then | 		if (( ${#DIRSTACK[*]} < 2 )); then | ||||||
| 			\builtin print -u2 pushd: No other directory. | 			\\builtin print -ru2 pushd: No other directory. | ||||||
| 			\return 1 | 			\\builtin return 1 | ||||||
| 		fi | 		fi | ||||||
| 		d=${DIRSTACK[1]} | 		d=${DIRSTACK[1]} | ||||||
| 		DIRSTACK[1]=${DIRSTACK[0]} | 		DIRSTACK[1]=${DIRSTACK[0]} | ||||||
| 		\cd_csh "$d" || \return 1 | 		\cd_csh "$d" || \\builtin return 1 | ||||||
| 	elif (( $# > 1 )); then | 	elif (( $# > 1 )); then | ||||||
| 		\builtin print -u2 pushd: Too many arguments. | 		\\builtin print -ru2 pushd: Too many arguments. | ||||||
| 		\return 1 | 		\\builtin return 1 | ||||||
| 	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then | 	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then | ||||||
| 		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then | 		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then | ||||||
| 			\builtin print -u2 pushd: Directory stack not that deep. | 			\\builtin print -ru2 pushd: Directory stack not that deep. | ||||||
| 			\return 1 | 			\\builtin return 1 | ||||||
| 		fi | 		fi | ||||||
| 		while (( n-- )); do | 		while (( n-- )); do | ||||||
| 			d=${DIRSTACK[0]} | 			d=${DIRSTACK[0]} | ||||||
| 			\unset DIRSTACK[0] | 			\\builtin unset DIRSTACK[0] | ||||||
| 			\set -A DIRSTACK -- "${DIRSTACK[@]}" "$d" | 			\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}" "$d" | ||||||
| 		done | 		done | ||||||
| 		\cd_csh "${DIRSTACK[0]}" || \return 1 | 		\cd_csh "${DIRSTACK[0]}" || \\builtin return 1 | ||||||
| 	else | 	else | ||||||
| 		\set -A DIRSTACK -- placeholder "${DIRSTACK[@]}" | 		\\builtin set -A DIRSTACK -- placeholder "${DIRSTACK[@]}" | ||||||
| 		\cd_csh "$1" || \return 1 | 		\cd_csh "$1" || \\builtin return 1 | ||||||
| 	fi | 	fi | ||||||
| 	\dirs $fa | 	\dirs $fa | ||||||
| } | } | ||||||
|  |  | ||||||
| # base64 encoder and decoder, RFC compliant, NUL safe, not EBCDIC safe | # base64 encoder and decoder, RFC compliant, NUL safe, not EBCDIC safe | ||||||
| function Lb64decode { | function Lb64decode { | ||||||
| 	\set +U | 	\\builtin set +U | ||||||
| 	\typeset c s="$*" t | 	\\builtin typeset c s="$*" t | ||||||
| 	[[ -n $s ]] || { s=$(\cat; \builtin print x); s=${s%x}; } | 	[[ -n $s ]] || { s=$(\\builtin cat; \\builtin print x); s=${s%x}; } | ||||||
| 	\typeset -i i=0 j=0 n=${#s} p=0 v x | 	\\builtin typeset -i i=0 j=0 n=${#s} p=0 v x | ||||||
| 	\typeset -i16 o | 	\\builtin typeset -i16 o | ||||||
|  |  | ||||||
| 	while (( i < n )); do | 	while (( i < n )); do | ||||||
| 		c=${s:(i++):1} | 		c=${s:(i++):1} | ||||||
| 		case $c { | 		case $c { | ||||||
| 		(=)	\break ;; | 		(=)	\\builtin break ;; | ||||||
| 		([A-Z])	(( v = 1#$c - 65 )) ;; | 		([A-Z])	(( v = 1#$c - 65 )) ;; | ||||||
| 		([a-z])	(( v = 1#$c - 71 )) ;; | 		([a-z])	(( v = 1#$c - 71 )) ;; | ||||||
| 		([0-9])	(( v = 1#$c + 4 )) ;; | 		([0-9])	(( v = 1#$c + 4 )) ;; | ||||||
| 		(+)	v=62 ;; | 		(+)	v=62 ;; | ||||||
| 		(/)	v=63 ;; | 		(/)	v=63 ;; | ||||||
| 		(*)	\continue ;; | 		(*)	\\builtin continue ;; | ||||||
| 		} | 		} | ||||||
| 		(( x = (x << 6) | v )) | 		(( x = (x << 6) | v )) | ||||||
| 		case $((p++)) { | 		case $((p++)) { | ||||||
| 		(0)	\continue ;; | 		(0)	\\builtin continue ;; | ||||||
| 		(1)	(( o = (x >> 4) & 255 )) ;; | 		(1)	(( o = (x >> 4) & 255 )) ;; | ||||||
| 		(2)	(( o = (x >> 2) & 255 )) ;; | 		(2)	(( o = (x >> 2) & 255 )) ;; | ||||||
| 		(3)	(( o = x & 255 )) | 		(3)	(( o = x & 255 )) | ||||||
| @@ -309,25 +313,24 @@ function Lb64decode { | |||||||
| 			;; | 			;; | ||||||
| 		} | 		} | ||||||
| 		t+=\\x${o#16#} | 		t+=\\x${o#16#} | ||||||
| 		(( ++j & 4095 )) && \continue | 		(( ++j & 4095 )) && \\builtin continue | ||||||
| 		\builtin print -n $t | 		\\builtin print -n $t | ||||||
| 		t= | 		t= | ||||||
| 	done | 	done | ||||||
| 	\builtin print -n $t | 	\\builtin print -n $t | ||||||
| } | } | ||||||
|  |  | ||||||
| \set -A Lb64encode_tbl -- 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 { | function Lb64encode { | ||||||
| 	\set +U | 	\\builtin set +U | ||||||
| 	\typeset c s t | 	\\builtin typeset c s t table | ||||||
|  | 	\\builtin set -A table -- 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 + / | ||||||
| 	if (( $# )); then | 	if (( $# )); then | ||||||
| 		\read -raN-1 s <<<"$*" | 		\\builtin read -raN-1 s <<<"$*" | ||||||
| 		\unset s[${#s[*]}-1] | 		\\builtin unset s[${#s[*]}-1] | ||||||
| 	else | 	else | ||||||
| 		\read -raN-1 s | 		\\builtin read -raN-1 s | ||||||
| 	fi | 	fi | ||||||
| 	\typeset -i i=0 n=${#s[*]} j v | 	\\builtin typeset -i i=0 n=${#s[*]} j v | ||||||
|  |  | ||||||
| 	while (( i < n )); do | 	while (( i < n )); do | ||||||
| 		(( v = s[i++] << 16 )) | 		(( v = s[i++] << 16 )) | ||||||
| @@ -335,37 +338,37 @@ function Lb64encode { | |||||||
| 		(( v |= j << 8 )) | 		(( v |= j << 8 )) | ||||||
| 		(( j = i < n ? s[i++] : 0 )) | 		(( j = i < n ? s[i++] : 0 )) | ||||||
| 		(( v |= j )) | 		(( v |= j )) | ||||||
| 		t+=${Lb64encode_tbl[v >> 18]}${Lb64encode_tbl[v >> 12 & 63]} | 		t+=${table[v >> 18]}${table[v >> 12 & 63]} | ||||||
| 		c=${Lb64encode_tbl[v >> 6 & 63]} | 		c=${table[v >> 6 & 63]} | ||||||
| 		if (( i <= n )); then | 		if (( i <= n )); then | ||||||
| 			t+=$c${Lb64encode_tbl[v & 63]} | 			t+=$c${table[v & 63]} | ||||||
| 		elif (( i == n + 1 )); then | 		elif (( i == n + 1 )); then | ||||||
| 			t+=$c= | 			t+=$c= | ||||||
| 		else | 		else | ||||||
| 			t+=== | 			t+=== | ||||||
| 		fi | 		fi | ||||||
| 		if (( ${#t} == 76 || i >= n )); then | 		if (( ${#t} == 76 || i >= n )); then | ||||||
| 			\builtin print $t | 			\\builtin print -r $t | ||||||
| 			t= | 			t= | ||||||
| 		fi | 		fi | ||||||
| 	done | 	done | ||||||
| } | } | ||||||
|  |  | ||||||
| # Better Avalanche for the Jenkins Hash | # Better Avalanche for the Jenkins Hash | ||||||
| \typeset -Z11 -Uui16 Lbafh_v | \\builtin typeset -Z11 -Uui16 Lbafh_v | ||||||
| function Lbafh_init { | function Lbafh_init { | ||||||
| 	Lbafh_v=0 | 	Lbafh_v=0 | ||||||
| } | } | ||||||
| function Lbafh_add { | function Lbafh_add { | ||||||
| 	\set +U | 	\\builtin set +U | ||||||
| 	\typeset s | 	\\builtin typeset s | ||||||
| 	if (( $# )); then | 	if (( $# )); then | ||||||
| 		\read -raN-1 s <<<"$*" | 		\\builtin read -raN-1 s <<<"$*" | ||||||
| 		\unset s[${#s[*]}-1] | 		\\builtin unset s[${#s[*]}-1] | ||||||
| 	else | 	else | ||||||
| 		\read -raN-1 s | 		\\builtin read -raN-1 s | ||||||
| 	fi | 	fi | ||||||
| 	\typeset -i i=0 n=${#s[*]} | 	\\builtin typeset -i i=0 n=${#s[*]} | ||||||
|  |  | ||||||
| 	while (( i < n )); do | 	while (( i < n )); do | ||||||
| 		((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 )) | 		((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 )) | ||||||
| @@ -373,7 +376,7 @@ function Lbafh_add { | |||||||
| 	done | 	done | ||||||
| } | } | ||||||
| function Lbafh_finish { | function Lbafh_finish { | ||||||
| 	\typeset -Ui t | 	\\builtin typeset -Ui t | ||||||
|  |  | ||||||
| 	((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \ | 	((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \ | ||||||
| 	    ((Lbafh_v << 1) & 0xFEFEFEFE) )) | 	    ((Lbafh_v << 1) & 0xFEFEFEFE) )) | ||||||
| @@ -385,33 +388,33 @@ function Lbafh_finish { | |||||||
| # strip comments (and leading/trailing whitespace if IFS is set) from | # strip comments (and leading/trailing whitespace if IFS is set) from | ||||||
| # any file(s) given as argument, or stdin if none, and spew to stdout | # any file(s) given as argument, or stdin if none, and spew to stdout | ||||||
| function Lstripcom { | function Lstripcom { | ||||||
| 	\set -o noglob | 	\\builtin set -o noglob | ||||||
| 	\cat "$@" | while \read _line; do | 	\\builtin cat "$@" | while \\builtin read _line; do | ||||||
| 		_line=${_line%%#*} | 		_line=${_line%%#*} | ||||||
| 		[[ -n $_line ]] && \builtin print -r -- $_line | 		[[ -n $_line ]] && \\builtin print -r -- $_line | ||||||
| 	done | 	done | ||||||
| } | } | ||||||
|  |  | ||||||
| # toggle built-in aliases and utilities, and aliases and functions from mkshrc | # toggle built-in aliases and utilities, and aliases and functions from mkshrc | ||||||
| function enable { | function enable { | ||||||
| 	\typeset doprnt=0 mode=1 x y z rv=0 | 	\\builtin typeset doprnt=0 mode=1 x y z rv=0 | ||||||
| 	\typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all | 	\\builtin typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all | ||||||
| 	\set -A b_alias | 	\\builtin set -A b_alias | ||||||
| 	\set -A i_alias | 	\\builtin set -A i_alias | ||||||
| 	\set -A i_func | 	\\builtin set -A i_func | ||||||
|  |  | ||||||
| 	# accumulate mksh built-in aliases, in ASCIIbetical order | 	# accumulate mksh built-in aliases, in ASCIIbetical order | ||||||
| 	i_alias[nalias]=autoload; b_alias[nalias++]='\typeset -fu' | 	i_alias[nalias]=autoload; b_alias[nalias++]='\\builtin typeset -fu' | ||||||
| 	i_alias[nalias]=functions; b_alias[nalias++]='\typeset -f' | 	i_alias[nalias]=functions; b_alias[nalias++]='\\builtin typeset -f' | ||||||
| 	i_alias[nalias]=hash; b_alias[nalias++]='\builtin alias -t' | 	i_alias[nalias]=hash; b_alias[nalias++]='\\builtin alias -t' | ||||||
| 	i_alias[nalias]=history; b_alias[nalias++]='\builtin fc -l' | 	i_alias[nalias]=history; b_alias[nalias++]='\\builtin fc -l' | ||||||
| 	i_alias[nalias]=integer; b_alias[nalias++]='\typeset -i' | 	i_alias[nalias]=integer; b_alias[nalias++]='\\builtin typeset -i' | ||||||
| 	i_alias[nalias]=local; b_alias[nalias++]='\typeset' | 	i_alias[nalias]=local; b_alias[nalias++]='\\builtin typeset' | ||||||
| 	i_alias[nalias]=login; b_alias[nalias++]='\exec login' | 	i_alias[nalias]=login; b_alias[nalias++]='\\builtin exec login' | ||||||
| 	i_alias[nalias]=nameref; b_alias[nalias++]='\typeset -n' | 	i_alias[nalias]=nameref; b_alias[nalias++]='\\builtin typeset -n' | ||||||
| 	i_alias[nalias]=nohup; b_alias[nalias++]='nohup ' | 	i_alias[nalias]=nohup; b_alias[nalias++]='nohup ' | ||||||
| 	i_alias[nalias]=r; b_alias[nalias++]='\builtin fc -e -' | 	i_alias[nalias]=r; b_alias[nalias++]='\\builtin fc -e -' | ||||||
| 	i_alias[nalias]=type; b_alias[nalias++]='\builtin whence -v' | 	i_alias[nalias]=type; b_alias[nalias++]='\\builtin whence -v' | ||||||
|  |  | ||||||
| 	# accumulate mksh built-in utilities, in definition order, even ifndef | 	# accumulate mksh built-in utilities, in definition order, even ifndef | ||||||
| 	i_func[nfunc++]=. | 	i_func[nfunc++]=. | ||||||
| @@ -419,6 +422,7 @@ function enable { | |||||||
| 	i_func[nfunc++]='[' | 	i_func[nfunc++]='[' | ||||||
| 	i_func[nfunc++]=alias | 	i_func[nfunc++]=alias | ||||||
| 	i_func[nfunc++]=break | 	i_func[nfunc++]=break | ||||||
|  | 	# \\builtin cannot, by design, be overridden | ||||||
| 	i_func[nfunc++]=builtin | 	i_func[nfunc++]=builtin | ||||||
| 	i_func[nfunc++]=cat | 	i_func[nfunc++]=cat | ||||||
| 	i_func[nfunc++]=cd | 	i_func[nfunc++]=cd | ||||||
| @@ -437,7 +441,7 @@ function enable { | |||||||
| 	i_func[nfunc++]=jobs | 	i_func[nfunc++]=jobs | ||||||
| 	i_func[nfunc++]=kill | 	i_func[nfunc++]=kill | ||||||
| 	i_func[nfunc++]=let | 	i_func[nfunc++]=let | ||||||
| 	i_func[nfunc++]='let]' | 	i_func[nfunc++]='let]' #XXX going | ||||||
| 	i_func[nfunc++]=print | 	i_func[nfunc++]=print | ||||||
| 	i_func[nfunc++]=pwd | 	i_func[nfunc++]=pwd | ||||||
| 	i_func[nfunc++]=read | 	i_func[nfunc++]=read | ||||||
| @@ -474,11 +478,13 @@ function enable { | |||||||
| 	i_alias[nalias]=la; b_alias[nalias++]='l -a' | 	i_alias[nalias]=la; b_alias[nalias++]='l -a' | ||||||
| 	i_alias[nalias]=ll; b_alias[nalias++]='l -l' | 	i_alias[nalias]=ll; b_alias[nalias++]='l -l' | ||||||
| 	i_alias[nalias]=lo; b_alias[nalias++]='l -alo' | 	i_alias[nalias]=lo; b_alias[nalias++]='l -alo' | ||||||
| 	i_alias[nalias]=doch; b_alias[nalias++]='sudo mksh -c "$(\builtin fc -ln -1)"' | 	i_alias[nalias]=doch; b_alias[nalias++]='sudo mksh -c "$(\\builtin fc -ln -1)"' | ||||||
| 	i_alias[nalias]=rot13; b_alias[nalias++]='tr abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | 	i_alias[nalias]=rot13; b_alias[nalias++]='tr abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | ||||||
| 	i_alias[nalias]=cls; b_alias[nalias++]='\builtin print -n \\ec' | 	i_alias[nalias]=cls; b_alias[nalias++]='\\builtin print -n \\ec' | ||||||
|  |  | ||||||
| 	# accumulate functions from dot.mkshrc, in definition order | 	# accumulate functions from dot.mkshrc, in definition order | ||||||
|  | 	i_func[nfunc++]=setenv | ||||||
|  | 	i_func[nfunc++]=smores | ||||||
| 	i_func[nfunc++]=hd | 	i_func[nfunc++]=hd | ||||||
| 	i_func[nfunc++]=chpwd | 	i_func[nfunc++]=chpwd | ||||||
| 	i_func[nfunc++]=cd | 	i_func[nfunc++]=cd | ||||||
| @@ -486,21 +492,19 @@ function enable { | |||||||
| 	i_func[nfunc++]=dirs | 	i_func[nfunc++]=dirs | ||||||
| 	i_func[nfunc++]=popd | 	i_func[nfunc++]=popd | ||||||
| 	i_func[nfunc++]=pushd | 	i_func[nfunc++]=pushd | ||||||
| 	i_func[nfunc++]=smores |  | ||||||
| 	i_func[nfunc++]=Lb64decode | 	i_func[nfunc++]=Lb64decode | ||||||
| 	i_func[nfunc++]=Lb64encode | 	i_func[nfunc++]=Lb64encode | ||||||
| 	i_func[nfunc++]=Lbafh_init | 	i_func[nfunc++]=Lbafh_init | ||||||
| 	i_func[nfunc++]=Lbafh_add | 	i_func[nfunc++]=Lbafh_add | ||||||
| 	i_func[nfunc++]=Lbafh_finish | 	i_func[nfunc++]=Lbafh_finish | ||||||
| 	i_func[nfunc++]=Lstripcom | 	i_func[nfunc++]=Lstripcom | ||||||
| 	i_func[nfunc++]=setenv |  | ||||||
| 	i_func[nfunc++]=enable | 	i_func[nfunc++]=enable | ||||||
|  |  | ||||||
| 	# collect all identifiers, sorted ASCIIbetically | 	# collect all identifiers, sorted ASCIIbetically | ||||||
| 	\set -sA i_all -- "${i_alias[@]}" "${i_func[@]}" | 	\\builtin set -sA i_all -- "${i_alias[@]}" "${i_func[@]}" | ||||||
|  |  | ||||||
| 	# handle options, we don't do dynamic loading | 	# handle options, we don't do dynamic loading | ||||||
| 	while \getopts "adf:nps" x; do | 	while \\builtin getopts "adf:nps" x; do | ||||||
| 		case $x { | 		case $x { | ||||||
| 		(a) | 		(a) | ||||||
| 			mode=-1 | 			mode=-1 | ||||||
| @@ -509,8 +513,8 @@ function enable { | |||||||
| 			# deliberately causing an error, like bash-static | 			# deliberately causing an error, like bash-static | ||||||
| 			;| | 			;| | ||||||
| 		(f) | 		(f) | ||||||
| 			\builtin print -u2 enable: dynamic loading not available | 			\\builtin print -ru2 enable: dynamic loading not available | ||||||
| 			\return 2 | 			\\builtin return 2 | ||||||
| 			;; | 			;; | ||||||
| 		(n) | 		(n) | ||||||
| 			mode=0 | 			mode=0 | ||||||
| @@ -519,87 +523,88 @@ function enable { | |||||||
| 			doprnt=1 | 			doprnt=1 | ||||||
| 			;; | 			;; | ||||||
| 		(s) | 		(s) | ||||||
| 			\set -sA i_all -- . : break continue eval exec exit \ | 			\\builtin set -sA i_all -- . : break continue eval \ | ||||||
| 			    export readonly return set shift times trap unset | 			    exec exit export readonly return set shift times \ | ||||||
|  | 			    trap unset | ||||||
| 			;; | 			;; | ||||||
| 		(*) | 		(*) | ||||||
| 			\builtin print -u2 enable: usage: \ | 			\\builtin print -ru2 enable: usage: \ | ||||||
| 			    "enable [-adnps] [-f filename] [name ...]" | 			    "enable [-adnps] [-f filename] [name ...]" | ||||||
| 			return 2 | 			return 2 | ||||||
| 			;; | 			;; | ||||||
| 		} | 		} | ||||||
| 	done | 	done | ||||||
| 	\shift $((OPTIND - 1)) | 	\\builtin shift $((OPTIND - 1)) | ||||||
|  |  | ||||||
| 	# display builtins enabled/disabled/all/special? | 	# display builtins enabled/disabled/all/special? | ||||||
| 	if (( doprnt || ($# == 0) )); then | 	if (( doprnt || ($# == 0) )); then | ||||||
| 		for x in "${i_all[@]}"; do | 		for x in "${i_all[@]}"; do | ||||||
| 			y=$(\alias "$x") || y= | 			y=$(\\builtin alias "$x") || y= | ||||||
| 			[[ $y = "$x='\\builtin whence -p $x >/dev/null || (\\builtin print mksh: $x: not found; exit 127) && \$(\\builtin whence -p $x)'" ]]; z=$? | 			[[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$? | ||||||
| 			case $mode:$z { | 			case $mode:$z { | ||||||
| 			(-1:0|0:0) | 			(-1:0|0:0) | ||||||
| 				\print -r -- "enable -n $x" | 				\\builtin print -r -- "enable -n $x" | ||||||
| 				;; | 				;; | ||||||
| 			(-1:1|1:1) | 			(-1:1|1:1) | ||||||
| 				\print -r -- "enable $x" | 				\\builtin print -r -- "enable $x" | ||||||
| 				;; | 				;; | ||||||
| 			} | 			} | ||||||
| 		done | 		done | ||||||
| 		\return 0 | 		\\builtin return 0 | ||||||
| 	fi | 	fi | ||||||
|  |  | ||||||
| 	for x in "$@"; do | 	for x in "$@"; do | ||||||
| 		z=0 | 		z=0 | ||||||
| 		for y in "${i_alias[@]}" "${i_func[@]}"; do | 		for y in "${i_alias[@]}" "${i_func[@]}"; do | ||||||
| 			[[ $x = "$y" ]] || \continue | 			[[ $x = "$y" ]] || \\builtin continue | ||||||
| 			z=1 | 			z=1 | ||||||
| 			\break | 			\\builtin break | ||||||
| 		done | 		done | ||||||
| 		if (( !z )); then | 		if (( !z )); then | ||||||
| 			\builtin print -ru2 enable: "$x": not a shell builtin | 			\\builtin print -ru2 enable: "$x": not a shell builtin | ||||||
| 			rv=1 | 			rv=1 | ||||||
| 			\continue | 			\\builtin continue | ||||||
| 		fi | 		fi | ||||||
| 		if (( !mode )); then | 		if (( !mode )); then | ||||||
| 			# disable this | 			# disable this | ||||||
| 			\alias "$x=\\builtin whence -p $x >/dev/null || (\\builtin print mksh: $x: not found; exit 127) && \$(\\builtin whence -p $x)" | 			\\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)" | ||||||
| 		else | 		else | ||||||
| 			# find out if this is an alias or not, first | 			# find out if this is an alias or not, first | ||||||
| 			z=0 | 			z=0 | ||||||
| 			y=-1 | 			y=-1 | ||||||
| 			while (( ++y < nalias )); do | 			while (( ++y < nalias )); do | ||||||
| 				[[ $x = "${i_alias[y]}" ]] || \continue | 				[[ $x = "${i_alias[y]}" ]] || \\builtin continue | ||||||
| 				z=1 | 				z=1 | ||||||
| 				\break | 				\\builtin break | ||||||
| 			done | 			done | ||||||
| 			if (( z )); then | 			if (( z )); then | ||||||
| 				# re-enable the original alias body | 				# re-enable the original alias body | ||||||
| 				\alias "$x=${b_alias[y]}" | 				\\builtin alias "$x=${b_alias[y]}" | ||||||
| 			else | 			else | ||||||
| 				# re-enable the original utility/function | 				# re-enable the original utility/function | ||||||
| 				\unalias "$x" | 				\\builtin unalias "$x" | ||||||
| 			fi | 			fi | ||||||
| 		fi | 		fi | ||||||
| 	done | 	done | ||||||
| 	\return $rv | 	\\builtin return $rv | ||||||
| } | } | ||||||
|  |  | ||||||
| \: place customisations below this line | \: place customisations below this line | ||||||
|  |  | ||||||
| [[ $PATH = *\;?:\\* ]] || for p in ~/.etc/bin ~/bin; do | [[ $PATH = *\;?:\\* ]] || for p in ~/.etc/bin ~/bin; do | ||||||
| 	[[ -d $p/. ]] || \continue | 	[[ -d $p/. ]] || \\builtin continue | ||||||
| 	[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH | 	[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH | ||||||
| done | done | ||||||
|  |  | ||||||
| \export SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=- | \\builtin export SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=- | ||||||
| \alias cls='\builtin print -n \\ec' | \\builtin alias cls='\\builtin print -n \\ec' | ||||||
|  |  | ||||||
| #\unset LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_IDENTIFICATION LC_MONETARY \ | #\\builtin unset LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_IDENTIFICATION LC_MONETARY \ | ||||||
| #    LC_NAME LC_NUMERIC LC_TELEPHONE LC_TIME | #    LC_NAME LC_NUMERIC LC_TELEPHONE LC_TIME | ||||||
| #p=en_GB.UTF-8 | #p=en_GB.UTF-8 | ||||||
| #\export LANG=C LC_CTYPE=$p LC_MEASUREMENT=$p LC_MESSAGES=$p LC_PAPER=$p | #\\builtin export LANG=C LC_CTYPE=$p LC_MEASUREMENT=$p LC_MESSAGES=$p LC_PAPER=$p | ||||||
| #\set -U | #\\builtin set -U | ||||||
|  |  | ||||||
| \unset p | \\builtin unset p | ||||||
|  |  | ||||||
| \: place customisations above this line | \: place customisations above this line | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main.c
									
									
									
									
									
								
							| @@ -34,7 +34,7 @@ | |||||||
| #include <locale.h> | #include <locale.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/main.c,v 1.324 2017/03/11 23:22:36 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/main.c,v 1.325 2017/03/19 20:36:07 tg Exp $"); | ||||||
|  |  | ||||||
| extern char **environ; | extern char **environ; | ||||||
|  |  | ||||||
| @@ -71,18 +71,18 @@ static const char *initcoms[] = { | |||||||
| 	Ttypeset, "-x", "HOME", TPATH, TSHELL, NULL, | 	Ttypeset, "-x", "HOME", TPATH, TSHELL, NULL, | ||||||
| 	Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL, | 	Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL, | ||||||
| 	Talias, | 	Talias, | ||||||
| 	"integer=\\typeset -i", | 	"integer=\\\\builtin typeset -i", | ||||||
| 	"local=\\typeset", | 	"local=\\\\builtin typeset", | ||||||
| 	/* not "alias -t --": hash -r needs to work */ | 	/* not "alias -t --": hash -r needs to work */ | ||||||
| 	"hash=\\builtin alias -t", | 	"hash=\\\\builtin alias -t", | ||||||
| 	"type=\\builtin whence -v", | 	"type=\\\\builtin whence -v", | ||||||
| 	"autoload=\\typeset -fu", | 	"autoload=\\\\builtin typeset -fu", | ||||||
| 	"functions=\\typeset -f", | 	"functions=\\\\builtin typeset -f", | ||||||
| 	"history=\\builtin fc -l", | 	"history=\\\\builtin fc -l", | ||||||
| 	"nameref=\\typeset -n", | 	"nameref=\\\\builtin typeset -n", | ||||||
| 	"nohup=nohup ", | 	"nohup=nohup ", | ||||||
| 	"r=\\builtin fc -e -", | 	"r=\\\\builtin fc -e -", | ||||||
| 	"login=\\exec login", | 	"login=\\\\builtin exec login", | ||||||
| 	NULL, | 	NULL, | ||||||
| 	 /* this is what AT&T ksh seems to track, with the addition of emacs */ | 	 /* this is what AT&T ksh seems to track, with the addition of emacs */ | ||||||
| 	Talias, "-tU", | 	Talias, "-tU", | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								mksh.1
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								mksh.1
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| .\" $MirOS: src/bin/mksh/mksh.1,v 1.431 2017/03/19 18:05:29 tg Exp $ | .\" $MirOS: src/bin/mksh/mksh.1,v 1.432 2017/03/19 20:36:08 tg Exp $ | ||||||
| .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ | .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ | ||||||
| .\"- | .\"- | ||||||
| .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, | .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, | ||||||
| @@ -1137,17 +1137,17 @@ also by newline) may be one same parse tree. | |||||||
| .Pp | .Pp | ||||||
| The following command aliases are defined automatically by the shell: | The following command aliases are defined automatically by the shell: | ||||||
| .Bd -literal -offset indent | .Bd -literal -offset indent | ||||||
| autoload=\*(aq\etypeset \-fu\*(aq | autoload=\*(aq\e\ebuiltin typeset \-fu\*(aq | ||||||
| functions=\*(aq\etypeset \-f\*(aq | functions=\*(aq\e\ebuiltin typeset \-f\*(aq | ||||||
| hash=\*(aq\ebuiltin alias \-t\*(aq | hash=\*(aq\e\ebuiltin alias \-t\*(aq | ||||||
| history=\*(aq\ebuiltin fc \-l\*(aq | history=\*(aq\e\ebuiltin fc \-l\*(aq | ||||||
| integer=\*(aq\etypeset \-i\*(aq | integer=\*(aq\e\ebuiltin typeset \-i\*(aq | ||||||
| local=\*(aq\etypeset\*(aq | local=\*(aq\e\ebuiltin typeset\*(aq | ||||||
| login=\*(aq\eexec login\*(aq | login=\*(aq\e\ebuiltin exec login\*(aq | ||||||
| nameref=\*(aq\etypeset \-n\*(aq | nameref=\*(aq\e\ebuiltin typeset \-n\*(aq | ||||||
| nohup=\*(aqnohup \*(aq | nohup=\*(aqnohup \*(aq | ||||||
| r=\*(aq\ebuiltin fc \-e \-\*(aq | r=\*(aq\e\ebuiltin fc \-e \-\*(aq | ||||||
| type=\*(aq\ebuiltin whence \-v\*(aq | type=\*(aq\e\ebuiltin whence \-v\*(aq | ||||||
| .Ed | .Ed | ||||||
| .Pp | .Pp | ||||||
| Tracked aliases allow the shell to remember where it found a particular | Tracked aliases allow the shell to remember where it found a particular | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user