Debian Codegraph @

doc/fconfigure.n

raw
1 '\"
2 '\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH fconfigure n 8.3 Tcl "Tcl Built-In Commands"
8 .so man.macros
9 .BS
10 '\" Note: do not modify the .SH NAME line immediately below!
11 .SH NAME
12 fconfigure \- Set and get options on a channel
13 .SH SYNOPSIS
14 .nf
15 \fBfconfigure \fIchannelId\fR
16 \fBfconfigure \fIchannelId\fR \fIname\fR
17 \fBfconfigure \fIchannelId\fR \fIname value \fR?\fIname value ...\fR?
18 .fi
19 .BE
20 .SH DESCRIPTION
21 .PP
22 The \fBfconfigure\fR command sets and retrieves options for channels.
23 .PP
24 \fIChannelId\fR identifies the channel for which to set or query an
25 option and must refer to an open channel such as a Tcl standard
26 channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), the return
27 value from an invocation of \fBopen\fR or \fBsocket\fR, or the result
28 of a channel creation command provided by a Tcl extension.
29 .PP
30 If no \fIname\fR or \fIvalue\fR arguments are supplied, the command
31 returns a list containing alternating option names and values for the channel.
32 If \fIname\fR is supplied but no \fIvalue\fR then the command returns
33 the current value of the given option.
34 If one or more pairs of \fIname\fR and \fIvalue\fR are supplied, the
35 command sets each of the named options to the corresponding \fIvalue\fR;
36 in this case the return value is an empty string.
37 .PP
38 The options described below are supported for all channels. In addition,
39 each channel type may add options that only it supports. See the manual
40 entry for the command that creates each type of channels for the options
41 that that specific type of channel supports. For example, see the manual
42 entry for the \fBsocket\fR command for additional options for sockets, and
43 the \fBopen\fR command for additional options for serial devices.
44 .TP
45 \fB\-blocking\fR \fIboolean\fR
46 The \fB\-blocking\fR option determines whether I/O operations on the
47 channel can cause the process to block indefinitely.
48 The value of the option must be a proper boolean value.
49 Channels are normally in blocking mode; if a channel is placed into
50 nonblocking mode it will affect the operation of the \fBgets\fR,
51 \fBread\fR, \fBputs\fR, \fBflush\fR, and \fBclose\fR commands by
52 allowing them to operate asynchronously;
53 see the documentation for those commands for details.
54 For nonblocking mode to work correctly, the application must be
55 using the Tcl event loop (e.g. by calling \fBTcl_DoOneEvent\fR or
56 invoking the \fBvwait\fR command).
57 .TP
58 \fB\-buffering\fR \fInewValue\fR
59 .
60 If \fInewValue\fR is \fBfull\fR then the I/O system will buffer output
61 until its internal buffer is full or until the \fBflush\fR command is
62 invoked. If \fInewValue\fR is \fBline\fR, then the I/O system will
63 automatically flush output for the channel whenever a newline character
64 is output. If \fInewValue\fR is \fBnone\fR, the I/O system will flush
65 automatically after every output operation. The default is for
66 \fB\-buffering\fR to be set to \fBfull\fR except for channels that
67 connect to terminal-like devices; for these channels the initial setting
68 is \fBline\fR. Additionally, \fBstdin\fR and \fBstdout\fR are
69 initially set to \fBline\fR, and \fBstderr\fR is set to \fBnone\fR.
70 .TP
71 \fB\-buffersize\fR \fInewSize\fR
72 .
73 \fINewvalue\fR must be an integer; its value is used to set the size of
74 buffers, in bytes, subsequently allocated for this channel to store input
75 or output. \fINewvalue\fR must be between one and one million, allowing
76 buffers of one to one million bytes in size.
77 .TP
78 \fB\-encoding\fR \fIname\fR
79 .
80 This option is used to specify the encoding of the channel, so that the data
81 can be converted to and from Unicode for use in Tcl. For instance, in
82 order for Tcl to read characters from a Japanese file in \fBshiftjis\fR
83 and properly process and display the contents, the encoding would be set
84 to \fBshiftjis\fR. Thereafter, when reading from the channel, the bytes in
85 the Japanese file would be converted to Unicode as they are read.
86 Writing is also supported \- as Tcl strings are written to the channel they
87 will automatically be converted to the specified encoding on output.
88 .RS
89 .PP
90 If a file contains pure binary data (for instance, a JPEG image), the
91 encoding for the channel should be configured to be \fBbinary\fR. Tcl
92 will then assign no interpretation to the data in the file and simply read or
93 write raw bytes. The Tcl \fBbinary\fR command can be used to manipulate this
94 byte-oriented data. It is usually better to set the
95 \fB\-translation\fR option to \fBbinary\fR when you want to transfer
96 binary data, as this turns off the other automatic interpretations of
97 the bytes in the stream as well.
98 .PP
99 The default encoding for newly opened channels is the same platform- and
100 locale-dependent system encoding used for interfacing with the operating
101 system, as returned by \fBencoding system\fR.
102 .RE
103 .TP
104 \fB\-eofchar\fR \fIchar\fR
105 .TP
106 \fB\-eofchar\fR \fB{\fIinChar outChar\fB}\fR
107 .
108 This option supports DOS file systems that use Control-z (\ex1A) as an
109 end of file marker. If \fIchar\fR is not an empty string, then this
110 character signals end-of-file when it is encountered during input. For
111 output, the end-of-file character is output when the channel is closed.
112 If \fIchar\fR is the empty string, then there is no special end of file
113 character marker. For read-write channels, a two-element list specifies
114 the end of file marker for input and output, respectively. As a
115 convenience, when setting the end-of-file character for a read-write
116 channel you can specify a single value that will apply to both reading
117 and writing. When querying the end-of-file character of a read-write
118 channel, a two-element list will always be returned. The default value
119 for \fB\-eofchar\fR is the empty string in all cases except for files
120 under Windows. In that case the \fB\-eofchar\fR is Control-z (\ex1A) for
121 reading and the empty string for writing.
122 The acceptable range for \fB\-eofchar\fR values is \ex01 - \ex7F;
123 attempting to set \fB\-eofchar\fR to a value outside of this range will
124 generate an error.
125 .TP
126 \fB\-translation\fR \fImode\fR
127 .TP
128 \fB\-translation\fR \fB{\fIinMode outMode\fB}\fR
129 .
130 In Tcl scripts the end of a line is always represented using a single
131 newline character (\en). However, in actual files and devices the end of
132 a line may be represented differently on different platforms, or even for
133 different devices on the same platform. For example, under UNIX newlines
134 are used in files, whereas carriage-return-linefeed sequences are
135 normally used in network connections. On input (i.e., with \fBgets\fR
136 and \fBread\fR) the Tcl I/O system automatically translates the external
137 end-of-line representation into newline characters. Upon output (i.e.,
138 with \fBputs\fR), the I/O system translates newlines to the external
139 end-of-line representation. The default translation mode, \fBauto\fR,
140 handles all the common cases automatically, but the \fB\-translation\fR
141 option provides explicit control over the end of line translations.
142 .RS
143 .PP
144 The value associated with \fB\-translation\fR is a single item for
145 read-only and write-only channels. The value is a two-element list for
146 read-write channels; the read translation mode is the first element of
147 the list, and the write translation mode is the second element. As a
148 convenience, when setting the translation mode for a read-write channel
149 you can specify a single value that will apply to both reading and
150 writing. When querying the translation mode of a read-write channel, a
151 two-element list will always be returned. The following values are
152 currently supported:
153 .TP
154 \fBauto\fR
155 .
156 As the input translation mode, \fBauto\fR treats any of newline
157 (\fBlf\fR), carriage return (\fBcr\fR), or carriage return followed by a
158 newline (\fBcrlf\fR) as the end of line representation. The end of line
159 representation can even change from line-to-line, and all cases are
160 translated to a newline. As the output translation mode, \fBauto\fR
161 chooses a platform specific representation; for sockets on all platforms
162 Tcl chooses \fBcrlf\fR, for all Unix flavors, it chooses \fBlf\fR, and
163 for the various flavors of Windows it chooses \fBcrlf\fR. The default
164 setting for \fB\-translation\fR is \fBauto\fR for both input and output.
165 .TP
166 \fBbinary\fR
167 .
168 No end-of-line translations are performed. This is nearly identical to
169 \fBlf\fR mode, except that in addition \fBbinary\fR mode also sets the
170 end-of-file character to the empty string (which disables it) and sets the
171 encoding to \fBbinary\fR (which disables encoding filtering). See the
172 description of \fB\-eofchar\fR and \fB\-encoding\fR for more information.
173 .RS
174 .PP
175 Internally, i.e. when it comes to the actual behaviour of the
176 translator this value \fBis\fR identical to \fBlf\fR and is therefore
177 reported as such when queried. Even if \fBbinary\fR was used to set
178 the translation.
179 .RE
180 .TP
181 \fBcr\fR
182 .
183 The end of a line in the underlying file or device is represented by a
184 single carriage return character. As the input translation mode,
185 \fBcr\fR mode converts carriage returns to newline characters. As the
186 output translation mode, \fBcr\fR mode translates newline characters to
187 carriage returns.
188 .TP
189 \fBcrlf\fR
190 .
191 The end of a line in the underlying file or device is represented by a
192 carriage return character followed by a linefeed character. As the input
193 translation mode, \fBcrlf\fR mode converts carriage-return-linefeed
194 sequences to newline characters. As the output translation mode,
195 \fBcrlf\fR mode translates newline characters to carriage-return-linefeed
196 sequences. This mode is typically used on Windows platforms and for
197 network connections.
198 .TP
199 \fBlf\fR
200 .
201 The end of a line in the underlying file or device is represented by a
202 single newline (linefeed) character. In this mode no translations occur
203 during either input or output. This mode is typically used on UNIX
204 platforms.
205 .RE
206 .PP
207 .SH "STANDARD CHANNELS"
208 .PP
209 The Tcl standard channels (\fBstdin\fR, \fBstdout\fR, and \fBstderr\fR)
210 can be configured through this command like every other channel opened
211 by the Tcl library. Beyond the standard options described above they
212 will also support any special option according to their current type.
213 If, for example, a Tcl application is started by the \fBinet\fR
214 super-server common on Unix system its Tcl standard channels will be
215 sockets and thus support the socket options.
216 .SH EXAMPLES
217 .PP
218 Instruct Tcl to always send output to \fBstdout\fR immediately,
219 whether or not it is to a terminal:
220 .PP
221 .CS
222 \fBfconfigure\fR stdout -buffering none
223 .CE
224 .PP
225 Open a socket and read lines from it without ever blocking the
226 processing of other events:
227 .PP
228 .CS
229 set s [socket some.where.com 12345]
230 \fBfconfigure\fR $s -blocking 0
231 fileevent $s readable "readMe $s"
232 proc readMe chan {
233 if {[gets $chan line] < 0} {
234 if {[eof $chan]} {
235 close $chan
236 return
237 }
238 # Could not read a complete line this time; Tcl's
239 # internal buffering will hold the partial line for us
240 # until some more data is available over the socket.
241 } else {
242 puts stdout $line
243 }
244 }
245 .CE
246 .PP
247 Read a PPM-format image from a file:
248 .PP
249 .CS
250 # Open the file and put it into Unix ASCII mode
251 set f [open teapot.ppm]
252 \fBfconfigure\fR $f \-encoding ascii \-translation lf
253
254 # Get the header
255 if {[gets $f] ne "P6"} {
256 error "not a raw\-bits PPM"
257 }
258
259 # Read lines until we have got non-comment lines
260 # that supply us with three decimal values.
261 set words {}
262 while {[llength $words] < 3} {
263 gets $f line
264 if {[string match "#*" $line]} continue
265 lappend words {*}[join [scan $line %d%d%d]]
266 }
267
268 # Those words supply the size of the image and its
269 # overall depth per channel. Assign to variables.
270 lassign $words xSize ySize depth
271
272 # Now switch to binary mode to pull in the data,
273 # one byte per channel (red,green,blue) per pixel.
274 \fBfconfigure\fR $f \-translation binary
275 set numDataBytes [expr {3 * $xSize * $ySize}]
276 set data [read $f $numDataBytes]
277
278 close $f
279 .CE
280 .SH "SEE ALSO"
281 close(n), flush(n), gets(n), open(n), puts(n), read(n), socket(n),
282 Tcl_StandardChannels(3)
283 .SH KEYWORDS
284 blocking, buffering, carriage return, end of line, flushing, linemode,
285 newline, nonblocking, platform, translation, encoding, filter, byte array,
286 binary
287 '\" Local Variables:
288 '\" mode: nroff
289 '\" End: