[comp.sys.apple] console FST EOF

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/13/89)

How does one type an "end of file" to the console when, e.g., the following
APW C program is run:

/* character counter */
#include <stdio.h>
main()
{	int n = 0;
	while (getchar() != EOF)
		++n;
	printf("%d\n", n);
}

I desperately need this facility and was unable to find any mention of it
in the various GS/OS and ProDOS-16 docs I have obtained from APDA.

If this is currently impossible, please fix it in a near-future release
of GS/OS.  It is absurd to have to reboot the computer simply because
one's program happens to be stuck in a read loop.

wombat@claris.com (Scott Lindsey) (08/14/89)

In article <10727@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:

>  How does one type an "end of file" to the console when, e.g., the following
>  APW C program is run:

In this situation, EOF is the null character, not ^D.  This is typed as ^@,
which is the same as CTL-2 on the GS keyboard.  I have no idea if/where this
is documented.

Scott Lindsey     |"Cold and misty morning. I heard a warning borne in the air
Claris Corp.      |    About an age of power when no one had an hour to spare"
ames!claris!wombat| DISCLAIMER: These are not the opinions of Claris, Apple,
wombat@claris.com |    StyleWare, the author, or anyone else living or dead.

farrier@Apple.COM (Cary Farrier) (08/14/89)

In article <10727@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>How does one type an "end of file" to the console when, e.g., the following
>APW C program is run:
>
>/* character counter */
>#include <stdio.h>
>main()
>{	int n = 0;
>	while (getchar() != EOF)
>		++n;
>	printf("%d\n", n);
>}
>
>I desperately need this facility and was unable to find any mention of it
>in the various GS/OS and ProDOS-16 docs I have obtained from APDA.
>
>If this is currently impossible, please fix it in a near-future release
>of GS/OS.  It is absurd to have to reboot the computer simply because
>one's program happens to be stuck in a read loop.

	Try Ctrl-Z, it is the ASCII code for EOF.

Cary Farrier
-- 
+--------------+-------------------------+----------------------------------+
| Cary Farrier | farrier@goofy.apple.com | The contents of this article are |
+--------------+-------------------------+ real.  Only the facts have been  |
|      Copyright 1989 Cary Farrier       | changed to protect the innocent. |
|          All Rights Reserved           |                                  |
+----------------------------------------+----------------------------------+

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/15/89)

In article <3539@internal.Apple.COM> farrier@Apple.COM (Cary Farrier) writes:
>	Try Ctrl-Z, it is the ASCII code for EOF.

Wrong, and wrong.  Please don't answer unless you know what you're saying.

farrier@Apple.COM (Cary Farrier) (08/15/89)

In article <10736@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <3539@internal.Apple.COM> farrier@Apple.COM (Cary Farrier) writes:
>>	Try Ctrl-Z, it is the ASCII code for EOF.
>
>Wrong, and wrong.  Please don't answer unless you know what you're saying.

	Take a look at any ASCII chart, look at the definition of character
	number 26, and you will see that it is CTRL-Z, the EOF marker.

Cary Farrier
-- 
+--------------+-------------------------+----------------------------------+
| Cary Farrier | farrier@goofy.apple.com | The contents of this article are |
+--------------+-------------------------+ real.  Only the facts have been  |
|      Copyright 1989 Cary Farrier       | changed to protect the innocent. |
|          All Rights Reserved           |                                  |
+----------------------------------------+----------------------------------+

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/15/89)

In article <3571@internal.Apple.COM> farrier@Apple.COM (Cary Farrier) writes:
>	Take a look at any ASCII chart, look at the definition of character
>	number 26, and you will see that it is CTRL-Z, the EOF marker.

I wish people would follow their own advice.  Ctrl-Z results in code value 26
almost by definition.  However, if you do consult an ASCII chart, you will see
that code 26 has nothing to do with EOF.  It is in fact the ASCII SUB(stitute)
character; ASCII has no end-of-file character, although it has a couple of
likely candidates EOT and ETX (which do NOT do what I was asking for).

Nevertheless, Ctrl-Z was among the first things I tried (right after Ctrl-D),
because I was aware that some OSes have historically pressed SUB into service
for a terminal EOF indicator.   CP/M and RT-11 even used an embedded SUB
(followed by NULs to pad out the block) to mark the end of a text file, since
they maintained disk file size only in blocks, not in bytes as on UNIX.
Typing Ctrl-Z does NOT cause the GS/OS console FST to report end-of-file, at
least not at a C application's getchar() level.

