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