home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Parser / intrcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-28  |  3.8 KB  |  189 lines  |  [TEXT/CWIE]

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. 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 or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* Check for interrupts */
  33.  
  34. #include "config.h"
  35. #include "myproto.h"
  36. #include "intrcheck.h"
  37.  
  38.  
  39. #ifdef QUICKWIN
  40.  
  41. #include <io.h>
  42.  
  43. void
  44. initintr()
  45. {
  46. }
  47.  
  48. int
  49. intrcheck()
  50. {
  51.     _wyield();
  52. }
  53.  
  54. #define OK
  55.  
  56. #endif /* QUICKWIN */
  57.  
  58. #ifdef _M_IX86
  59. #include <io.h>
  60. #endif
  61.  
  62. #if defined(MSDOS) && !defined(QUICKWIN)
  63.  
  64. #ifdef __GNUC__
  65.  
  66. /* This is for DJGPP's GO32 extender.  I don't know how to trap
  67.  * control-C  (There's no API for ctrl-C, and I don't want to mess with
  68.  * the interrupt vectors.)  However, this DOES catch control-break.
  69.  * --Amrit
  70.  */
  71.  
  72. #include <go32.h>
  73.  
  74. void
  75. initintr()
  76. {
  77.     _go32_want_ctrl_break(1 /* TRUE */);
  78. }
  79.  
  80. int
  81. intrcheck()
  82. {
  83.     return _go32_was_ctrl_break_hit();
  84. }
  85.  
  86. #else /* !__GNUC__ */
  87.  
  88. /* This might work for MS-DOS (untested though): */
  89.  
  90. void
  91. initintr()
  92. {
  93. }
  94.  
  95. int
  96. intrcheck()
  97. {
  98.     int interrupted = 0;
  99.     while (kbhit()) {
  100.         if (getch() == '\003')
  101.             interrupted = 1;
  102.     }
  103.     return interrupted;
  104. }
  105.  
  106. #endif /* __GNUC__ */
  107.  
  108. #define OK
  109.  
  110. #endif /* MSDOS && !QUICKWIN */
  111.  
  112.  
  113. #ifdef macintosh
  114.  
  115. /* The Mac interrupt code has moved to macglue.c */
  116. #define OK
  117.  
  118. #endif /* macintosh */
  119.  
  120.  
  121. #ifndef OK
  122.  
  123. /* Default version -- for real operating systems and for Standard C */
  124.  
  125. #include <stdio.h>
  126. #include <string.h>
  127. #include <signal.h>
  128.  
  129. static int interrupted;
  130.  
  131. void
  132. PyErr_SetInterrupt()
  133. {
  134.     interrupted = 1;
  135. }
  136.  
  137. /* ARGSUSED */
  138. static RETSIGTYPE
  139. #ifdef _M_IX86
  140. intcatcher(int sig)    /* So the C compiler shuts up */
  141. #else /* _M_IX86 */
  142. intcatcher(sig)
  143.     int sig; /* Not used by required by interface */
  144. #endif /* _M_IX86 */
  145. {
  146.     extern void goaway PROTO((int));
  147.     static char message[] =
  148. "python: to interrupt a truly hanging Python program, interrupt once more.\n";
  149.     switch (interrupted++) {
  150.     case 0:
  151.         break;
  152.     case 1:
  153.         write(2, message, strlen(message));
  154.         break;
  155.     case 2:
  156.         interrupted = 0;
  157.         goaway(1);
  158.         break;
  159.     }
  160.     signal(SIGINT, intcatcher);
  161. }
  162.  
  163. void
  164. initintr()
  165. {
  166.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  167.         signal(SIGINT, intcatcher);
  168. #ifdef HAVE_SIGINTERRUPT
  169.     /* This is for SunOS and other modern BSD derivatives.
  170.        It means that system calls (like read()) are not restarted
  171.        after an interrupt.  This is necessary so interrupting a
  172.        read() or readline() call works as expected.
  173.        XXX On old BSD (pure 4.2 or older) you may have to do this
  174.        differently! */
  175.     siginterrupt(SIGINT, 1);
  176. #endif /* HAVE_SIGINTERRUPT */
  177. }
  178.  
  179. int
  180. intrcheck()
  181. {
  182.     if (!interrupted)
  183.         return 0;
  184.     interrupted = 0;
  185.     return 1;
  186. }
  187.  
  188. #endif /* !OK */
  189.