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