summaryrefslogtreecommitdiffstats
path: root/doc/fconfigure.n
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-05-20 21:18:44 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-05-20 21:18:44 (GMT)
commit136a8d9c345ceacdf8e3f271941fed791a2bd314 (patch)
treec80f83d3cc67347c72913c645346f1404794d0f5 /doc/fconfigure.n
parent9478d8fca0ecff55cdeb771cea0d765ead777c5d (diff)
downloadtcl-136a8d9c345ceacdf8e3f271941fed791a2bd314.zip
tcl-136a8d9c345ceacdf8e3f271941fed791a2bd314.tar.gz
tcl-136a8d9c345ceacdf8e3f271941fed791a2bd314.tar.bz2
Added examples.
Diffstat (limited to 'doc/fconfigure.n')
-rw-r--r--doc/fconfigure.n63
1 files changed, 61 insertions, 2 deletions
diff --git a/doc/fconfigure.n b/doc/fconfigure.n
index 12609f5..dcea8cd 100644
--- a/doc/fconfigure.n
+++ b/doc/fconfigure.n
@@ -4,7 +4,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: fconfigure.n,v 1.9 2004/03/17 18:14:12 das Exp $
+'\" RCS: @(#) $Id: fconfigure.n,v 1.10 2004/05/20 21:18:44 dkf Exp $
'\"
.so man.macros
.TH fconfigure n 8.3 Tcl "Tcl Built-In Commands"
@@ -191,7 +191,6 @@ during either input or output. This mode is typically used on UNIX
platforms.
.RE
.PP
-
.SH "STANDARD CHANNELS"
.PP
The Tcl standard channels (\fBstdin\fR, \fBstdout\fR, and \fBstderr\fR)
@@ -201,6 +200,66 @@ will also support any special option according to their current type.
If, for example, a Tcl application is started by the \fBinet\fR
super-server common on Unix system its Tcl standard channels will be
sockets and thus support the socket options.
+.SH EXAMPLES
+Instruct Tcl to always send output to \fBstdout\fR immediately,
+whether or not it is to a terminal:
+.CS
+fconfigure stdout -buffering none
+.CE
+
+Open a socket and read lines from it without ever blocking the
+processing of other events:
+.CS
+set s [socket some.where.com 12345]
+fconfigure $s -blocking 0
+fileevent $s readable "readMe $s"
+proc readMe chan {
+ if {[gets $chan line] < 0} {
+ if {[eof $chan]} {
+ close $chan
+ return
+ }
+ # Could not read a complete line this time; Tcl's
+ # internal buffering will hold the partial line for us
+ # until some more data is available over the socket.
+ } else {
+ puts stdout $line
+ }
+}
+.CE
+
+Read a PPM-format image from a file:
+.CS
+# Open the file and put it into Unix ASCII mode
+set f [open teapot.ppm]
+fconfigure $f \-encoding ascii \-translation lf
+
+# Get the header
+if {[gets $f] ne "P6"} {
+ error "not a raw\-bits PPM"
+}
+
+# Read lines until we have got non-comment lines
+# that supply us with three decimal values.
+set words {}
+while {[llength $words] < 3} {
+ gets $f line
+ if {[string match "#*" $line]} continue
+ lappend words {expand}[join [scan $line %d%d%d]]
+}
+
+# Those words supply the size of the image and its
+# overall depth per channel.
+lassign $words xSize ySize depth
+
+# Now switch to binary mode to pull in the data,
+# one byte per channel (red,gree,blue) per pixel.
+fconfigure $f \-translation binary
+set numDataBytes [expr {3 * $xSize * $ySize}]
+set data [read $f $numDataBytes]
+
+close $f
+.CE
.SH "SEE ALSO"
close(n), flush(n), gets(n), open(n), puts(n), read(n), socket(n),