[comp.sources.bugs] v07i001: ularn - ultra-larn, an enhancement of the larn adventure game, Part01/08

kevin@kosman.UUCP (Kevin O'Gorman) (07/11/89)

I could not compile this on my (SYSV) 3b1, because gcc could not find
TCIFLUSH.  Neither could I.  What am I missing here.

BTW, what's tcflush()?  It's the function being called with the above
symbol, but I don't know anything else.

guy@auspex.auspex.com (Guy Harris) (07/13/89)

>I could not compile this on my (SYSV) 3b1, because gcc could not find
>TCIFLUSH.  Neither could I.  What am I missing here.
>
>BTW, what's tcflush()?  It's the function being called with the above
>symbol, but I don't know anything else.

Wow.  Does this mean "ularn" is one of the first programs ever written
to the POSIX interface?  Unfortunately, since I don't know how many
systems have implemented that interface yet but think the answer is
"very few, if any", the author may be jumping the gun a bit....

Instead of having "ioctl()", POSIX introduced functions for various
"ioctl" functions; "tcflush()" is the function for the TCFLSH "ioctl". 
They also introduced defined constants instead of the small integers
used by those "ioctl"s; TCIFLUSH is "flush the input queue", i.e. 0.

So

	tcflush(fd, TCIFLUSH)

is equivalent to

	ioctl(fd, TCFLSH, 0)

and returns the same value (0 on success, -1 on error after setting
"errno"). 

guy@auspex.auspex.com (Guy Harris) (07/13/89)

Yes, the author is jumping the gun; the claim seems to be that System V
has "tcflush" and company, but only recent releases have it, i.e. it
must be S5R3.2 or later, since S5R3.1 from AT&T doesn't have that
POSIXism.

The routine "flushall()" is best replaced by something like:

#ifdef BSD
#include <sys/file.h>	/* to get FREAD */
#endif

/*
 *	flushall()	Function to flush all type-ahead in the input buffer
 */
flushall()
{
#ifdef BSD
	static int fread = FREAD;

	ioctl(0, TIOCFLUSH, &fread);
#else /* SYSV */
#  ifdef unix
	ioctl(0, TCFLSH, 0);
#  endif /* unix */
#endif /* BSD */
}

since not only should all System V systems (including Xenix System V, if
it's truly SVID-compatible in its tty driver) have TCFLSH in that form,
even if they don't have POSIX stuff, but BSD has had the ability to
selectively flush the input, output, or both queues since 4.2BSD (if you
have 4.1BSD, you lose here, oh well).  If the intent of the "#ifdef
unix" is to eliminate Xenix (although, if Xenix doesn't define "unix",
somebody screwed up), it can be eliminated.

djl@dplace.UUCP (Dave Lampe) (07/13/89)

kevin@kosman.UUCP (Kevin O'Gorman) writes:

>I could not compile this on my (SYSV) 3b1, because gcc could not find
>TCIFLUSH. what's tcflush()?  It's the function being called with the above
>symbol, but I don't know anything else.

What I changed it to was 
    ioctl(0, TCFLSH, 0);
That drains the input in stdin. I think that was what was desired,
anyway it works.

-- 
Dave Lampe
{ames | lll-tis | sun | pyramid}!pacbell!dplace!djl
(415) 455-1571 (H)
(408) 986-9770 (W)

uri@arnor.UUCP (Uri Blumenthal) (07/13/89)

From article <2232@auspex.auspex.com>, by guy@auspex.auspex.com (Guy Harris):
> Yes, the author is jumping the gun; the claim seems to be that System V
> has "tcflush" and company, but only recent releases have it, i.e. it
> must be S5R3.2 or later, since S5R3.1 from AT&T doesn't have that
> POSIXism.

Nope! I daresay System V R3.2 DOESN'T have "tcflush". At least I couldn't
find it in any of the libraries which came with the system. And of course,
there's NOTHING like TCIFLUSH in any of *.h files (it was checked out :-).

Uri.