NLSL
catch.c
Go to the documentation of this file.
1 /*
2  * SIGINT handler
3  * rewritten to use portable standard C routines.
4  * Note that handlers cannot nest!
5  * - WH 20020210
6  */
7 
8 #include <stddef.h>
9 #include <signal.h>
10 #include "fortrancall.h"
11 
12 static int *flagptr=NULL;
13 void (*prev_handler)(int);
14 
15 
16 /***********************************************************************
17  *
18  * ctrlc_handler: simple handler for receiving SIGINT signal
19  *
20  ***********************************************************************/
21 void sigint_handler(int sig)
22 {
23  *flagptr=1;
24 }
25 
26 /* **********************************************************************
27  * subroutine catchc
28  *
29  * Installs a SIGINT handler that sets flag non-zero
30  *
31  ***********************************************************************/
32 
33 void FORTRAN(catchc)(int *flag)
34 {
35  if (flagptr==NULL) {
36  flagptr=flag;
37  *flagptr=0;
38  prev_handler=signal(SIGINT, &sigint_handler);
39  }
40 }
41 
42 /* **********************************************************************
43  *
44  * subroutine uncatchc()
45  *
46  * Restores default action for handling SIGINT signal
47  *
48  ********************************************************************** */
49 void FORTRAN(uncatchc)(int *flag)
50 {
51  if (flagptr==flag) {
52  if (flagptr) *flagptr=0; /* test */
53  signal(SIGINT, prev_handler);
54  flagptr=NULL;
55  }
56 }
57 
void(* prev_handler)(int)
Definition: catch.c:13
void FORTRAN() uncatchc(int *flag)
Definition: catch.c:49
#define FORTRAN(n)
Definition: fortrancall.h:8
void FORTRAN() catchc(int *flag)
Definition: catch.c:33
void sigint_handler(int sig)
Definition: catch.c:21