about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/tcpsys.yo9
-rw-r--r--Functions/TCP/tcp_send30
3 files changed, 32 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 5614e9774..4c72e8cac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-08  Peter Stephenson  <pws@csr.com>
+
+	* 22592: Functions/TCP/tcp_send, Doc/Zsh/tcpsys.yo: add tcp_send
+	-c to behave in a catlike fashion.
+
 2006-08-07  Peter Stephenson  <pws@csr.com>
 
 	* unposted: Src/Zle/complist.c: another bad declaration.
diff --git a/Doc/Zsh/tcpsys.yo b/Doc/Zsh/tcpsys.yo
index f8f65b634..f1586b602 100644
--- a/Doc/Zsh/tcpsys.yo
+++ b/Doc/Zsh/tcpsys.yo
@@ -185,13 +185,18 @@ non-zero return status indicates some error condition.
 See tt(tcp_log) for how to control where data is sent by tt(tcp_read).
 )
 findex(tcp_send)
-xitem(tt(tcp_send [-nq] [ -s) var(sess) tt(| -l) var(sess)tt(,... ]) var(data) tt(...))
-item(tt(tcp_send [-nq] -a) var(data) tt(...))(
+xitem(tt(tcp_send [-cnq] [ -s) var(sess) tt(| -l) var(sess)tt(,... ]) var(data) tt(...))
+item(tt(tcp_send [-cnq] -a) var(data) tt(...))(
 Send the supplied data strings to all the specified sessions in turn.  The
 underlying operation differs little from a `tt(print -r)' to the session's
 file descriptor, although it attempts to prevent the shell from dying owing
 to a tt(SIGPIPE) caused by an attempt to write to a defunct session.
 
+The option tt(-c) causes tt(tcp_send) to behave like tt(cat).  It reads
+lines from standard input until end of input and sends them in turn to the
+specified session+LPAR()s+RPAR() exactly as if they were given as var(data)
+arguments to individual tt(tcp_send) commands.
+
 The option tt(-n) prevents tt(tcp_send) from putting a newline at the end
 of the data strings.
 
diff --git a/Functions/TCP/tcp_send b/Functions/TCP/tcp_send
index c6d8ad637..d5edf05bd 100644
--- a/Functions/TCP/tcp_send
+++ b/Functions/TCP/tcp_send
@@ -1,14 +1,16 @@
 emulate -L zsh
 setopt extendedglob cbases
 
-local opt quiet all sess fd nonewline
+local opt quiet all sess fd nonewline cat line
 local -a sessions write_fds
 integer mystat
 
-while getopts "al:nqs:" opt; do
+while getopts "acl:nqs:" opt; do
     case $opt in
 	(a) all=1
 	    ;;
+        (c) cat=1
+	    ;;
 	(n) nonewline=-n
 	    ;;
 	(q) quiet=1
@@ -55,21 +57,29 @@ trap 'TCP_FD_CLOSED=1' PIPE
 
 local TCP_SESS
 
-for TCP_SESS in $sessions; do
+while true; do
+  if [[ -n $cat ]]; then
+    read -r line || break
+  else
+    line="$*"
+  fi
+  for TCP_SESS in $sessions; do
     fd=${tcp_by_name[$TCP_SESS]}
     if [[ -z $fd ]]; then
-	print "No such session: $TCP_SESS" >&2
-	mystat=1
-	continue
+      print "No such session: $TCP_SESS" >&2
+      mystat=1
+      continue
     fi
-    print -u $fd $nonewline -r -- $*
+    print -u $fd $nonewline -r -- $line
     if [[ $? -ne 0 || -n $TCP_FD_CLOSED ]]; then
-	print "Session ${TCP_SESS}: fd $fd unusable." >&2
-	unset TCP_FD_CLOSED
+      print "Session ${TCP_SESS}: fd $fd unusable." >&2
+      unset TCP_FD_CLOSED
     fi
     if [[ -n $TCP_OUTPUT ]]; then
-	tcp_output -P "$TCP_OUTPUT" -S $TCP_SESS -F $fd -q "${(j. .)*}"
+      tcp_output -P "$TCP_OUTPUT" -S $TCP_SESS -F $fd -q "${(j. .)*}"
     fi
+  done
+  [[ -z $cat ]] && break
 done
 
 return $mystat