Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Parser / intrcheck.c
blobb1cfb7cd92c22a1d5e26f9e31696d52423098157
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Check for interrupts */
34 #include "config.h"
36 /* config.h may or may not define DL_IMPORT */
37 #ifndef DL_IMPORT /* declarations for DLL import/export */
38 #define DL_IMPORT(RTYPE) RTYPE
39 #endif
41 #include "myproto.h"
42 #include "mymalloc.h" /* For ANY */
43 #include "intrcheck.h"
45 /* Copied here from ceval.h -- can't include that file. */
46 int Py_AddPendingCall Py_PROTO((int (*func) Py_PROTO((ANY *)), ANY *arg));
49 #ifdef QUICKWIN
51 #include <io.h>
53 void
54 PyOS_InitInterrupts()
58 void
59 PyOS_FiniInterrupts()
63 int
64 PyOS_InterruptOccurred()
66 _wyield();
69 #define OK
71 #endif /* QUICKWIN */
73 #if defined(_M_IX86) && !defined(__QNX__)
74 #include <io.h>
75 #endif
77 #if defined(MSDOS) && !defined(QUICKWIN)
79 #ifdef __GNUC__
81 /* This is for DJGPP's GO32 extender. I don't know how to trap
82 * control-C (There's no API for ctrl-C, and I don't want to mess with
83 * the interrupt vectors.) However, this DOES catch control-break.
84 * --Amrit
87 #include <go32.h>
89 void
90 PyOS_InitInterrupts()
92 _go32_want_ctrl_break(1 /* TRUE */);
95 void
96 PyOS_FiniInterrupts()
101 PyOS_InterruptOccurred()
103 return _go32_was_ctrl_break_hit();
106 #else /* !__GNUC__ */
108 /* This might work for MS-DOS (untested though): */
110 void
111 PyOS_InitInterrupts()
115 void
116 PyOS_FiniInterrupts()
121 PyOS_InterruptOccurred()
123 int interrupted = 0;
124 while (kbhit()) {
125 if (getch() == '\003')
126 interrupted = 1;
128 return interrupted;
131 #endif /* __GNUC__ */
133 #define OK
135 #endif /* MSDOS && !QUICKWIN */
138 #ifdef macintosh
140 /* The Mac interrupt code has moved to macglue.c */
141 #define OK
143 #endif /* macintosh */
146 #ifndef OK
148 /* Default version -- for real operating systems and for Standard C */
150 #include <stdio.h>
151 #include <string.h>
152 #include <signal.h>
153 #ifdef HAVE_UNISTD_H
154 #include <unistd.h>
155 #endif
157 static int interrupted;
159 void
160 PyErr_SetInterrupt()
162 interrupted = 1;
165 extern int PyErr_CheckSignals();
167 /* ARGSUSED */
168 static RETSIGTYPE
169 #if defined(_M_IX86) && !defined(__QNX__)
170 intcatcher(int sig) /* So the C compiler shuts up */
171 #else /* _M_IX86 */
172 intcatcher(sig)
173 int sig; /* Not used by required by interface */
174 #endif /* _M_IX86 */
176 extern void Py_Exit Py_PROTO((int));
177 static char message[] =
178 "python: to interrupt a truly hanging Python program, interrupt once more.\n";
179 switch (interrupted++) {
180 case 0:
181 break;
182 case 1:
183 write(2, message, strlen(message));
184 break;
185 case 2:
186 interrupted = 0;
187 Py_Exit(1);
188 break;
190 signal(SIGINT, intcatcher);
191 Py_AddPendingCall(PyErr_CheckSignals, NULL);
194 static RETSIGTYPE (*old_siginthandler)() = SIG_DFL;
196 void
197 PyOS_InitInterrupts()
199 if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN)
200 signal(SIGINT, intcatcher);
201 #ifdef HAVE_SIGINTERRUPT
202 /* This is for SunOS and other modern BSD derivatives.
203 It means that system calls (like read()) are not restarted
204 after an interrupt. This is necessary so interrupting a
205 read() or readline() call works as expected.
206 XXX On old BSD (pure 4.2 or older) you may have to do this
207 differently! */
208 siginterrupt(SIGINT, 1);
209 #endif /* HAVE_SIGINTERRUPT */
212 void
213 PyOS_FiniInterrupts()
215 signal(SIGINT, old_siginthandler);
219 PyOS_InterruptOccurred()
221 if (!interrupted)
222 return 0;
223 interrupted = 0;
224 return 1;
227 #endif /* !OK */
229 void
230 PyOS_AfterFork()