Commit | Line | Data |
---|---|---|
547779a8 WH |
1 | /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */ |
2 | ||
3 | #include "stdio.h" | |
4 | #include "signal.h" | |
5 | ||
6 | #ifndef SIGIOT | |
7 | #define SIGIOT SIGABRT | |
8 | #endif | |
9 | ||
10 | #ifndef KR_headers | |
11 | #include "stdlib.h" | |
12 | #endif | |
13 | #ifdef __cplusplus | |
14 | extern "C" { | |
15 | #endif | |
16 | ||
17 | #ifdef NO__STDC | |
18 | #define ONEXIT onexit | |
19 | extern void f_exit(); | |
20 | #else | |
21 | #ifndef KR_headers | |
22 | extern void f_exit(void); | |
23 | #ifndef NO_ONEXIT | |
24 | #define ONEXIT atexit | |
25 | extern int atexit(void (*)(void)); | |
26 | #endif | |
27 | #else | |
28 | #ifndef NO_ONEXIT | |
29 | #define ONEXIT onexit | |
30 | extern void f_exit(); | |
31 | #endif | |
32 | #endif | |
33 | #endif | |
34 | ||
35 | #ifdef KR_headers | |
36 | extern void f_init(), sig_die(); | |
37 | extern int MAIN__(); | |
38 | #define Int /* int */ | |
39 | #else | |
40 | extern void f_init(void), sig_die(char*, int); | |
41 | extern int MAIN__(void); | |
42 | #define Int int | |
43 | #endif | |
44 | ||
45 | static void sigfdie(Int n) | |
46 | { | |
47 | sig_die("Floating Exception", 1); | |
48 | } | |
49 | ||
50 | ||
51 | static void sigidie(Int n) | |
52 | { | |
53 | sig_die("IOT Trap", 1); | |
54 | } | |
55 | ||
56 | #ifdef SIGQUIT | |
57 | static void sigqdie(Int n) | |
58 | { | |
59 | sig_die("Quit signal", 1); | |
60 | } | |
61 | #endif | |
62 | ||
63 | ||
64 | static void sigindie(Int n) | |
65 | { | |
66 | sig_die("Interrupt", 0); | |
67 | } | |
68 | ||
69 | static void sigtdie(Int n) | |
70 | { | |
71 | sig_die("Killed", 0); | |
72 | } | |
73 | ||
74 | #ifdef SIGTRAP | |
75 | static void sigtrdie(Int n) | |
76 | { | |
77 | sig_die("Trace trap", 1); | |
78 | } | |
79 | #endif | |
80 | ||
81 | ||
82 | int xargc; | |
83 | char **xargv; | |
84 | ||
85 | #ifdef KR_headers | |
86 | main(argc, argv) int argc; char **argv; | |
87 | #else | |
88 | main(int argc, char **argv) | |
89 | #endif | |
90 | { | |
91 | xargc = argc; | |
92 | xargv = argv; | |
93 | signal(SIGFPE, sigfdie); /* ignore underflow, enable overflow */ | |
94 | signal(SIGIOT, sigidie); | |
95 | #ifdef SIGTRAP | |
96 | signal(SIGTRAP, sigtrdie); | |
97 | #endif | |
98 | #ifdef SIGQUIT | |
99 | if(signal(SIGQUIT,sigqdie) == SIG_IGN) | |
100 | signal(SIGQUIT, SIG_IGN); | |
101 | #endif | |
102 | if(signal(SIGINT, sigindie) == SIG_IGN) | |
103 | signal(SIGINT, SIG_IGN); | |
104 | signal(SIGTERM,sigtdie); | |
105 | ||
106 | #ifdef pdp11 | |
107 | ldfps(01200); /* detect overflow as an exception */ | |
108 | #endif | |
109 | ||
110 | f_init(); | |
111 | #ifndef NO_ONEXIT | |
112 | ONEXIT(f_exit); | |
113 | #endif | |
114 | MAIN__(); | |
115 | #ifdef NO_ONEXIT | |
116 | f_exit(); | |
117 | #endif | |
118 | exit(0); /* exit(0) rather than return(0) to bypass Cray bug */ | |
119 | return 0; /* For compilers that complain of missing return values; */ | |
120 | /* others will complain that this is unreachable code. */ | |
121 | } | |
122 | #ifdef __cplusplus | |
123 | } | |
124 | #endif |