Configuring a file

As mentioned previously, you may use the fconfigure command to set or get the configuration options for an open channel. The syntax is as follows:

	fconfigure channel name value name value…

If invoked with no option names or values, the fconfigure command will return the configuration options for the channel specified. Optionally, a configuration name may be passed to get the configurations for the option specified. If name and value pairs are passed the file will be configured based on the name/value pairs supplied.

The syntax of acceptable options and their descriptions are as follows:

Option

Description

-blocking boolean

This determines if the I/O operations can result in indefinite blocking. Acceptable values must be provided in the standard Tcl Boolean format.

-buffering value

If set to full all output is buffered until a flush command is invoked. If set to line, then the system will automatically flush when a newline character is output. If set to none the system will flush after each operation.

-buffersize size

The value of size may be any valid integer value. This will configure the size for the buffer s in bytes and allocate the specified amount for the channel.

-encoding name

This will set the encoding for the channel to allow data to be converted to and from Unicode for use by Tcl. Default encoding is system and locale specific.

-eofchar char

Specifies the end of file character.

-translation mode

Acceptable values for mode are as follows:

auto treats any newline, carriage return or carriage return/newline as the end of line representation.

binary no end of line translations are performed.

cr specifies that the end of line character is a carriage return.

crlf specifies that the end of line character is a carriage return/linefeed pair.

Lf specifies that the end of line character is a linefeed.

How to do it…

Enter the following command:


% set fp [open text.txt r]
file3f40


$fconfigure $fp
-blocking 1 -buffering full -buffersize 4096 -encoding cp1252 -eofchar -> 


-translation auto

In the preceding example, we have returned the current options for the file specified by $fp. To obtain a single value, we would perform the following:


% fconfigure $fp -buffersize
4096

There's more…

Now enter the following command line:


% fconfigure $fp -blocking 0
% fconfigure $fp -blocking
0

In the first command, we have set the blocking for $fp to false by passing a 0. The second line returned the value for blocking, based on the new configuration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.254.118