Update libexec/rc/debug.sh and hooks.sh

Use local_works() to test if 'local' actually works for
current shell.
This commit is contained in:
Simon J. Gerraty 2024-12-31 10:47:06 -08:00
parent b47dcb4b1f
commit 203027b2d5
2 changed files with 51 additions and 32 deletions

View file

@ -83,7 +83,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: debug.sh,v 1.42 2024/10/30 18:23:19 sjg Exp $
# $Id: debug.sh,v 1.46 2024/12/13 03:55:52 sjg Exp $
#
# @(#) Copyright (c) 1994-2024 Simon J. Gerraty
#
@ -107,27 +107,45 @@ DEBUG_DO=:
DEBUG_SKIP=
export DEBUGGING DEBUG_DO DEBUG_SKIP
case "$isPOSIX_SHELL,$local" in
:,:|:,local|false,:) ;; # sane
*) # this is the bulk of isposix-shell.sh
# have is handy
if test -z "$_HAVE_SH"; then
_HAVE_SH=:
##
# have that does not rely on return code of type
#
have() {
case `(type "$1") 2>&1` in
*" found") return 1;;
esac
return 0
}
fi
# does local *actually* work?
local_works() {
local _fu
}
if local_works > /dev/null 2>&1; then
_local=local
else
_local=:
fi
# for backwards compatability
local=$_local
if test -z "$isPOSIX_SHELL"; then
if (echo ${PATH%:*}) > /dev/null 2>&1; then
# true should be a builtin, : certainly is
isPOSIX_SHELL=:
# you need to eval $local var
local=local
: KSH_VERSION=$KSH_VERSION
case "$KSH_VERSION" in
Version*) local=: ;; # broken
esac
else
isPOSIX_SHELL=false
local=:
false() {
return 1
}
fi
;;
esac
fi
is_posix_shell() {
$isPOSIX_SHELL
@ -142,7 +160,7 @@ is_posix_shell() {
# a suffix of :debug_add:tag we will add tag to DEBUG_SH
#
_debugAdd() {
eval $local tag
eval $_local tag
for tag in `IFS=,; echo $DEBUG_SH`
do

View file

@ -50,7 +50,7 @@
#
# RCSid:
# $Id: hooks.sh,v 1.21 2024/09/06 16:53:45 sjg Exp $
# $Id: hooks.sh,v 1.24 2024/12/13 03:55:52 sjg Exp $
#
# @(#)Copyright (c) 2000-2024 Simon J. Gerraty
#
@ -64,18 +64,19 @@
# avoid multiple inclusion
_HOOKS_SH=:
# We want to use local if we can
# if isposix-shell.sh has been sourced isPOSIX_SHELL will be set
# as will local
case "$local" in
local|:) ;;
*) if (echo ${PATH%:*}) > /dev/null 2>&1; then
local=local
else
local=:
fi
;;
esac
# does local *actually* work?
local_works() {
local _fu
}
if local_works > /dev/null 2>&1; then
_local=local
else
_local=:
fi
# for backwards compatability
local=$_local
##
# hooks_add_all list func ...
@ -83,7 +84,7 @@ esac
# add "func"s to "list" regardless
#
hooks_add_all() {
eval $local __h
eval $_local __h
__h=$1; shift
case "$1" in
--first)
@ -100,7 +101,7 @@ hooks_add_all() {
# add "func"s to "list" if not already there
#
hooks_add_once() {
eval $local __h __hh __first
eval $_local __h __hh __first
__h=$1; shift
case "$1" in
--first) shift; __first=:;;
@ -154,7 +155,7 @@ hooks_add() {
# return $list
#
hooks_get() {
eval $local __h __h2 e __l
eval $_local __h __h2 e __l
case "$1" in
--lifo) __l=LIFO; shift;;
esac
@ -178,7 +179,7 @@ hooks_get() {
# is func in $list ?
#
hooks_has() {
eval $local __h
eval $_local __h
eval "__h=\$$1"
case " $__h " in
*" $1 "*) return 0;;
@ -193,7 +194,7 @@ hooks_has() {
# Without '--all'; if any return non-zero return that immediately
#
hooks_run() {
eval $local __a e __h __hl __h2 __l
eval $_local __a e __h __hl __h2 __l
__a=return
__l=