Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: use of read/print -u



I'm getting a bit worried that my TCP session file descriptors are
creeping up towards the double digit area as the complexity of my
Bluetooth network topology increases... this doesn't work with <& and >&
since single digits are enforced by the parser.

This patch alters the TCP function system to use the -u options to print
and read, which don't have the single-digit limit now they're properly
parsed.

There's a slight tweak to the print and read manual entries to separate
the -u from the argument in the description: the history is that the
lack of space was required before the option changes, and it didn't get
altered in the manual when the text for -u was changed.  It might as
well use the standard form for options with arguments now.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.61
diff -u -r1.61 builtins.yo
--- Doc/Zsh/builtins.yo	15 May 2003 09:39:57 -0000	1.61
+++ Doc/Zsh/builtins.yo	25 Jul 2003 10:34:03 -0000
@@ -657,7 +657,7 @@
 `tt(-)' in this context are swapped.
 )
 findex(print)
-xitem(tt(print) [ tt(-abcDilmnNoOpPrsz) ] [ tt(-u)var(n) ] [ tt(-f) var(format) ] [ tt(-C) var(cols) ])
+xitem(tt(print) [ tt(-abcDilmnNoOpPrsz) ] [ tt(-u) var(n) ] [ tt(-f) var(format) ] [ tt(-C) var(cols) ])
 item(  [ tt(-R) [ tt(-en) ]] [ var(arg) ... ])(
 With the `tt(-f)' option the arguments are printed as described by tt(printf).
 With no flags or with the flag `tt(-)', the arguments are printed on
@@ -738,7 +738,7 @@
 item(tt(-s))(
 Place the results in the history list instead of on the standard output.
 )
-item(tt(-u)var(n))(
+item(tt(-u) var(n))(
 Print the arguments to file descriptor var(n).
 )
 item(tt(-z))(
@@ -827,7 +827,7 @@
 findex(read)
 vindex(IFS, use of)
 ifzman(xitem(tt(read) [ tt(-rszpqAclneE) ] [ tt(-t) [ var(num) ] ] [ tt(-k) [ var(num) ] ] [ tt(-d) var(delim) ]))
-item(ifnzman(tt(read) [ tt(-rszpqAclneE) ] [ tt(-t) [ var(num) ] ] [ tt(-k) [ var(num) ] ] [ tt(-d) var(delim) ]) [ tt(-u)var(n) ] [ var(name)[tt(?)var(prompt)] ] [ var(name) ...  ])(
+item(ifnzman(tt(read) [ tt(-rszpqAclneE) ] [ tt(-t) [ var(num) ] ] [ tt(-k) [ var(num) ] ] [ tt(-d) var(delim) ]) [ tt(-u) var(n) ] [ var(name)[tt(?)var(prompt)] ] [ var(name) ...  ])(
 vindex(REPLY, use of)
 vindex(reply, use of)
 Read one line and break it into fields using the characters
@@ -895,7 +895,7 @@
 and that when the cursor is at the end of the line, its character
 index is the length of the line plus one.
 )
-item(tt(-u)var(n))(
+item(tt(-u) var(n))(
 Input is read from file descriptor var(n).
 )
 item(tt(-p))(
Index: Functions/TCP/tcp_fd_handler
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/TCP/tcp_fd_handler,v
retrieving revision 1.1
diff -u -r1.1 tcp_fd_handler
--- Functions/TCP/tcp_fd_handler	6 Feb 2003 12:21:51 -0000	1.1
+++ Functions/TCP/tcp_fd_handler	25 Jul 2003 10:34:03 -0000
@@ -20,14 +20,14 @@
   zle -I
   # Handle fds not in the TCP set similarly.
   # This does the drain thing, to try and get as much data out as possible.
-  if ! read line <&$1; then
+  if ! read -u $1 line; then
     print "[Reading on $1 failed; removing from poll list]" >& 2
     zle -F $1
     return 1
   fi
   line="fd$1:$line"
   local newline
-  while read -t newline <&$1; do
+  while read -u $1 -t newline; do
     line="${line}
 fd$1:$newline"
   done
Index: Functions/TCP/tcp_read
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/TCP/tcp_read,v
retrieving revision 1.3
diff -u -r1.3 tcp_read
--- Functions/TCP/tcp_read	4 Jul 2003 16:27:36 -0000	1.3
+++ Functions/TCP/tcp_read	25 Jul 2003 10:34:03 -0000
@@ -190,7 +190,7 @@
     print "[tcp_read: returned fds ${reply}]" >&2
   fi
   for read_fd in ${reply[2,-1]}; do
-    if ! read -r line <&$read_fd; then
+    if ! read -u $read_fd -r line; then
       unset "read_fds[$read_fd]"
       stat=1
       continue
Index: Functions/TCP/tcp_send
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/TCP/tcp_send,v
retrieving revision 1.2
diff -u -r1.2 tcp_send
--- Functions/TCP/tcp_send	4 Jul 2003 16:27:36 -0000	1.2
+++ Functions/TCP/tcp_send	25 Jul 2003 10:34:03 -0000
@@ -62,7 +62,7 @@
 	mystat=1
 	continue
     fi
-    print $nonewline -r -- $* >&$fd
+    print -u $fd $nonewline -r -- $*
     if [[ $? -ne 0 || -n $TCP_FD_CLOSED ]]; then
 	print "Session ${TCP_SESS}: fd $fd unusable." >&2
 	unset TCP_FD_CLOSED
Index: Functions/TCP/tcp_sess
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/TCP/tcp_sess,v
retrieving revision 1.1
diff -u -r1.1 tcp_sess
--- Functions/TCP/tcp_sess	6 Feb 2003 12:21:51 -0000	1.1
+++ Functions/TCP/tcp_sess	25 Jul 2003 10:34:03 -0000
@@ -33,7 +33,7 @@
   else
     cur=
   fi
-  print "sess:$name; fd:$fd$cur" >&$__myfd
+  print -u $__myfd "sess:$name; fd:$fd$cur"
 done
 
 return $(( __myfd - 1 ))

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author