A more reliable source claims that NUL will do the trick.  I haven't had
a chance to try it yet, although I could have sworn it was one of the things
I had already tried.

sedwards@tybalt.caltech.edu (Stephen A. Edwards) (08/16/89)

Hmmm. A quick glance at a couple of ASCII charts showed that CTRL-Z is and is
not the code for "end of file." According to two references (Apple IIgs
hardware reference manual, Apple IIgs assembly language programming by Scanlon)
CTRL-Z is "SUB" short for "Substitute." Another reference (Programming the
65816 by Eyes & Lichty, see a trend here?) said that it was "End of file."

So who knows...

Ctrl-C is definied as "End of Text." Ctrl-D, which Unix uses, is defined as
"End of Trasmission." Ctrl-Y is "End of Medium" Ctrl-W is "End of Text Block,"
and Ctrl-\ is "File Separator." So, basically, you have a choice.

Of course, we could simply use what the MCP in TRON used:
End of Line. 

wombat@claris.com (Scott Lindsey) (08/16/89)

In article <10740@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:


   A more reliable source claims that NUL will do the trick.  I haven't had
   a chance to try it yet, although I could have sworn it was one of the things
   I had already tried.

Actually, I'm not certain about this: the question may simply be ill-phrased.
I'm not sure what if anything the console driver, going through the CHAR.FST,
uses for EOF.  However, using APW C 1.0 with APW 1.0, the following code uses
NUL as end of file (this is not the same thing as the value EOF returned by
getchar(), which is pre-defined as -1).

#include <stdio.h>
main()
{
	while (getchar() != EOF)
		;
}

...and I finally found the reference.  On page 3-7 of the APW C 1.0 manual
from APDA, under the section 'Running your program' an example shows 
"Control-@" as terminating stdin.  As far as I know, this is the only place
it's documented.

Scott Lindsey     |"Cold and misty morning. I heard a warning borne in the air
Claris Corp.      |    About an age of power when no one had an hour to spare"
ames!claris!wombat| DISCLAIMER: These are not the opinions of Claris, Apple,
wombat@claris.com |    StyleWare, the author, or anyone else living or dead.

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/16/89)

In article <WOMBAT.89Aug15145553@claris.com> wombat@claris.com (Scott Lindsey) writes:
>...and I finally found the reference.  On page 3-7 of the APW C 1.0 manual
>from APDA, under the section 'Running your program' an example shows 
>"Control-@" as terminating stdin.  As far as I know, this is the only place
>it's documented.

Thanks for the information, Scott.

There are only two ways this could be implemented:  either the APW C
run-time support (stdio internals) maps a received 0 byte from the
console keyboard into a simulated end-of-file, or the console driver
(FST) itself returns "0 bytes read" when it detects some special
condition, in this case typing of Ctrl-@.  The latter is a true end-
of-file-from-terminal implementation and the former is a kludge,
albeit an essential one if real support is lacking in the OS.  I
suspect the kludge approach is actually used, because the console FST
documentation mentioned nothing about this, and you would think it
would have been worthy of note.

Assuming the C run-time implementation provides this service, I sure
hope it's also done in ByteWorks's Orca/C, which is a more pleasant
programming environment than APW C.

dlyons@Apple.COM (David Lyons) (08/17/89)

In article <10751@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>[...]
>There are only two ways this could be implemented:  either the APW C
>run-time support (stdio internals) maps a received 0 byte from the
>console keyboard into a simulated end-of-file, or the console driver
>(FST) itself returns "0 bytes read" when it detects some special
>condition, in this case typing of Ctrl-@. [...]

I don't know how end-of-file detection is implemented in APW C, ORCA/C,
APW, and ORCA, but note that the Character FST and Console Driver have
not always been around!  I'm sure APW C 1.0 and APW 1.0 aren't making
Console Driver calls.

 --Dave Lyons, Apple Computer, Inc.          |   DAL Systems
   AppleLink--Apple Edition: DAVE.LYONS      |   P.O. Box 875
   AppleLink--Personal Edition: Dave Lyons   |   Cupertino, CA 95015-0875
   GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
   Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons

   My opinions are my own, not Apple's.