home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 8014 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.9 KB  |  79 lines

  1. Newsgroups: comp.lang.perl
  2. 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
  3. From: turbo@cse.uta.edu (Chris Turbeville)
  4. Subject: $| for stdin and Ultrix
  5. Message-ID: <1993Jan27.065945.3709@utagraph.uta.edu>
  6. Summary: Why doesn't TIOCFLUSH work in large script
  7. Keywords: ioctl ultirx stdin
  8. Sender: news@utagraph.uta.edu (USENET News System)
  9. Nntp-Posting-Host: cse.uta.edu
  10. Organization: Computer Science Engineering at the University of Texas at Arlington
  11. Date: Wed, 27 Jan 1993 06:59:45 GMT
  12. Lines: 65
  13.  
  14. A few months ago I asked what one would do to flush stdin like $| does
  15. for stdout.  I got this working in test code like this.
  16.  
  17. #!/usr/local/bin/perl
  18. #
  19. # To see this work run it and hit keys inbetween when it says
  20. #  Sleeping and when it says Please enter.
  21. #
  22. require <sys/ioctl.pl>; # Note .pl, one has to convert ioctls beforehand
  23.                 # see h2pl.
  24. require <sys/file.ph>;
  25. print "Sleeping\n";
  26. sleep(5);
  27. die "Can't ioctl STDIN : $!" unless ioctl(STDIN,$TIOCFLUSH,&FREAD);
  28. print "Please enter stuff now:";
  29. $in = <STDIN>;
  30. print "\nI got $in";
  31.  
  32. Generating ioctl.pl is a bit of a pain but that isn't what has me
  33. stumped.  Under Ultrix v4.0 this test program works fine but when
  34. involved in a LARGE script it seems to eat output lines which follow
  35. input statements preceded by this flusher! (not under SunOs it works
  36. great and not under Dynix) So basically the prompt after the first is
  37. eaten (not printed) if the clear cleared something.  So in the code
  38. below (under the debugger it works fine of course) if we clear some
  39. extraneuos input in the ioctl the print of the prompt on the next user
  40. input request will not display but hang waiting for unannounced input. If
  41. anyone has even the slightest idea about Ultirx' quirkieness I would be
  42. eternalally grateful.  I hesitate to post much of the large script but
  43. it has sig handlers and formats and many many many wonderful things.
  44. So if this rings a bell with anyone kind enough to read I'd love
  45. to hear where you saw it, and why it happened, if you were more fortunate
  46. than I and found that out:).
  47. Thanks
  48. -Chris
  49.  
  50. ... <Package decl and much setup deleted>
  51.  
  52.     do {
  53.     print $prompt;
  54.     # we now do the alarm here so we reset after each input -Turbo
  55.     alarm 900;
  56.         # we also want to flush all previous input.
  57.     &'terminate_program unless ioctl(STDIN,$'TIOCFLUSH,$'IO_SEL);
  58. <NOTE this program uses hardcoded values in main' to set TIOC and IO_SEL>
  59. <not .pl and .ph files. Needless to say I have checked these values many>
  60. <times.                                    >
  61.  
  62.     chop($_ = <STDIN>);
  63.     # and turn it off
  64.     alarm 0;
  65.  
  66.       CASE: {
  67.       if (/exit|quit|Exit|Quit|EXIT|QUIT/) { 
  68.           &'terminate_program;
  69.       }
  70.       if (/\?|help/) {
  71.               print "$help_message\n";
  72.           $response = ""; 
  73.           last CASE; 
  74.       }
  75.  
  76. ... <much input testing deleted>
  77.  
  78.     } until ($response ne "");
  79.