about summary refs log tree commit diff
path: root/Functions/TCP/tcp_read
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-07-04 16:27:36 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-07-04 16:27:36 +0000
commit554605ee04946160e360354c4aee9102c877ac19 (patch)
tree0488e3d86aefe4a93707e44a5b267a5379cb4393 /Functions/TCP/tcp_read
parente50b688cd5d246a6134fe614ae4efdf9e7dd649e (diff)
downloadzsh-554605ee04946160e360354c4aee9102c877ac19.tar.gz
zsh-554605ee04946160e360354c4aee9102c877ac19.tar.xz
zsh-554605ee04946160e360354c4aee9102c877ac19.zip
18810: Various enhancements and bug fixes for the TCP function suite
Diffstat (limited to 'Functions/TCP/tcp_read')
-rw-r--r--Functions/TCP/tcp_read24
1 files changed, 20 insertions, 4 deletions
diff --git a/Functions/TCP/tcp_read b/Functions/TCP/tcp_read
index d9aa47e0e..51e5356cc 100644
--- a/Functions/TCP/tcp_read
+++ b/Functions/TCP/tcp_read
@@ -60,7 +60,7 @@ setopt extendedglob cbases
 
 zmodload -i zsh/mathfunc
 
-local opt drain line quiet block read_fd all sess
+local opt drain line quiet block read_fd all sess key val
 local -A read_fds
 read_fds=()
 float timeout timeout_all endtime
@@ -139,8 +139,12 @@ tcp_lines=()
 local helper_stat=2 skip tpat reply REPLY
 float newtimeout
 
-# Get extra accuracy by making SECONDS floating point locally
-typeset -F SECONDS
+if [[ ${(t)SECONDS} != float* ]]; then
+    # If called from another function, don't override
+    typeset -F TCP_SECONDS_START=$SECONDS
+    # Get extra accuracy by making SECONDS floating point locally
+    typeset -F SECONDS
+fi
 
 if (( timeout_all )); then
   (( endtime = SECONDS + timeout_all ))
@@ -194,11 +198,23 @@ while (( ${#read_fds} )); do
 
     helper_stat=0
     sess=${tcp_by_fd[$read_fd]}
-    tcp_output -P "${TCP_PROMPT:=<-[%s] }" -S $sess -F $read_fd \
+    tcp_output -P "${TCP_PROMPT=<-[%s] }" -S $sess -F $read_fd \
       ${TCP_SILENT:+-q} "$line"
     # REPLY is now set to the line with an appropriate prompt.
     tcp_lines+=($REPLY)
     TCP_LINE=$REPLY TCP_LINE_FD=$read_fd
+
+    # Handle user-defined triggers
+    if (( ${+tcp_on_read} )); then
+	# Call the function given in the key for each matching value.
+	# It is this way round because function names must be
+	# unique, while patterns do not need to be.  Furthermore,
+	# this keeps the use of subscripting under control.
+	for key val in ${(kv)tcp_on_read}; do
+	    [[ $line = ${~val} ]] && $key "$sess" "$line"
+	done
+    fi
+
     # Only handle one line from one device at a time unless draining.
     [[ -z $drain ]] && return $stat
   done