blob: fdd27b9938931b07eba666a74a650eeed6df0142 [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
34
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000035#ifdef MSDOS
36
Guido van Rossum3f5da241990-12-20 15:06:42 +000037/* This might work for MS-DOS (untested though): */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000038
39void
40initintr()
41{
42}
43
44int
45intrcheck()
46{
47 int interrupted = 0;
48 while (kbhit()) {
49 if (getch() == '\003')
50 interrupted = 1;
51 }
52 return interrupted;
53}
54
55#define OK
56
57#endif
58
59
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000060#ifdef macintosh
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000061
Guido van Rossum1055ece1991-07-01 18:46:03 +000062#ifdef applec /* MPW */
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000063#include <OSEvents.h>
64#include <SysEqu.h>
65#endif
66
Guido van Rossum875eb7d1991-01-16 14:04:51 +000067#include <signal.h>
68#include "sigtype.h"
69
70static int interrupted;
71
72static SIGTYPE
Guido van Rossum1055ece1991-07-01 18:46:03 +000073intcatcher(sig)
Guido van Rossum875eb7d1991-01-16 14:04:51 +000074 int sig;
75{
76 interrupted = 1;
77 signal(SIGINT, intcatcher);
78}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000079
80void
81initintr()
82{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000083 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
84 signal(SIGINT, intcatcher);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000085}
86
87int
88intrcheck()
89{
Guido van Rossum875eb7d1991-01-16 14:04:51 +000090 register EvQElPtr q;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000091
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000092 q = (EvQElPtr) GetEvQHdr()->qHead;
93
94 for (; q; q = (EvQElPtr)q->qLink) {
Guido van Rossum875eb7d1991-01-16 14:04:51 +000095 if (q->evtQWhat == keyDown &&
96 (char)q->evtQMessage == '.' &&
97 (q->evtQModifiers & cmdKey) != 0) {
Guido van Rossumd6a15ad1991-06-24 22:30:42 +000098 FlushEvents(keyDownMask, 0);
Guido van Rossum875eb7d1991-01-16 14:04:51 +000099 interrupted = 1;
100 break;
101 }
102 }
103 if (interrupted) {
104 interrupted = 0;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000105 return 1;
106 }
107 return 0;
108}
109
110#define OK
111
Guido van Rossumd6a15ad1991-06-24 22:30:42 +0000112#endif /* macintosh */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000113
114
115#ifndef OK
116
Guido van Rossum3f5da241990-12-20 15:06:42 +0000117/* Default version -- for real operating systems and for Standard C */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000118
119#include <stdio.h>
120#include <signal.h>
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000121#include "sigtype.h"
122
123static int interrupted;
124
125static SIGTYPE
126intcatcher(sig)
127 int sig;
128{
129 interrupted = 1;
130 signal(SIGINT, intcatcher);
131}
132
133void
134initintr()
135{
136 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
137 signal(SIGINT, intcatcher);
138}
139
140int
141intrcheck()
142{
143 if (!interrupted)
144 return 0;
145 interrupted = 0;
146 return 1;
147}
148
149#endif /* !OK */