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