blob: a3db360dce6012312c71eea054ddbce5ae2e162e [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
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
129static SIGTYPE
130intcatcher(sig)
131 int sig;
132{
133 interrupted = 1;
134 signal(SIGINT, intcatcher);
135}
136
137void
138initintr()
139{
140 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
141 signal(SIGINT, intcatcher);
142}
143
144int
145intrcheck()
146{
147 if (!interrupted)
148 return 0;
149 interrupted = 0;
150 return 1;
151}
152
153#endif /* !OK */