corrections by Bob Corbett. DLW
[unix-history] / usr / src / usr.bin / f77 / libF77 / main.c
CommitLineData
dd27c76e 1/* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */
046698fa 2char id_libF77[] = "@(#)main.c 2.11 %G%";
dd27c76e
DW
3
4#include <stdio.h>
5#include <signal.h>
d2397273 6#include "../libI77/fiodefs.h"
dd27c76e
DW
7
8int xargc;
9char **xargv;
10
11main(argc, argv, arge)
12int argc;
13char **argv;
14char **arge;
15{
be7a6737 16int sigdie();
dd27c76e 17long int (*sigf)();
66aca6b3 18int signum;
dd27c76e
DW
19
20xargc = argc;
21xargv = argv;
66aca6b3
DW
22
23for (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
32f_init();
33MAIN__();
34f_exit();
35}
36
be7a6737
DW
37struct 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 */
046698fa 44#ifdef UCBVAX
f81417e8 45 {"Illegal ", 1}, /* SIGILL */
046698fa 46#else UCBVAX
be7a6737 47 {"Illegal instruction", 1}, /* SIGILL */
046698fa 48#endif UCBVAX
66aca6b3 49 {"Trace Trap", 1}, /* SIGTRAP */
be7a6737 50 {"IOT Trap", 1}, /* SIGIOT */
e0eb2f2c 51 {"EMT Trap", 1}, /* SIGEMT */
046698fa 52#ifdef UCBVAX
eb5713ad 53 {"Arithmetic Exception", 1}, /* SIGFPE */
046698fa 54#else UCBVAX
e0eb2f2c 55 {"Floating Point Exception", 1},/* SIGFPE */
046698fa 56#endif UCBVAX
be7a6737
DW
57 { 0, 0}, /* SIGKILL */
58 {"Bus error", 1}, /* SIGBUS */
59 {"Segmentation violation", 1}, /* SIGSEGV */
66aca6b3
DW
60 {"Sys arg", 1}, /* SIGSYS */
61 {"Open pipe", 0}, /* SIGPIPE */
62 {"Alarm", 0}, /* SIGALRM */
be7a6737 63 {"Terminated", 0}, /* SIGTERM */
66aca6b3 64 {"Sig 16", 0}, /* unassigned */
be7a6737
DW
65};
66
046698fa 67#ifdef UCBVAX
eb5713ad
DW
68struct 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};
f81417e8
DW
80
81struct action act_ill[] = {
82 {"addr mode", 1},
83 {"instruction", 1},
84 {"operand", 0},
85};
046698fa 86#endif UCBVAX
be7a6737 87
eb5713ad
DW
88sigdie(s, t, pc)
89int s; int t; long pc;
dd27c76e 90{
d2397273 91extern unit units[];
be7a6737 92register struct action *act = &sig_act[s-1];
2913b66e
DW
93/* print error message, then flush buffers */
94
eb5713ad
DW
95if (act->mesg)
96 {
046698fa 97#ifdef UCBVAX
511b0121 98 fprintf(units[STDERR].ufd, "*** %s", act->mesg);
eb5713ad 99 if (s == SIGFPE)
66aca6b3
DW
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)
f81417e8
DW
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 }
66aca6b3 114 putc('\n', units[STDERR].ufd);
046698fa 115#else UCBVAX
511b0121 116 fprintf(units[STDERR].ufd, "*** %s\n", act->mesg);
046698fa 117#endif UCBVAX
eb5713ad 118 }
2913b66e 119f_exit();
dd27c76e
DW
120_cleanup();
121
be7a6737 122if(act->core)
dd27c76e
DW
123 {
124 /* now get a core */
046698fa 125#if vax
eb5713ad 126 signal(SIGILL, SIG_DFL);
046698fa 127#else vax
be7a6737 128 signal(SIGIOT, SIG_DFL);
046698fa 129#endif vax
dd27c76e
DW
130 abort();
131 }
be7a6737 132exit(s);
dd27c76e 133}