1 /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */ 2 char id_libF77[] = "@(#)main.c 2.14 08/08/83"; 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 {"Illegal ", 1}, /* SIGILL */ 45 {"Trace Trap", 1}, /* SIGTRAP */ 46 {"IOT Trap", 1}, /* SIGIOT */ 47 {"EMT Trap", 1}, /* SIGEMT */ 48 {"Arithmetic Exception", 1}, /* SIGFPE */ 49 { 0, 0}, /* SIGKILL */ 50 {"Bus error", 1}, /* SIGBUS */ 51 {"Segmentation violation", 1}, /* SIGSEGV */ 52 {"Sys arg", 1}, /* SIGSYS */ 53 {"Open pipe", 0}, /* SIGPIPE */ 54 {"Alarm", 0}, /* SIGALRM */ 55 {"Terminated", 0}, /* SIGTERM */ 56 {"Sig 16", 0}, /* unassigned */ 57 }; 58 59 struct action act_fpe[] = { 60 {"Integer overflow", 1}, 61 {"Integer divide by 0", 1}, 62 {"Floating point overflow trap", 1}, 63 {"Floating divide by zero trap", 1}, 64 {"Floating point underflow trap", 1}, 65 {"Decimal overflow", 1}, 66 {"Subscript range", 1}, 67 {"Floating point overflow", 0}, 68 {"Floating divide by zero", 0}, 69 {"Floating point underflow", 0}, 70 }; 71 72 struct action act_ill[] = { 73 {"addr mode", 1}, 74 {"instruction", 1}, 75 {"operand", 0}, 76 }; 77 78 #if vax 79 sigdie(s, t, sc) 80 int s; int t; struct sigcontext *sc; 81 82 #else pdp11 83 sigdie(s, t, pc) 84 int s; int t; long pc; 85 86 #endif 87 { 88 extern unit units[]; 89 register struct action *act = &sig_act[s-1]; 90 /* print error message, then flush buffers */ 91 92 if (act->mesg) 93 { 94 fprintf(units[STDERR].ufd, "*** %s", act->mesg); 95 if (s == SIGFPE) 96 { 97 if (t >= 1 && t <= 10) 98 fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); 99 else 100 fprintf(units[STDERR].ufd, ": Type=%d?", t); 101 } 102 else if (s == SIGILL) 103 { 104 if (t == 4) t = 2; /* 4.0bsd botch */ 105 if (t >= 0 && t <= 2) 106 fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); 107 else 108 fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); 109 } 110 putc('\n', units[STDERR].ufd); 111 } 112 f_exit(); 113 _cleanup(); 114 115 if(act->core) 116 { 117 /* now get a core */ 118 #if vax 119 signal(SIGILL, SIG_DFL); 120 sigsetmask(0); 121 #else pdp11 122 signal(SIGIOT, SIG_DFL); 123 #endif 124 abort(); 125 } 126 exit(s); 127 } 128