Detecting End-of-File using READLINE command
John Esak
john at valar.com
Mon Sep 13 12:09:27 PDT 2004
<top-posted becuase I can not quote an html message...>
John,
There are lots of ways to do what you want. I've picked one that will show
you the use of SEEK (and you can explore TELL on your own.) But start with a
file like this... called /tmp/file1.
line1
line22
line333
[...] a newline here
[...] a newline here
[...} EOF
Then run the following processing table and it should show you how to find
the size of the file and then run a readline on the file...
Any questions, please ask.
John Esak
Vist The FP Room www.tinyurl.com/yuag7 24/7
filePro File: test
Processing Table: input
Last Modified: Monday - Sep 13, 2004 at 3:01 PM
Documented: Monday - Sep 13, 2004 at 3:02 PM
1 Then: end
@keyT If:
2 Then:
If: 'size-of-file,begin-of-file,open_handle, #-chars-ret
3 Then: s(4,.0); b(4,.0); h(4,.0); i(4,.0)
If: 'value, counter, close_handle
4 Then: aa(1024); j(4,.0); z(4,.0)
5 Then: h=open("/tmp/file1","rw"); j="1"
If: 'seek to end get filesize, seek back to begin of file
6 Then: s=seek(h,"0","2"); b=seek(h,"0","0")
loop If: tell(h) ge s
7 Then: z=close(h); end
8 Then: i=readline(h,aa,"1024")
9 Then: show "@i=" { i < "aa=" { aa < "j=" { j
10 Then: j=j+"1"
11 Then: goto loop
~
**** unquote-able message below ****
-----Original Message-----
From: filepro-list-bounces at lists.celestial.com
[mailto:filepro-list-bounces at lists.celestial.com]On Behalf Of John Hemmer
Sent: Monday, September 13, 2004 12:08 PM
To: filePro mailing list
Subject: Detecting End-of-File using READLINE command
When using the READLINE command to read sequential records
e.g.
bytes=READLINE(handle,destination,length)
When a line consists of just a newline character, the number of
bytes read and returned in "bytes" may be zero. However, there
could be many records that follow this line.
How can I detect the EOF, End-of-File? Is a negative number
of bytes returned?
None of the Documentation I have, STN Manual, Online FilePro
help, etc, answers these questions.
TIAA
John
More information about the Filepro-list
mailing list