Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
interrupt.c
Go to the documentation of this file.
1 /* Copyright 1991 Digital Equipment Corporation.
2 ** All Rights Reserved.
3 *****************************************************************/
4 /* $Id: interrupt.c,v 1.2 1994/12/08 23:25:19 duchier Exp $ */
5 
6 #include "defs.h"
7 
9 /******** INTERRUPT()
10  This routine is called whenever the user types CONTROL C which generates an
11  interrupt. The interrupt is dealt with later, when convenient, or ignored.
12 */
13 void interrupt()
14 {
15  void (*f)(); /* RM: Apr 7 1993 Weird problem in GCC and C89 */
16 
18  f=interrupt;
19  (void)signal(SIGINT,f);/* RM: Feb 15 1993 */
20 }
21 
22 
23 
24 /******** INIT_INTERRUPT
25  This initialises interrupts by trapping the interrupt signal and sending it
26  to INTERRUPT.
27 */
29 {
30  void (*f)(); /* RM: Apr 7 1993 Weird problem in GCC and C89 */
31  f=interrupt;
32  if (signal(SIGINT,SIG_IGN)!=SIG_IGN)
33  (void)signal(SIGINT,f);
34 }
35 
36 
37 
38 /******** HANDLE_INTERRUPT()
39  This deals with an eventual interrupt.
40  Return TRUE if execution continues normally, otherwise abort query, toggle
41  trace on or off, or quit Wild_Life (suicide).
42 */
44 {
45  ptr_psi_term old_state_loc;
46  char *old_prompt;
47  int old_quiet; /* 21.1 */
48  long c,d; /* 21.12 (prev. char) */
49  long count;
50 
51  if (interrupted) printf("\n");
53  old_prompt=prompt;
54  old_quiet=quietflag; /* 21.1 */
56 
57  /* new_state(&old_state_loc); */
58  old_state_loc=input_state;
59  (void)open_input_file("stdin");
61 
62  StartAgain:
63  do {
64  printf("*** Command ");
65  prompt="(q,c,a,s,t,h)?";
66  quietflag=FALSE; /* 21.1 */
67 
68  do {
69  c=read_char();
70  } while (c!=EOLN && c>0 && c<=32);
71 
72  d=c;
73  count=0;
74  while (DIGIT(d)) { count=count*10+(d-'0'); d=read_char(); }
75 
76  while (d!=EOLN && d!=EOF) d=read_char();
77 
78  if (c=='h' || c=='?') {
79  printf("*** [Quit (q), Continue (c), Abort (a), Step (s,RETURN), Trace (t), Help (h,?)]\n");
80  }
81 
82  } while (c=='h' || c=='?');
83 
84  prompt=old_prompt;
85  quietflag=old_quiet; /* 21.1 */
86 
87  switch (c) {
88  case 'v':
89  case 'V':
90  verbose=TRUE;
91  break;
92  case 'q':
93  case 'Q':
94  case EOF:
95  if (c==EOF) printf("\n");
97  break;
98  case 'a':
99  case 'A':
100  (void)abort_life(FALSE);
101  show_count();
102  break;
103  case 'c':
104  case 'C':
105  trace=FALSE;
106  stepflag=FALSE;
107  break;
108  case 't':
109  case 'T':
110  trace=TRUE;
111  stepflag=FALSE;
112  break;
113  case 's':
114  case 'S':
115  case EOLN:
116  trace=TRUE;
117  stepflag=TRUE;
118  break;
119  case '0': case '1': case '2': case '3': case '4':
120  case '5': case '6': case '7': case '8': case '9':
121  trace=TRUE;
122  stepflag=TRUE;
123  if (count>0) {
124  stepcount=count;
125  stepflag=FALSE;
126  }
127  break;
128  default:
129  goto StartAgain;
130  }
131  input_state=old_state_loc;
133 }
void exit_life(long nl_flag)
Definition: built_ins.c:2090
void init_interrupt()
Definition: interrupt.c:28
long verbose
Definition: def_glob.h:273
#define DIGIT(C)
Definition: def_macro.h:37
long quietflag
Definition: def_glob.h:271
void show_count()
Definition: login.c:1085
ptr_psi_term input_state
Definition: def_glob.h:199
long steptrace
Definition: def_glob.h:274
void interrupt()
Definition: interrupt.c:13
long abort_life(int nlflag)
Definition: built_ins.c:2124
long trace
Definition: def_glob.h:272
long stepcount
Definition: def_glob.h:275
#define EOLN
Definition: def_const.h:140
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
long stepflag
Definition: def_glob.h:150
void restore_state(ptr_psi_term t)
Definition: token.c:267
char * prompt
Definition: def_glob.h:42
long read_char()
Definition: token.c:587
void handle_interrupt()
Definition: interrupt.c:43
long interrupted
Definition: interrupt.c:8
void stdin_cleareof()
Definition: token.c:42
long open_input_file(char *file)
Definition: token.c:504