| [25] | 1 | '\" |
|---|
| 2 | '\" Copyright (c) 1993 The Regents of the University of California. |
|---|
| 3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
|---|
| 4 | '\" |
|---|
| 5 | '\" See the file "license.terms" for information on usage and redistribution |
|---|
| 6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|---|
| 7 | '\" |
|---|
| 8 | '\" RCS: @(#) $Id: eof.n,v 1.9 2007/12/13 15:22:32 dgp Exp $ |
|---|
| 9 | '\" |
|---|
| 10 | .so man.macros |
|---|
| 11 | .TH eof n 7.5 Tcl "Tcl Built-In Commands" |
|---|
| 12 | .BS |
|---|
| 13 | '\" Note: do not modify the .SH NAME line immediately below! |
|---|
| 14 | .SH NAME |
|---|
| 15 | eof \- Check for end of file condition on channel |
|---|
| 16 | .SH SYNOPSIS |
|---|
| 17 | \fBeof \fIchannelId\fR |
|---|
| 18 | .BE |
|---|
| 19 | |
|---|
| 20 | .SH DESCRIPTION |
|---|
| 21 | .PP |
|---|
| 22 | Returns 1 if an end of file condition occurred during the most |
|---|
| 23 | recent input operation on \fIchannelId\fR (such as \fBgets\fR), |
|---|
| 24 | 0 otherwise. |
|---|
| 25 | .PP |
|---|
| 26 | \fIChannelId\fR must be an identifier for an open channel such as a |
|---|
| 27 | Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), |
|---|
| 28 | the return value from an invocation of \fBopen\fR or \fBsocket\fR, or |
|---|
| 29 | the result of a channel creation command provided by a Tcl extension. |
|---|
| 30 | .SH EXAMPLES |
|---|
| 31 | Read and print out the contents of a file line-by-line: |
|---|
| 32 | .CS |
|---|
| 33 | set f [open somefile.txt] |
|---|
| 34 | while {1} { |
|---|
| 35 | set line [gets $f] |
|---|
| 36 | if {[\fBeof\fR $f]} { |
|---|
| 37 | close $f |
|---|
| 38 | break |
|---|
| 39 | } |
|---|
| 40 | puts "Read line: $line" |
|---|
| 41 | } |
|---|
| 42 | .CE |
|---|
| 43 | .PP |
|---|
| 44 | Read and print out the contents of a file by fixed-size records: |
|---|
| 45 | .CS |
|---|
| 46 | set f [open somefile.dat] |
|---|
| 47 | fconfigure $f -translation binary |
|---|
| 48 | set recordSize 40 |
|---|
| 49 | while {1} { |
|---|
| 50 | set record [read $f $recordSize] |
|---|
| 51 | if {[\fBeof\fR $f]} { |
|---|
| 52 | close $f |
|---|
| 53 | break |
|---|
| 54 | } |
|---|
| 55 | puts "Read record: $record" |
|---|
| 56 | } |
|---|
| 57 | .CE |
|---|
| 58 | |
|---|
| 59 | .SH "SEE ALSO" |
|---|
| 60 | file(n), open(n), close(n), fblocked(n), Tcl_StandardChannels(3) |
|---|
| 61 | |
|---|
| 62 | .SH KEYWORDS |
|---|
| 63 | channel, end of file |
|---|