00001
00002
00003
00004
00005
00006 #ifndef lint
00007 static char vcid[] = "$Id: interrupt.c,v 1.2 1994/12/08 23:25:19 duchier Exp $";
00008 #endif
00009
00010 #include "extern.h"
00011 #include <signal.h>
00012 #include "token.h"
00013 #include "login.h"
00014 #ifndef OS2_PORT
00015 #include "built_ins.h"
00016 #else
00017 #include "built_in.h"
00018 #endif
00019
00020 #include "error.h"
00021
00022 long interrupted=FALSE;
00023
00024
00025
00026
00027
00028
00029
00030 void interrupt()
00031 {
00032 void (*f)();
00033
00034 interrupted=TRUE;
00035 f=interrupt;
00036 signal(SIGINT,f);
00037 }
00038
00039
00040
00041
00042
00043
00044
00045 void init_interrupt()
00046 {
00047 void (*f)();
00048 f=interrupt;
00049 if (signal(SIGINT,SIG_IGN)!=SIG_IGN)
00050 signal(SIGINT,f);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060 void handle_interrupt()
00061 {
00062 ptr_psi_term old_state;
00063 char *old_prompt;
00064 int old_quiet;
00065 long c,d;
00066 long count;
00067
00068 if (interrupted) printf("\n");
00069 interrupted=FALSE;
00070 old_prompt=prompt;
00071 old_quiet=quietflag;
00072 steptrace=FALSE;
00073
00074
00075 old_state=input_state;
00076 open_input_file("stdin");
00077 stdin_cleareof();
00078
00079 StartAgain:
00080 do {
00081 printf("*** Command ");
00082 prompt="(q,c,a,s,t,h)?";
00083 quietflag=FALSE;
00084
00085 do {
00086 c=read_char();
00087 } while (c!=EOLN && c>0 && c<=32);
00088
00089 d=c;
00090 count=0;
00091 while (DIGIT(d)) { count=count*10+(d-'0'); d=read_char(); }
00092
00093 while (d!=EOLN && d!=EOF) d=read_char();
00094
00095 if (c=='h' || c=='?') {
00096 printf("*** [Quit (q), Continue (c), Abort (a), Step (s,RETURN), Trace (t), Help (h,?)]\n");
00097 }
00098
00099 } while (c=='h' || c=='?');
00100
00101 prompt=old_prompt;
00102 quietflag=old_quiet;
00103
00104 switch (c) {
00105 case 'v':
00106 case 'V':
00107 verbose=TRUE;
00108 break;
00109 case 'q':
00110 case 'Q':
00111 case EOF:
00112 if (c==EOF) printf("\n");
00113 exit_life(FALSE);
00114 break;
00115 case 'a':
00116 case 'A':
00117 abort_life(FALSE);
00118 show_count();
00119 break;
00120 case 'c':
00121 case 'C':
00122 trace=FALSE;
00123 stepflag=FALSE;
00124 break;
00125 case 't':
00126 case 'T':
00127 trace=TRUE;
00128 stepflag=FALSE;
00129 break;
00130 case 's':
00131 case 'S':
00132 case EOLN:
00133 trace=TRUE;
00134 stepflag=TRUE;
00135 break;
00136 case '0': case '1': case '2': case '3': case '4':
00137 case '5': case '6': case '7': case '8': case '9':
00138 trace=TRUE;
00139 stepflag=TRUE;
00140 if (count>0) {
00141 stepcount=count;
00142 stepflag=FALSE;
00143 }
00144 break;
00145 default:
00146 goto StartAgain;
00147 }
00148 input_state=old_state;
00149 restore_state(input_state);
00150 }