home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Parser / intrcheck.c < prev    next >
C/C++ Source or Header  |  1994-02-24  |  4KB  |  205 lines

  1. /***********************************************************
  2. Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
  3. Amsterdam, The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* Check for interrupts */
  26.  
  27. #ifdef THINK_C
  28. #include <MacHeaders>
  29. #define macintosh
  30. #endif
  31.  
  32. #ifdef HAVE_CONFIG_H
  33. #include "config.h"
  34. #endif
  35.  
  36. #include "myproto.h"
  37. #include "intrcheck.h"
  38.  
  39.  
  40. #ifdef QUICKWIN
  41.  
  42. #include <io.h>
  43.  
  44. void
  45. initintr()
  46. {
  47. }
  48.  
  49. int
  50. intrcheck()
  51. {
  52.     _wyield();
  53. }
  54.  
  55. #define OK
  56.  
  57. #endif /* QUICKWIN */
  58.  
  59. #ifdef _M_IX86
  60. #include <io.h>
  61. #endif
  62.  
  63. #if defined(MSDOS) && !defined(QUICKWIN)
  64.  
  65. /* This might work for MS-DOS (untested though): */
  66.  
  67. void
  68. initintr()
  69. {
  70. }
  71.  
  72. int
  73. intrcheck()
  74. {
  75.     int interrupted = 0;
  76.     while (kbhit()) {
  77.         if (getch() == '\003')
  78.             interrupted = 1;
  79.     }
  80.     return interrupted;
  81. }
  82.  
  83. #define OK
  84.  
  85. #endif /* MSDOS && !QUICKWIN */
  86.  
  87.  
  88. #ifdef macintosh
  89.  
  90. #ifdef applec /* MPW */
  91. #include <OSEvents.h>
  92. #include <SysEqu.h>
  93. #endif /* applec */
  94.  
  95. #include <signal.h>
  96.  
  97. static int interrupted;
  98.  
  99. static RETSIGTYPE intcatcher PROTO((int));
  100. static RETSIGTYPE
  101. intcatcher(sig)
  102.     int sig;
  103. {
  104.     interrupted = 1;
  105.     signal(SIGINT, intcatcher);
  106. }
  107.  
  108. void
  109. initintr()
  110. {
  111.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  112.         signal(SIGINT, intcatcher);
  113. }
  114.  
  115. int
  116. intrcheck()
  117. {
  118.     register EvQElPtr q;
  119.     
  120.     q = (EvQElPtr) GetEvQHdr()->qHead;
  121.     
  122.     for (; q; q = (EvQElPtr)q->qLink) {
  123.         if (q->evtQWhat == keyDown &&
  124.                 (char)q->evtQMessage == '.' &&
  125.                 (q->evtQModifiers & cmdKey) != 0) {
  126.             FlushEvents(keyDownMask, 0);
  127.             interrupted = 1;
  128.             break;
  129.         }
  130.     }
  131.     if (interrupted) {
  132.         interrupted = 0;
  133.         return 1;
  134.     }
  135.     return 0;
  136. }
  137.  
  138. #define OK
  139.  
  140. #endif /* macintosh */
  141.  
  142.  
  143. #ifndef OK
  144.  
  145. /* Default version -- for real operating systems and for Standard C */
  146.  
  147. #include <stdio.h>
  148. #include <string.h>
  149. #include <signal.h>
  150.  
  151. static int interrupted;
  152.  
  153. /* ARGSUSED */
  154. static RETSIGTYPE
  155. #ifdef _M_IX86
  156. intcatcher(int sig)    /* So the C compiler shuts up */
  157. #else /* _M_IX86 */
  158. intcatcher(sig)
  159.     int sig; /* Not used by required by interface */
  160. #endif /* _M_IX86 */
  161. {
  162.     extern void goaway PROTO((int));
  163.     static char message[] =
  164. "python: to interrupt a truly hanging Python program, interrupt once more.\n";
  165.     switch (interrupted++) {
  166.     case 0:
  167.         break;
  168.     case 1:
  169.         write(2, message, strlen(message));
  170.         break;
  171.     case 2:
  172.         interrupted = 0;
  173.         goaway(1);
  174.         break;
  175.     }
  176.     signal(SIGINT, intcatcher);
  177. }
  178.  
  179. void
  180. initintr()
  181. {
  182.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  183.         signal(SIGINT, intcatcher);
  184. #ifdef HAVE_SIGINTERRUPT
  185.     /* This is for SunOS and other modern BSD derivatives.
  186.        It means that system calls (like read()) are not restarted
  187.        after an interrupt.  This is necessary so interrupting a
  188.        read() or readline() call works as expected.
  189.        XXX On old BSD (pure 4.2 or older) you may have to do this
  190.        differently! */
  191.     siginterrupt(SIGINT, 1);
  192. #endif /* HAVE_SIGINTERRUPT */
  193. }
  194.  
  195. int
  196. intrcheck()
  197. {
  198.     if (!interrupted)
  199.         return 0;
  200.     interrupted = 0;
  201.     return 1;
  202. }
  203.  
  204. #endif /* !OK */
  205.