sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

D1863.RETURN-recursive.sh (1372B)


      1 
      2 # 通常の RETURN の使い方
      3 
      4 f2() {
      5   trap 'echo "RETURN/f2 @ ${BLE_TRAP_FUNCNAME:-$FUNCNAME}"; trap - RETURN' RETURN
      6   echo f2
      7   echo /f2
      8 }
      9 
     10 f1() {
     11   trap 'echo "RETURN/f1 @ ${BLE_TRAP_FUNCNAME:-$FUNCNAME}"; trap - RETURN' RETURN
     12   echo f1
     13   f2
     14   echo /f1
     15 }
     16 
     17 f0() {
     18   echo f0
     19   f1
     20   echo /f0
     21 }
     22 
     23 f0
     24 trap -p
     25 echo
     26 
     27 # ble.sh 内部の構造 (function trap に対して RETURN trap が発火しない様
     28 # に install-hook した時)
     29 
     30 ihandler=0
     31 trap_handler() {
     32   local offset
     33   for ((offset=1;offset<${#FUNCNAME[@]};offset++)); do
     34     case ${FUNCNAME[offset]} in
     35     (ble/builtin/trap/invoke.sandbox | ble/builtin/trap/invoke | ble/builtin/trap/.handler) ;;
     36     (trap_set | trap | ble/builtin/trap) return 0 ;;
     37     (*) break ;;
     38     esac
     39   done
     40   #echo "trap_handler(offset=$offset,${FUNCNAME[*]})" >/dev/tty
     41   eval "${trap_handlers[$1]}"
     42 }
     43 declare -ft trap_handler
     44 trap_set() {
     45   if [[ $1 == - ]]; then
     46     trap - RETURN
     47     echo "[note: current RETURN trap: $(trap -p RETURN)]"
     48   else
     49     trap_handlers[ihandler]=$1
     50     trap "trap_handler $((ihandler++))" RETURN
     51   fi
     52 }
     53 declare -ft trap_set
     54 
     55 f2() {
     56   trap_set 'echo "RETURN/f2 @ ${BLE_TRAP_FUNCNAME:-${FUNCNAME[1]}}"; trap_set -'
     57   echo f2
     58   echo /f2
     59 }
     60 
     61 f1() {
     62   trap_set 'echo "RETURN/f1 @ ${BLE_TRAP_FUNCNAME:-${FUNCNAME[1]}}"; trap_set -'
     63   echo f1
     64   f2
     65   echo /f1
     66 }
     67 
     68 f0() {
     69   echo f0
     70   f1
     71   echo /f0
     72 }
     73 
     74 f0
     75 trap -p