dave@utcsrgv.UUCP (Dave Sherman) (06/22/83)
I am writing an interactive program to be used by non-computer people. I want to spit some text to the screen, and say "press RETURN to continue", and somehow ensure that only a CR pressed after I put the text on the screen will be caught. The obvious thing is to flush all input with ioctl-TIOCFLUSH, immediately before saying "press RETURN". But when I do that, the TIOCFLUSH stops some of the output from getting to the screen. Is there any way to flush the input queue without flushing the output, or a way to wait until the chars on the output queue have actually been sent to the terminal? Thanks for any (*pointer)s. Dave Sherman Toronto
guy@rlgvax.UUCP (06/23/83)
A quick check of the manual (and, of course, the code - this IS UNIX, after all!) reveals that doing a TIOCGETP to get the current mode and a TIOCSETP to the same mode will call "wflushtty", which will wait for the output to drain and then flush the input. Note that this is another thing that the USG driver will happily do - TCFLSH can be told to flush the input queue, the output queue, or both. BTW, anybody know whose "bright" idea it was to put all the device documentation in the System V ADMINISTRATOR'S manual, and NOT in the USER'S manual? Only system administrators should be allowed to write screen editors? If you're upgrading to System V, save your System III manuals! Guy Harris RLG Corporation {seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy
richl@tektronix.UUCP (06/24/83)
The documentation states that an ioctl(fd,TIOCGETP,&foo) will "wait until output is quiescent", and then fetch the parameters. So what I did is do two consecutive ioctl calls: ioctl(fd,TIOCGETP,&foo); ioctl(fd,TIOCSETP,&foo); where foo is the appropriate structure. Yes, it is two system calls where one should do, but unless you have local mods, it seems to be the only standard way to do it. The TIOCSETP, of course, flushes both queues, but output is now empty). Rick Lindsley richl@tektronix ..!tektronix!richl
gwyn%brl-vld@sri-unix.UUCP (06/24/83)
From: Doug Gwyn (VLD/VMB) <gwyn@brl-vld> I assume you are on a 4.1?BSD system. You must gobble up the input in a loop to simulate "flush input only" unless you have one of the newer (4.1c for example) BSDs in which case: int arg = 1; /* 1 is "FREAD" bit */ ioctl( fd, TIOCFLUSH, &arg ); which flushes input only.
dbj.rice%rand-relay@sri-unix.UUCP (06/25/83)
From: Dave Johnson <dbj.rice@rand-relay> If the third parameter to a TIOCFLUSH ioctl is nonzero, it is used as the address of an integer which specifies whether the input or the output queues or both are to be flushed. For example, the following should flush only the input queue: int i = FREAD; ioctl(fd, TIOCFLUSH, &i); The values FREAD for the input queue and FWRITE for the output queue may be specified (these come from sys/file.h). I haven't actually tried this, but the the code in the kernel (routines ttioctl and flushtty in tty.c) looks pretty straight forward. Dave Johnson Dept. of Math Science Rice University dbj.rice@Rand-Relay
guy@rlgvax.UUCP (06/28/83)
The code to support passing an argument (FREAD, FWRITE, or FREAD|FWRITE) to the TIOCFLUSH ioctl (or, to be precise, passing the address of an int which has the desired value) is present in vanilla 4.1BSD. It is not present in vanilla V7. The most portable way of doing it is to do a TIOCGETP followed by a TIOCSETP of the values gotten with the GETP. Guy Harris Computer Consoles, Inc. Office Systems Group {seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy