blob: 8dbeb5f0cfc01106d2960994213031cfa88bc123 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
2Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025/* Check for interrupts */
26
27#ifdef MSDOS
28
Guido van Rossum3f5da241990-12-20 15:06:42 +000029/* This might work for MS-DOS (untested though): */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030
31void
32initintr()
33{
34}
35
36int
37intrcheck()
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 Rossum875eb7d1991-01-16 14:04:51 +000054/* This is for THINK C 4.0.
55 For 3.0, you may have to remove the signal stuff. */
56
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000057#include <MacHeaders>
Guido van Rossum875eb7d1991-01-16 14:04:51 +000058#include <signal.h>
59#include "sigtype.h"
60
61static int interrupted;
62
63static SIGTYPE
64intcatcher(sig)
65 int sig;
66{
67 interrupted = 1;
68 signal(SIGINT, intcatcher);
69}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000070
71void
72initintr()
73{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000074 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
75 signal(SIGINT, intcatcher);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000076}
77
78int
79intrcheck()
80{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000081 register EvQElPtr q;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000082
Guido van Rossum875eb7d1991-01-16 14:04:51 +000083 /* 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 Rossum85a5fbb1990-10-14 12:07:46 +0000100 return 1;
101 }
102 return 0;
103}
104
105#define OK
106
107#endif /* THINK_C */
108
109
110#ifndef OK
111
Guido van Rossum3f5da241990-12-20 15:06:42 +0000112/* Default version -- for real operating systems and for Standard C */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000113
114#include <stdio.h>
115#include <signal.h>
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000116#include "sigtype.h"
117
118static int interrupted;
119
120static SIGTYPE
121intcatcher(sig)
122 int sig;
123{
124 interrupted = 1;
125 signal(SIGINT, intcatcher);
126}
127
128void
129initintr()
130{
131 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
132 signal(SIGINT, intcatcher);
133}
134
135int
136intrcheck()
137{
138 if (!interrupted)
139 return 0;
140 interrupted = 0;
141 return 1;
142}
143
144#endif /* !OK */