blob: 4636b3f7c2fe7428dc2fd1fc6d6017a79399aa9a [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum9bfef441993-03-29 10:43:31 +00002Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
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
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000027#ifdef THINK_C
Guido van Rossum1055ece1991-07-01 18:46:03 +000028/* This is for THINK C 4.0.
29 For 3.0, you may have to remove the signal stuff. */
30#include <MacHeaders>
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000031#define macintosh
32#endif
33
Guido van Rossum189e8f91992-01-19 16:29:05 +000034#include "PROTO.h"
35#include "intrcheck.h"
36
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000037
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000038#ifdef MSDOS
39
Guido van Rossum3f5da241990-12-20 15:06:42 +000040/* This might work for MS-DOS (untested though): */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000041
42void
43initintr()
44{
45}
46
47int
48intrcheck()
49{
50 int interrupted = 0;
51 while (kbhit()) {
52 if (getch() == '\003')
53 interrupted = 1;
54 }
55 return interrupted;
56}
57
58#define OK
59
60#endif
61
62
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000063#ifdef macintosh
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000064
Guido van Rossum1055ece1991-07-01 18:46:03 +000065#ifdef applec /* MPW */
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000066#include <OSEvents.h>
67#include <SysEqu.h>
68#endif
69
Guido van Rossum875eb7d1991-01-16 14:04:51 +000070#include <signal.h>
71#include "sigtype.h"
72
73static int interrupted;
74
Guido van Rossum189e8f91992-01-19 16:29:05 +000075static SIGTYPE intcatcher PROTO((int));
Guido van Rossum875eb7d1991-01-16 14:04:51 +000076static SIGTYPE
Guido van Rossum1055ece1991-07-01 18:46:03 +000077intcatcher(sig)
Guido van Rossum875eb7d1991-01-16 14:04:51 +000078 int sig;
79{
80 interrupted = 1;
81 signal(SIGINT, intcatcher);
82}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000083
84void
85initintr()
86{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000087 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
88 signal(SIGINT, intcatcher);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000089}
90
91int
92intrcheck()
93{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000094 register EvQElPtr q;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000095
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000096 q = (EvQElPtr) GetEvQHdr()->qHead;
97
98 for (; q; q = (EvQElPtr)q->qLink) {
Guido van Rossum875eb7d1991-01-16 14:04:51 +000099 if (q->evtQWhat == keyDown &&
100 (char)q->evtQMessage == '.' &&
101 (q->evtQModifiers & cmdKey) != 0) {
Guido van Rossumd6a15ad1991-06-24 22:30:42 +0000102 FlushEvents(keyDownMask, 0);
Guido van Rossum875eb7d1991-01-16 14:04:51 +0000103 interrupted = 1;
104 break;
105 }
106 }
107 if (interrupted) {
108 interrupted = 0;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000109 return 1;
110 }
111 return 0;
112}
113
114#define OK
115
Guido van Rossumd6a15ad1991-06-24 22:30:42 +0000116#endif /* macintosh */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000117
118
119#ifndef OK
120
Guido van Rossum3f5da241990-12-20 15:06:42 +0000121/* Default version -- for real operating systems and for Standard C */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000122
123#include <stdio.h>
124#include <signal.h>
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000125#include "sigtype.h"
126
127static int interrupted;
128
Guido van Rossumdf840d91992-03-27 17:29:44 +0000129/* ARGSUSED */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000130static SIGTYPE
131intcatcher(sig)
Guido van Rossumdf840d91992-03-27 17:29:44 +0000132 int sig; /* Not used by required by interface */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000133{
134 interrupted = 1;
135 signal(SIGINT, intcatcher);
136}
137
138void
139initintr()
140{
141 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
142 signal(SIGINT, intcatcher);
Guido van Rossumacbe8da1993-04-15 15:33:52 +0000143#ifdef SV_INTERRUPT
144 /* This is for SunOS and other modern BSD derivatives.
145 It means that system calls (like read()) are not restarted
146 after an interrupt. This is necessary so interrupting a
147 read() or readline() call works as expected.
148 XXX On old BSD (pure 4.2 or older) you may have to do this
149 differently! */
150 siginterrupt(SIGINT, 1);
151#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000152}
153
154int
155intrcheck()
156{
157 if (!interrupted)
158 return 0;
159 interrupted = 0;
160 return 1;
161}
162
163#endif /* !OK */