🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.atari16
Article #863

I/O redirection and reading EOF

#863
From: Andrew Smith
Date: Tue, 10 Jun 1986 10:06
38 lines
2011 bytes
Hi,

I have just written a 'shell' for the ATARI ST and implemented I/O redirection
from the command level. I have a real problem when redirecting stdin as the 
called program has no way of detecting EOF if the input is from a redirected
file. When trying the following:

	cat < file

'cat' just keeps trying to read past the end of file (cat is just a while not 
EOF getc loop).

I have implemented redirection as:

	handle = Fopen(filename,R_ONLY);
	Fforce(KEYBOARD,handle);

Is this OK ? (there is a small problem when the file is closed - I get a 
never ending bleep from the speeker - it appears as if stdin is not being
set back to the console correctly).

The problem appears to be because the GEMDOS call 'READ' ($3F) has no notion
of EOF (the manual states that to detect EOF you must compare the size of the
file with the number of characters read), so if you open the file with fopen
all is OK as it is taken care of by the library stdio functions. 

The only way around this (as far as I can see) is to write my own detect_eof
function which would return the standard FEOF if we have a 'real' file, but
if we have stdin from the console look for say ^D, else check for EOF on the
redirected file. The only problem with this is how do I check a file descriptor
to see if it is realy stdin or a redirected stdin ?

Can anybody help me ? I would be pleased of any help.

Thanks in advance,

Andrew Smith (..!mcvax!ukc!kcl-cs!andrew).
Technical Details
Message-ID: <691@neon.kcl-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!kcl-cs!andrew

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!kcl-cs!andrew
From: andrew@kcl-cs.UUCP (Andrew Smith)
Newsgroups: net.micro.atari16
Subject: I/O redirection and reading EOF
Message-ID: <691@neon.kcl-cs.UUCP>
Date: Tue, 10-Jun-86 06:06:15 EDT
Article-I.D.: neon.691
Posted: Tue Jun 10 06:06:15 1986
Date-Received: Sat, 14-Jun-86 06:47:14 EDT
Reply-To: andrew@kcl-cs.UUCP ()
Organization: Department of Computing, Kings College, University of London.
Lines: 38