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