Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1 | /* Check for interrupts */ |
| 2 | |
| 3 | #ifdef MSDOS |
| 4 | |
| 5 | /* This might work for MS-DOS: */ |
| 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 | |
| 30 | #include <MacHeaders> |
| 31 | |
| 32 | void |
| 33 | initintr() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | int |
| 38 | intrcheck() |
| 39 | { |
| 40 | /* Static to make it faster(?) only */ |
| 41 | static EventRecord e; |
| 42 | |
| 43 | /* XXX This fails if the user first types ahead and then |
| 44 | decides to interrupt -- repeating Command-. until the |
| 45 | event queue overflows may work though. */ |
| 46 | if (EventAvail(keyDownMask|autoKeyMask, &e) && |
| 47 | (e.modifiers & cmdKey) && |
| 48 | (e.message & charCodeMask) == '.') { |
| 49 | (void) GetNextEvent(keyDownMask|autoKeyMask, &e); |
| 50 | return 1; |
| 51 | } |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | #define OK |
| 56 | |
| 57 | #endif /* THINK_C */ |
| 58 | |
| 59 | |
| 60 | #ifndef OK |
| 61 | |
| 62 | /* Default version -- should work for Unix and Standard C */ |
| 63 | |
| 64 | #include <stdio.h> |
| 65 | #include <signal.h> |
| 66 | |
| 67 | #include "sigtype.h" |
| 68 | |
| 69 | static int interrupted; |
| 70 | |
| 71 | static SIGTYPE |
| 72 | intcatcher(sig) |
| 73 | int sig; |
| 74 | { |
| 75 | interrupted = 1; |
| 76 | signal(SIGINT, intcatcher); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | initintr() |
| 81 | { |
| 82 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
| 83 | signal(SIGINT, intcatcher); |
| 84 | } |
| 85 | |
| 86 | int |
| 87 | intrcheck() |
| 88 | { |
| 89 | if (!interrupted) |
| 90 | return 0; |
| 91 | interrupted = 0; |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | #endif /* !OK */ |