Add support for external html docs
[maxima.git] / interfaces / xmaxima / Tkmaxima / Readdata.tcl
blobd7f30b60730fda3f2a84a2ae26f39527c5d74527
1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: Readdata.tcl,v 1.2 2002-09-07 05:21:42 mikeclarkson Exp $
5 ###### Readdata.tcl ######
6 ############################################################
7 # Netmath Copyright (C) 1998 William F. Schelter #
8 # For distribution under GNU public License. See COPYING. #
9 ############################################################
14 #-----------------------------------------------------------------
16 # readDataTilEof -- read data from CHANNEL appending to VAR
17 # allowing no more than TIMEOUT milliseconds between reads.
19 # Results: 1 on success, and -1 if it fails or times out.
21 # Side Effects: CHANNEL will be closed and the global variable VAR will
22 # be set..
24 #----------------------------------------------------------------
26 proc readDataTilEof { channel var timeout } {
27 global readDataDone_ _readDataData
28 global readDataDone_
29 upvar 1 $var variable
30 set _readDataData ""
31 set readDataDone_ 0
32 set $var ""
34 set after_id [after $timeout "set readDataDone_ -1"]
35 fconfigure $channel -blocking 0
36 fileevent $channel readable \
37 [list readDataTilEof1 $channel _readDataData $timeout $after_id]
39 myVwait readDataDone_
40 after cancel $after_id
41 catch { close $channel}
42 set res $readDataDone_
43 if {$res > 0 } { append variable $_readDataData }
44 return $res
47 proc readDataTilEof1 { channel var timeout after_id} {
48 global readDataDone_ $var
50 set new [read $channel]
51 append $var $new
53 if { [eof $channel] } {
54 set readDataDone_ 1
55 close $channel
56 } else {
57 after cancel $after_id
58 after $timeout "set readDataDone_ -1"
63 ## endsource Readdata.tcl