1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-28 15:01:21 +02:00

22592: add tcp_send -c option for cat

This commit is contained in:
Peter Stephenson 2006-08-08 11:27:39 +00:00
parent 98e306e251
commit 901e6c7387
3 changed files with 32 additions and 12 deletions

@ -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.

@ -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.

@ -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