mirror of
https://github.com/zsh-users/zsh
synced 2024-10-14 11:53:24 +00:00
TCP functions: fix some variable handling problems,
also standardise indentation add-zsh-hook: fix check for existence of hook function in existing hook
This commit is contained in:
parent
dc72699b6c
commit
5e7e797ca9
11
ChangeLog
11
ChangeLog
|
@ -1,5 +1,16 @@
|
||||||
|
2008-08-01 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* unposted: Functions/Misc/add-zsh-hook: testing for existence
|
||||||
|
of hook function when hook was already defined was broken.
|
||||||
|
|
||||||
|
* unposted: Functions/TCP/tcp_open, Functions/TCP/tcp_sess:
|
||||||
|
improve some variable handling and standardise some indentation.
|
||||||
|
|
||||||
2008-07-31 Peter Stephenson <pws@csr.com>
|
2008-07-31 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 25364: Doc/Zsh/params.yo, Src/params.c, Test/D06subscript.ztst:
|
||||||
|
(k) hash subscript didn't work due to sense of test.
|
||||||
|
|
||||||
* 25345, 25347: Src/builtin.c, Src/exec.c, Src/hist.c, Src/init.c,
|
* 25345, 25347: Src/builtin.c, Src/exec.c, Src/hist.c, Src/init.c,
|
||||||
Src/input.c, Src/jobs.c, Src/loop.c, Src/options.c, Src/signals.c,
|
Src/input.c, Src/jobs.c, Src/loop.c, Src/options.c, Src/signals.c,
|
||||||
Src/utils.c, Src/zsh.h, Src/Zle/zle_main.c: Neaten interface
|
Src/utils.c, Src/zsh.h, Src/Zle/zle_main.c: Neaten interface
|
||||||
|
|
|
@ -66,7 +66,7 @@ if (( del )); then
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if (( ${(P)+hook} )); then
|
if (( ${(P)+hook} )); then
|
||||||
if (( ${(P)hook[(I)$fn]} == 0 )); then
|
if (( ${${(P)hook}[(I)$fn]} == 0 )); then
|
||||||
set -A $hook ${(P)hook} $fn
|
set -A $hook ${(P)hook} $fn
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
|
@ -72,30 +72,30 @@ local -a sessnames sessargs
|
||||||
integer stat
|
integer stat
|
||||||
|
|
||||||
while getopts "a:f:l:qs:z" opt; do
|
while getopts "a:f:l:qs:z" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
(a) accept=$OPTARG
|
(a) accept=$OPTARG
|
||||||
if [[ $accept != [[:digit:]]## ]]; then
|
if [[ $accept != [[:digit:]]## ]]; then
|
||||||
print "option -a takes a file descriptor" >&2
|
print "option -a takes a file descriptor" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(f) fake=$OPTARG
|
(f) fake=$OPTARG
|
||||||
if [[ $fake != [[:digit:]]## ]]; then
|
if [[ $fake != [[:digit:]]## ]]; then
|
||||||
print "option -f takes a file descriptor" >&2
|
print "option -f takes a file descriptor" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(l) sessnames+=(${(s.,.)OPTARG})
|
(l) sessnames+=(${(s.,.)OPTARG})
|
||||||
;;
|
;;
|
||||||
(q) quiet=1
|
(q) quiet=1
|
||||||
;;
|
;;
|
||||||
(s) sessnames+=($OPTARG)
|
(s) sessnames+=($OPTARG)
|
||||||
;;
|
;;
|
||||||
(z) nozle=1
|
(z) nozle=1
|
||||||
;;
|
;;
|
||||||
(*) return 1
|
(*) return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
|
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
|
||||||
|
|
||||||
|
@ -104,50 +104,50 @@ done
|
||||||
typeset -A sessassoc
|
typeset -A sessassoc
|
||||||
|
|
||||||
if (( ${#sessnames} )); then
|
if (( ${#sessnames} )); then
|
||||||
if [[ $# -ne 0 || -n $accept || -n $fake ]]; then
|
if [[ $# -ne 0 || -n $accept || -n $fake ]]; then
|
||||||
print "Incompatible arguments with \`-s' option." >&2
|
print "Incompatible arguments with \`-s' option." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
for sess in ${sessnames}; do
|
for sess in ${sessnames}; do
|
||||||
sessassoc[$sess]=
|
sessassoc[$sess]=
|
||||||
done
|
done
|
||||||
|
|
||||||
sessfile=${ZDOTDIR:-$HOME}/.ztcp_sessions
|
sessfile=${ZDOTDIR:-$HOME}/.ztcp_sessions
|
||||||
if [[ ! -r $sessfile ]]; then
|
if [[ ! -r $sessfile ]]; then
|
||||||
print "No session file: $sessfile" >&2
|
print "No session file: $sessfile" >&2
|
||||||
return 1
|
return 1
|
||||||
|
fi
|
||||||
|
while read -A sessargs; do
|
||||||
|
[[ ${sessargs[1]} = '#'* ]] && continue
|
||||||
|
if (( ${+sessassoc[${sessargs[1]}]} )); then
|
||||||
|
sessassoc[${sessargs[1]}]="${sessargs[2,-1]}"
|
||||||
fi
|
fi
|
||||||
while read -A sessargs; do
|
done < $sessfile
|
||||||
[[ ${sessargs[1]} = '#'* ]] && continue
|
for sess in ${sessnames}; do
|
||||||
if (( ${+sessassoc[${sessargs[1]}]} )); then
|
if [[ -z $sessassoc[$sess] ]]; then
|
||||||
sessassoc[${sessargs[1]}]="${sessargs[2,-1]}"
|
print "Couldn't find session $sess in $sessfile." >&2
|
||||||
fi
|
return 1
|
||||||
done < $sessfile
|
fi
|
||||||
for sess in ${sessnames}; do
|
done
|
||||||
if [[ -z $sessassoc[$sess] ]]; then
|
|
||||||
print "Couldn't find session $sess in $sessfile." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
else
|
||||||
if [[ -z $accept && -z $fake ]]; then
|
if [[ -z $accept && -z $fake ]]; then
|
||||||
if (( $# < 2 )); then
|
if (( $# < 2 )); then
|
||||||
set -- wrong number of arguments
|
set -- wrong number of arguments
|
||||||
else
|
|
||||||
host=$1 port=$2
|
|
||||||
shift $(( $# > 1 ? 2 : 1 ))
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n $1 ]]; then
|
|
||||||
sessnames=($1)
|
|
||||||
shift
|
|
||||||
else
|
else
|
||||||
sessnames=($(( ${#tcp_by_fd} + 1 )))
|
host=$1 port=$2
|
||||||
while [[ -n $tcp_by_name[$sessnames[1]] ]]; do
|
shift $(( $# > 1 ? 2 : 1 ))
|
||||||
(( sessnames[1]++ ))
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
sessassoc[$sessnames[1]]="$host $port"
|
fi
|
||||||
|
if [[ -n $1 ]]; then
|
||||||
|
sessnames=($1)
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
sessnames=($(( ${#tcp_by_fd} + 1 )))
|
||||||
|
while [[ -n $tcp_by_name[$sessnames[1]] ]]; do
|
||||||
|
(( sessnames[1]++ ))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
sessassoc[$sessnames[1]]="$host $port"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( $# )); then
|
if (( $# )); then
|
||||||
|
@ -158,64 +158,67 @@ fi
|
||||||
|
|
||||||
local REPLY fd
|
local REPLY fd
|
||||||
for sess in $sessnames; do
|
for sess in $sessnames; do
|
||||||
if [[ -n $tcp_by_name[$sess] ]]; then
|
if [[ -n $tcp_by_name[$sess] ]]; then
|
||||||
print "Session \`$sess' already exists." >&2
|
print "Session \`$sess' already exists." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sessargs=()
|
sessargs=()
|
||||||
if [[ -n $fake ]]; then
|
if [[ -n $fake ]]; then
|
||||||
fd=$fake;
|
fd=$fake;
|
||||||
|
else
|
||||||
|
if [[ -n $accept ]]; then
|
||||||
|
ztcp -a $accept || return 1
|
||||||
else
|
else
|
||||||
if [[ -n $accept ]]; then
|
sessargs=(${=sessassoc[$sess]})
|
||||||
ztcp -a $accept || return 1
|
ztcp $sessargs || return 1
|
||||||
else
|
|
||||||
sessargs=(${=sessassoc[$sess]})
|
|
||||||
ztcp $sessargs || return 1
|
|
||||||
fi
|
|
||||||
fd=$REPLY
|
|
||||||
fi
|
fi
|
||||||
|
fd=$REPLY
|
||||||
|
fi
|
||||||
|
|
||||||
tcp_by_fd[$fd]=$sess
|
tcp_by_fd[$fd]=$sess
|
||||||
tcp_by_name[$sess]=$fd
|
tcp_by_name[$sess]=$fd
|
||||||
|
|
||||||
[[ -o zle && -z $nozle ]] && zle -F $fd tcp_fd_handler
|
[[ -o zle && -z $nozle ]] && zle -F $fd tcp_fd_handler
|
||||||
|
|
||||||
# needed for new completion system, so I'm not too sanguine
|
# needed for new completion system, so I'm not too sanguine
|
||||||
# about requiring this here...
|
# about requiring this here...
|
||||||
if zmodload -i zsh/parameter; then
|
if zmodload -i zsh/parameter; then
|
||||||
if (( ${+functions[tcp_on_open]} )); then
|
if (( ${+functions[tcp_on_open]} )); then
|
||||||
if ! tcp_on_open $sess $fd; then
|
if ! tcp_on_open $sess $fd; then
|
||||||
if [[ -z $quiet ]]; then
|
if [[ -z $quiet ]]; then
|
||||||
if (( ${#sessargs} )); then
|
if (( ${#sessargs} )); then
|
||||||
print "Session $sess" \
|
|
||||||
"(host $sessargs[1], port $sessargs[2] fd $fd): tcp_on_open FAILED."
|
|
||||||
else
|
|
||||||
print "Session $sess (fd $fd) tcp_on_open FAILED."
|
|
||||||
fi
|
|
||||||
tcp_close -- $sess
|
|
||||||
else
|
|
||||||
tcp_close -q -- $sess
|
|
||||||
fi
|
|
||||||
stat=1
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z $quiet ]]; then
|
|
||||||
if (( ${#sessargs} )); then
|
|
||||||
print "Session $sess" \
|
print "Session $sess" \
|
||||||
"(host $sessargs[1], port $sessargs[2] fd $fd) opened OK."
|
"(host $sessargs[1], port $sessargs[2] fd $fd): tcp_on_open FAILED."
|
||||||
|
else
|
||||||
|
print "Session $sess (fd $fd) tcp_on_open FAILED."
|
||||||
|
fi
|
||||||
|
tcp_close -- $sess
|
||||||
else
|
else
|
||||||
print "Session $sess (fd $fd) opened OK."
|
tcp_close -q -- $sess
|
||||||
fi
|
fi
|
||||||
|
stat=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $quiet ]]; then
|
||||||
|
if (( ${#sessargs} )); then
|
||||||
|
print "Session $sess" \
|
||||||
|
"(host $sessargs[1], port $sessargs[2] fd $fd) opened OK."
|
||||||
|
else
|
||||||
|
print "Session $sess (fd $fd) opened OK."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z $TCP_SESS ]]; then
|
if [[ -z $TCP_SESS || -z $tcp_by_name[$TCP_SESS] ]]; then
|
||||||
|
# careful in case we closed it again...
|
||||||
|
if [[ -n $tcp_by_name[$sessnames[1]] ]]; then
|
||||||
[[ -z $quiet ]] && print "Setting default TCP session $sessnames[1]"
|
[[ -z $quiet ]] && print "Setting default TCP session $sessnames[1]"
|
||||||
typeset -g TCP_SESS=$sessnames[1]
|
typeset -g TCP_SESS=$sessnames[1]
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $stat
|
return $stat
|
||||||
|
|
|
@ -17,7 +17,7 @@ if [[ -n $1 ]]; then
|
||||||
eval $__cmd \$\*
|
eval $__cmd \$\*
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
TCP_SESS=$1
|
typeset -g TCP_SESS=$1
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue