1 /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */ 2 char id_libF77[] = "@(#)main.c 2.11 10/30/82"; 3 4 #include <stdio.h> 5 #include <signal.h> 6 #include "../libI77/fiodefs.h" 7 8 int xargc; 9 char **xargv; 10 11 main(argc, argv, arge) 12 int argc; 13 char **argv; 14 char **arge; 15 { 16 int sigdie(); 17 long int (*sigf)(); 18 int signum; 19 20 xargc = argc; 21 xargv = argv; 22 23 for (signum=1; signum<=16; signum++) 24 { 25 if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf); 26 } 27 28 #ifdef pdp11 29 ldfps(01200); /* detect overflow as an exception */ 30 #endif 31 32 f_init(); 33 MAIN__(); 34 f_exit(); 35 } 36 37 struct action { 38 char *mesg; 39 int core; 40 } sig_act[16] = { 41 {"Hangup", 0}, /* SIGHUP */ 42 {"Interrupt!", 0}, /* SIGINT */ 43 {"Quit!", 1}, /* SIGQUIT */ 44 #ifdef UCBVAX 45 {"Illegal ", 1}, /* SIGILL */ 46 #else UCBVAX 47 {"Illegal instruction", 1}, /* SIGILL */ 48 #endif UCBVAX 49 {"Trace Trap", 1}, /* SIGTRAP */ 50 {"IOT Trap", 1}, /* SIGIOT */ 51 {"EMT Trap", 1}, /* SIGEMT */ 52 #ifdef UCBVAX 53 {"Arithmetic Exception", 1}, /* SIGFPE */ 54 #else UCBVAX 55 {"Floating Point Exception", 1},/* SIGFPE */ 56 #endif UCBVAX 57 { 0, 0}, /* SIGKILL */ 58 {"Bus error", 1}, /* SIGBUS */ 59 {"Segmentation violation", 1}, /* SIGSEGV */ 60 {"Sys arg", 1}, /* SIGSYS */ 61 {"Open pipe", 0}, /* SIGPIPE */ 62 {"Alarm", 0}, /* SIGALRM */ 63 {"Terminated", 0}, /* SIGTERM */ 64 {"Sig 16", 0}, /* unassigned */ 65 }; 66 67 #ifdef UCBVAX 68 struct action act_fpe[] = { 69 {"Integer overflow", 1}, 70 {"Integer divide by 0", 1}, 71 {"Floating point overflow", 1}, 72 {"Floating divide by zero", 1}, 73 {"Floating point underflow", 1}, 74 {"Decimal overflow", 1}, 75 {"Subscript range", 1}, 76 {"Floating point overflow", 0}, 77 {"Floating divide by zero", 0}, 78 {"Floating point underflow", 0}, 79 }; 80 81 struct action act_ill[] = { 82 {"addr mode", 1}, 83 {"instruction", 1}, 84 {"operand", 0}, 85 }; 86 #endif UCBVAX 87 88 sigdie(s, t, pc) 89 int s; int t; long pc; 90 { 91 extern unit units[]; 92 register struct action *act = &sig_act[s-1]; 93 /* print error message, then flush buffers */ 94 95 if (act->mesg) 96 { 97 #ifdef UCBVAX 98 fprintf(units[STDERR].ufd, "*** %s", act->mesg); 99 if (s == SIGFPE) 100 { 101 if (t >= 1 && t <= 10) 102 fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); 103 else 104 fprintf(units[STDERR].ufd, ": Type=%d?", t); 105 } 106 else if (s == SIGILL) 107 { 108 if (t == 4) t = 2; /* 4.0bsd botch */ 109 if (t >= 0 && t <= 2) 110 fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); 111 else 112 fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); 113 } 114 putc('\n', units[STDERR].ufd); 115 #else UCBVAX 116 fprintf(units[STDERR].ufd, "*** %s\n", act->mesg); 117 #endif UCBVAX 118 } 119 f_exit(); 120 _cleanup(); 121 122 if(act->core) 123 { 124 /* now get a core */ 125 #if vax 126 signal(SIGILL, SIG_DFL); 127 #else vax 128 signal(SIGIOT, SIG_DFL); 129 #endif vax 130 abort(); 131 } 132 exit(s); 133 } 134