home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!news.oc.com!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: $| for stdin?
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Nov7.045809.25737@news.eng.convex.com>
- Date: Sat, 7 Nov 1992 04:58:09 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <1992Nov4.235759.14315@utagraph.uta.edu>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- Keywords: stdin $| and life
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 41
-
- From the keyboard of turbo@cse.uta.edu (Chris Turbeville):
- :I am looking for some way of clearing standard in before every read.
- :You know the stdin counter-part of $|. I have a large program
- :responsable for helping non-unices do unix admin things safely but I
- :can't seem to keep it from getting a wrong char occasionally. If the
- :enter key is a little sticky then I get default responses when they may
- :have wanted to enter something just because their fingers are a little
- :heavy. Does anyone know of a way to flush stdin up to now (by now I
- :mean some point in the code) and then read something so these extra \n's
- :won't clutter up the place. I have tried seeks and all sorts of
- :trickery but to naught.
-
- Here's how Larry did it:
-
- void
- eat_typeahead()
- {
- #ifdef PUSHBACK
- if (!typeahead && nextin==nextout) /* cancel only keyboard stuff */
- #else
- if (!typeahead)
- #endif
- {
- #ifdef PENDING
- while (input_pending())
- read_tty(buf,sizeof(buf));
- #else /* this is probably v7 */
- ioctl(_tty_ch,TIOCSETP,&_tty);
- #endif
- }
- }
-
-
- Conversion into Perl is left as an exercise to the reader. :-(
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- Besides, it's good to force C programmers to use the toolbox occasionally. :-)
- --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
-