Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1a 12/4/83; site rlgvax.UUCP
Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!houxz!vax135!floyd!cmcl2!seismo!rlgvax!guy
From: guy@rlgvax.UUCP (Guy Harris)
Newsgroups: net.unix-wizards
Subject: Re: output redirection from a  compat
Message-ID: <2001@rlgvax.UUCP>
Date: Fri, 8-Jun-84 20:57:02 EDT
Article-I.D.: rlgvax.2001
Posted: Fri Jun  8 20:57:02 1984
Date-Received: Sun, 10-Jun-84 00:32:01 EDT
References: <972@linus.UUCP> <7422@umcp-cs.UUCP>
Organization: CCI Office Systems Group, Reston, VA
Lines: 47

> THe chess program supplied with Berkeley (4.1 and 4.2) runs as a pdp-11
> compatibility package. Note the following behavior:

...

> 2. Then redirect the output thru a simple filter like cat.

> chess |& cat -u

> and do the same things. This time no error message, no format
> characters and Oh,yes, the title "Chess" is held till the end. When you
> resign, all the stacked output tumbles out.

> I have tried many ways to overcome this with no success, including
> trying piping from a C program. I have run the v7trc (trace compat) to
> see what is happening and it looks like somehow the program is
> determining that the output is redirected and holding on to some
> messages. It runs properly under an emacs shell so I guess mpxio might
> help.

Followup:

> You have to change the chess program itself to do ``fflush''es
> after writing a line to stdout, or change the compat C library to
> fflush even if (!isatty(1)).

The problem with "chess" would probably have existed on a PDP-11 as well
(sorry, we don't have any here any more so I can't test that).  Chris
Torek's followup is correct; since the output of "chess" is not a terminal, it
doesn't do character-at-a-time writes, but buffered 512-bytes-at-a-time
writes.  That's the standard behavior for the Standard I/O Library, which
I presume the V7 PDP-11 "chess" used.

Unfortunately, it's a bit hard to change the chess program, as the source
doesn't come with any version of UNIX later than V7 and it's in a mixture
of C and PDP-11 assembler.  You'd have to get the source from a V7 tape
and get the PDP-11 C compiler, assembler, and linker running in compatibility
mode (the PDP-11 assembler is written in assembler, so it will only run
in compatibility mode on a VAX).

This'll probably happen on a VAX as well; it will flush "stdout" whenever
a Standard I/O read is done on "stdin", but only if "stdout" is line-buffered;
if it's not going to a terminal, it won't be line-buffered but block-buffered.
(This may be different in 4.2BSD; I checked our 4.1c source.)

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy