Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The |
| 3 | 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 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | /* Check for interrupts */ |
| 26 | |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 27 | #ifdef THINK_C |
Guido van Rossum | 1055ece | 1991-07-01 18:46:03 +0000 | [diff] [blame] | 28 | /* This is for THINK C 4.0. |
| 29 | For 3.0, you may have to remove the signal stuff. */ |
| 30 | #include <MacHeaders> |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 31 | #define macintosh |
| 32 | #endif |
| 33 | |
| 34 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 35 | #ifdef MSDOS |
| 36 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 37 | /* This might work for MS-DOS (untested though): */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 38 | |
| 39 | void |
| 40 | initintr() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | int |
| 45 | intrcheck() |
| 46 | { |
| 47 | int interrupted = 0; |
| 48 | while (kbhit()) { |
| 49 | if (getch() == '\003') |
| 50 | interrupted = 1; |
| 51 | } |
| 52 | return interrupted; |
| 53 | } |
| 54 | |
| 55 | #define OK |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 60 | #ifdef macintosh |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 1055ece | 1991-07-01 18:46:03 +0000 | [diff] [blame] | 62 | #ifdef applec /* MPW */ |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 63 | #include <OSEvents.h> |
| 64 | #include <SysEqu.h> |
| 65 | #endif |
| 66 | |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 67 | #include <signal.h> |
| 68 | #include "sigtype.h" |
| 69 | |
| 70 | static int interrupted; |
| 71 | |
| 72 | static SIGTYPE |
Guido van Rossum | 1055ece | 1991-07-01 18:46:03 +0000 | [diff] [blame] | 73 | intcatcher(sig) |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 74 | int sig; |
| 75 | { |
| 76 | interrupted = 1; |
| 77 | signal(SIGINT, intcatcher); |
| 78 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 79 | |
| 80 | void |
| 81 | initintr() |
| 82 | { |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 83 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
| 84 | signal(SIGINT, intcatcher); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int |
| 88 | intrcheck() |
| 89 | { |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 90 | register EvQElPtr q; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 91 | |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 92 | q = (EvQElPtr) GetEvQHdr()->qHead; |
| 93 | |
| 94 | for (; q; q = (EvQElPtr)q->qLink) { |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 95 | if (q->evtQWhat == keyDown && |
| 96 | (char)q->evtQMessage == '.' && |
| 97 | (q->evtQModifiers & cmdKey) != 0) { |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 98 | FlushEvents(keyDownMask, 0); |
Guido van Rossum | 875eb7d | 1991-01-16 14:04:51 +0000 | [diff] [blame] | 99 | interrupted = 1; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | if (interrupted) { |
| 104 | interrupted = 0; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 105 | return 1; |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | #define OK |
| 111 | |
Guido van Rossum | d6a15ad | 1991-06-24 22:30:42 +0000 | [diff] [blame] | 112 | #endif /* macintosh */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 113 | |
| 114 | |
| 115 | #ifndef OK |
| 116 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 117 | /* Default version -- for real operating systems and for Standard C */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 118 | |
| 119 | #include <stdio.h> |
| 120 | #include <signal.h> |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 121 | #include "sigtype.h" |
| 122 | |
| 123 | static int interrupted; |
| 124 | |
| 125 | static SIGTYPE |
| 126 | intcatcher(sig) |
| 127 | int sig; |
| 128 | { |
| 129 | interrupted = 1; |
| 130 | signal(SIGINT, intcatcher); |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | initintr() |
| 135 | { |
| 136 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
| 137 | signal(SIGINT, intcatcher); |
| 138 | } |
| 139 | |
| 140 | int |
| 141 | intrcheck() |
| 142 | { |
| 143 | if (!interrupted) |
| 144 | return 0; |
| 145 | interrupted = 0; |
| 146 | return 1; |
| 147 | } |
| 148 | |
| 149 | #endif /* !OK */ |