blob: f963208154c459c1006a7caef70ed0dab26182dc [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* Check for interrupts */
2
3#ifdef MSDOS
4
5/* This might work for MS-DOS: */
6
7void
8initintr()
9{
10}
11
12int
13intrcheck()
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
32void
33initintr()
34{
35}
36
37int
38intrcheck()
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
69static int interrupted;
70
71static SIGTYPE
72intcatcher(sig)
73 int sig;
74{
75 interrupted = 1;
76 signal(SIGINT, intcatcher);
77}
78
79void
80initintr()
81{
82 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
83 signal(SIGINT, intcatcher);
84}
85
86int
87intrcheck()
88{
89 if (!interrupted)
90 return 0;
91 interrupted = 0;
92 return 1;
93}
94
95#endif /* !OK */