home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ftpbox!news.acns.nwu.edu!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!haven.umd.edu!darwin.sura.net!bogus.sura.net!howland.reston.ans.net!usc!cs.utexas.edu!news.uta.edu!cse.uta.edu!turbo
- From: turbo@cse.uta.edu (Chris Turbeville)
- Subject: $| for stdin and Ultrix
- Message-ID: <1993Jan27.065945.3709@utagraph.uta.edu>
- Summary: Why doesn't TIOCFLUSH work in large script
- Keywords: ioctl ultirx stdin
- Sender: news@utagraph.uta.edu (USENET News System)
- Nntp-Posting-Host: cse.uta.edu
- Organization: Computer Science Engineering at the University of Texas at Arlington
- Date: Wed, 27 Jan 1993 06:59:45 GMT
- Lines: 65
-
- A few months ago I asked what one would do to flush stdin like $| does
- for stdout. I got this working in test code like this.
-
- #!/usr/local/bin/perl
- #
- # To see this work run it and hit keys inbetween when it says
- # Sleeping and when it says Please enter.
- #
- require <sys/ioctl.pl>; # Note .pl, one has to convert ioctls beforehand
- # see h2pl.
- require <sys/file.ph>;
- print "Sleeping\n";
- sleep(5);
- die "Can't ioctl STDIN : $!" unless ioctl(STDIN,$TIOCFLUSH,&FREAD);
- print "Please enter stuff now:";
- $in = <STDIN>;
- print "\nI got $in";
-
- Generating ioctl.pl is a bit of a pain but that isn't what has me
- stumped. Under Ultrix v4.0 this test program works fine but when
- involved in a LARGE script it seems to eat output lines which follow
- input statements preceded by this flusher! (not under SunOs it works
- great and not under Dynix) So basically the prompt after the first is
- eaten (not printed) if the clear cleared something. So in the code
- below (under the debugger it works fine of course) if we clear some
- extraneuos input in the ioctl the print of the prompt on the next user
- input request will not display but hang waiting for unannounced input. If
- anyone has even the slightest idea about Ultirx' quirkieness I would be
- eternalally grateful. I hesitate to post much of the large script but
- it has sig handlers and formats and many many many wonderful things.
- So if this rings a bell with anyone kind enough to read I'd love
- to hear where you saw it, and why it happened, if you were more fortunate
- than I and found that out:).
- Thanks
- -Chris
-
- ... <Package decl and much setup deleted>
-
- do {
- print $prompt;
- # we now do the alarm here so we reset after each input -Turbo
- alarm 900;
- # we also want to flush all previous input.
- &'terminate_program unless ioctl(STDIN,$'TIOCFLUSH,$'IO_SEL);
- <NOTE this program uses hardcoded values in main' to set TIOC and IO_SEL>
- <not .pl and .ph files. Needless to say I have checked these values many>
- <times. >
-
- chop($_ = <STDIN>);
- # and turn it off
- alarm 0;
-
- CASE: {
- if (/exit|quit|Exit|Quit|EXIT|QUIT/) {
- &'terminate_program;
- }
- if (/\?|help/) {
- print "$help_message\n";
- $response = "";
- last CASE;
- }
-
- ... <much input testing deleted>
-
- } until ($response ne "");
-