Jspice3
signal.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Wayne A. Christopher
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * The signal routines for spice 3 and nutmeg.
10  */
11 
12 #include "spice.h"
13 #include "ftedefs.h"
14 #include "iferrmsg.h"
15 #include "plotdev.h"
16 #include <setjmp.h>
17 #ifdef HAVE_SIGNAL
18 #include <signal.h>
19 #endif
20 
21 #ifdef HAVE_SIGNAL
22 #ifdef HAVE_SETJMP
23 
24 extern jmp_buf jbuf;
25 
26 #ifdef __STDC__
27 static void killplot(void);
28 #else
29 static void killplot();
30 #endif
31 
32 /* The signal handlers... SIGINT is the only one that gets reset (by
33  * cshpar) so it is global. They are ifdef BSD because of the sigmask
34  * stuff in sigstop. We set the interrupt flag and return if ft_setflag
35  * is true.
36  */
37 
38 RETSIGTYPE
39 ft_sigintr()
40 
41 {
42  /* should never get here from sced */
43  (void) signal( SIGINT, (RETSIGTYPE(*)())ft_sigintr );
44 
45  if (ft_intrpt)
46  fprintf(cp_err, " Interrupt (ouch)\n");
47  else {
48  ft_intrpt = true;
49  }
50 }
51 
52 
53 /* ARGSUSED */
54 RETSIGTYPE
55 sigfloat(sig, code)
56 
57 {
58  /* should never get here from sced */
59  killplot();
60  fperror("Error", code);
61  rewind(cp_out);
62  (void) signal( SIGFPE, (RETSIGTYPE(*)())sigfloat );
63  longjmp(jbuf, 1);
64 }
65 
66 
67 static void
68 killplot()
69 
70 /* To restore screen after an interrupt to a plot */
71 {
72  int id;
73 
74  if (!currentgraph) return;
75  switch (currentgraph->graphtype) {
76  case GR_PLOT:
79  case GR_GRAF:
80  case GR_MPLT:
81  DevHalt();
82  id = currentgraph->graphid;
84  DestroyGraph(id);
85  break;
86  }
87 }
88 
89 
90 /* This should give a new prompt if cshpar is waiting for input. */
91 
92 #ifdef SIGTSTP
93 
94 RETSIGTYPE
95 sigstop( )
96 {
97  cp_ccon(false);
98  (void) signal(SIGTSTP, SIG_DFL);
99  (void) kill(getpid(), SIGTSTP); /* This should stop us */
100 }
101 
102 
103 RETSIGTYPE
104 sigcont( )
105 {
106  (void) signal(SIGTSTP, (RETSIGTYPE(*)())sigstop);
107  if (cp_cwait)
108  longjmp(jbuf, 1);
109 }
110 
111 #endif
112 
113 /* Special signal handlers. */
114 
115 
116 RETSIGTYPE
117 sigill()
118 
119 {
120  while (currentgraph) {
121  DevHalt();
122  PopGraphContext();
123  }
124  fprintf(cp_err, "\ninternal error -- illegal instruction\n");
125  fatal();
126 }
127 
128 
129 RETSIGTYPE
130 sigbus()
131 
132 {
133  while (currentgraph) {
134  DevHalt();
135  PopGraphContext();
136  }
137  fprintf(cp_err, "\ninternal error -- bus error\n");
138  fatal();
139 }
140 
141 
142 RETSIGTYPE
143 sigsegv()
144 
145 {
146  while (currentgraph) {
147  DevHalt();
148  PopGraphContext();
149  }
150  fprintf(cp_err, "\ninternal error -- segmentation violation\n");
151  fatal();
152 }
153 
154 
155 RETSIGTYPE
156 sig_sys()
157 
158 {
159  while (currentgraph) {
160  DevHalt();
161  PopGraphContext();
162  }
163  fprintf(cp_err,
164  "\ninternal error -- bad argument to system call\n");
165  fatal();
166 }
167 
168 #endif
169 #endif
bool ft_intrpt
Definition: main.c:47
RETSIGTYPE sigbus()
RETSIGTYPE sigstop()
RETSIGTYPE sigill()
RETSIGTYPE sigsegv()
GRDATA(* copydata)()
Definition: ftegraph.h:72
RETSIGTYPE ft_sigintr()
RETSIGTYPE sig_sys()
RETSIGTYPE sigcont()
FILE * cp_err
Definition: help.c:101
RETSIGTYPE sigfloat()
void DevHalt()
Definition: display.c:226
int graphtype
Definition: ftegraph.h:31
int graphid
Definition: ftegraph.h:30
GRDATA plotdata
Definition: ftegraph.h:33
FILE * cp_out
Definition: help.c:101
bool cp_cwait
Definition: front.c:120
void PopGraphContext()
Definition: graphdb.c:270
int DestroyGraph()
int getpid()
Definition: libfuncs.c:137
#define GR_PLOT
Definition: ftegraph.h:20
void fperror()
#define GR_MPLT
Definition: ftegraph.h:22
jmp_buf jbuf
Definition: main.c:99
GRAPH * currentgraph
Definition: graphdb.c:21
void fatal()
Definition: help.c:174
#define GR_GRAF
Definition: ftegraph.h:21
void cp_ccon()