home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / wizards / 4624 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.5 KB  |  61 lines

  1. Newsgroups: comp.unix.wizards
  2. Path: sparky!uunet!sangam!shakti!saathi.ncst.ernet.in!howard
  3. From: howard@saathi.ncst.ernet.in (Howard D'Souza)
  4. Subject: Re: Keyboard hit in C programs
  5. Message-ID: <BxLpHJ.J5A@shakti.ncst.ernet.in>
  6. Keywords: Keyboard hit, C programs, UNIX
  7. Sender: news@shakti.ncst.ernet.in (News account)
  8. Organization: National Centre for Software Technology, Bombay, India.
  9. References: <1dms9iINNa6m@agate.berkeley.edu> <1992Nov10.155417@rbg.informatik.th-darmstadt.de>
  10. Date: Thu, 12 Nov 1992 11:34:31 GMT
  11. Lines: 48
  12.  
  13. In article <1992Nov10.155417@rbg.informatik.th-darmstadt.de> misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
  14. >In article <1dms9iINNa6m@agate.berkeley.edu>, bernt@valois (Bernt Skottun) writes:
  15. >> 
  16. >> I am in the process of adapting a C program from the PC for
  17. >> the UNIX environment (for SUN 3 running SUNOS 4.1.1).
  18. >> In this program it is essential that
  19. >> the user be able to stop certain parts of the program
  20. >> (e.g. an inner loop) by hitting the keyboard (any key
  21. >> is fine) while as long as the keyboard is not touched the execution
  22. >> of the program will continue un-interupted (thus a procedure
  23. >> which requires, or expects, the user to type in a key stroke at certain
  24. >> intervals will not do). In the DOS environment
  25. >> I have been able to do this with the "kbhit()" function.
  26. >> My question is: what is the equivalent function in the UNIX
  27. >> environment? or how does one go about creating such a function?
  28. >> Any suggestions will be very welcome. Thanks a lot.
  29. >> Bernt Skottun, bernt@valois.berkeley.edu 
  30. >>
  31. >
  32. >Ok, since ^C is an 'any key' you only have to catch the SIGINT you
  33. >get if ^C is hit.  
  34. >
  35.  
  36. Obviously, by "any key" Bernt Skottun means any key that the user wishes to
  37. hit and not one that the program wants him to.  For this kind of thing, the
  38. CBREAK mode for the tty immediately suggests itself. (Check out the sg_flags
  39. field of the sgttyb structure for ioctl(2) called with TIOCSETP). If the
  40. program does not wish to wait till the user hits the key, select(2) could be
  41. used (if available) or the terminal could be put in non-blocking mode ( by
  42. setting the O_NDELAY status flag for the tty's descriptor using fcntl(2).
  43.  
  44.  
  45. >In function() ( prototyped as void function(void) ) the first call should
  46. >be signal(SIGINT,function) because the behavior of SIGINT is reset to default
  47. >by the signal-handler.
  48.  
  49. What version of UNIX are you using, may I ask? And isn't it time you treated
  50. yourself to an update? :)
  51.  
  52. Howard
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. Howard M. D'Souza
  60. National Centre For Software Technology, Graphics Division
  61.