home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / baseline / jove-4.14.6.lha / jove-4.14.6 / kbd.c < prev    next >
C/C++ Source or Header  |  1992-01-10  |  1KB  |  80 lines

  1. #include "jove.h"
  2. #include <signal.h>
  3. #include <errno.h>
  4.  
  5. #ifdef    PIPEPROCS    /* only needed for systems with iproc-pipes */
  6.  
  7. #ifdef    BSD_SIGS
  8. # define pause()    sigpause(0L)
  9. #endif
  10.  
  11. struct header {
  12.     int    pid,
  13.         nbytes;
  14.     char    buf[10];
  15. };
  16.  
  17. #define HEADER_SIZE    (2 * sizeof (int))
  18.  
  19. /* JOVE sends SIGQUIT whenever it wants the kbd process (this program)
  20.    to stop competing for input from the keyboard.  JOVE does this when
  21.    JOVE realizes that there are no more interactive processes running.
  22.    The reason we go through all this trouble is that JOVE slows down
  23.    a lot when it's getting its keyboard input via a pipe. */
  24.  
  25. private SIGRESULT strt_read proto((int));
  26.  
  27. private SIGRESULT
  28. hold_read(junk)
  29. int    junk;    /* passed in when invoked by a signal; of no interest */
  30. {
  31.     signal(KBDSIG, strt_read);
  32.     pause();
  33.     SIGRETURN;
  34. }
  35.  
  36. private SIGRESULT
  37. strt_read(junk)
  38. int    junk;
  39. {
  40.     signal(KBDSIG, hold_read);
  41.     SIGRETURN;
  42. }
  43.  
  44. int
  45. main(argc, argv)
  46. int    argc;
  47. char    **argv;
  48. {
  49.     struct header    header;
  50.     int    pid,
  51.         n;
  52.  
  53.     signal(SIGINT, SIG_IGN);
  54.     pid = getpid();
  55.     header.pid = pid;
  56.  
  57.     hold_read(0);
  58.     for (;;) {
  59.         n = read(0, (UnivPtr) header.buf, sizeof (header.buf));
  60.         if (n == -1) {
  61.             if (errno != EINTR)
  62.                 break;
  63.             continue;
  64.         }
  65.         header.nbytes = n;
  66.         write(1, (UnivPtr) &header, HEADER_SIZE + n);
  67.     }
  68.     return 0;
  69. }
  70.  
  71. #else    /* !PIPEPROCS */
  72.  
  73. int
  74. main()
  75. {
  76.     return 0;
  77. }
  78.  
  79. #endif    /* !PIPEPROCS */
  80.